diff --git a/src/d_main.c b/src/d_main.c index 4b7db807..6c209e32 100644 --- a/src/d_main.c +++ b/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 diff --git a/src/i_system.h b/src/i_system.h index 2f4b1b5c..3e589c69 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -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); diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index 41874e9f..a2ce653e 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -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 diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 4cdac36b..51f708d0 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -34,7 +34,6 @@ #ifdef _WIN32 #define RPC_NO_WINDOWS_H #include -#include #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;