Skip to content

Commit 0cc44a6

Browse files
committed
Migrate to Azure (Thanks, Leo!)
1 parent 9f7623f commit 0cc44a6

7 files changed

Lines changed: 143 additions & 122 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "SVG"]
55
path = SVG
66
url = https://github.com/vvvv/SVG.git
7+
[submodule "Newtonsoft.Json"]
8+
path = Newtonsoft.Json
9+
url = https://github.com/JamesNK/Newtonsoft.Json.git

Content/background.png

-3.88 KB
Loading

Everest.Installer.csproj

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
<IsWebBootstrapper>false</IsWebBootstrapper>
2929
<UseApplicationTrust>false</UseApplicationTrust>
3030
<BootstrapperEnabled>true</BootstrapperEnabled>
31+
<NewtonsoftConstants>NET20;HAVE_LINQ;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CAS;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_DB_NULL_TYPE_CODE;HAVE_EMPTY_TYPES;HAVE_FAST_REVERSE;HAVE_FULL_REFLECTION;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_MEMORY_BARRIER;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_REFLECTION_EMIT;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;</NewtonsoftConstants>
3132
</PropertyGroup>
3233
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3334
<PlatformTarget>AnyCPU</PlatformTarget>
3435
<DebugSymbols>true</DebugSymbols>
3536
<DebugType>full</DebugType>
3637
<Optimize>false</Optimize>
3738
<OutputPath>bin\Debug\</OutputPath>
38-
<DefineConstants>TRACE;DEBUG;MONOMOD_NO_ENTRY</DefineConstants>
39+
<DefineConstants>TRACE;DEBUG;MONOMOD_NO_ENTRY;$(NewtonsoftConstants)</DefineConstants>
3940
<ErrorReport>prompt</ErrorReport>
4041
<WarningLevel>4</WarningLevel>
4142
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -46,11 +47,12 @@
4647
<DebugType>pdbonly</DebugType>
4748
<Optimize>true</Optimize>
4849
<OutputPath>bin\Release\</OutputPath>
49-
<DefineConstants>TRACE;MONOMOD_NO_ENTRY</DefineConstants>
50+
<DefineConstants>TRACE;MONOMOD_NO_ENTRY;$(NewtonsoftConstants)</DefineConstants>
5051
<ErrorReport>prompt</ErrorReport>
5152
<WarningLevel>4</WarningLevel>
5253
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5354
<Prefer32Bit>false</Prefer32Bit>
55+
<LangVersion>7.3</LangVersion>
5456
</PropertyGroup>
5557
<PropertyGroup>
5658
<StartupObject>MonoMod.Installer.Program</StartupObject>
@@ -60,6 +62,7 @@
6062
</PropertyGroup>
6163
<ItemGroup>
6264
<Reference Include="System" />
65+
<Reference Include="System.Data" />
6366
<Reference Include="System.Drawing" />
6467
<Reference Include="System.IO.Compression" />
6568
<Reference Include="System.Web" />
@@ -522,14 +525,21 @@
522525
<Compile Include="SVG\Source\Transforms\SvgTranslate.cs" />
523526
<Compile Include="SVG\Source\Web\SvgHandler.cs" />
524527
</ItemGroup>
528+
<ItemGroup>
529+
<!-- Newtonsoft.Json -->
530+
<Compile Include="Newtonsoft.Json\Src\Newtonsoft.Json\**\*.cs" />
531+
<Compile Remove="Newtonsoft.Json\Src\Newtonsoft.Json\Properties\*.cs" />
532+
</ItemGroup>
525533
<ItemGroup>
526534
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
527535
<Visible>False</Visible>
528536
<ProductName>.NET Framework 3.5 SP1</ProductName>
529537
<Install>true</Install>
530538
</BootstrapperPackage>
531539
</ItemGroup>
532-
<ItemGroup />
540+
<ItemGroup>
541+
<WCFMetadata Include="Connected Services\" />
542+
</ItemGroup>
533543
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
534544
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
535545
Other similar extension points exist, see Microsoft.Common.targets.

Newtonsoft.Json

Submodule Newtonsoft.Json added at b371ab1

Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
// You can specify all the values or you can default the Build and Revision Numbers
3535
// by using the '*' as shown below:
3636
// [assembly: AssemblyVersion("1.0.*")]
37-
[assembly: AssemblyVersion("18.06.0.*")]
37+
[assembly: AssemblyVersion("19.03.0.*")]
3838
[assembly: AssemblyFileVersion("1.0.0.0")]

src/GameModder.cs

Lines changed: 95 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,27 @@ private void _DownloadAndUnpack() {
184184
int i = 0;
185185
foreach (ZipArchiveEntry entry in zip.Entries) {
186186
OnProgress?.Invoke(Status.Unpack, (i + 1) / (float) zip.Entries.Count);
187-
string to = Path.Combine(root, entry.Name);
188-
string toParent = Path.GetDirectoryName(to);
189-
Console.WriteLine($"{entry.Name} -> {to}");
190-
if (!Directory.Exists(toParent))
191-
Directory.CreateDirectory(toParent);
192-
if (File.Exists(to))
193-
File.Delete(to);
194-
using (FileStream fs = File.OpenWrite(to))
195-
using (Stream compressed = entry.Open())
196-
compressed.CopyTo(fs);
187+
188+
if (!entry.Name.EndsWith("/") && entry.Length != 0) {
189+
string entryName = entry.Name;
190+
if (entryName.StartsWith("main/"))
191+
entryName = entryName.Substring(5);
192+
193+
string to = Path.Combine(root, entryName);
194+
string toParent = Path.GetDirectoryName(to);
195+
Console.WriteLine($"{entry.Name} -> {to}");
196+
197+
if (!Directory.Exists(toParent))
198+
Directory.CreateDirectory(toParent);
199+
200+
if (File.Exists(to))
201+
File.Delete(to);
202+
203+
using (FileStream fs = File.OpenWrite(to))
204+
using (Stream compressed = entry.Open())
205+
compressed.CopyTo(fs);
206+
}
207+
197208
i++;
198209
}
199210
}
@@ -274,77 +285,91 @@ private byte[] _Download(string url) {
274285

275286
// The following blob of code comes from the old ETGMod.Installer.
276287

277-
byte[] data = null;
278-
279288
Console.WriteLine($"Downloading {url}");
280289

281-
DateTime timeStart = DateTime.Now;
282-
using (WebClient wc = new WebClient()) {
283-
using (Stream s = wc.OpenRead(url)) {
284-
long sLength;
285-
if (s.CanSeek) {
286-
// Mono
287-
sLength = s.Length;
288-
} else {
289-
// .NET
290-
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
291-
request.UserAgent = $"MonoMod.Installer {Assembly.GetEntryAssembly().GetName().Version}";
292-
request.Method = "HEAD";
293-
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
294-
sLength = response.ContentLength;
290+
using (MemoryStream copy = new MemoryStream()) {
291+
DateTime timeStart = DateTime.Now;
292+
using (WebClient wc = new WebClient()) {
293+
using (Stream input = wc.OpenRead(url)) {
294+
long length;
295+
if (input.CanSeek) {
296+
// Mono
297+
length = input.Length;
298+
} else {
299+
// .NET
300+
try {
301+
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
302+
request.UserAgent = $"MonoMod.Installer {Assembly.GetEntryAssembly().GetName().Version}";
303+
request.Method = "HEAD";
304+
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
305+
length = response.ContentLength;
306+
}
307+
} catch (Exception) {
308+
length = 0;
309+
}
295310
}
296-
}
297-
Console.WriteLine($"{sLength} bytes");
298-
data = new byte[sLength];
299-
300-
long progressSize = sLength;
301-
int progressScale = 1;
302-
while (progressSize > int.MaxValue) {
303-
progressScale *= 10;
304-
progressSize = sLength / progressScale;
305-
}
311+
Console.WriteLine($"{length} bytes");
306312

307-
OnProgress?.Invoke(Status.Download, 0f);
308-
309-
DateTime timeLast = timeStart;
310-
311-
int read;
312-
int readForSpeed = 0;
313-
int pos = 0;
314-
int speed = 0;
315-
TimeSpan td;
316-
while (pos < data.Length) {
317-
read = s.Read(data, pos, Math.Min(2048, data.Length - pos));
318-
pos += read;
319-
readForSpeed += read;
320-
321-
td = (DateTime.Now - timeLast);
322-
if (td.TotalMilliseconds > 100) {
323-
speed = (int) ((readForSpeed / 1024D) / td.TotalSeconds);
324-
readForSpeed = 0;
325-
timeLast = DateTime.Now;
313+
long progressSize = length;
314+
int progressScale = 1;
315+
while (progressSize > int.MaxValue) {
316+
progressScale *= 10;
317+
progressSize = length / progressScale;
326318
}
327319

328-
OnProgress?.Invoke(Status.Download, (float) ((pos / progressScale) / (double) progressSize));
329-
LogWriter.OnWriteLine?.Invoke(
330-
"Downloading - " +
331-
(int) (Math.Round(100D * ((pos / progressScale) / (double) progressSize))) + "%, " +
332-
speed + " KiB/s"
333-
);
334-
}
320+
OnProgress?.Invoke(Status.Download, 0f);
321+
322+
DateTime timeLast = timeStart;
323+
324+
byte[] buffer = new byte[4096];
325+
DateTime timeLastSpeed = timeStart;
326+
int read = 1;
327+
int readForSpeed = 0;
328+
int pos = 0;
329+
int speed = 0;
330+
int count = 0;
331+
TimeSpan td;
332+
while (read > 0) {
333+
count = length > 0 ? (int) Math.Min(buffer.Length, length - pos) : buffer.Length;
334+
read = input.Read(buffer, 0, count);
335+
copy.Write(buffer, 0, read);
336+
pos += read;
337+
readForSpeed += read;
338+
339+
td = (DateTime.Now - timeLast);
340+
if (td.TotalMilliseconds > 100) {
341+
speed = (int) ((readForSpeed / 1024D) / td.TotalSeconds);
342+
readForSpeed = 0;
343+
timeLast = DateTime.Now;
344+
}
345+
346+
if (length > 0) {
347+
OnProgress?.Invoke(Status.Download, (float) ((pos / progressScale) / (double) progressSize));
348+
LogWriter.OnWriteLine?.Invoke(
349+
$"Downloading: {((int) Math.Floor(100D * (pos / (double) length)))}% @ {speed} KiB/s"
350+
);
351+
} else {
352+
OnProgress?.Invoke(Status.Download, 1f);
353+
LogWriter.OnWriteLine?.Invoke(
354+
$"Downloading: {((int) Math.Floor(pos / 1000D))}KiB @ {speed} KiB/s"
355+
);
356+
}
357+
}
335358

359+
}
336360
}
337-
}
338361

339-
OnProgress?.Invoke(Status.Download, 1f);
362+
OnProgress?.Invoke(Status.Download, 1f);
340363

341-
string logSize = (data.Length / 1024D).ToString(CultureInfo.InvariantCulture);
342-
logSize = logSize.Substring(0, Math.Min(logSize.IndexOf('.') + 3, logSize.Length));
343-
string logTime = (DateTime.Now - timeStart).TotalSeconds.ToString(CultureInfo.InvariantCulture);
344-
logTime = logTime.Substring(0, Math.Min(logTime.IndexOf('.') + 3, logTime.Length));
345-
Console.WriteLine($"Downloaded {logSize} KiB in {logTime} seconds.");
364+
byte[] data = copy.ToArray();
365+
string logSize = (data.Length / 1024D).ToString(CultureInfo.InvariantCulture);
366+
logSize = logSize.Substring(0, Math.Min(logSize.IndexOf('.') + 3, logSize.Length));
367+
string logTime = (DateTime.Now - timeStart).TotalSeconds.ToString(CultureInfo.InvariantCulture);
368+
logTime = logTime.Substring(0, Math.Min(logTime.IndexOf('.') + 3, logTime.Length));
369+
Console.WriteLine($"Downloaded {logSize} KiB in {logTime} seconds.");
346370

347-
return data;
371+
return data;
372+
}
348373
}
349374

350375
public enum Status {

src/Infos/EverestInfo.cs

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Text.RegularExpressions;
1313
using System.Threading;
1414
using System.IO.Compression;
15+
using Newtonsoft.Json.Linq;
1516

1617
namespace MonoMod.Installer.Everest {
1718
public partial class EverestInfo : GameModInfo {
@@ -83,18 +84,39 @@ public override Dictionary<string, string> GameIDs {
8384

8485
public override List<ModVersion> ModVersions {
8586
get {
86-
string data = null;
87-
using (WebClient wc = new WebClient())
88-
data = wc.DownloadString("https://ams3.digitaloceanspaces.com/lollyde/everest-travis/builds_index.txt");
87+
const int offset = 700;
88+
const string artifactFormat = "https://dev.azure.com/EverestAPI/Everest/_apis/build/builds/{0}/artifacts?artifactName=main&api-version=5.0&%24format=zip";
89+
const string index = "https://dev.azure.com/EverestAPI/Everest/_apis/build/builds?api-version=5.0";
8990

90-
string[] lines = data.Split('\n');
91+
string dataRaw = null;
92+
using (WebClient wc = new WebClient())
93+
dataRaw = wc.DownloadString(index);
9194

9295
List<ModVersion> versions = new List<ModVersion>();
93-
for (int i = 0; i < lines.Length; i++) {
94-
string line = lines[i].Trim('\r', '\n').Trim();
95-
if (line.Length == 0 || line.StartsWith("#"))
96+
97+
JObject root = JObject.Parse(dataRaw);
98+
JArray list = root["value"] as JArray;
99+
foreach (JObject build in list) {
100+
if (build["status"].ToObject<string>() != "completed" || build["result"].ToObject<string>() != "succeeded")
101+
continue;
102+
103+
string reason = build["reason"].ToObject<string>();
104+
if (reason != "manual" && reason != "individualCI")
96105
continue;
97-
versions.Add(ParseLine(line, "https://ams3.digitaloceanspaces.com"));
106+
107+
int id = build["id"].ToObject<int>();
108+
string branch = build["sourceBranch"].ToObject<string>().Replace("refs/heads/", "");
109+
string url = string.Format(artifactFormat, id);
110+
111+
string name = (id + offset).ToString();
112+
if (branch != "master")
113+
name = $"{name} ({branch})";
114+
115+
versions.Add(new ModVersion() {
116+
Name = name,
117+
URL = url,
118+
Version = new Version(1, 0, id)
119+
});
98120
}
99121

100122
return versions;
@@ -208,46 +230,6 @@ public override string CurrentExecutablePath {
208230
}
209231
}
210232

211-
// Copy-paste of Everest's updater version parser.
212-
private static ModVersion ParseLine(string line, string root) {
213-
string[] split = line.Split(' ');
214-
if (split.Length < 2 || split.Length > 3)
215-
throw new Exception("Version list format incompatible!");
216-
217-
string url = split[0];
218-
if (!url.StartsWith("http://") && !url.StartsWith("https://"))
219-
// The index contains a relative path.
220-
url = root + url;
221-
222-
if (!url.EndsWith("/" + split[1]))
223-
throw new Exception("URL (first column) must end in filename (second column)!");
224-
225-
string name = split[1];
226-
string branch = "master";
227-
228-
if (name.EndsWith(".zip"))
229-
name = name.Substring(0, name.Length - 4);
230-
231-
if (name.StartsWith("build-"))
232-
name = name.Substring(6);
233-
234-
int indexOfBranch = name.IndexOf('-');
235-
if (indexOfBranch != -1) {
236-
branch = name.Substring(indexOfBranch + 1);
237-
name = name.Substring(0, indexOfBranch);
238-
}
239-
240-
Version version;
241-
if (split.Length == 3)
242-
version = new Version(split[2]);
243-
else
244-
version = new Version(0, 0, int.Parse(Regex.Match(split[1], @"\d+").Value));
245-
246-
if (branch != "master")
247-
name = $"{name} ({branch})";
248-
return new ModVersion { Name = name, URL = url, Version = version };
249-
}
250-
251233
public override bool VerifyMod(ZipArchive zip, out string name) {
252234
name = null;
253235
bool valid = false;

0 commit comments

Comments
 (0)