Skip to content

Commit 6f391ed

Browse files
committed
ExternalPointerData pulled from git again but without writing file - uses HTTPClient instead of deprecated webclient
1 parent a0b0295 commit 6f391ed

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

HCMExternal/Services/DataPointersService/DataPointersService.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
using Serilog;
22
using System;
33
using System.Collections.Generic;
4+
using System.Collections.Specialized;
45
using System.IO;
56
using System.Linq;
7+
using System.Net.Http;
68
using System.Reflection;
9+
using System.Security.Policy;
10+
using System.Text;
11+
using System.Threading.Tasks;
12+
using System.Windows.Media.Animation;
713
using System.Xml.Linq;
814

915
namespace HCMExternal.Services.DataPointersServiceNS
@@ -87,45 +93,36 @@ public void LoadPointerDataFromSource(out string failedReads)
8793
string localPointerDataPath = Directory.GetCurrentDirectory() + "\\ExternalPointerData.xml";
8894
failedReads = "";
8995

90-
// Debug mode to use local data file
96+
9197
#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+
}
95105

96106
#else
97-
// Old code use to try downloading the file from the git but Anti-Viruses don't like that
98-
/*
107+
99108
try
100109
{
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;
108112
}
109-
catch
113+
catch (HttpRequestException e)
110114
{
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)
114119
{
115-
Log.Information("Grabbing local xml data");
116-
xml = File.ReadAllText(localPointerDataPath);
120+
StreamReader reader = new StreamReader(stream);
121+
xml = reader.ReadToEnd();
117122
}
118123
}
119-
*/
120124

121125

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-
}
129126

130127
#endif
131128

0 commit comments

Comments
 (0)