Skip to content

Commit 9b72e31

Browse files
author
whichtwix
committed
handle multiple download urls, errors show now
1 parent db7a8d8 commit 9b72e31

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

src/Downloader.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
<PublishSingleFile>true</PublishSingleFile>
1212
<PublishTrimmed>true</PublishTrimmed>
1313
</PropertyGroup>
14+
15+
<PropertyGroup>
16+
<NoWarn>IL2026</NoWarn>
17+
</PropertyGroup>
1418
</Project>

src/code/Downloader.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@ public static async Task Main(string[] args)
2323
if (File.Exists(path + "\\Among Us.exe")) acceptedpath = true;
2424
}
2525
Console.WriteLine("Downloading town of us");
26-
await Handlezip(path);
26+
await Handlezip(path);
2727
Movefiles(path, Touversion);
28-
Console.WriteLine("Done!");
2928
}
30-
public static async Task Handlezip(string path)
29+
public static async Task Handlezip(string path)
3130
{
3231
try
3332
{
3433
client.DefaultRequestHeaders.Add("User-Agent", "TownOfUs Downloader");
3534
Json assets = await client.GetFromJsonAsync<Json>(url);
36-
string linktozip = assets.Assets[0].Browser_download_url;
35+
Assets linktozip = assets.Assets.Find(link => link.Browser_download_url.EndsWith("zip"));
3736
Touversion = assets.Name;
38-
var connection = await client.GetAsync(linktozip);
39-
37+
var connection = await client.GetAsync(linktozip.Browser_download_url);
38+
4039
string zippath = $@"{path}" + "\\tou.zip";
4140
var zip = new FileInfo(zippath);
4241
if (connection.IsSuccessStatusCode)
@@ -57,12 +56,14 @@ public static async Task Handlezip(string path)
5756
{
5857
Console.WriteLine("Error in Handlezip()");
5958
Console.WriteLine(e);
59+
Console.ReadLine();
60+
6061
}
6162
}
6263
public static void Movefiles(string path, string version)
6364
{
64-
try
65-
{
65+
try
66+
{
6667
if (Directory.Exists(path + "\\BepInEx")) Directory.Delete(path + "\\BepInEx", true);
6768
if (Directory.Exists(path + "\\mono")) Directory.Delete(path + "\\mono", true);
6869
string subfolder = $@"{path}" + $"\\ToU {version}";
@@ -79,12 +80,13 @@ public static void Movefiles(string path, string version)
7980
}
8081

8182
Directory.Delete(subfolder);
82-
}
83-
catch (Exception e)
84-
{
83+
}
84+
catch (Exception e)
85+
{
8586
Console.WriteLine("Error in movefiles()");
8687
Console.WriteLine(e);
87-
}
88+
Console.ReadLine();
89+
}
8890
}
8991
}
9092
}

src/code/Json.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace Modinstaller
44
{
55
public class Json
66
{
7-
public string Name {get; set;}
8-
public List<Assets> Assets {get; set;}
7+
public string Name { get; set; }
8+
public List<Assets> Assets { get; set; }
99
}
1010
public class Assets
1111
{
12-
public string Browser_download_url {get; set;}
12+
public string Browser_download_url { get; set; }
1313
}
1414
}

0 commit comments

Comments
 (0)