mirror of https://github.com/PCSX2/pcsx2.git
Cleaned up Path namespace and moved it and wxDirName to /common/Utilities.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1803 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
87d038949e
commit
76045a4722
|
@ -69,7 +69,8 @@
|
||||||
<Unit filename="../../include/Utilities/Exceptions.h" />
|
<Unit filename="../../include/Utilities/Exceptions.h" />
|
||||||
<Unit filename="../../include/Utilities/General.h" />
|
<Unit filename="../../include/Utilities/General.h" />
|
||||||
<Unit filename="../../include/Utilities/MemcpyFast.h" />
|
<Unit filename="../../include/Utilities/MemcpyFast.h" />
|
||||||
<Unit filename="../../include/Utilities/RedtapeWindows.h" />
|
<Unit filename="../../include/Utilities/Path.h" />
|
||||||
|
<Unit filename="../../include/Utilities/RedtapeWindows.h" />
|
||||||
<Unit filename="../../include/Utilities/SafeArray.h" />
|
<Unit filename="../../include/Utilities/SafeArray.h" />
|
||||||
<Unit filename="../../include/Utilities/ScopedPtr.h" />
|
<Unit filename="../../include/Utilities/ScopedPtr.h" />
|
||||||
<Unit filename="../../include/Utilities/StringHelpers.h" />
|
<Unit filename="../../include/Utilities/StringHelpers.h" />
|
||||||
|
@ -84,8 +85,8 @@
|
||||||
<Unit filename="../../src/Utilities/Linux/LnxHostSys.cpp" />
|
<Unit filename="../../src/Utilities/Linux/LnxHostSys.cpp" />
|
||||||
<Unit filename="../../src/Utilities/Linux/LnxMisc.cpp" />
|
<Unit filename="../../src/Utilities/Linux/LnxMisc.cpp" />
|
||||||
<Unit filename="../../src/Utilities/Linux/LnxThreads.cpp" />
|
<Unit filename="../../src/Utilities/Linux/LnxThreads.cpp" />
|
||||||
<Unit filename="../../src/Utilities/PrecompiledHeader.h" />
|
<Unit filename="../../src/Utilities/PathUtils.cpp" />
|
||||||
<Unit filename="../../src/Utilities/StringHelpers.cpp" />
|
<Unit filename="../../src/Utilities/StringHelpers.cpp" />
|
||||||
<Unit filename="../../src/Utilities/ThreadTools.cpp" />
|
<Unit filename="../../src/Utilities/ThreadTools.cpp" />
|
||||||
<Unit filename="../../src/Utilities/vssprintf.cpp" />
|
<Unit filename="../../src/Utilities/vssprintf.cpp" />
|
||||||
<Unit filename="../../src/Utilities/x86/MemcpyFast.S" />
|
<Unit filename="../../src/Utilities/x86/MemcpyFast.S" />
|
||||||
|
|
|
@ -210,6 +210,10 @@
|
||||||
RelativePath="..\..\src\Utilities\x86\MemcpyFast.cpp"
|
RelativePath="..\..\src\Utilities\x86\MemcpyFast.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\src\Utilities\PathUtils.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\Utilities\StringHelpers.cpp"
|
RelativePath="..\..\src\Utilities\StringHelpers.cpp"
|
||||||
>
|
>
|
||||||
|
@ -388,6 +392,10 @@
|
||||||
RelativePath="..\..\include\Utilities\MemcpyFast.h"
|
RelativePath="..\..\include\Utilities\MemcpyFast.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\include\Utilities\Path.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\Utilities\PrecompiledHeader.h"
|
RelativePath="..\..\src\Utilities\PrecompiledHeader.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -13,18 +13,10 @@
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _PCSX2_PATHS_H_
|
#include <wx/filename.h>
|
||||||
#define _PCSX2_PATHS_H_
|
|
||||||
|
|
||||||
#define g_MaxPath 255 // 255 is safer with antiquated Win32 ASCII APIs.
|
#define g_MaxPath 255 // 255 is safer with antiquated Win32 ASCII APIs.
|
||||||
|
|
||||||
//#ifdef __LINUX__
|
|
||||||
//extern char MAIN_DIR[g_MaxPath];
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
// Windows.h namespace pollution!
|
|
||||||
#undef CreateDirectory
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
class wxDirName : protected wxFileName
|
class wxDirName : protected wxFileName
|
||||||
|
@ -32,8 +24,7 @@ class wxDirName : protected wxFileName
|
||||||
public:
|
public:
|
||||||
explicit wxDirName( const wxFileName& src )
|
explicit wxDirName( const wxFileName& src )
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( src.IsDir(), L"Warning: Creating a directory from what looks to be a filename..." );
|
Assign( src.GetPath(), wxEmptyString );
|
||||||
Assign( src.GetPath() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDirName() : wxFileName() {}
|
wxDirName() : wxFileName() {}
|
||||||
|
@ -67,7 +58,9 @@ public:
|
||||||
bool IsReadable() const { return IsDirReadable(); }
|
bool IsReadable() const { return IsDirReadable(); }
|
||||||
bool Exists() const { return DirExists(); }
|
bool Exists() const { return DirExists(); }
|
||||||
bool IsOk() const { return wxFileName::IsOk(); }
|
bool IsOk() const { return wxFileName::IsOk(); }
|
||||||
|
bool IsRelative() const { return wxFileName::IsRelative(); }
|
||||||
|
bool IsAbsolute() const { return wxFileName::IsAbsolute(); }
|
||||||
|
|
||||||
bool SameAs( const wxDirName& filepath ) const
|
bool SameAs( const wxDirName& filepath ) const
|
||||||
{
|
{
|
||||||
return wxFileName::SameAs( filepath );
|
return wxFileName::SameAs( filepath );
|
||||||
|
@ -119,89 +112,21 @@ public:
|
||||||
wxFileName& GetFilename() { return *this; }
|
wxFileName& GetFilename() { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// remove windows.h namespace pollution:
|
|
||||||
#undef GetFileSize
|
|
||||||
#undef CreateDirectory
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Path Namespace
|
// Path Namespace
|
||||||
// Cross-platform utilities for manipulation of paths and filenames.
|
// Cross-platform utilities for manipulation of paths and filenames.
|
||||||
//
|
//
|
||||||
namespace Path
|
namespace Path
|
||||||
{
|
{
|
||||||
extern bool IsRooted( const wxString& path );
|
extern bool IsRelative( const wxString& path );
|
||||||
extern int GetFileSize( const wxString& path );
|
|
||||||
|
extern wxString Combine( const wxString& srcPath, const wxString& srcFile );
|
||||||
extern wxString Combine( const wxString& srcPath, const wxString& srcFile );
|
extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile );
|
||||||
extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile );
|
extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile );
|
||||||
extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile );
|
extern wxString ReplaceExtension( const wxString& src, const wxString& ext );
|
||||||
extern wxString ReplaceExtension( const wxString& src, const wxString& ext );
|
extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename );
|
||||||
extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename );
|
extern wxString GetFilename( const wxString& src );
|
||||||
extern wxString GetFilename( const wxString& src );
|
extern wxString GetDirectory( const wxString& src );
|
||||||
extern wxString GetDirectory( const wxString& src );
|
extern wxString GetFilenameWithoutExt( const wxString& src );
|
||||||
extern wxString GetFilenameWithoutExt( const wxString& src );
|
extern wxString GetRootDirectory( const wxString& src );
|
||||||
extern wxString GetRootDirectory( const wxString& src );
|
|
||||||
|
|
||||||
extern void CreateDirectory( const wxString& src );
|
|
||||||
extern void RemoveDirectory( const wxString& src );
|
|
||||||
}
|
}
|
||||||
extern std::string GetWorkingDirectory(void);
|
|
||||||
extern void ChangeDirectory(const std::string& src);
|
|
||||||
enum FoldersEnum_t
|
|
||||||
{
|
|
||||||
FolderId_Plugins = 0,
|
|
||||||
FolderId_Settings,
|
|
||||||
FolderId_Bios,
|
|
||||||
FolderId_Snapshots,
|
|
||||||
FolderId_Savestates,
|
|
||||||
FolderId_MemoryCards,
|
|
||||||
FolderId_Logs,
|
|
||||||
FolderId_COUNT
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// PathDefs Namespace -- contains default values for various pcsx2 path names and locations.
|
|
||||||
//
|
|
||||||
// Note: The members of this namespace are intended for default value initialization only.
|
|
||||||
// Most of the time you should use the path folder assignments in g_Conf instead, since those
|
|
||||||
// are user-configurable.
|
|
||||||
//
|
|
||||||
namespace PathDefs
|
|
||||||
{
|
|
||||||
// complete pathnames are returned by these functions
|
|
||||||
// For 99% of all code, you should use these.
|
|
||||||
|
|
||||||
extern wxDirName GetDocuments();
|
|
||||||
extern wxDirName GetSnapshots();
|
|
||||||
extern wxDirName GetBios();
|
|
||||||
extern wxDirName GetThemes();
|
|
||||||
extern wxDirName GetPlugins();
|
|
||||||
extern wxDirName GetSavestates();
|
|
||||||
extern wxDirName GetMemoryCards();
|
|
||||||
extern wxDirName GetSettings();
|
|
||||||
extern wxDirName GetLogs();
|
|
||||||
extern wxDirName GetThemes();
|
|
||||||
|
|
||||||
extern wxDirName Get( FoldersEnum_t folderidx );
|
|
||||||
|
|
||||||
// Base folder names used to extend out the documents/approot folder base into a complete
|
|
||||||
// path. These are typically for internal AppConfig use only, barring a few special cases.
|
|
||||||
namespace Base
|
|
||||||
{
|
|
||||||
extern const wxDirName& Snapshots();
|
|
||||||
extern const wxDirName& Savestates();
|
|
||||||
extern const wxDirName& MemoryCards();
|
|
||||||
extern const wxDirName& Settings();
|
|
||||||
extern const wxDirName& Plugins();
|
|
||||||
extern const wxDirName& Themes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace FilenameDefs
|
|
||||||
{
|
|
||||||
extern wxFileName GetConfig();
|
|
||||||
extern wxFileName GetUsermodeConfig();
|
|
||||||
extern const wxFileName& Memcard( int slot );
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,173 @@
|
||||||
|
/* PCSX2 - PS2 Emulator for PCs
|
||||||
|
* Copyright (C) 2002-2009 PCSX2 Dev Team
|
||||||
|
*
|
||||||
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||||
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "Path.h"
|
||||||
|
|
||||||
|
#ifdef __LINUX__
|
||||||
|
#ifndef _S_IFDIR
|
||||||
|
#define _S_IFDIR S_IFDIR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _S_IFREG
|
||||||
|
#define _S_IFREG S_IFREG
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <direct.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
// wxDirName Implementations
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxFileName wxDirName::Combine( const wxFileName& right ) const
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wxDirName concatenation." );
|
||||||
|
if( right.IsAbsolute() )
|
||||||
|
return right;
|
||||||
|
|
||||||
|
// Append any directory parts from right, and then set the filename.
|
||||||
|
// Except we can't do that because our m_members are private (argh!) and there is no API
|
||||||
|
// for getting each component of the path. So instead let's use Normalize:
|
||||||
|
|
||||||
|
wxFileName result( right );
|
||||||
|
result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDirName wxDirName::Combine( const wxDirName& right ) const
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( IsDir() && right.IsDir(), L"Warning: Malformed directory name detected during wDirName concatenation." );
|
||||||
|
|
||||||
|
wxDirName result( right );
|
||||||
|
result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDirName& wxDirName::Normalize( int flags, const wxString& cwd )
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." );
|
||||||
|
if( !wxFileName::Normalize( flags, cwd ) )
|
||||||
|
throw Exception::RuntimeError( "wxDirName::Normalize operation failed." );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDirName& wxDirName::MakeRelativeTo( const wxString& pathBase )
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." );
|
||||||
|
if( !wxFileName::MakeRelativeTo( pathBase ) )
|
||||||
|
throw Exception::RuntimeError( "wxDirName::MakeRelativeTo operation failed." );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDirName& wxDirName::MakeAbsolute( const wxString& cwd )
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." );
|
||||||
|
if( !wxFileName::MakeAbsolute( cwd ) )
|
||||||
|
throw Exception::RuntimeError( "wxDirName::MakeAbsolute operation failed." );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDirName::Rmdir()
|
||||||
|
{
|
||||||
|
if( !Exists() ) return;
|
||||||
|
wxFileName::Rmdir();
|
||||||
|
// TODO : Throw exception if operation failed? Do we care?
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDirName::Mkdir()
|
||||||
|
{
|
||||||
|
if( Exists() ) return true;
|
||||||
|
|
||||||
|
// Recursively create child directories as needed:
|
||||||
|
wxDirName recurse( *this );
|
||||||
|
recurse.RemoveLastDir();
|
||||||
|
if( !recurse.Mkdir() ) return false;
|
||||||
|
|
||||||
|
return wxFileName::Mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
// Path namespace (wxFileName helpers)
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
bool Path::IsRelative( const wxString& path )
|
||||||
|
{
|
||||||
|
return wxDirName( path ).IsRelative();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Concatenates two pathnames together, inserting delimiters (backslash on win32)
|
||||||
|
// as needed! Assumes the 'dest' is allocated to at least g_MaxPath length.
|
||||||
|
//
|
||||||
|
wxString Path::Combine( const wxString& srcPath, const wxString& srcFile )
|
||||||
|
{
|
||||||
|
return (wxDirName( srcPath ) + srcFile).GetFullPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString Path::Combine( const wxDirName& srcPath, const wxFileName& srcFile )
|
||||||
|
{
|
||||||
|
return (srcPath + srcFile).GetFullPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString Path::Combine( const wxString& srcPath, const wxDirName& srcFile )
|
||||||
|
{
|
||||||
|
return ((wxDirName)srcPath + srcFile).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replaces the extension of the file with the one given.
|
||||||
|
// This function works for path names as well as file names.
|
||||||
|
wxString Path::ReplaceExtension( const wxString& src, const wxString& ext )
|
||||||
|
{
|
||||||
|
wxFileName jojo( src );
|
||||||
|
jojo.SetExt( ext );
|
||||||
|
return jojo.GetFullPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString Path::ReplaceFilename( const wxString& src, const wxString& newfilename )
|
||||||
|
{
|
||||||
|
wxFileName jojo( src );
|
||||||
|
jojo.SetFullName( newfilename );
|
||||||
|
return jojo.GetFullPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString Path::GetFilename( const wxString& src )
|
||||||
|
{
|
||||||
|
return wxFileName(src).GetFullName();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString Path::GetFilenameWithoutExt( const wxString& src )
|
||||||
|
{
|
||||||
|
return wxFileName(src).GetName();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString Path::GetDirectory( const wxString& src )
|
||||||
|
{
|
||||||
|
return wxFileName(src).GetPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// returns the base/root directory of the given path.
|
||||||
|
// Example /this/that/something.txt -> dest == "/"
|
||||||
|
wxString Path::GetRootDirectory( const wxString& src )
|
||||||
|
{
|
||||||
|
int pos = src.find_first_of( wxFileName::GetPathSeparators() );
|
||||||
|
if( pos == wxString::npos )
|
||||||
|
return wxString();
|
||||||
|
else
|
||||||
|
return wxString( src.begin(), src.begin()+pos );
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "RedtapeWindows.h"
|
#include "RedtapeWindows.h"
|
||||||
#include "WinVersion.h"
|
#include "WinVersion.h"
|
||||||
|
|
||||||
|
#include <ShTypes.h>
|
||||||
#include <shlwapi.h> // for IsOS()
|
#include <shlwapi.h> // for IsOS()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -538,7 +538,7 @@ void loadElfFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
if( filename.IsEmpty() ) return;
|
if( filename.IsEmpty() ) return;
|
||||||
|
|
||||||
int elfsize;
|
wxULongLong elfsize;
|
||||||
Console::Status( wxsFormat( L"loadElfFile: %s", filename.c_str() ) );
|
Console::Status( wxsFormat( L"loadElfFile: %s", filename.c_str() ) );
|
||||||
|
|
||||||
const wxCharBuffer buffer( filename.ToAscii() );
|
const wxCharBuffer buffer( filename.ToAscii() );
|
||||||
|
@ -548,8 +548,7 @@ void loadElfFile(const wxString& filename)
|
||||||
if( !filename.StartsWith( L"cdrom0:" ) && !filename.StartsWith( L"cdrom1:" ) )
|
if( !filename.StartsWith( L"cdrom0:" ) && !filename.StartsWith( L"cdrom1:" ) )
|
||||||
{
|
{
|
||||||
DevCon::WriteLn("Loading from a file (or non-cd image)");
|
DevCon::WriteLn("Loading from a file (or non-cd image)");
|
||||||
|
elfsize = wxFileName::GetSize( filename );
|
||||||
elfsize = Path::GetFileSize( filename );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -562,11 +561,14 @@ void loadElfFile(const wxString& filename)
|
||||||
elfsize = toc.fileSize;
|
elfsize = toc.fileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::Status( wxsFormat(L"loadElfFile: %d", elfsize) );
|
if( elfsize.GetHi() != 0 )
|
||||||
|
throw Exception::BadStream( filename, wxLt("Illegal ELF file size, over 4GB: ") );
|
||||||
|
|
||||||
|
Console::Status( wxsFormat(L"loadElfFile: %d", elfsize.GetLo()) );
|
||||||
if( elfsize == 0 )
|
if( elfsize == 0 )
|
||||||
throw Exception::BadStream( filename, wxLt("Unexpected end of ELF file: ") );
|
throw Exception::BadStream( filename, wxLt("Unexpected end of ELF file: ") );
|
||||||
|
|
||||||
ElfObject elfobj( filename, elfsize );
|
ElfObject elfobj( filename, elfsize.GetLo() );
|
||||||
|
|
||||||
if( elfobj.proghead == NULL )
|
if( elfobj.proghead == NULL )
|
||||||
{
|
{
|
||||||
|
|
|
@ -214,8 +214,7 @@
|
||||||
<Unit filename="../NakedAsm.h" />
|
<Unit filename="../NakedAsm.h" />
|
||||||
<Unit filename="../Patch.cpp" />
|
<Unit filename="../Patch.cpp" />
|
||||||
<Unit filename="../Patch.h" />
|
<Unit filename="../Patch.h" />
|
||||||
<Unit filename="../PathUtils.cpp" />
|
<Unit filename="../PathDefs.h" />
|
||||||
<Unit filename="../Paths.h" />
|
|
||||||
<Unit filename="../Pcsx2Config.cpp" />
|
<Unit filename="../Pcsx2Config.cpp" />
|
||||||
<Unit filename="../PluginManager.cpp" />
|
<Unit filename="../PluginManager.cpp" />
|
||||||
<Unit filename="../Plugins.h" />
|
<Unit filename="../Plugins.h" />
|
||||||
|
|
|
@ -191,7 +191,7 @@ void LoadGSState(const wxString& file)
|
||||||
catch( Exception::FileNotFound& )
|
catch( Exception::FileNotFound& )
|
||||||
{
|
{
|
||||||
// file not found? try prefixing with sstates folder:
|
// file not found? try prefixing with sstates folder:
|
||||||
if( !Path::IsRooted( file ) )
|
if( !Path::IsRelative( file ) )
|
||||||
{
|
{
|
||||||
f = new gzLoadingState( Path::Combine( g_Conf->Folders.Savestates, file ) );
|
f = new gzLoadingState( Path::Combine( g_Conf->Folders.Savestates, file ) );
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/* PCSX2 - PS2 Emulator for PCs
|
||||||
|
* Copyright (C) 2002-2009 PCSX2 Dev Team
|
||||||
|
*
|
||||||
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||||
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum FoldersEnum_t
|
||||||
|
{
|
||||||
|
FolderId_Plugins = 0,
|
||||||
|
FolderId_Settings,
|
||||||
|
FolderId_Bios,
|
||||||
|
FolderId_Snapshots,
|
||||||
|
FolderId_Savestates,
|
||||||
|
FolderId_MemoryCards,
|
||||||
|
FolderId_Logs,
|
||||||
|
FolderId_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// PathDefs Namespace -- contains default values for various pcsx2 path names and locations.
|
||||||
|
//
|
||||||
|
// Note: The members of this namespace are intended for default value initialization only.
|
||||||
|
// Most of the time you should use the path folder assignments in g_Conf instead, since those
|
||||||
|
// are user-configurable.
|
||||||
|
//
|
||||||
|
namespace PathDefs
|
||||||
|
{
|
||||||
|
// complete pathnames are returned by these functions
|
||||||
|
// For 99% of all code, you should use these.
|
||||||
|
|
||||||
|
extern wxDirName GetDocuments();
|
||||||
|
extern wxDirName GetSnapshots();
|
||||||
|
extern wxDirName GetBios();
|
||||||
|
extern wxDirName GetThemes();
|
||||||
|
extern wxDirName GetPlugins();
|
||||||
|
extern wxDirName GetSavestates();
|
||||||
|
extern wxDirName GetMemoryCards();
|
||||||
|
extern wxDirName GetSettings();
|
||||||
|
extern wxDirName GetLogs();
|
||||||
|
extern wxDirName GetThemes();
|
||||||
|
|
||||||
|
extern wxDirName Get( FoldersEnum_t folderidx );
|
||||||
|
|
||||||
|
// Base folder names used to extend out the documents/approot folder base into a complete
|
||||||
|
// path. These are typically for internal AppConfig use only, barring a few special cases.
|
||||||
|
namespace Base
|
||||||
|
{
|
||||||
|
extern const wxDirName& Snapshots();
|
||||||
|
extern const wxDirName& Savestates();
|
||||||
|
extern const wxDirName& MemoryCards();
|
||||||
|
extern const wxDirName& Settings();
|
||||||
|
extern const wxDirName& Plugins();
|
||||||
|
extern const wxDirName& Themes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace FilenameDefs
|
||||||
|
{
|
||||||
|
extern wxFileName GetConfig();
|
||||||
|
extern wxFileName GetUsermodeConfig();
|
||||||
|
extern const wxFileName& Memcard( int slot );
|
||||||
|
};
|
||||||
|
|
|
@ -1,193 +0,0 @@
|
||||||
/* PCSX2 - PS2 Emulator for PCs
|
|
||||||
* Copyright (C) 2002-2009 PCSX2 Dev Team
|
|
||||||
*
|
|
||||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
||||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
||||||
* ation, either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE. See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "PrecompiledHeader.h"
|
|
||||||
#include "Common.h"
|
|
||||||
|
|
||||||
#ifdef __LINUX__
|
|
||||||
#ifndef _S_IFDIR
|
|
||||||
#define _S_IFDIR S_IFDIR
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _S_IFREG
|
|
||||||
#define _S_IFREG S_IFREG
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#include <direct.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Path
|
|
||||||
{
|
|
||||||
|
|
||||||
static bool IsPathSeparator( wxChar src )
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
return (src == wxFileName::GetPathSeparator()) || (src == L'/');
|
|
||||||
#else
|
|
||||||
return src == wxFileName::GetPathSeparator();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the length of the file.
|
|
||||||
// returns -1 if the file is not found.
|
|
||||||
int GetFileSize( const wxString& path )
|
|
||||||
{
|
|
||||||
wxStructStat sbuf;
|
|
||||||
if( wxStat( path.c_str(), &sbuf ) == -1 ) return -1;
|
|
||||||
return sbuf.st_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsRooted( const wxString& path )
|
|
||||||
{
|
|
||||||
// if the first character is a backslash or period, or the second character
|
|
||||||
// a colon, it's a safe bet we're rooted.
|
|
||||||
|
|
||||||
if( path[0] == 0 ) return false;
|
|
||||||
#ifdef WIN32
|
|
||||||
return IsPathSeparator(path[0]) || ( (path[1] == ':') && IsPathSeparator(path[2]) );
|
|
||||||
#else
|
|
||||||
return IsPathSeparator(path[0]);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
// Concatenates two pathnames together, inserting delimiters (backslash on win32)
|
|
||||||
// as needed! Assumes the 'dest' is allocated to at least g_MaxPath length.
|
|
||||||
//
|
|
||||||
wxString Combine( const wxString& srcPath, const wxString& srcFile )
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
int pathlen;
|
|
||||||
|
|
||||||
if( srcFile.empty() )
|
|
||||||
{
|
|
||||||
// No source filename? Return the path unmodified.
|
|
||||||
return srcPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( IsRooted( srcFile ) || srcPath.empty() )
|
|
||||||
{
|
|
||||||
// No source path? Or source filename is rooted?
|
|
||||||
// Return the filename unmodified.
|
|
||||||
return srcFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
// strip off the srcPath's trailing backslashes (if any)
|
|
||||||
// Note: The win32 build works better if I check for both forward and backslashes.
|
|
||||||
// This might be a problem on Linux builds or maybe it doesn't matter?
|
|
||||||
|
|
||||||
pathlen = srcPath.length();
|
|
||||||
while( pathlen > 0 && IsPathSeparator(srcPath[pathlen-1]) )
|
|
||||||
--pathlen;
|
|
||||||
|
|
||||||
// Concatenate strings:
|
|
||||||
guesslen = pathlen + srcFile.length() + 2;
|
|
||||||
|
|
||||||
if( guesslen >= g_MaxPath )
|
|
||||||
throw Exception::PathTooLong();
|
|
||||||
|
|
||||||
// Concatenate!
|
|
||||||
|
|
||||||
wxString dest( srcPath.begin(), srcPath.begin()+pathlen );
|
|
||||||
dest += Separator;
|
|
||||||
dest += srcFile;
|
|
||||||
return dest;
|
|
||||||
|
|
||||||
#else
|
|
||||||
// Use wx's Path system for concatenation because it's pretty smart.
|
|
||||||
|
|
||||||
return (wxDirName( srcPath ) + srcFile).GetFullPath();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile )
|
|
||||||
{
|
|
||||||
return (srcPath + srcFile).GetFullPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString Combine( const wxString& srcPath, const wxDirName& srcFile )
|
|
||||||
{
|
|
||||||
return ((wxDirName)srcPath + srcFile).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replaces the extension of the file with the one given.
|
|
||||||
// This function works for path names as well as file names.
|
|
||||||
wxString ReplaceExtension( const wxString& src, const wxString& ext )
|
|
||||||
{
|
|
||||||
wxString dest;
|
|
||||||
|
|
||||||
int pos = src.find_last_of( L'.' );
|
|
||||||
if( pos == wxString::npos || pos == 0 )
|
|
||||||
dest = src;
|
|
||||||
else
|
|
||||||
dest.assign( src.begin(), src.begin()+pos );
|
|
||||||
|
|
||||||
if( !ext.empty() )
|
|
||||||
{
|
|
||||||
dest += '.';
|
|
||||||
dest += ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString ReplaceFilename( const wxString& src, const wxString& newfilename )
|
|
||||||
{
|
|
||||||
// Implementation note: use wxWidgets to do this job.
|
|
||||||
|
|
||||||
wxFileName jojo( src );
|
|
||||||
jojo.SetFullName( newfilename );
|
|
||||||
return jojo.GetFullPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString GetFilename( const wxString& src )
|
|
||||||
{
|
|
||||||
return wxFileName(src).GetFullName();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString GetFilenameWithoutExt( const wxString& src )
|
|
||||||
{
|
|
||||||
return wxFileName(src).GetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString GetDirectory( const wxString& src )
|
|
||||||
{
|
|
||||||
return wxFileName(src).GetPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// returns the base/root directory of the given path.
|
|
||||||
// Example /this/that/something.txt -> dest == "/"
|
|
||||||
wxString GetRootDirectory( const wxString& src )
|
|
||||||
{
|
|
||||||
int pos = src.find_first_of( wxFileName::GetPathSeparators() );
|
|
||||||
if( pos == wxString::npos )
|
|
||||||
return wxString();
|
|
||||||
else
|
|
||||||
return wxString( src.begin(), src.begin()+pos );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreateDirectory( const wxString& src )
|
|
||||||
{
|
|
||||||
wxFileName::Mkdir( src );
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveDirectory( const wxString& src )
|
|
||||||
{
|
|
||||||
wxFileName::Rmdir( src );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -81,9 +81,9 @@ typedef int BOOL;
|
||||||
#include "zlib/zlib.h"
|
#include "zlib/zlib.h"
|
||||||
#include "Pcsx2Defs.h"
|
#include "Pcsx2Defs.h"
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
#include "Paths.h"
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Utilities/wxBaseTools.h"
|
#include "Utilities/wxBaseTools.h"
|
||||||
|
#include "Utilities/Path.h"
|
||||||
#include "Utilities/Console.h"
|
#include "Utilities/Console.h"
|
||||||
#include "Utilities/Exceptions.h"
|
#include "Utilities/Exceptions.h"
|
||||||
#include "Utilities/MemcpyFast.h"
|
#include "Utilities/MemcpyFast.h"
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Paths.h"
|
|
||||||
#include "Utilities/SafeArray.h"
|
#include "Utilities/SafeArray.h"
|
||||||
#include "Utilities/Threading.h" // to use threading stuff, include the Threading namespace in your file.
|
#include "Utilities/Threading.h" // to use threading stuff, include the Threading namespace in your file.
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
|
|
|
@ -272,73 +272,6 @@ namespace FilenameDefs
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
wxFileName wxDirName::Combine( const wxFileName& right ) const
|
|
||||||
{
|
|
||||||
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wxDirName concatenation." );
|
|
||||||
if( right.IsAbsolute() )
|
|
||||||
return right;
|
|
||||||
|
|
||||||
// Append any directory parts from right, and then set the filename.
|
|
||||||
// Except we can't do that because our m_members are private (argh!) and there is no API
|
|
||||||
// for getting each component of the path. So instead let's use Normalize:
|
|
||||||
|
|
||||||
wxFileName result( right );
|
|
||||||
result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDirName wxDirName::Combine( const wxDirName& right ) const
|
|
||||||
{
|
|
||||||
wxASSERT_MSG( IsDir() && right.IsDir(), L"Warning: Malformed directory name detected during wDirName concatenation." );
|
|
||||||
|
|
||||||
wxDirName result( right );
|
|
||||||
result.Normalize( wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, GetPath() );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDirName& wxDirName::Normalize( int flags, const wxString& cwd )
|
|
||||||
{
|
|
||||||
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." );
|
|
||||||
if( !wxFileName::Normalize( flags, cwd ) )
|
|
||||||
throw Exception::RuntimeError( "wxDirName::Normalize operation failed." );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDirName& wxDirName::MakeRelativeTo( const wxString& pathBase )
|
|
||||||
{
|
|
||||||
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." );
|
|
||||||
if( !wxFileName::MakeRelativeTo( pathBase ) )
|
|
||||||
throw Exception::RuntimeError( "wxDirName::MakeRelativeTo operation failed." );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxDirName& wxDirName::MakeAbsolute( const wxString& cwd )
|
|
||||||
{
|
|
||||||
wxASSERT_MSG( IsDir(), L"Warning: Malformed directory name detected during wDirName normalization." );
|
|
||||||
if( !wxFileName::MakeAbsolute( cwd ) )
|
|
||||||
throw Exception::RuntimeError( "wxDirName::MakeAbsolute operation failed." );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxDirName::Rmdir()
|
|
||||||
{
|
|
||||||
if( !Exists() ) return;
|
|
||||||
wxFileName::Rmdir();
|
|
||||||
// TODO : Throw exception if operation failed? Do we care?
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxDirName::Mkdir()
|
|
||||||
{
|
|
||||||
if( Exists() ) return true;
|
|
||||||
|
|
||||||
// Recursively create child directories as needed:
|
|
||||||
wxDirName recurse( *this );
|
|
||||||
recurse.RemoveLastDir();
|
|
||||||
if( !recurse.Mkdir() ) return false;
|
|
||||||
|
|
||||||
return wxFileName::Mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString AppConfig::FullpathTo( PluginsEnum_t pluginidx ) const
|
wxString AppConfig::FullpathTo( PluginsEnum_t pluginidx ) const
|
||||||
{
|
{
|
||||||
return Path::Combine( Folders.Plugins, BaseFilenames[pluginidx] );
|
return Path::Combine( Folders.Plugins, BaseFilenames[pluginidx] );
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "PathDefs.h"
|
||||||
#include "CDVD/CDVDaccess.h"
|
#include "CDVD/CDVDaccess.h"
|
||||||
|
|
||||||
class IniInterface;
|
class IniInterface;
|
||||||
|
|
|
@ -107,20 +107,20 @@ static u32 GetBiosVersion()
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// ext - extension of the sub-component to load. Valid options are rom1, rom2, AND erom.
|
// ext - extension of the sub-component to load. Valid options are rom1, rom2, AND erom.
|
||||||
//
|
//
|
||||||
static void loadBiosRom( const wxChar *ext, u8 *dest, long maxSize )
|
static void loadBiosRom( const wxChar *ext, u8 *dest, u64 maxSize )
|
||||||
{
|
{
|
||||||
wxString Bios1;
|
wxString Bios1;
|
||||||
long filesize;
|
u64 filesize;
|
||||||
|
|
||||||
// Try first a basic extension concatenation (normally results in something like name.bin.rom1)
|
// Try first a basic extension concatenation (normally results in something like name.bin.rom1)
|
||||||
const wxString Bios( g_Conf->FullpathToBios() );
|
const wxString Bios( g_Conf->FullpathToBios() );
|
||||||
Bios1.Printf( L"%s.%s", Bios.c_str(), ext);
|
Bios1.Printf( L"%s.%s", Bios.c_str(), ext);
|
||||||
|
|
||||||
if( (filesize=Path::GetFileSize( Bios1 ) ) <= 0 )
|
if( (filesize=wxFileName::GetSize( Bios1 ).GetValue() ) <= 0 )
|
||||||
{
|
{
|
||||||
// Try the name properly extensioned next (name.rom1)
|
// Try the name properly extensioned next (name.rom1)
|
||||||
Bios1 = Path::ReplaceExtension( Bios, ext );
|
Bios1 = Path::ReplaceExtension( Bios, ext );
|
||||||
if( (filesize=Path::GetFileSize( Bios1 ) ) <= 0 )
|
if( (filesize=wxFileName::GetSize( Bios1 ).GetValue() ) <= 0 )
|
||||||
{
|
{
|
||||||
Console::Notice( "Load Bios Warning: %s not found (this is not an error!)", wxString(ext).ToAscii().data() );
|
Console::Notice( "Load Bios Warning: %s not found (this is not an error!)", wxString(ext).ToAscii().data() );
|
||||||
return;
|
return;
|
||||||
|
@ -149,11 +149,11 @@ void LoadBIOS()
|
||||||
|
|
||||||
wxString Bios( g_Conf->FullpathToBios() );
|
wxString Bios( g_Conf->FullpathToBios() );
|
||||||
|
|
||||||
long filesize = Path::GetFileSize( Bios );
|
u64 filesize = wxFileName::GetSize( Bios ).GetValue();
|
||||||
if( filesize > 0 )
|
if( filesize > 0 )
|
||||||
{
|
{
|
||||||
wxFile fp( Bios.c_str() );
|
wxFile fp( Bios.c_str() );
|
||||||
fp.Read( PS2MEM_ROM, min( (long)Ps2MemSize::Rom, filesize ) );
|
fp.Read( PS2MEM_ROM, min( (u64)Ps2MemSize::Rom, filesize ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1870,10 +1870,6 @@
|
||||||
<Filter
|
<Filter
|
||||||
Name="SysCore"
|
Name="SysCore"
|
||||||
>
|
>
|
||||||
<File
|
|
||||||
RelativePath="..\..\PathUtils.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\PluginManager.cpp"
|
RelativePath="..\..\PluginManager.cpp"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in New Issue