mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-11-10 15:22:20 +00:00
Save srb2path to %LOCALAPPDATA%\SRB2Kart\lastwaddir, and chdir here if srb2.srb cannot be found
Windows code goes brrr
This commit is contained in:
parent
c76c1b8420
commit
2a2d43a20b
3 changed files with 98 additions and 5 deletions
33
src/d_main.c
33
src/d_main.c
|
@ -845,6 +845,24 @@ static inline void D_CleanFile(char **filearray)
|
|||
// Identify the SRB2 version, and IWAD file to use.
|
||||
// ==========================================================================
|
||||
|
||||
static boolean AddIWAD(char *srb2wad1, char *srb2wad2)
|
||||
{
|
||||
if (srb2wad2 != NULL && FIL_ReadFileOK(srb2wad2))
|
||||
{
|
||||
D_AddFile(srb2wad2, startupwadfiles);
|
||||
return true;
|
||||
}
|
||||
else if (srb2wad1 != NULL && FIL_ReadFileOK(srb2wad1))
|
||||
{
|
||||
D_AddFile(srb2wad1, startupwadfiles);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void IdentifyVersion(void)
|
||||
{
|
||||
char *srb2wad1, *srb2wad2;
|
||||
|
@ -896,12 +914,17 @@ static void IdentifyVersion(void)
|
|||
configfile[sizeof configfile - 1] = '\0';
|
||||
|
||||
// Load the IWAD
|
||||
if (srb2wad2 != NULL && FIL_ReadFileOK(srb2wad2))
|
||||
D_AddFile(srb2wad2, startupwadfiles);
|
||||
else if (srb2wad1 != NULL && FIL_ReadFileOK(srb2wad1))
|
||||
D_AddFile(srb2wad1, startupwadfiles);
|
||||
if (AddIWAD(srb2wad1, srb2wad2))
|
||||
{
|
||||
I_SaveCurrentWadDirectory();
|
||||
}
|
||||
else
|
||||
I_Error("SRB2.SRB/SRB2.WAD not found! Expected in %s, ss files: %s or %s\n", srb2waddir, srb2wad1, srb2wad2);
|
||||
{
|
||||
if (!( I_UseSavedWadDirectory() && AddIWAD(srb2wad1, srb2wad2) ))
|
||||
{
|
||||
I_Error("SRB2.SRB/SRB2.WAD not found! Expected in %s, ss files: %s or %s\n", srb2waddir, srb2wad1, srb2wad2);
|
||||
}
|
||||
}
|
||||
|
||||
if (srb2wad1)
|
||||
free(srb2wad1);
|
||||
|
|
|
@ -318,6 +318,15 @@ const CPUInfoFlags *I_CPUInfo(void);
|
|||
*/
|
||||
const char *I_LocateWad(void);
|
||||
|
||||
/** \brief Save current wad directory to appdata
|
||||
*/
|
||||
void I_SaveCurrentWadDirectory(void);
|
||||
|
||||
/** \brief Change directory to last known directory saved in appdata
|
||||
\return whether the directory could be saved
|
||||
*/
|
||||
boolean I_UseSavedWadDirectory(void);
|
||||
|
||||
/** \brief First Joystick's events
|
||||
*/
|
||||
void I_GetJoystickEvents(void);
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#ifdef _WIN32
|
||||
#define RPC_NO_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include "../doomtype.h"
|
||||
typedef BOOL (WINAPI *p_GetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
|
||||
typedef BOOL (WINAPI *p_IsProcessorFeaturePresent) (DWORD);
|
||||
|
@ -3758,6 +3759,66 @@ static const char *locateWad(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static FILE * openAppDataFile(const char *filename, const char *mode)
|
||||
{
|
||||
FILE * file = NULL;
|
||||
char kdir[MAX_PATH];
|
||||
|
||||
if (SHGetFolderPathAndSubDirA(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE,
|
||||
NULL, 0, "SRB2Kart", kdir) == S_OK)
|
||||
{
|
||||
strcat(kdir, "\\");
|
||||
strcat(kdir, filename);
|
||||
file = fopen(kdir, mode);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
#endif
|
||||
|
||||
void I_SaveCurrentWadDirectory(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char path[MAX_PATH];
|
||||
FILE * file = openAppDataFile("lastwaddir", "w");
|
||||
if (file != NULL)
|
||||
{
|
||||
if (strcmp(srb2path, ".") == 0)
|
||||
{
|
||||
GetCurrentDirectoryA(sizeof path, path);
|
||||
fputs(path, file);
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs(srb2path, file);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
boolean I_UseSavedWadDirectory(void)
|
||||
{
|
||||
boolean ok = false;
|
||||
#ifdef _WIN32
|
||||
char path[MAX_PATH];
|
||||
FILE * file = openAppDataFile("lastwaddir", "r");
|
||||
if (file != NULL)
|
||||
{
|
||||
if (fgets(path, sizeof path, file) != NULL)
|
||||
{
|
||||
I_OutputMsg(
|
||||
"Going to the last known directory with srb2.srb: %s\n",
|
||||
path);
|
||||
ok = SetCurrentDirectoryA(path);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
return ok;
|
||||
}
|
||||
|
||||
const char *I_LocateWad(void)
|
||||
{
|
||||
const char *waddir;
|
||||
|
|
Loading…
Reference in a new issue