@@ -69,20 +69,41 @@ if "%selection%"=="1" (
6969)
7070
7171
72- rem Finds the latest version folder for the selected Discord flavor
73- set " latestVersion = "
72+ rem Finds the latest major, minor, and patch version numbers for the selected Discord flavor
73+ set " latestMajor = 0"
74+ set " latestMinor = 0"
75+ set " latestPatch = 0"
7476
7577for /f " delims=" %%d in ('dir /b /ad /on " %localappdata% \%discordApp% \app-*" ') do (
7678 set " folderName = %%~nxd "
77- rem just the version number (without the app- prefix)
78- set " version = !folderName:~4 ! "
79- if " !version! " gtr " !latestVersion! " (
80- set " latestVersion = !version! "
79+ rem Split the version number into major, minor, and patch
80+ for /f " tokens=1-3 delims=.-" %%a in (" !folderName:~4 ! " ) do (
81+ set /a " major = %%a "
82+ set /a " minor = %%b "
83+ set /a " patch = %%c "
84+ rem Compare numerically
85+ if !major! gtr !latestMajor! (
86+ set " latestMajor = !major! "
87+ set " latestMinor = !minor! "
88+ set " latestPatch = !patch! "
89+ ) else if !major! equ !latestMajor! (
90+ if !minor! gtr !latestMinor! (
91+ set " latestMinor = !minor! "
92+ set " latestPatch = !patch! "
93+ ) else if !minor! equ !latestMinor! (
94+ if !patch! gtr !latestPatch! (
95+ set " latestPatch = !patch! "
96+ )
97+ )
98+ )
8199 )
82100)
83101
102+ rem Construct the latest version string
103+ set " latestVersion = !latestMajor! .!latestMinor! .!latestPatch! "
104+
84105rem If no version folders are found, exit. We can't continue
85- if not defined latestVersion (
106+ if " ! latestVersion! " == " 0.0.0 " (
86107 color 04
87108 echo No version folders found.
88109 color
@@ -143,23 +164,28 @@ if errorlevel 1 (
143164rem Download OpenAsar, change the color so the download bar blends in
144165color 36
145166echo 2. Downloading OpenAsar
146- if exist " %localappdata% \%discordApp% \app-%version % \resources\_app.asar.backup" (
147- powershell -Command " Invoke-WebRequest https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar -OutFile " %localappdata% \%discordApp% \app-%version % \resources\_app.asar" " > nul
148- ) else ( if exist " %localappdata% \%discordApp% \app-%version % \resources\app.orig.asar.backup" (
149- powershell -Command " Invoke-WebRequest https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar -OutFile " %localappdata% \%discordApp% \app-%version % \resources\app.orig.asar" " > nul
167+ if exist " %localappdata% \%discordApp% \app-%latestVersion % \resources\_app.asar.backup" (
168+ powershell -Command " Invoke-WebRequest https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar -OutFile " %localappdata% \%discordApp% \app-%latestVersion % \resources\_app.asar" " > nul
169+ ) else ( if exist " %localappdata% \%discordApp% \app-%latestVersion % \resources\app.orig.asar.backup" (
170+ powershell -Command " Invoke-WebRequest https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar -OutFile " %localappdata% \%discordApp% \app-%latestVersion % \resources\app.orig.asar" " > nul
150171) else (
151172 rem No mod known
152- powershell -Command " Invoke-WebRequest https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar -OutFile " %localappdata% \%discordApp% \app-%version % \resources\app.asar" " > nul
173+ powershell -Command " Invoke-WebRequest https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar -OutFile " %localappdata% \%discordApp% \app-%latestVersion % \resources\app.asar" " > nul
153174))
154175
155- rem If the download command failed, exit
156- if errorlevel 1 (
176+ rem Check if the download command failed
177+ if not %errorlevel% == 0 (
157178 color 04
158179 echo Error: Failed to download and replace the asar file.
159- echo Please check your internet connection. Also make sure that the Discord client is closed.
160- echo .
161- color
162- pause
180+ echo Attempting to restore backup...
181+ move /y " %localappdata% \%discordApp% \app-%latestVersion% \resources\app.asar.backup" " %localappdata% \%discordApp% \app-%latestVersion% \resources\app.asar" > nul
182+
183+ if not %errorlevel% == 0 (
184+ echo Error: Failed to restore the backup. Check %localappdata% \%discordApp% \app-%latestVersion% \resources\ and make sure to restore the .backup file to .asar for Discord to be able to launch again.
185+ pause
186+ ) else (
187+ echo Backup restored successfully. Discord was not modded but should be able to be launched.
188+ )
163189 exit
164190)
165191
0 commit comments