Skip to content

Commit d47f0c5

Browse files
committed
store mods online & simpify file moving
1 parent d5054bd commit d47f0c5

11 files changed

Lines changed: 85 additions & 72 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode
2+
.vs
23
obj/
34
bin/

ModList.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Town of Us": "https://api.github.com/repos/eDonnes124/Town-Of-Us-R/releases/latest",
3+
"The Other Roles": "https://api.github.com/repos/TheOtherRolesAU/TheOtherRoles/releases/latest",
4+
"Town of Host": "https://api.github.com/repos/tukasa0001/TownOfHost/releases/latest",
5+
"Town of Host Enhanced" : "https://github.com/0xDrMoe/TownofHost-Enhanced/releases/latest",
6+
"Project Lotus": "https://api.github.com/repos/ImaMapleTree/Lotus/releases/latest",
7+
"Las Monjas": "https://api.github.com/repos/KiraYamato94/LasMonjas/releases/latest"
8+
}

src/Modinstaller.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFramework>Net6.0</TargetFramework>
44
<Configuration>Release</Configuration>
5-
<Version>3.2.0</Version>
5+
<Version>3.3.0</Version>
66
<DebugType>embedded</DebugType>
77
<LangVersion>latest</LangVersion>
88
<OutputType>Exe</OutputType>

src/Modinstaller.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modinstaller", "Modinstaller.csproj", "{A84817EF-449F-491A-B518-750507F5AF9C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A84817EF-449F-491A-B518-750507F5AF9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A84817EF-449F-491A-B518-750507F5AF9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A84817EF-449F-491A-B518-750507F5AF9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A84817EF-449F-491A-B518-750507F5AF9C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {E9CBD119-0041-4CDE-9887-4F4D0975E12A}
24+
EndGlobalSection
25+
EndGlobal

src/code/Constants.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,15 @@ namespace Modinstaller
88
{
99
public sealed class Constants
1010
{
11-
public static readonly string Jsonpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\\Modinstaller\\InstallPresets.json";
11+
public static readonly string PresetsJson = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\\Modinstaller\\InstallPresets.json";
1212

1313
public static readonly string ErrorLog = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\\Modinstaller\\ErrorLog.txt";
1414

15-
public static readonly JsonSerializerOptions opts = new() { WriteIndented = true };
16-
17-
public static readonly Dictionary<string, string> Mods = new()
18-
{
19-
{"Town of Us", "https://api.github.com/repos/eDonnes124/Town-Of-Us-R/releases/latest"},
20-
21-
{"The Other Roles", "https://api.github.com/repos/TheOtherRolesAU/TheOtherRoles/releases/latest"},
15+
public static readonly string ModsJson = "https://github.com/whichtwix/Modinstaller/raw/Master/ModList.json";
2216

23-
{"Town of Host", "https://api.github.com/repos/tukasa0001/TownOfHost/releases/latest"},
24-
25-
{"Project Lotus", "https://api.github.com/repos/ImaMapleTree/Lotus/releases/latest"},
17+
public static readonly JsonSerializerOptions opts = new() { WriteIndented = true };
2618

27-
{"Las Monjas", "https://api.github.com/repos/KiraYamato94/LasMonjas/releases/latest"},
28-
};
19+
public static Dictionary<string, string> Mods = new();
2920

3021
public static readonly Dictionary<string, Func<Task>> Actions = new()
3122
{

src/code/Fetchapi.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
using System.Net.Http;
2+
using System.Text.Json;
23
using System.Net.Http.Json;
34
using System.Threading.Tasks;
45
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
57

68
namespace Modinstaller
79
{
810
public sealed class GithubApi
911
{
10-
public static async Task<HttpResponseMessage> Fetchlatestrelease(string url, Modversion modversion)
12+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "No sideaffects")]
13+
public static async Task<HttpResponseMessage> Fetchlatestrelease(string url)
1114
{
1215
HttpResponseMessage connection;
1316
ApiJson assets = await Constants.Client.GetFromJsonAsync<ApiJson>(url);
1417
Assets linktozip = assets.Assets.Find(link => link.Browser_download_url.EndsWith("zip"));
15-
modversion.Version = assets.Name;
1618
return connection = await Constants.Client.GetAsync(linktozip.Browser_download_url);
1719
}
1820

19-
public static async Task<HttpResponseMessage> Fetchfromallreleases(string url, Modversion modversion)
21+
public static async Task<HttpResponseMessage> Fetchfromallreleases(string url)
2022
{
2123
HttpResponseMessage connection;
2224
List<ApiJson> data = new();
2325
var jsonstring = Constants.Client.GetAsync(url).Result;
2426
data = await jsonstring.Content.ReadAsAsync<List<ApiJson>>();
2527
ApiJson zip = data.Find(x => x.Assets[0].Browser_download_url.Contains("zip"));
26-
modversion.Version = zip.Name;
2728
System.Console.WriteLine(zip.Assets[0].Browser_download_url);
2829
return connection = await Constants.Client.GetAsync(zip.Assets[0].Browser_download_url);
2930
}
31+
32+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "No sideaffects")]
33+
public static async Task FetchMods()
34+
{
35+
var request = await Constants.Client.GetAsync(Constants.ModsJson);
36+
var text = await request.Content.ReadAsStringAsync();
37+
Constants.Mods = JsonSerializer.Deserialize<Dictionary<string, string>>(text);
38+
}
3039
}
3140
}

src/code/ObjectTemplates.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,4 @@ public sealed class PresetsJson
2222

2323
public string DestinationFolder { get; set; }
2424
}
25-
26-
public sealed class Modversion
27-
{
28-
public string Version { get; set; }
29-
}
3025
}

src/code/Operations.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.Threading.Tasks;
77
using System.Collections.Generic;
8+
using System.Diagnostics.CodeAnalysis;
89

910
namespace Modinstaller
1011
{
@@ -22,7 +23,7 @@ public static async Task InstallByUser()
2223

2324
await ModZip.Install(Basepath, Destinationpath, mod);
2425

25-
if (!File.Exists(Constants.Jsonpath) || !Presetfile.GetPresets().ConvertAll(x => x.Mod).Contains(mod))
26+
if (!File.Exists(Constants.PresetsJson) || !Presetfile.GetPresets().ConvertAll(x => x.Mod).Contains(mod))
2627
{
2728
bool save = AnsiConsole.Confirm("Do you want to save these details as a preset now for future use?");
2829
if (save)
@@ -40,7 +41,7 @@ public static async Task InstallByUser()
4041

4142
public static async Task InstallByJson()
4243
{
43-
if (!File.Exists(Constants.Jsonpath))
44+
if (!File.Exists(Constants.PresetsJson))
4445
{
4546
Console.WriteLine("Presets file does not exist");
4647
return;
@@ -89,9 +90,10 @@ public static async Task AddToJson()
8990
Presetfile.WriteJson(preset);
9091
}
9192

93+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "no sideaffects")]
9294
public static async Task RemoveFromJson()
9395
{
94-
if (!File.Exists(Constants.Jsonpath))
96+
if (!File.Exists(Constants.PresetsJson))
9597
{
9698
Console.WriteLine("Presets file does not exist");
9799
return;
@@ -106,24 +108,24 @@ public static async Task RemoveFromJson()
106108

107109
if (mod != "Cancel" && presets.Count == 1)
108110
{
109-
File.Delete(Constants.Jsonpath);
111+
File.Delete(Constants.PresetsJson);
110112
return;
111113
}
112114

113115
presets = presets.FindAll(x => x.Mod != mod);
114116
string serial = JsonSerializer.Serialize(presets, Constants.opts);
115-
await File.WriteAllTextAsync(Constants.Jsonpath, serial);
117+
await File.WriteAllTextAsync(Constants.PresetsJson, serial);
116118
}
117119

118120
public static async Task ViewPresets()
119121
{
120-
if (!File.Exists(Constants.Jsonpath))
122+
if (!File.Exists(Constants.PresetsJson))
121123
{
122124
Console.WriteLine("Presets file does not exist");
123125
return;
124126
}
125127

126-
Process.Start("notepad.exe", Constants.Jsonpath);
128+
Process.Start("notepad.exe", Constants.PresetsJson);
127129
}
128130
}
129131
}

src/code/Presetsfile.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
using System;
21
using System.IO;
32
using System.Linq;
43
using System.Text.Json;
54
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
66

77
namespace Modinstaller
88
{
99
public sealed class Presetfile
1010
{
11+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
1112
public static List<PresetsJson> GetPresets()
1213
{
13-
string file = File.ReadAllText(Constants.Jsonpath);
14+
string file = File.ReadAllText(Constants.PresetsJson);
1415
return (List<PresetsJson>) JsonSerializer.Deserialize(file, typeof(List<PresetsJson>));
1516
}
1617

18+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
1719
public static async void WriteJson(PresetsJson preset)
1820
{
19-
if (!File.Exists(Constants.Jsonpath))
21+
if (!File.Exists(Constants.PresetsJson))
2022
{
21-
Directory.CreateDirectory(Constants.Jsonpath.Replace("\\InstallPresets.json", string.Empty));
23+
Directory.CreateDirectory(Constants.PresetsJson.Replace("\\InstallPresets.json", string.Empty));
2224
List<PresetsJson> presets = new() { preset };
2325
string Serial = JsonSerializer.Serialize(presets, Constants.opts);
24-
await File.WriteAllTextAsync(Constants.Jsonpath, Serial);
26+
await File.WriteAllTextAsync(Constants.PresetsJson, Serial);
2527
return;
2628
}
2729
var currentfile = GetPresets();
2830
currentfile = currentfile.FindAll(x => x.Mod != preset.Mod);
2931
currentfile.Add(preset);
3032
string serial = JsonSerializer.Serialize(currentfile, Constants.opts);
31-
await File.WriteAllTextAsync(Constants.Jsonpath, serial);
33+
await File.WriteAllTextAsync(Constants.PresetsJson, serial);
3234
}
3335

3436
public static bool ClashingPaths(List<PresetsJson> presets, bool CheckBasefolders)

src/code/ZipHandling.cs

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Net.Http;
45
using System.IO.Compression;
56
using System.Threading.Tasks;
@@ -10,25 +11,21 @@ public sealed class ModZip
1011
{
1112
public static async Task Install(string Basepath, string Destinationpath, string mod)
1213
{
13-
Modversion modversion = new()
14-
{
15-
Version = string.Empty
16-
};
1714
if (Destinationpath != string.Empty)
1815
{
1916
Console.WriteLine($"Downloading {mod} to {Destinationpath}");
20-
await DownloadExtractzip(Basepath, Destinationpath, mod, modversion);
21-
Movefiles(Destinationpath, mod, modversion.Version);
17+
await DownloadExtractzip(Basepath, Destinationpath, mod);
18+
Movefiles(Destinationpath);
2219
return;
2320
}
2421
Console.WriteLine($"Downloading {mod} to {Basepath}");
25-
await DownloadExtractzip(Basepath, mod, modversion);
26-
Movefiles(Basepath, mod, modversion.Version);
22+
await DownloadExtractzip(Basepath, mod);
23+
Movefiles(Basepath);
2724

2825
Console.WriteLine($"installation of {mod} complete");
2926
}
3027

31-
public static async Task DownloadExtractzip(string Basepath, string selectedmod, Modversion modversion)
28+
public static async Task DownloadExtractzip(string Basepath, string selectedmod)
3229
{
3330
try
3431
{
@@ -38,11 +35,11 @@ public static async Task DownloadExtractzip(string Basepath, string selectedmod,
3835
//we have to differentiate due to pre-releases
3936
if (url.Contains("latest"))
4037
{
41-
connection = await GithubApi.Fetchlatestrelease(url, modversion);
38+
connection = await GithubApi.Fetchlatestrelease(url);
4239
}
4340
else
4441
{
45-
connection = await GithubApi.Fetchfromallreleases(url, modversion);
42+
connection = await GithubApi.Fetchfromallreleases(url);
4643
}
4744

4845
string zippath = $"{Basepath}" + "\\mod.zip";
@@ -67,7 +64,7 @@ public static async Task DownloadExtractzip(string Basepath, string selectedmod,
6764
}
6865
}
6966

70-
public static async Task DownloadExtractzip(string Basepath, string Destinationpath, string selectedmod, Modversion modversion)
67+
public static async Task DownloadExtractzip(string Basepath, string Destinationpath, string selectedmod)
7168
{
7269
try
7370
{
@@ -77,11 +74,11 @@ public static async Task DownloadExtractzip(string Basepath, string Destinationp
7774
//we have to differentiate due to pre-releases
7875
if (url.Contains("latest"))
7976
{
80-
connection = await GithubApi.Fetchlatestrelease(url, modversion);
77+
connection = await GithubApi.Fetchlatestrelease(url);
8178
}
8279
else
8380
{
84-
connection = await GithubApi.Fetchfromallreleases(url, modversion);
81+
connection = await GithubApi.Fetchfromallreleases(url);
8582
}
8683

8784
if (!Directory.Exists(Destinationpath)) Directory.CreateDirectory(Destinationpath);
@@ -108,32 +105,14 @@ public static async Task DownloadExtractzip(string Basepath, string Destinationp
108105
}
109106
}
110107

111-
public static void Movefiles(string path, string mod, string modversion)
108+
public static void Movefiles(string path)
112109
{
113-
//no intermediate folder thus nothing to move: return
114-
//tou uses acronym in folder
115-
//the Name property from the Json class gives the folder name for las monjas
116110
try
117111
{
118-
switch (mod)
119-
{
120-
case "The Other Roles":
121-
case "Town of Host":
122-
return;
123-
case "Town of Us":
124-
mod = "ToU";
125-
break;
126-
case "Las Monjas":
127-
mod = modversion;
128-
modversion = string.Empty;
129-
break;
130-
case "Project Lotus":
131-
mod = $"Lotus{modversion[16..]}";
132-
modversion = string.Empty;
133-
break;
134-
}
112+
var folders = Directory.GetDirectories(path);
135113

136-
string subfolder = modversion != string.Empty ? $"{path}\\{mod} {modversion}" : $"{path}\\{mod}";
114+
var subfolder = folders.FirstOrDefault(x => Directory.Exists($"{x}\\BepInEx") && Directory.Exists($"{x}\\dotnet"));
115+
if (subfolder == null) return;
137116
foreach (string file in Directory.GetFiles(subfolder))
138117
{
139118
File.Move($"{file}", $"{path}\\{file[(subfolder.Length + 1)..]}", true);

0 commit comments

Comments
 (0)