@@ -15,7 +15,7 @@ private static void StartScreen_Start()
1515 if ( ! Plugin . config . autoUpdate ) return ;
1616 if ( Environment . GetEnvironmentVariable ( "WINEPREFIX" ) != null )
1717 {
18- Plugin . logger . LogWarning ( "Wine/Proton is not supported!") ;
18+ Plugin . logger . LogError ( "Autoupdate is not supported on Wine !") ;
1919 return ;
2020 }
2121 HttpClient client = new ( ) ;
@@ -34,20 +34,24 @@ private static void StartScreen_Start()
3434 latest = release ;
3535 break ;
3636 }
37- if (
38- new Version ( latest ? . GetProperty ( "tag_name" ) . GetString ( ) ! . TrimStart ( 'v' ) ! . Split ( '-' ) [ 0 ] ! )
39- <=
40- new Version ( Plugin . VERSION . Split ( '-' ) [ 0 ] )
41- ) return ;
37+ string newVersion = latest ? . GetProperty ( "tag_name" ) . GetString ( ) ! . TrimStart ( 'v' ) ! ;
38+ if ( newVersion . IsVersionOlderOrEqual ( Plugin . VERSION ) ) return ;
4239 string os = Application . platform switch
4340 {
4441 RuntimePlatform . WindowsPlayer => "win" ,
4542 RuntimePlatform . LinuxPlayer => "linux" ,
4643 RuntimePlatform . OSXPlayer => "macos" ,
4744 _ => "unknown" ,
4845 } ;
49- if ( os == "unknown" ) return ;
50- string bepinex_url = client . GetAsync ( "https://polymod.dev/data/bepinex.txt" ) . UnwrapAsync ( ) . Content . ReadAsStringAsync ( ) . UnwrapAsync ( ) . Replace ( "{os}" , os ) ;
46+ if ( os == "unknown" )
47+ {
48+ Plugin . logger . LogError ( "Unsupported platform for autoupdate!" ) ;
49+ return ;
50+ }
51+ string bepinex_url = client
52+ . GetAsync ( "https://polymod.dev/data/bepinex.txt" ) . UnwrapAsync ( )
53+ . Content . ReadAsStringAsync ( ) . UnwrapAsync ( )
54+ . Replace ( "{os}" , os ) ;
5155 void Update ( )
5256 {
5357 Time . timeScale = 0 ;
@@ -63,46 +67,28 @@ void Update()
6367 WorkingDirectory = Path . Combine ( Plugin . BASE_PATH ) ,
6468 CreateNoWindow = true ,
6569 } ;
66- Console . Write ( 5 ) ;
6770 if ( Application . platform == RuntimePlatform . WindowsPlayer )
6871 {
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- " ) ;
9172 info . FileName = "cmd.exe" ;
92- info . Arguments = $ "/C start \" \" \" { batchPath } \" ";
93- info . WorkingDirectory = Plugin . BASE_PATH ;
94- info . CreateNoWindow = true ;
95- info . UseShellExecute = false ;
73+ info . Arguments = "/C " +
74+ ":waitloop & " +
75+ "tasklist | findstr /I \" Polytopia.exe\" >nul && (timeout /T 1 >nul & goto waitloop) & " +
76+ "robocopy \" New\" . /E /MOVE /NFL /NDL /NJH /NJS /NP >nul & " +
77+ "rmdir /S /Q \" New\" & " +
78+ "del /F /Q \" BepInEx\\ plugins\\ PolyMod.dll\" & " +
79+ "move /Y \" PolyMod.new.dll\" \" BepInEx\\ plugins\\ PolyMod.dll\" & " +
80+ "start steam://rungameid/874390" ;
9681 }
97- else
82+ if ( Application . platform == RuntimePlatform . LinuxPlayer || Application . platform == RuntimePlatform . OSXPlayer )
9883 {
9984 info . FileName = "/bin/bash" ;
100- info . Arguments =
101- "-c 'sleep 3" +
102- " && mv -f New/* . && mv -f New/.* . 2>/dev/null || true && rm -rf New" +
103- " && rm -f BepInEx/plugins/PolyMod.dll" +
104- " && mv -f PolyMod.new.dll BepInEx/plugins/PolyMod.dll" +
105- " && xdg-open steam://rungameid/874390'" ;
85+ info . Arguments = "-c \" " +
86+ "while pgrep -x Polytopia > /dev/null; do sleep 1; done && " +
87+ "mv New/* . && rm -rf New && " +
88+ "rm -f BepInEx/plugins/PolyMod.dll && " +
89+ "mv PolyMod.new.dll BepInEx/plugins/PolyMod.dll && " +
90+ "steam steam://rungameid/874390" +
91+ "\" " ;
10692 }
10793 Process . Start ( info ) ;
10894 Application . Quit ( ) ;
0 commit comments