mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-13 13:21:31 +00:00
Merge branch 'better-windows-path' into 'next'
SetCurrentDirectory to where the exe lives See merge request KartKrew/Kart-Public!219
This commit is contained in:
commit
55dccfe801
4 changed files with 20 additions and 78 deletions
11
src/d_main.c
11
src/d_main.c
|
@ -895,16 +895,9 @@ static void IdentifyVersion(void)
|
|||
}
|
||||
|
||||
// Load the IWAD
|
||||
if (AddIWAD())
|
||||
if (! AddIWAD())
|
||||
{
|
||||
I_SaveCurrentWadDirectory();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!( I_UseSavedWadDirectory() && AddIWAD() ))
|
||||
{
|
||||
I_Error("SRB2.SRB not found! Expected in %s\n", srb2waddir);
|
||||
}
|
||||
I_Error("SRB2.SRB not found! Expected in %s\n", srb2waddir);
|
||||
}
|
||||
|
||||
// will be overwritten in case of -cdrom or unix/win home
|
||||
|
|
|
@ -318,15 +318,6 @@ 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);
|
||||
|
|
|
@ -97,6 +97,20 @@ static inline VOID MakeCodeWritable(VOID)
|
|||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
static void
|
||||
ChDirToExe (void)
|
||||
{
|
||||
CHAR path[MAX_PATH];
|
||||
if (GetModuleFileNameA(NULL, path, MAX_PATH) > 0)
|
||||
{
|
||||
strrchr(path, '\\')[0] = '\0';
|
||||
SetCurrentDirectoryA(path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** \brief The main function
|
||||
|
||||
\param argc number of arg
|
||||
|
@ -126,6 +140,10 @@ int main(int argc, char **argv)
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
ChDirToExe();
|
||||
#endif
|
||||
|
||||
logdir = D_Home();
|
||||
|
||||
#ifdef LOGMESSAGES
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#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);
|
||||
|
@ -3766,65 +3765,6 @@ 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
|
||||
FILE * file = openAppDataFile("lastwaddir", "r");
|
||||
if (file != NULL)
|
||||
{
|
||||
if (fgets(srb2path, sizeof srb2path, file) != NULL)
|
||||
{
|
||||
I_OutputMsg(
|
||||
"Going to the last known directory with srb2.srb: %s\n",
|
||||
srb2path);
|
||||
ok = SetCurrentDirectoryA(srb2path);
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
return ok;
|
||||
}
|
||||
|
||||
const char *I_LocateWad(void)
|
||||
{
|
||||
const char *waddir;
|
||||
|
|
Loading…
Reference in a new issue