Skip to content

Commit df8b063

Browse files
Add localization and prerelease option
1 parent d44d839 commit df8b063

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

installer/main.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"darwin": "macos",
1616
}[sys.platform]
1717
BEPINEX = f"733/BepInEx-Unity.IL2CPP-{OS}-x64-6.0.0-be.733%2B995f049"
18-
POLYMOD = "https://github.com/PolyModdingTeam/PolyMod/releases/latest/download/PolyMod.dll"
18+
POLYMOD = "https://api.github.com/repos/PolyModdingTeam/PolyMod/releases"
1919

2020

2121
def resource_path(path):
@@ -53,6 +53,7 @@ def prepare(target):
5353
return
5454
path_entry.configure(state=customtkinter.DISABLED)
5555
browse_button.configure(state=customtkinter.DISABLED)
56+
prerelease_checkbox.destroy()
5657
install_button.destroy()
5758
uninstall_button.destroy()
5859
progress_bar = customtkinter.CTkProgressBar(app, determinate_speed=50 / 2)
@@ -69,8 +70,11 @@ def install(path):
6970
).extractall(path)
7071
progress_bar.step()
7172

73+
for release in requests.get(POLYMOD).json():
74+
if release["prerelease"] and not prerelease_checkbox.get(): continue
75+
latest = release
7276
open(path + "/BepInEx/plugins/PolyMod.dll", "wb").write(
73-
requests.get(POLYMOD).content
77+
requests.get(latest["assets"][0]["browser_download_url"]).content
7478
)
7579
progress_bar.step()
7680

@@ -127,14 +131,17 @@ def quit():
127131
app, placeholder_text="Game path", width=228)
128132
browse_button = customtkinter.CTkButton(
129133
app, text="Browse", command=browse, width=1)
134+
prerelease_checkbox = customtkinter.CTkCheckBox(
135+
app, text="Prerelease", width=1)
130136
install_button = customtkinter.CTkButton(
131137
app, text="Install", command=lambda: prepare(install))
132138
uninstall_button = customtkinter.CTkButton(
133139
app, text="Uninstall", command=lambda: prepare(uninstall))
134140

135141
path_entry.grid(column=0, row=0, padx=5, pady=5)
136142
browse_button.grid(column=1, row=0, padx=(0, 5), pady=5)
137-
install_button.grid(column=0, row=1, columnspan=2, padx=5, pady=5)
138-
uninstall_button.grid(column=0, row=2, columnspan=2, padx=5, pady=5)
143+
prerelease_checkbox.grid(column=0, row=1, columnspan=2, padx=5, pady=5)
144+
install_button.grid(column=0, row=2, columnspan=2, padx=5, pady=5)
145+
uninstall_button.grid(column=0, row=3, columnspan=2, padx=5, pady=5)
139146

140147
app.mainloop()

resources/localization.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,17 @@
160160
"Portuguese (Brazil)": "Essa versão do PolyMod não foi desenvolvida para a versão atual do aplicativo e pode não funcionar corretamente!",
161161
"Elyrion": "πȱ∫ỹmȱδ ƒƒƒƒƒƒƒ ŋȱŧ ȱrrȱ #₺rr∑ŋŧ ƒƒƒƒƒƒƒ ỹ maỹ ŋȱŧ ~ȱr§ #ȱrr∑#ŧ∫ỹ!",
162162
"German (Germany)": "Diese Version von PolyMod ist nicht für die aktuelle Version der Anwendung ausgelegt und könnte nicht funktionieren!"
163+
},
164+
"polymod_autoupdate": {
165+
"English": "Auto-update",
166+
"Russian": "Автообновление"
167+
},
168+
"polymod_autoupdate_description": {
169+
"English": "New update available!",
170+
"Russian": "Доступно новое обновление!"
171+
},
172+
"polymod_autoupdate_update": {
173+
"English": "Update",
174+
"Russian": "Обновить"
163175
}
164176
}

src/Managers/AutoUpdate.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,33 @@ internal static class AutoUpdate
1010
[HarmonyPatch(typeof(StartScreen), nameof(StartScreen.Start))]
1111
private static void StartScreen_Start()
1212
{
13+
if (!Plugin.config.autoUpdate) return;
1314
HttpClient client = new();
1415
client.DefaultRequestHeaders.Add("User-Agent", "PolyMod");
1516
try
1617
{
1718
var json = JsonDocument.Parse(
18-
client.GetAsync("https://api.github.com/repos/PolyModdingTeam/PolyMod/releases/latest").UnwrapAsync()
19+
client.GetAsync("https://api.github.com/repos/PolyModdingTeam/PolyMod/releases").UnwrapAsync()
1920
.Content.ReadAsStringAsync().UnwrapAsync()
2021
);
22+
JsonElement? latest = null;
23+
for (int i = 0; i < json.RootElement.GetArrayLength(); i++)
24+
{
25+
var release = json.RootElement[i];
26+
if (release.GetProperty("prerelease").GetBoolean() && !Plugin.config.updatePrerelease) continue;
27+
latest = release;
28+
break;
29+
}
2130
if (
22-
new Version(json.RootElement.GetProperty("tag_name").GetString()!.TrimStart('v'))
23-
<=
31+
new Version(latest?.GetProperty("tag_name").GetString()!.TrimStart('v')!)
32+
<=
2433
new Version(Plugin.VERSION)
2534
) return;
2635
void Update()
2736
{
2837
File.WriteAllBytes(
2938
Path.Combine(Plugin.BASE_PATH, "BepInEx", "plugins", "PolyMod.new.dll"),
30-
client.GetAsync(json.RootElement.GetProperty("assets")[0].GetProperty("browser_download_url").GetString()!).UnwrapAsync()
39+
client.GetAsync(latest?.GetProperty("assets")[0].GetProperty("browser_download_url").GetString()!).UnwrapAsync()
3140
.Content.ReadAsByteArrayAsync().UnwrapAsync()
3241
);
3342
ProcessStartInfo info = new()
@@ -38,24 +47,24 @@ void Update()
3847
if (Application.platform == RuntimePlatform.WindowsPlayer)
3948
{
4049
info.FileName = "cmd.exe";
41-
info.Arguments
50+
info.Arguments
4251
= "/C timeout 3 && del /F /Q PolyMod.dll && move /Y PolyMod.new.dll PolyMod.dll && start steam://rungameid/874390";
4352
}
4453
else
4554
{
4655
info.FileName = "/bin/bash";
47-
info.Arguments
48-
= "-c 'sleep 3 && rm -f PolyMod.dll && mv PolyMod.new.dll PolyMod.dll && xdg-open steam://rungameid/874390'";
56+
info.Arguments
57+
= "-c 'sleep 3 && rm -f PolyMod.dll && mv PolyMod.new.dll PolyMod.dll && xdg-open steam://rungameid/874390'";
4958
}
5059
Process.Start(info);
5160
Application.Quit();
5261
}
5362
PopupManager.GetBasicPopup(new(
54-
Localization.Get("polymod.version.autoupdate"),
55-
Localization.Get("polymod.version.autoupdate.description"),
63+
Localization.Get("polymod.autoupdate"),
64+
Localization.Get("polymod.autoupdate.description"),
5665
new(new PopupBase.PopupButtonData[] {
5766
new(
58-
"buttons.ok",
67+
"polymod.autoupdate.update",
5968
PopupBase.PopupButtonData.States.None,
6069
(Il2CppSystem.Action)Update,
6170
closesPopup: false

src/Plugin.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ namespace PolyMod;
1010
public partial class Plugin : BepInEx.Unity.IL2CPP.BasePlugin
1111
{
1212
internal record PolyConfig(
13-
bool debug = false
13+
bool debug = false,
14+
bool autoUpdate = true,
15+
bool updatePrerelease = false
1416
);
1517

1618
internal const int AUTOIDX_STARTS_FROM = 1000;

0 commit comments

Comments
 (0)