mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-14 13:51:31 +00:00
Just SetCurrentDirectory to the exe's folder on windoze
This commit is contained in:
parent
328d6d9a36
commit
3e6b45abe9
4 changed files with 19 additions and 80 deletions
12
src/d_main.c
12
src/d_main.c
|
@ -895,17 +895,7 @@ static void IdentifyVersion(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the IWAD
|
// Load the IWAD
|
||||||
if (AddIWAD())
|
AddIWAD();
|
||||||
{
|
|
||||||
I_SaveCurrentWadDirectory();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!( I_UseSavedWadDirectory() && AddIWAD() ))
|
|
||||||
{
|
|
||||||
I_Error("SRB2.SRB not found! Expected in %s\n", srb2waddir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// will be overwritten in case of -cdrom or unix/win home
|
// will be overwritten in case of -cdrom or unix/win home
|
||||||
snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2waddir);
|
snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2waddir);
|
||||||
|
|
|
@ -318,15 +318,6 @@ const CPUInfoFlags *I_CPUInfo(void);
|
||||||
*/
|
*/
|
||||||
const char *I_LocateWad(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
|
/** \brief First Joystick's events
|
||||||
*/
|
*/
|
||||||
void I_GetJoystickEvents(void);
|
void I_GetJoystickEvents(void);
|
||||||
|
|
|
@ -97,6 +97,20 @@ static inline VOID MakeCodeWritable(VOID)
|
||||||
#endif
|
#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
|
/** \brief The main function
|
||||||
|
|
||||||
\param argc number of arg
|
\param argc number of arg
|
||||||
|
@ -126,6 +140,10 @@ int main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
ChDirToExe();
|
||||||
|
#endif
|
||||||
|
|
||||||
logdir = D_Home();
|
logdir = D_Home();
|
||||||
|
|
||||||
#ifdef LOGMESSAGES
|
#ifdef LOGMESSAGES
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define RPC_NO_WINDOWS_H
|
#define RPC_NO_WINDOWS_H
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shlobj.h>
|
|
||||||
#include "../doomtype.h"
|
#include "../doomtype.h"
|
||||||
typedef BOOL (WINAPI *p_GetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
|
typedef BOOL (WINAPI *p_GetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
|
||||||
typedef BOOL (WINAPI *p_IsProcessorFeaturePresent) (DWORD);
|
typedef BOOL (WINAPI *p_IsProcessorFeaturePresent) (DWORD);
|
||||||
|
@ -3766,65 +3765,6 @@ static const char *locateWad(void)
|
||||||
return NULL;
|
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 *I_LocateWad(void)
|
||||||
{
|
{
|
||||||
const char *waddir;
|
const char *waddir;
|
||||||
|
|
Loading…
Reference in a new issue