diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index 5f1b445f24..02b4385f1c 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -7,6 +7,7 @@ #include "RageLog.h" #include "RageThreads.h" #include "Foreach.h" +#include "arch/ArchHooks/ArchHooks.h" #include #if defined(LINUX) @@ -22,8 +23,8 @@ RageFileManager *FILEMAN = NULL; /* Lock this before touching any of these globals (except FILEMAN itself). */ static RageEvent *g_Mutex; -CString InitialWorkingDirectory; -CString DirOfExecutable; +CString RageFileManagerUtil::sInitialWorkingDirectory; +CString RageFileManagerUtil::sDirOfExecutable; struct LoadedDriver { @@ -213,15 +214,15 @@ static CString GetDirOfExecutable( CString argv0 ) static void ChangeToDirOfExecutable( CString argv0 ) { - InitialWorkingDirectory = GetCwd(); - DirOfExecutable = GetDirOfExecutable( argv0 ); + RageFileManagerUtil::sInitialWorkingDirectory = GetCwd(); + RageFileManagerUtil::sDirOfExecutable = GetDirOfExecutable( argv0 ); /* Set the CWD. Any effects of this is platform-specific; most files are read and * written through RageFile. See also RageFileManager::RageFileManager. */ #if defined(_WINDOWS) - chdir( DirOfExecutable + "/.." ); + chdir( RageFileManagerUtil::sDirOfExecutable + "/.." ); #elif defined(MACOSX) - chdir( DirOfExecutable + "/../../.." ); + chdir( sDirOfExecutable + "/../../.." ); #endif } @@ -244,70 +245,7 @@ RageFileManager::RageFileManager( CString argv0 ) void RageFileManager::MountInitialFilesystems() { - /* Add file search paths, higher priority first. */ -#if defined(XBOX) - RageFileManager::Mount( "dir", "D:\\", "/" ); -#elif defined(LINUX) - /* Mount the root filesystem, so we can read files in /proc, /etc, and so on. - * This is /rootfs, not /root, to avoid confusion with root's home directory. */ - RageFileManager::Mount( "dir", "/", "/rootfs" ); - - /* Mount /proc, so Alsa9Buf::GetSoundCardDebugInfo() and others can access it. - * (Deprecated; use rootfs.) */ - RageFileManager::Mount( "dir", "/proc", "/proc" ); - - /* We can almost do this, to have machine profiles be system-global to eg. share - * scores. It would need to handle permissions properly. */ -/* RageFileManager::Mount( "dir", "/var/lib/games/stepmania", "/Save/Profiles" ); */ - - // CString Home = getenv( "HOME" ) + "/" + PRODUCT_NAME; - - /* - * Next: path to write general mutable user data. If the above path fails (eg. - * wrong permissions, doesn't exist), machine memcard data will also go in here. - * XXX: It seems silly to have two ~ directories. If we're going to create a - * directory on our own, it seems like it should be a dot directory, but it - * seems wrong to put lots of data (eg. music) in one. Hmm. - */ - /* XXX: create */ -/* RageFileManager::Mount( "dir", Home + "." PRODUCT_NAME, "/Data" ); */ - - /* Next, search ~/StepMania. This is where users can put music, themes, etc. */ - /* RageFileManager::Mount( "dir", Home + PRODUCT_NAME, "/" ); */ - - /* Search for a directory with "Songs" in it. Be careful: the CWD is likely to - * be ~, and it's possible that some users will have a ~/Songs/ directory that - * has nothing to do with us, so check the initial directory last. */ - CString Root = ""; - struct stat st; - if( Root == "" && !stat( DirOfExecutable + "/Songs", &st ) && st.st_mode&S_IFDIR ) - Root = DirOfExecutable; - if( Root == "" && !stat( InitialWorkingDirectory + "/Songs", &st ) && st.st_mode&S_IFDIR ) - Root = InitialWorkingDirectory; - if( Root == "" ) - RageException::Throw( "Couldn't find \"Songs\"" ); - - RageFileManager::Mount( "dir", Root, "/" ); -#elif defined(_WINDOWS) - /* All Windows data goes in the directory one level above the executable. */ - CHECKPOINT_M( ssprintf( "DOE \"%s\"", DirOfExecutable.c_str()) ); - CStringArray parts; - split( DirOfExecutable, "/", parts ); - CHECKPOINT_M( ssprintf( "... %i parts", parts.size()) ); - ASSERT_M( parts.size() > 1, ssprintf("Strange DirOfExecutable: %s", DirOfExecutable.c_str()) ); - CString Dir = join( "/", parts.begin(), parts.end()-1 ); - RageFileManager::Mount( "dir", Dir, "/" ); -#elif defined(MACOSX) - CHECKPOINT_M( ssprintf("DOE \"%s\"", DirOfExecutable.c_str()) ); - CStringArray parts; - split( DirOfExecutable, "/", parts ); - ASSERT( parts.size() > 3 ); - CString Dir = '/' + join( "/", parts.begin(), parts.end()-3 ); - RageFileManager::Mount( "dir", Dir, "/" ); -#else - /* Paths relative to the CWD: */ - RageFileManager::Mount( "dir", ".", "/" ); -#endif + HOOKS->MountInitialFilesystems( RageFileManagerUtil::sDirOfExecutable ); } RageFileManager::~RageFileManager() diff --git a/stepmania/src/RageFileManager.h b/stepmania/src/RageFileManager.h index 4625a2d448..9b91806ba0 100644 --- a/stepmania/src/RageFileManager.h +++ b/stepmania/src/RageFileManager.h @@ -3,8 +3,12 @@ #ifndef RAGE_FILE_MANAGER_H #define RAGE_FILE_MANAGER_H -extern CString InitialWorkingDirectory; -extern CString DirOfExecutable; +namespace RageFileManagerUtil +{ + extern CString sInitialWorkingDirectory; + extern CString sDirOfExecutable; +} + class RageFileDriver; class RageFileBasic; diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.h b/stepmania/src/arch/ArchHooks/ArchHooks.h index 35fbc55c85..5f93a616ea 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks.h @@ -70,6 +70,11 @@ public: */ static int64_t GetMicrosecondsSinceStart( bool bAccurate ); + /* + * Add file search paths, higher priority first. + */ + virtual void MountInitialFilesystems( const CString &sDirOfExecutable ) = 0; + private: /* This are helpers for GetMicrosecondsSinceStart on systems with a timer * that may loop or move backwards. */ diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp index 20e8e0df34..1c7b55d88a 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Unix.cpp @@ -183,6 +183,58 @@ void ArchHooks_Unix::SetTime( tm newtime ) system( "hwclock --systohc" ); } +#inlcude "RageFileManager.h" + +void ArchHooks_Unix::MountInitialFilesystems( const CString &sDirOfExecutable ) +{ +#if defined(LINUX) + HOOKS->MountInitialFilesystems( sDirOfExecutable ); + /* Mount the root filesystem, so we can read files in /proc, /etc, and so on. + * This is /rootfs, not /root, to avoid confusion with root's home directory. */ + RageFileManager::Mount( "dir", "/", "/rootfs" ); + + /* Mount /proc, so Alsa9Buf::GetSoundCardDebugInfo() and others can access it. + * (Deprecated; use rootfs.) */ + RageFileManager::Mount( "dir", "/proc", "/proc" ); + + /* We can almost do this, to have machine profiles be system-global to eg. share + * scores. It would need to handle permissions properly. */ +/* RageFileManager::Mount( "dir", "/var/lib/games/stepmania", "/Save/Profiles" ); */ + + // CString Home = getenv( "HOME" ) + "/" + PRODUCT_NAME; + + /* + * Next: path to write general mutable user data. If the above path fails (eg. + * wrong permissions, doesn't exist), machine memcard data will also go in here. + * XXX: It seems silly to have two ~ directories. If we're going to create a + * directory on our own, it seems like it should be a dot directory, but it + * seems wrong to put lots of data (eg. music) in one. Hmm. + */ + /* XXX: create */ +/* RageFileManager::Mount( "dir", Home + "." PRODUCT_NAME, "/Data" ); */ + + /* Next, search ~/StepMania. This is where users can put music, themes, etc. */ + /* RageFileManager::Mount( "dir", Home + PRODUCT_NAME, "/" ); */ + + /* Search for a directory with "Songs" in it. Be careful: the CWD is likely to + * be ~, and it's possible that some users will have a ~/Songs/ directory that + * has nothing to do with us, so check the initial directory last. */ + CString Root = ""; + struct stat st; + if( Root == "" && !stat( sDirOfExecutable + "/Songs", &st ) && st.st_mode&S_IFDIR ) + Root = sDirOfExecutable; + if( Root == "" && !stat( InitialWorkingDirectory + "/Songs", &st ) && st.st_mode&S_IFDIR ) + Root = InitialWorkingDirectory; + if( Root == "" ) + RageException::Throw( "Couldn't find \"Songs\"" ); + + RageFileManager::Mount( "dir", Root, "/" ); +#else + /* Paths relative to the CWD: */ + RageFileManager::Mount( "dir", ".", "/" ); +#endif +} + /* * (c) 2003-2004 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Unix.h b/stepmania/src/arch/ArchHooks/ArchHooks_Unix.h index 98d63d9a26..a6930ad5ef 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Unix.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Unix.h @@ -10,6 +10,8 @@ public: void SetTime( tm newtime ); int64_t GetMicrosecondsSinceStart(); + + void MountInitialFilesystems( const CString &sDirOfExecutable ); }; #ifdef ARCH_HOOKS diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h index e10fe13780..cb371b48ca 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h @@ -23,6 +23,7 @@ public: void BoostPriority(); void UnBoostPriority(); void SetupConcurrentRenderingThread(); + void MountInitialFilesystems( const CString &sDirOfExecutable ); private: void CheckVideoDriver(); diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.cpp index 744aa19343..87de4181a9 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.cpp @@ -133,6 +133,13 @@ ArchHooks_Xbox::~ArchHooks_Xbox() XLaunchNewImage( NULL, NULL ); } +#inlcude "RageFileManager.h" + +void ArchHooks_Xbox::MountInitialFilesystems( const CString &sDirOfExecutable ) +{ + FILEMAN->Mount( "dir", "D:\\", "/" ); +} + /* * (c) 2003-2004 Glenn Maynard, Chris Danford * All rights reserved. diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.h b/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.h index b9c438b0cc..e0abcdad87 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Xbox.h @@ -9,6 +9,8 @@ class ArchHooks_Xbox: public ArchHooks public: ArchHooks_Xbox(); ~ArchHooks_Xbox(); + + void MountInitialFilesystems( const CString &sDirOfExecutable ); }; // Read a 64 bit MSR register diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp index 662acbd3fc..44a449df8f 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp @@ -287,6 +287,23 @@ int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) return ret; } +#inlcude "RageFileManager.h" + +void ArchHooks_darwin::MountInitialFilesystems( const CString &sDirOfExecutable ) +{ +#if defined(MACOSX) + CHECKPOINT_M( ssprintf("DOE \"%s\"", sDirOfExecutable.c_str()) ); + CStringArray parts; + split( sDirOfExecutable, "/", parts ); + ASSERT( parts.size() > 3 ); + CString Dir = '/' + join( "/", parts.begin(), parts.end()-3 ); + RageFileManager::Mount( "dir", Dir, "/" ); +else + /* Paths relative to the CWD: */ + FILEMAN->Mount( "dir", ".", "/" ); +#endif +} + /* * (c) 2003-2005 Steve Checkoway * All rights reserved. diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h index 03622aedc9..e9e9c87c5d 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h @@ -13,6 +13,7 @@ public: CString GetPreferredLanguage(); void EnterTimeCriticalSection(); void ExitTimeCriticalSection(); + void MountInitialFilesystems( const CString &sDirOfExecutable ); protected: //RageMutex *TimeCritMutex;