clean up floating globals
move FS mounting to ArchHooks
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "RageLog.h"
|
||||
#include "RageThreads.h"
|
||||
#include "Foreach.h"
|
||||
#include "arch/ArchHooks/ArchHooks.h"
|
||||
|
||||
#include <cerrno>
|
||||
#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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -10,6 +10,8 @@ public:
|
||||
|
||||
void SetTime( tm newtime );
|
||||
int64_t GetMicrosecondsSinceStart();
|
||||
|
||||
void MountInitialFilesystems( const CString &sDirOfExecutable );
|
||||
};
|
||||
|
||||
#ifdef ARCH_HOOKS
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
void BoostPriority();
|
||||
void UnBoostPriority();
|
||||
void SetupConcurrentRenderingThread();
|
||||
void MountInitialFilesystems( const CString &sDirOfExecutable );
|
||||
|
||||
private:
|
||||
void CheckVideoDriver();
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
CString GetPreferredLanguage();
|
||||
void EnterTimeCriticalSection();
|
||||
void ExitTimeCriticalSection();
|
||||
void MountInitialFilesystems( const CString &sDirOfExecutable );
|
||||
|
||||
protected:
|
||||
//RageMutex *TimeCritMutex;
|
||||
|
||||
Reference in New Issue
Block a user