Skip to content

Commit c61a53f

Browse files
committed
Fixed windows auto update
1 parent a13e6b6 commit c61a53f

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

src/Managers/AutoUpdate.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ private static void StartScreen_Start()
3939
<=
4040
new Version(Plugin.VERSION.Split('-')[0])
4141
) return;
42-
string bepinex_version = client.GetAsync("https://polymod.dev/data/bepinex.txt").UnwrapAsync().Content.ReadAsStringAsync().UnwrapAsync();
4342
string os = Application.platform switch
4443
{
4544
RuntimePlatform.WindowsPlayer => "win",
@@ -48,6 +47,7 @@ private static void StartScreen_Start()
4847
_ => "unknown",
4948
};
5049
if (os == "unknown") return;
50+
string bepinex_url = client.GetAsync("https://polymod.dev/data/bepinex.txt").UnwrapAsync().Content.ReadAsStringAsync().UnwrapAsync().Replace("{os}", os);
5151
void Update()
5252
{
5353
Time.timeScale = 0;
@@ -56,23 +56,43 @@ void Update()
5656
client.GetAsync(latest?.GetProperty("assets")[0].GetProperty("browser_download_url").GetString()!).UnwrapAsync()
5757
.Content.ReadAsByteArrayAsync().UnwrapAsync()
5858
);
59-
using ZipArchive bepinex = new(client.GetAsync(bepinex_version).UnwrapAsync().Content.ReadAsStream());
60-
bepinex.ExtractToDirectory(Path.Combine(Plugin.BASE_PATH, "New"));
59+
using ZipArchive bepinex = new(client.GetAsync(bepinex_url).UnwrapAsync().Content.ReadAsStream());
60+
bepinex.ExtractToDirectory(Path.Combine(Plugin.BASE_PATH, "New"), overwriteFiles: true);
6161
ProcessStartInfo info = new()
6262
{
6363
WorkingDirectory = Path.Combine(Plugin.BASE_PATH),
6464
CreateNoWindow = true,
6565
};
66+
Console.Write(5);
6667
if (Application.platform == RuntimePlatform.WindowsPlayer)
6768
{
69+
string batchPath = Path.Combine(Plugin.BASE_PATH, "update.bat");
70+
File.WriteAllText(batchPath, $@"
71+
@echo off
72+
echo Waiting for Polytopia.exe to exit...
73+
:waitloop
74+
tasklist | findstr /I ""Polytopia.exe"" >nul
75+
if not errorlevel 1 (
76+
timeout /T 1 >nul
77+
goto waitloop
78+
)
79+
80+
echo Updating...
81+
robocopy ""New"" . /E /MOVE /NFL /NDL /NJH /NJS /NP >nul
82+
rmdir /S /Q ""New""
83+
del /F /Q ""BepInEx\plugins\PolyMod.dll""
84+
move /Y ""PolyMod.new.dll"" ""BepInEx\plugins\PolyMod.dll""
85+
86+
echo Launching game...
87+
start steam://rungameid/874390
88+
timeout /T 3 /NOBREAK >nul
89+
exit
90+
");
6891
info.FileName = "cmd.exe";
69-
info.Arguments =
70-
"/C timeout 3" +
71-
" && robocopy \"New\" . /E /MOVE /NFL /NDL /NJH /NJS /NP" +
72-
" && rmdir /S /Q \"New\"" +
73-
" && del /F /Q \"BepInEx\\plugins\\PolyMod.dll\"" +
74-
" && move /Y \"PolyMod.new.dll\" \"BepInEx\\plugins\\PolyMod.dll\"" +
75-
" && start steam://rungameid/874390";
92+
info.Arguments = $"/C start \"\" \"{batchPath}\"";
93+
info.WorkingDirectory = Plugin.BASE_PATH;
94+
info.CreateNoWindow = true;
95+
info.UseShellExecute = false;
7696
}
7797
else
7898
{

0 commit comments

Comments
 (0)