diff --git a/src/command.c b/src/command.c index 47c6d2e5..16f18749 100644 --- a/src/command.c +++ b/src/command.c @@ -32,6 +32,7 @@ #include "hu_stuff.h" #include "p_setup.h" #include "lua_script.h" +#include "d_netfil.h" // findfile //======== // protos. @@ -641,6 +642,7 @@ static void COM_CEchoDuration_f(void) static void COM_Exec_f(void) { UINT8 *buf = NULL; + char filename[256]; if (COM_Argc() < 2 || COM_Argc() > 3) { @@ -649,13 +651,23 @@ static void COM_Exec_f(void) } // load file + // Try with Argv passed verbatim first, for back compat FIL_ReadFile(COM_Argv(1), &buf); if (!buf) { - if (!COM_CheckParm("-noerror")) - CONS_Printf(M_GetText("couldn't execute file %s\n"), COM_Argv(1)); - return; + // Now try by searching the file path + // filename is modified with the full found path + strcpy(filename, COM_Argv(1)); + if (findfile(filename, NULL, true) != FS_NOTFOUND) + FIL_ReadFile(filename, &buf); + + if (!buf) + { + if (!COM_CheckParm("-noerror")) + CONS_Printf(M_GetText("couldn't execute file %s\n"), COM_Argv(1)); + return; + } } if (!COM_CheckParm("-silent")) diff --git a/src/d_net.c b/src/d_net.c index 82c60e4a..cdd63ea3 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -27,6 +27,7 @@ #include "d_clisrv.h" #include "z_zone.h" #include "i_tcp.h" +#include "d_main.h" // srb2home // // NETWORKING @@ -1374,12 +1375,12 @@ boolean D_CheckNetGame(void) { k++; sprintf(filename, "debug%d.txt", k); - debugfile = fopen(filename, "w"); + debugfile = fopen(va("%s" PATHSEP "%s", srb2home, filename), "w"); } if (debugfile) - CONS_Printf(M_GetText("debug output to: %s\n"), filename); + CONS_Printf(M_GetText("debug output to: %s\n"), va("%s" PATHSEP "%s", srb2home, filename)); else - CONS_Alert(CONS_WARNING, M_GetText("cannot debug output to file %s!\n"), filename); + CONS_Alert(CONS_WARNING, M_GetText("cannot debug output to file %s!\n"), va("%s" PATHSEP "%s", srb2home, filename)); } #endif #endif diff --git a/src/dehacked.c b/src/dehacked.c index edc4e01d..db1d6eed 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -3080,7 +3080,7 @@ static void readmaincfg(MYFILE *f) strncpy(timeattackfolder, gamedatafilename, min(filenamelen, sizeof (timeattackfolder))); timeattackfolder[min(filenamelen, sizeof (timeattackfolder) - 1)] = '\0'; - strncpy(savegamename, timeattackfolder, strlen(timeattackfolder)); + strcpy(savegamename, timeattackfolder); strlcat(savegamename, "%u.ssg", sizeof(savegamename)); // can't use sprintf since there is %u in savegamename strcatbf(savegamename, srb2home, PATHSEP); diff --git a/src/m_misc.c b/src/m_misc.c index 1ab5f1fe..a4f53c71 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -518,6 +518,7 @@ void M_FirstLoadConfig(void) void M_SaveConfig(const char *filename) { FILE *f; + char *filepath; // make sure not to write back the config until it's been correctly loaded if (!gameconfig_loaded) @@ -532,13 +533,20 @@ void M_SaveConfig(const char *filename) return; } - f = fopen(filename, "w"); + // append srb2home to beginning of filename + // but check if srb2home isn't already there, first + if (!strstr(filename, srb2home)) + filepath = va(pandf,srb2home, filename); + else + filepath = Z_StrDup(filename); + + f = fopen(filepath, "w"); // change it only if valid if (f) - strcpy(configfile, filename); + strcpy(configfile, filepath); else { - CONS_Alert(CONS_ERROR, M_GetText("Couldn't save game config file %s\n"), filename); + CONS_Alert(CONS_ERROR, M_GetText("Couldn't save game config file %s\n"), filepath); return; } } diff --git a/windows-installer/! MAKE SURE FILES ARE IN new-install ARCHIVE FOLDER !.txt b/windows-installer/! MAKE SURE FILES ARE IN new-install ARCHIVE FOLDER !.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/windows-installer/.gitignore b/windows-installer/.gitignore deleted file mode 100644 index 40ca3713..00000000 --- a/windows-installer/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -* -*.* -!staging -!sfx -!uninstaller -!! MAKE SURE FILES ARE IN new-install ARCHIVE FOLDER !.txt -!BuildInstaller.bat -!README.txt -!VersionFileName.txt -!.gitignore diff --git a/windows-installer/BuildInstaller.bat b/windows-installer/BuildInstaller.bat deleted file mode 100644 index cc6ff74b..00000000 --- a/windows-installer/BuildInstaller.bat +++ /dev/null @@ -1,76 +0,0 @@ -@echo off - -set "SCRIPTDIR=%~dp0" -set "SCRIPTDIR=%SCRIPTDIR:~0,-1%" - -IF [%SRB2VERSIONNAME%] == [] set /p SRB2VERSIONNAME=<"%SCRIPTDIR%\VersionFileName.txt" - -:: Find 7z - -set SVZIP= - -if NOT [%1] == [] ( - echo.%~1 | findstr /C:"7z" 1>nul - if NOT errorlevel 1 ( - if exist "%~1" set "SVZIP=%~1" - ) -) - -if ["%SVZIP%"] == [""] ( - if exist "%ProgramFiles(x86)%\7-Zip\7z.exe" set "SVZIP=%ProgramFiles(x86)%\7-Zip\7z.exe" - if exist "%ProgramFiles%\7-Zip\7z.exe" set "SVZIP=%ProgramFiles%\7-Zip\7z.exe" - if exist "%ProgramW6432%\7-Zip\7z.exe" set "SVZIP=%ProgramW6432%\7-Zip\7z.exe" -) - -:: Is it in PATH? - -if ["%SVZIP%"] == [""] ( - "7z.exe" --help > NUL 2> NUL - if NOT errorlevel 1 ( - set "SVZIP=7z.exe" - ) -) - -:: Create the uninstaller - -if NOT ["%SVZIP%"] == [""] ( - del /f /q "%SCRIPTDIR%\Uninstaller.7z" 2> NUL - "%SVZIP%" a -t7z "%SCRIPTDIR%\Uninstaller.7z" "%SCRIPTDIR%\uninstaller\*" -m5=LZMA2 - copy /y /b "%SCRIPTDIR%\sfx\7zsd_LZMA2.sfx" + "%SCRIPTDIR%\sfx\config-uninstaller.txt" + "%SCRIPTDIR%\Uninstaller.7z" "%SCRIPTDIR%\staging\new-install\uninstall.exe" - del /f /q "%SCRIPTDIR%\uninstaller.7z" -) - -:: Operate on install archives - -type NUL > "%SCRIPTDIR%\staging\new-install\staging.txt" - -if exist "%SCRIPTDIR%\Installer.7z" ( - if NOT ["%SVZIP%"] == [""] ( - "%SVZIP%" a "%SCRIPTDIR%\Installer.7z" "%SCRIPTDIR%\staging\*" - ) - copy /y /b "%SCRIPTDIR%\sfx\7zsd_LZMA2.sfx" + "%SCRIPTDIR%\sfx\config-installer.txt" + "%SCRIPTDIR%\Installer.7z" "%SCRIPTDIR%\SRB2-%SRB2VERSIONNAME%-Installer.exe" -) - -if exist "%SCRIPTDIR%\Patch.7z" ( - if NOT ["%SVZIP%"] == [""] ( - "%SVZIP%" a "%SCRIPTDIR%\Patch.7z" "%SCRIPTDIR%\staging\*" - ) - copy /y /b "%SCRIPTDIR%\sfx\7zsd_LZMA2.sfx" + "%SCRIPTDIR%\sfx\config-patch.txt" + "%SCRIPTDIR%\Patch.7z" "%SCRIPTDIR%\SRB2-%SRB2VERSIONNAME%-Patch.exe" -) - -if exist "%SCRIPTDIR%\Installer_x64.7z" ( - if NOT ["%SVZIP%"] == [""] ( - "%SVZIP%" a "%SCRIPTDIR%\Installer_x64.7z" "%SCRIPTDIR%\staging\*" - ) - copy /y /b "%SCRIPTDIR%\sfx\7zsd_LZMA2_x64.sfx" + "%SCRIPTDIR%\sfx\config-installer.txt" + "%SCRIPTDIR%\Installer_x64.7z" "%SCRIPTDIR%\SRB2-%SRB2VERSIONNAME%-x64-Installer.exe" -) - -if exist "%SCRIPTDIR%\Patch_x64.7z" ( - if NOT ["%SVZIP%"] == [""] ( - "%SVZIP%" a "%SCRIPTDIR%\Patch_x64.7z" "%SCRIPTDIR%\staging\*" - ) - copy /y /b "%SCRIPTDIR%\sfx\7zsd_LZMA2_x64.sfx" + "%SCRIPTDIR%\sfx\config-patch.txt" + "%SCRIPTDIR%\Patch_x64.7z" "%SCRIPTDIR%\SRB2-%SRB2VERSIONNAME%-x64-Patch.exe" -) - -del /f /q "%SCRIPTDIR%\staging\new-install\staging.txt" -del /f /q "%SCRIPTDIR%\staging\new-install\uninstall.exe" diff --git a/windows-installer/README.txt b/windows-installer/README.txt deleted file mode 100644 index 67995f33..00000000 --- a/windows-installer/README.txt +++ /dev/null @@ -1,48 +0,0 @@ -Windows Install Builder -for SRB2 - -This installer is much like the 7-Zip self-extracting archive, except -this allows for scripting the post-install step. - -This also allows for some light customization, including dialog messages -and program shortcuts. - -The included install scripts manage the game data location depending on the -install location -- if installed in Program Files or AppData\Local, the -game data location is set to %UserProfile%\SRB2. - -Program shortcuts are also added, as well as an uninstaller that -will remove the icons and also selectively uninstall the core game files. -The uninstaller gives you the option to preserve your game data and mods. - -How to Use ----------- - -1. Zip up the install contents in 7z format. - * ALL FILES MUST BE IN THE `new-install/` ARCHIVE SUBFOLDER, OR THE - POST-INSTALL SCRIPT WILL NOT WORK! - * Make sure you are using the LZMA2 algorithm, which is 7-Zip's default. - -2. Copy the 7z archive to this folder using the following names: - * Installer.7z - 32-bit full installer - * Patch.7z - 32-bit patch - * Installer_x64.7z - 64-bit full installer - * Patch_x64.7z - 64-bit patch - -3. Set the text in VersionFilename.txt to the version identifier for the - installer's filename. - * e.g., v2121 for v2.1.21, from "SRB2-v2121-Installer.exe" - * Also look through sfx/config-installer.txt and sfx/config-patch.txt - and update the version strings. Templating is TODO. - -4. Run BuildInstaller.bat [7z.exe install path] - * First argument is the path to 7z.exe. If this is not specified, the - script will try to look for it in C:\Program Files [(x86)] - * This script will automatically add the install scripts to each - installer. - -Credit ------- - -OlegScherbakov/7zSFX -https://github.com/OlegScherbakov/7zSFX diff --git a/windows-installer/VersionFileName.txt b/windows-installer/VersionFileName.txt deleted file mode 100644 index 559abffe..00000000 --- a/windows-installer/VersionFileName.txt +++ /dev/null @@ -1 +0,0 @@ -v2121 \ No newline at end of file diff --git a/windows-installer/sfx/7zsd_LZMA2.sfx b/windows-installer/sfx/7zsd_LZMA2.sfx deleted file mode 100644 index c4ba9c58..00000000 Binary files a/windows-installer/sfx/7zsd_LZMA2.sfx and /dev/null differ diff --git a/windows-installer/sfx/7zsd_LZMA2_x64.sfx b/windows-installer/sfx/7zsd_LZMA2_x64.sfx deleted file mode 100644 index 758e4c2d..00000000 Binary files a/windows-installer/sfx/7zsd_LZMA2_x64.sfx and /dev/null differ diff --git a/windows-installer/sfx/config-installer.txt b/windows-installer/sfx/config-installer.txt deleted file mode 100644 index bdbddea5..00000000 --- a/windows-installer/sfx/config-installer.txt +++ /dev/null @@ -1,24 +0,0 @@ -;!@Install@!UTF-8! - -GUIFlags="8+32+64+4096" -GUIMode="1" - -Title="Sonic Robo Blast 2 v2.1.21" -BeginPrompt="Sonic Robo Blast 2 v2.1.21\nFull Installer\n\nSelect a folder to install SRB2 in.\n\nIf you install in \"AppData\\Local\" or \"Program Files\", your game data will be saved to:\n%UserProfile%\\SRB2\n\nOtherwise, your game data will be in the installation folder.\n\nShortcuts will be created in your Start Menu." - -ExtractPathText="Installation folder: (no exclamation points, please!)" -InstallPath="%LocalAppData%\\SRB2" -ExtractTitle="Installing..." -ExtractDialogText="Installing SRB2 v2.1.21...\n\nCheck out our modding community!\nWe make levels, characters, and much more!\n\nVisit http://www.srb2.org/mods" - -Shortcut="Pu,{%%T\\srb2win.exe},{},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2win.exe},{-win},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (Windowed)},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2win.exe},{-opengl},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (OpenGL)},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2win.exe},{-opengl -win},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (OpenGL, Windowed)},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2dd.exe},{},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (DirectDraw)},{%%T\\},{%%T\\srb2dd.exe},{0}" -Shortcut="Pu,{%%T\\srb2dd.exe},{-win},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (DirectDraw, Windowed)},{%%T\\},{%%T\\srb2dd.exe},{0}" -Shortcut="Pu,{%%T\\uninstall.exe},{},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{Uninstall SRB2},{%%T\\},{shell32.dll},{31}" - -RunProgram="nowait:\"%%T\\new-install\\staging.bat\"" - -;!@InstallEnd@! diff --git a/windows-installer/sfx/config-patch.txt b/windows-installer/sfx/config-patch.txt deleted file mode 100644 index bde6135d..00000000 --- a/windows-installer/sfx/config-patch.txt +++ /dev/null @@ -1,24 +0,0 @@ -;!@Install@!UTF-8! - -GUIFlags="8+32+64+4096" -GUIMode="1" - -Title="Sonic Robo Blast 2 v2.1.21" -BeginPrompt="Sonic Robo Blast 2 v2.1.21\nPatch Installer\n\nYou must have at least v2.1.15 to use this patch.\n\nSelect your current SRB2 folder.\n\nShortcuts will be created in your Start Menu." - -ExtractPathText="Current SRB2 folder: (no exclamation points, please!)" -InstallPath="%LocalAppData%\\SRB2" -ExtractTitle="Installing..." -ExtractDialogText="Installing SRB2 v2.1.21...\n\nCheck out our modding community!\nWe make levels, characters, and much more!\n\nVisit http://www.srb2.org/mods" - -Shortcut="Pu,{%%T\\srb2win.exe},{},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2win.exe},{-win},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (Windowed)},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2win.exe},{-opengl},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (OpenGL)},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2win.exe},{-opengl -win},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (OpenGL, Windowed)},{%%T\\},{%%T\\srb2win.exe},{0}" -Shortcut="Pu,{%%T\\srb2dd.exe},{},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (DirectDraw)},{%%T\\},{%%T\\srb2dd.exe},{0}" -Shortcut="Pu,{%%T\\srb2dd.exe},{-win},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{SRB2 (DirectDraw, Windowed)},{%%T\\},{%%T\\srb2dd.exe},{0}" -Shortcut="Pu,{%%T\\uninstall.exe},{},{Sonic Robo Blast 2},{Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame.},{Uninstall SRB2},{%%T\\},{shell32.dll},{31}" - -RunProgram="nowait:\"%%T\\new-install\\staging.bat\"" - -;!@InstallEnd@! diff --git a/windows-installer/sfx/config-uninstaller.txt b/windows-installer/sfx/config-uninstaller.txt deleted file mode 100644 index f3de9e26..00000000 --- a/windows-installer/sfx/config-uninstaller.txt +++ /dev/null @@ -1,13 +0,0 @@ -;!@Install@!UTF-8! - -GUIFlags="1+2+8" -GUIMode="2" - -Title="Uninstall SRB2" -BeginPrompt="Are you sure you want to uninstall Sonic Robo Blast 2?\n\nYour game data and mods will be preserved, as well as\nany extra files in your install folder." - -InstallPath="%%S" - -RunProgram="nowait:\"%%S\\uninstall.bat\" /y" - -;!@InstallEnd@! diff --git a/windows-installer/staging/! SRB2 INSTALL INSTRUCTIONS !.txt b/windows-installer/staging/! SRB2 INSTALL INSTRUCTIONS !.txt deleted file mode 100644 index f367296f..00000000 --- a/windows-installer/staging/! SRB2 INSTALL INSTRUCTIONS !.txt +++ /dev/null @@ -1,11 +0,0 @@ -SRB2 Install Instructions - -1. Move every file from the "new-install" folder to this main install folder. - -2. DELETE "staging.bat" and "staging.txt"! These can mess up your installation if run by accident! - -3. Optionally, create a folder in your user profile named "SRB2". This is where your game data and addons may live. For example, - - C:\Users\[User]\SRB2 - -4. Run the game! Double-click srb2win.exe -- or see if you have Start Menu icons under "Sonic Robo Blast 2". \ No newline at end of file diff --git a/windows-installer/staging/new-install/old-install-list.txt b/windows-installer/staging/new-install/old-install-list.txt deleted file mode 100644 index 6f33660a..00000000 --- a/windows-installer/staging/new-install/old-install-list.txt +++ /dev/null @@ -1,15 +0,0 @@ -exchndl.dll -fmodex.dll -libFLAC-8.dll -libgme.dll -libintl-8.dll -libmikmod-2.dll -libogg-0.dll -libvorbis-0.dll -libvorbisfile-3.dll -r_opengl.dll -SDL2.dll -SDL2_mixer.dll -smpeg2.dll -srb2dd.exe -srb2win.exe \ No newline at end of file diff --git a/windows-installer/staging/new-install/staging.bat b/windows-installer/staging/new-install/staging.bat deleted file mode 100644 index 2c3c9491..00000000 --- a/windows-installer/staging/new-install/staging.bat +++ /dev/null @@ -1,363 +0,0 @@ -@echo off - -setlocal enabledelayedexpansion - -cls - -:: SRB2 Install Staging -:: -:: This accomplishes the following tasks: -:: -:: 1. Creates a user profile folder if SRB2 is installed in AppData or Program Files, and config.cfg is not already in the install folder -:: -:: 2. Moves old installation files into old-install -:: -:: 3. Moves new installaton files into install folder -:: - -:: Get Parent folder (the SRB2 install folder) -:: -:: https://wiert.me/2011/08/30/batch-file-to-get-parent-directory-not-the-directory-of-the-batch-file-but-the-parent-of-that-directory/ - -set "STAGINGDIR=%~dp0" -:: strip trailing backslash -set "STAGINGDIR=!STAGINGDIR:~0,-1!" -:: ~dp only works for batch file parameters and loop indexes -for %%d in ("!STAGINGDIR!") do set "INSTALLDIR=%%~dpd" -set "INSTALLDIR=!INSTALLDIR:~0,-1!" - -:: Find 7z - -set SVZIP= -if ["%SVZIP%"] == [""] ( - if exist "!ProgramFiles(x86)!\7-Zip\7z.exe" set "SVZIP=!ProgramFiles(x86)!\7-Zip\7z.exe" - if exist "!ProgramFiles!\7-Zip\7z.exe" set "SVZIP=!ProgramFiles!\7-Zip\7z.exe" - if exist "!ProgramW6432!\7-Zip\7z.exe" set "SVZIP=!ProgramW6432!\7-Zip\7z.exe" -) - -:: Is it in PATH? - -if ["%SVZIP%"] == [""] ( - "7z.exe" --help > NUL 2> NUL - if NOT errorlevel 1 ( - set "SVZIP=7z.exe" - ) -) - -:: FAILSAFE: Check if staging.txt exists in the directory -:: If not, exit, so we don't mess up anything by accident. - -if NOT exist "!STAGINGDIR!\staging.txt" ( - exit -) - -: CheckPermissionsInstall - -:: Write a dummy file and check for an error. If error, we need administrator rights - -:: NOTE: We should never have to deal with this because the main installer should -:: already have the rights. - -mkdir "!INSTALLDIR!\install-dummy" - -:: TODO elevate automatically -if errorlevel 1 ( - echo Finish installing SRB2 with these steps: - echo. - echo 1. Go to your SRB2 install folder - echo. - echo !INSTALLDIR! - echo. - echo 2. Copy all files from the "new-install" subfolder into the main folder - echo and DELETE staging.bat and staging.txt!!! - echo. - echo 3. Optionally, create a folder in your user profile named "SRB2". - echo This is where your game data and addons may live. - echo To create the folder, go here: - echo. - echo !USERPROFILE! - echo. - echo If anything fails, you may delete the files and try to run the installer - echo again with Administrator Rights: Right-click on the icon and click - echo "Run as administrator." - echo. - "!SystemRoot!\explorer.exe" "!INSTALLDIR!" - set /p ADMINFINAL="Press Enter key to exit. " - - exit -) else ( - rmdir /s /q "!INSTALLDIR!\install-dummy" - goto CheckUserDir -) - -: CheckUserDir - -:: Check if we need to create !userprofile!\SRB2 - -set "USERDIR=!INSTALLDIR!" - -:: Is config.cfg in our install dir? -if exist "!INSTALLDIR!\config.cfg" goto MoveOldInstall - -:: Are we in AppData? -echo.!STAGINGDIR! | findstr /C:"!LocalAppData!" 1>nul -if errorlevel 1 ( - echo. -) else ( - goto SetUserDir -) - -: Are we in Program Files? -echo.!STAGINGDIR! | findstr /C:"!ProgramFiles!" 1>nul -if NOT errorlevel 1 ( - goto SetUserDir -) - -:: Are we in Program Files (x86)? -echo.!STAGINGDIR! | findstr /C:"!ProgramFiles(X86)!" 1>nul -if NOT errorlevel 1 ( - goto SetUserDir -) - -:: Are we 32-bit and actually in Program Files? -echo.!STAGINGDIR! | findstr /C:"!ProgramW6432!" 1>nul -if NOT errorlevel 1 ( - goto SetUserDir -) - -goto MoveOldInstall - -: SetUserDir -: CheckPermissionsUserDir - -set "USERDIR=!UserProfile!\SRB2" - -:: Check for permissions and create the folder -if exist "!USERDIR!\*" ( - mkdir "!USERDIR!\install-dummy" - - if errorlevel 1 ( - echo User profile folder exists, but we won't operate on it. - echo. - goto MoveOldInstall - ) else ( - rmdir /s /q "!USERDIR!\install-dummy" - ) -) else ( - mkdir "!USERDIR!" - - if errorlevel 1 ( - echo Could not create user profile folder - echo Defaulting to install dir: "!INSTALLDIR!" - echo. - set "USERDIR=!INSTALLDIR!" - goto MoveOldInstall - ) -) - -:: Now copy READMEs -:: echo f answers xcopy's prompt as to whether the destination is a file or a folder -echo f | xcopy /y "!STAGINGDIR!\README.txt" "!USERDIR!\README.txt" -echo f | xcopy /y "!STAGINGDIR!\LICENSE.txt" "!USERDIR!\LICENSE.txt" -echo f | xcopy /y "!STAGINGDIR!\LICENSE-3RD-PARTY.txt" "!USERDIR!\LICENSE-3RD-PARTY.txt" -echo Your game data and mods folder is: > "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo. >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo !USERDIR! >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo. >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo Your install folder is: >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo. >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo !INSTALLDIR! >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo. >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo To run SRB2, go to: >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo. >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" -echo Start Menu ^> Programs ^> Sonic Robo Blast 2 >> "!USERDIR!\^! Data and Mods Go Here ^!.txt" - -:: Copy path to install folder - -set "SCRIPT=!TEMP!\!RANDOM!-!RANDOM!-!RANDOM!-!RANDOM!.vbs" -echo Set oWS = WScript.CreateObject("WScript.Shell") >> "!SCRIPT!" -echo sLinkFile = "!USERDIR!\^! SRB2 Install Folder ^!.lnk" >> "!SCRIPT!" -echo Set oLink = oWS.CreateShortcut(sLinkFile) >> "!SCRIPT!" -echo oLink.TargetPath = "!INSTALLDIR!" >> "!SCRIPT!" -echo oLink.WorkingDirectory = "!INSTALLDIR!" >> "!SCRIPT!" -echo oLink.Arguments = "" >> "!SCRIPT!" -echo oLink.IconLocation = "!INSTALLDIR!\srb2win.exe,0" >> "!SCRIPT!" -echo oLink.Save >> "!SCRIPT!" -cscript /nologo "!SCRIPT!" -del "!SCRIPT!" - -:: Also do it the other way around - -set "SCRIPT=!TEMP!\!RANDOM!-!RANDOM!-!RANDOM!-!RANDOM!.vbs" -echo Set oWS = WScript.CreateObject("WScript.Shell") >> "!SCRIPT!" -echo sLinkFile = "!INSTALLDIR!\^! SRB2 Data Folder ^!.lnk" >> "!SCRIPT!" -echo Set oLink = oWS.CreateShortcut(sLinkFile) >> "!SCRIPT!" -echo oLink.TargetPath = "!USERDIR!" >> "!SCRIPT!" -echo oLink.WorkingDirectory = "!USERDIR!" >> "!SCRIPT!" -echo oLink.Arguments = "" >> "!SCRIPT!" -echo oLink.IconLocation = "!INSTALLDIR!\srb2win.exe,0" >> "!SCRIPT!" -echo oLink.Save >> "!SCRIPT!" -cscript /nologo "!SCRIPT!" -del "!SCRIPT!" - -: MoveOldInstall - -if exist "!INSTALLDIR!\old-install\*" ( - set "OLDINSTALLDIR=!INSTALLDIR!\old-install-!RANDOM!" -) else ( - set "OLDINSTALLDIR=!INSTALLDIR!\old-install" -) - -mkdir "!OLDINSTALLDIR!" - -:: -:: Move all old install files -:: We support a list of explicit files to copy to old-install -:: And later, we also loop through our staging files, look for the pre-existing copy in -:: install root, then copy that also to old-install -:: - -:: Extract the uninstall-list.txt and uninstall-userdir.txt files from uninstaller.exe -:: if it exists - -if exist "!INSTALLDIR!\uninstall.exe" ( - if NOT ["!SVZIP!"] == [""] ( - "!SVZIP!" x "!INSTALLDIR!\uninstall.exe" "uninstall-list.txt" -o"!INSTALLDIR!" - "!SVZIP!" x "!INSTALLDIR!\uninstall.exe" "uninstall-userdir.txt" -o"!INSTALLDIR!" - ) -) - -set OLDINSTALLCHANGED= - -if exist "!STAGINGDIR!\old-install-list.txt" ( - goto MoveOldInstallOldFiles -) else ( - goto MoveOldInstallNewFiles -) - -: MoveOldInstallOldFiles - -set "TESTFILE=!TEMP!\!RANDOM!.txt" - -:: Do our failsafes before copying the file in the list -:: See uninstall.bat for details -for /F "usebackq tokens=*" %%A in ("!STAGINGDIR!\old-install-list.txt") do ( - if exist "!INSTALLDIR!\%%A" ( - if NOT ["%%A"] == [""] ( - if NOT ["%%A"] == ["%~nx0"] ( - echo %%A> "!TESTFILE!" - findstr /r ".*[<>:\"\"/\\|?*%%].*" "!TESTFILE!" >nul - if !errorlevel! equ 0 ( - echo %%A has invalid characters, skipping... - ) else ( - if exist "!INSTALLDIR!\%%A\*" ( - echo %%A is a folder, skipping... - ) else ( - echo Moving !INSTALLDIR!\%%A to "old-install" folder - echo f | xcopy /y /v "!INSTALLDIR!\%%A" "!OLDINSTALLDIR!\%%A" - if errorlevel 0 del /f /q "!INSTALLDIR!\%%A" - ) - ) - ) - ) - ) -) - -del /q /f "!STAGINGDIR!\old-install-list.txt" - -for %%F in ("!OLDINSTALLDIR!\*") DO ( - set OLDINSTALLCHANGED=1 - goto MoveOldInstallNewFiles -) - -: MoveOldInstallNewFiles - -:: Save a list of standard files -:: So the uninstall script will know what to remove -:: Append to any existing file, in case we are a patch - -dir /b /a-d "!STAGINGDIR!" >> "!INSTALLDIR!\uninstall-list.txt" - -:: Overwrite the last known gamedata folder - -echo !USERDIR! > "!INSTALLDIR!\uninstall-userdir.txt" - -:: Add the install-generated to the uninstall list -:: NO FOLLOWING SPACES AFTER THE FILENAME!!! - -echo uninstall.bat>> "!INSTALLDIR!\uninstall-list.txt" -echo uninstall-list.txt>> "!INSTALLDIR!\uninstall-list.txt" -echo uninstall-userdir.txt>> "!INSTALLDIR!\uninstall-list.txt" -:: *ahem* Prints as ^! SRB2 Data Folder ^!.lnk -:: We need to escape the exclamations (^^!) and the carets themselves (^^^^) -echo ^^^^^^! SRB2 Data Folder ^^^^^^!.lnk>> "!INSTALLDIR!\uninstall-list.txt" - -:: Add the uninstall list files to the uninstall EXE - -if NOT ["!SVZIP!"] == [""] ( - if exist "!INSTALLDIR!\new-install\uninstall.exe" ( - "!SVZIP!" a "!INSTALLDIR!\new-install\uninstall.exe" "!INSTALLDIR!\uninstall-list.txt" -sdel - "!SVZIP!" a "!INSTALLDIR!\new-install\uninstall.exe" "!INSTALLDIR!\uninstall-userdir.txt" -sdel - ) -) - -:: Start moving files - -for %%F in ("!STAGINGDIR!\*") DO ( - if exist "!INSTALLDIR!\%%~nxF" ( - set OLDINSTALLCHANGED=1 - move "!INSTALLDIR!\%%~nxF" "!OLDINSTALLDIR!\%%~nxF" - ) - if NOT ["%%~nxF"] == ["staging.bat"] ( - if NOT ["%%~nxF"] == ["staging.txt"] ( - move "!STAGINGDIR!\%%~nxF" "!INSTALLDIR!\%%~nxF" - ) - ) -) - -: Finished - -del /q /f "!INSTALLDIR!\^! SRB2 INSTALL INSTRUCTIONS ^!.txt" - -set MSGEXE= -if exist "!SystemRoot!\System32\msg.exe" ( - set MSGEXE=!SystemRoot!\System32\msg.exe -) else ( - if exist "!SystemRoot!\Sysnative\msg.exe" ( - set MSGEXE=!SystemRoot!\Sysnative\msg.exe - ) -) - -if ["!OLDINSTALLCHANGED!"] == ["1"] ( - "!systemroot!\explorer.exe" /select, "!OLDINSTALLDIR!" - echo Finished^^! Some of your old installation files were moved to the "old-install" folder. > !TEMP!\srb2msgprompt.txt - echo. >> !TEMP!\srb2msgprompt.txt - echo If you no longer need these files, you may delete the folder safely. >> !TEMP!\srb2msgprompt.txt - echo. >> !TEMP!\srb2msgprompt.txt - echo To run SRB2, go to: Start Menu ^> Programs ^> Sonic Robo Blast 2. >> !TEMP!\srb2msgprompt.txt - !MSGEXE! "!username!" < !TEMP!\srb2msgprompt.txt - del !TEMP!\srb2msgprompt.txt -) else ( - if /I ["!USERDIR!"] == ["!INSTALLDIR!"] ( - "!systemroot!\explorer.exe" "!INSTALLDIR!" - echo Finished^^! > !TEMP!\srb2msgprompt.txt - echo. >> !TEMP!\srb2msgprompt.txt - echo To run SRB2, go to: Start Menu ^> Programs ^> Sonic Robo Blast 2. >> !TEMP!\srb2msgprompt.txt - !MSGEXE! "!username!" < !TEMP!\srb2msgprompt.txt - del !TEMP!\srb2msgprompt.txt - ) else ( - "!systemroot!\explorer.exe" "!USERDIR!" - echo Finished^^! You may find your game data in this folder: > !TEMP!\srb2msgprompt.txt - echo. >> !TEMP!\srb2msgprompt.txt - echo !USERDIR! >> !TEMP!\srb2msgprompt.txt - echo. >> !TEMP!\srb2msgprompt.txt - echo To run SRB2, go to: Start Menu ^> Programs ^> Sonic Robo Blast 2. >> !TEMP!\srb2msgprompt.txt - !MSGEXE! "!username!" < !TEMP!\srb2msgprompt.txt - del !TEMP!\srb2msgprompt.txt - ) -) - -: Attempt to remove OLDINSTALLDIR, in case it's empty -rmdir /q "!OLDINSTALLDIR!" -cd \ -start "" /b "cmd" /s /c " del /f /q "%STAGINGDIR%\*"&rmdir /s /q "%STAGINGDIR%"&exit /b " diff --git a/windows-installer/uninstaller/uninstall.bat b/windows-installer/uninstaller/uninstall.bat deleted file mode 100644 index ed7c3339..00000000 --- a/windows-installer/uninstaller/uninstall.bat +++ /dev/null @@ -1,183 +0,0 @@ -@echo off - -setlocal enabledelayedexpansion - -cls - -set "INSTALLDIR=%~dp0" -set "INSTALLDIR=!INSTALLDIR:~0,-1!" -set /p USERDIR=<"!INSTALLDIR!\uninstall-userdir.txt" -set "USERDIR=!USERDIR:~0,-1!" - -: ProceedPrompt - -if ["%1"] == ["/y"] ( - set "PROCEED=1" -) else ( - set PROCEED= - set /p PROCEED="Are you sure you want to uninstall SRB2? [yes/no] " - - if /I ["!PROCEED:~0,1!"] == ["n"] exit - if /I ["!PROCEED!"] == ["y"] ( - echo Type Yes or No - echo. - goto ProceedPrompt - ) else ( - if /I ["!PROCEED!"] == ["yes"] ( - set PROCEED=1 - ) else ( - echo. - goto ProceedPrompt - ) - ) -) - -:: Failsafe, in case we Ctrl+C and decline "Terminate batch file?" - -if NOT ["!PROCEED!"] == ["1"] ( - exit -) - -: CheckPermissions - -:: Write a dummy file and check for an error. If error, we need administrator rights - -mkdir "!INSTALLDIR!\uninstall-dummy" - -:: TODO elevate automatically -if errorlevel 1 ( - echo We need Administrator Rights to uninstall SRB2. - echo. - echo Try running this uninstaller by right-clicking on the icon - echo and click "Run as administrator" - echo. - set /p ADMINFINAL="Press Enter key to exit. " - exit -) else ( - rmdir /s /q "!INSTALLDIR!\uninstall-dummy" - goto DeleteFiles -) - -: DeleteFiles - -:: Our deletion list is a list of filenames, no paths, in the current folder -:: -:: We apply the following failsafes: -:: 1. Is filename the script itself? -:: 2. Does filename have illegal characters? https://stackoverflow.com/a/33625339/241046 -:: 3. Is filename a directory? -:: -:: TODO hack this to support .\file.txt relative paths -:: Can %%A be substring'd to get only the filename and extension? -:: If so, print that to the temp file instead of the whole line -:: And possibly do the folder check before the invalid char check. -:: ALSO: Don't honor upward relative paths! (..\) -:: -set "TESTFILE=!TEMP!\!RANDOM!.txt" - -for /F "usebackq tokens=*" %%A in ("!INSTALLDIR!\uninstall-list.txt") do ( - if exist "!INSTALLDIR!\%%A" ( - if NOT ["%%A"] == [""] ( - if NOT ["%%A"] == ["%~nx0"] ( - echo %%A> "!TESTFILE!" - findstr /r ".*[<>:\"\"/\\|?*%%].*" "!TESTFILE!" >nul - if !errorlevel! equ 0 ( - echo %%A has invalid characters, skipping... - ) else ( - if exist "!INSTALLDIR!\%%A\*" ( - echo %%A is a folder, skipping... - ) else ( - echo Deleting !INSTALLDIR!\%%A - del /q /f "!INSTALLDIR!\%%A" - ) - ) - ) - ) - ) -) - -del /q /f "!TESTFILE!" - -: AllDone - -:: Delete the program icons -echo Deleting your program icons... -echo. - -cd \ -rmdir /s /q "!AppData!\Microsoft\Windows\Start Menu\Programs\Sonic Robo Blast 2" - -:: Check if our install folder is non-empty - -set USERDIRFILLED= -set INSTALLDIRFILLED= -for /F %%i in ('dir /b /a "!USERDIR!\*"') do ( - if NOT ["%%i"] == ["%~nx0"] ( - set USERDIRFILLED=1 - goto InstallFilledCheck - ) -) - -: InstallFilledCheck - -if /I NOT ["!USERDIR!"] == ["!INSTALLDIR!"] ( - for /F %%i in ('dir /b /a "!INSTALLDIR!\*"') do ( - if ["%%i"] == ["%~nx0"] ( - echo. - ) else ( - set INSTALLDIRFILLED=1 - goto Final - ) - ) -) - -: Final - -echo All done^^! Visit http://www.srb2.org if you want to play SRB2 again^^! -echo. - -set "FINALPROMPT=Press Enter key to exit." -if ["!USERDIRFILLED!"] == ["1"] ( - echo We left your game data and mods alone, so you may delete those manually. - echo. - echo !USERDIR! - echo. - set "FINALPROMPT=Do you want to view your data? [yes/no]" -) - -if ["!INSTALLDIRFILLED!"] == ["1"] ( - echo We left some extra files alone in your install folder. - echo. - echo !INSTALLDIR! - echo. - set "FINALPROMPT=Do you want to view your data? [yes/no]" -) - -set FINALRESPONSE= -set /p FINALRESPONSE="!FINALPROMPT! " - -if NOT ["!FINALPROMPT!"] == ["Press Enter key to exit."] ( - if /I ["!FINALRESPONSE:~0,1!"] == ["y"] ( - if ["!USERDIRFILLED!"] == ["1"] ( - "!SystemRoot!\explorer.exe" "!USERDIR!" - ) - if ["!INSTALLDIRFILLED!"] == ["1"] ( - "!SystemRoot!\explorer.exe" "!INSTALLDIR!" - ) - ) else ( - if ["!FINALRESPONSE!"] == [""] ( - if ["!USERDIRFILLED!"] == ["1"] ( - "!SystemRoot!\explorer.exe" "!USERDIR!" - ) - if ["!INSTALLDIRFILLED!"] == ["1"] ( - "!SystemRoot!\explorer.exe" "!INSTALLDIR!" - ) - ) - ) -) - -: DeferredDelete - -:: Now let's delete our installation folder! -cd \ -start "" /b "cmd" /s /c " del /q /f "%INSTALLDIR%\uninstall.bat"&timeout /t 2 > NUL&rmdir "%INSTALLDIR%"&exit /b "