From ded559d84a397d75b79f4c4c01a918a4a22a9882 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 5 Sep 2003 06:39:32 +0000 Subject: [PATCH] Make DirOfExecutable available. --- stepmania/src/StepMania.cpp | 23 +++++++++++++++-------- stepmania/src/StepMania.h | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 2258a6bc74..e04291ebe1 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -78,22 +78,29 @@ char **g_argv = NULL; static bool g_bHasFocus = true; static bool g_bQuitting = false; +CString DirOfExecutable; + static void ChangeToDirOfExecutable(const char *argv0) { + DirOfExecutable = argv0; + // strip off executable name + unsigned n = DirOfExecutable.find_last_of("/\\"); + if( n != DirOfExecutable.npos ) + DirOfExecutable.erase(n); + else + DirOfExecutable.erase(); + + if( DirOfExecutable.size() == 0 || (DirOfExecutable[0] != '/' && DirOfExecutable[0] != '\\') ) + DirOfExecutable = GetCwd() + "/" + DirOfExecutable; + + printf("doe = '%s'\n", DirOfExecutable.c_str()); #ifndef _XBOX /* Make sure the current directory is the root program directory * We probably shouldn't do this; rather, we should know where things * are and use paths as needed, so we don't depend on the binary being * in the same place as "Songs" ... */ if( !DoesFileExist("Songs") ) - { - // strip off executable name - CString dir = argv0; - unsigned n = dir.find_last_of("/\\"); - if (n != dir.npos) dir.erase(n); - - chdir( dir.c_str() ); - } + chdir( DirOfExecutable ); #endif } diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 90f9896a57..15dad1a030 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -20,6 +20,8 @@ void ResetGame(); extern HWND g_hWndMain; #endif +extern CString DirOfExecutable; + extern int g_argc; extern char **g_argv;