|
1 | 1 | using Serilog; |
2 | 2 | using System; |
3 | 3 | using System.Collections.Generic; |
| 4 | +using System.Collections.Specialized; |
4 | 5 | using System.IO; |
5 | 6 | using System.Linq; |
| 7 | +using System.Net.Http; |
6 | 8 | using System.Reflection; |
| 9 | +using System.Security.Policy; |
| 10 | +using System.Text; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using System.Windows.Media.Animation; |
7 | 13 | using System.Xml.Linq; |
8 | 14 |
|
9 | 15 | namespace HCMExternal.Services.DataPointersServiceNS |
@@ -87,45 +93,36 @@ public void LoadPointerDataFromSource(out string failedReads) |
87 | 93 | string localPointerDataPath = Directory.GetCurrentDirectory() + "\\ExternalPointerData.xml"; |
88 | 94 | failedReads = ""; |
89 | 95 |
|
90 | | - // Debug mode to use local data file |
| 96 | + |
91 | 97 | #if HCM_DEBUG |
92 | | - Debug.Assert(File.Exists(localPointerDataPath)); |
93 | | - Log.Information("Grabbing xml data from local dev machine"); |
94 | | - xml = File.ReadAllText(localPointerDataPath); |
| 98 | +// Debug mode to use local data file as embedded resource |
| 99 | + var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HCMExternal.ExternalPointerData.xml"); |
| 100 | + if (stream != null) |
| 101 | + { |
| 102 | + StreamReader reader = new StreamReader(stream); |
| 103 | + xml = reader.ReadToEnd(); |
| 104 | + } |
95 | 105 |
|
96 | 106 | #else |
97 | | - // Old code use to try downloading the file from the git but Anti-Viruses don't like that |
98 | | - /* |
| 107 | + |
99 | 108 | try |
100 | 109 | { |
101 | | - string url = "https://raw.githubusercontent.com/Burnt-o/HaloCheckpointManager/master/HCMExternal/ExternalPointerData.xml"; |
102 | | - System.Net.WebClient client = new System.Net.WebClient(); |
103 | | - xml = client.DownloadString(url); |
104 | | -
|
105 | | - //Write the contents to local PointerData.xml for offline use |
106 | | - if (File.Exists(localPointerDataPath)) File.Delete(localPointerDataPath); |
107 | | - File.WriteAllText(localPointerDataPath, xml); |
| 110 | + var client = new System.Net.Http.HttpClient(); |
| 111 | + xml = client.GetStringAsync("https://raw.githubusercontent.com/Burnt-o/HaloCheckpointManager/master/HCMExternal/ExternalPointerData.xml").Result; |
108 | 112 | } |
109 | | - catch |
| 113 | + catch (HttpRequestException e) |
110 | 114 | { |
111 | | - // Couldn't grab online data, try offline backup |
112 | | - Log.Information("Couldn't find online xml data, trying local backup"); |
113 | | - if (File.Exists(localPointerDataPath)) |
| 115 | + Log.Error("Couldn't resolve github external pointer data, error: " + e.Message); |
| 116 | + // Couldn't grab online data, read offline embedded resource instead |
| 117 | + var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HCMExternal.ExternalPointerData.xml"); |
| 118 | + if (stream != null) |
114 | 119 | { |
115 | | - Log.Information("Grabbing local xml data"); |
116 | | - xml = File.ReadAllText(localPointerDataPath); |
| 120 | + StreamReader reader = new StreamReader(stream); |
| 121 | + xml = reader.ReadToEnd(); |
117 | 122 | } |
118 | 123 | } |
119 | | - */ |
120 | 124 |
|
121 | 125 |
|
122 | | - // New code: load from embedded xml file |
123 | | - var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HCMExternal.ExternalPointerData.xml"); |
124 | | - if (stream != null) |
125 | | - { |
126 | | - StreamReader reader = new StreamReader(stream); |
127 | | - xml = reader.ReadToEnd(); |
128 | | - } |
129 | 126 |
|
130 | 127 | #endif |
131 | 128 |
|
|
0 commit comments