From 852c6aaca179f7498ec6c6f016fd9c4dfccfe3d3 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Sat, 29 Nov 2008 09:54:39 +0000 Subject: [PATCH] Create a dir for setting.txt to git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1328 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/FileUtil.cpp | 43 ++++++++++++++++ Source/Core/Common/Src/FileUtil.h | 1 + Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp | 4 ++ .../Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp | 49 ++----------------- .../Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.h | 3 -- 5 files changed, 52 insertions(+), 48 deletions(-) diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 60bee857e1..68d333eb7a 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -149,6 +149,49 @@ bool CreateDir(const char *path) #endif } +// Create several dirs +bool CreateDirectoryStructure(const std::string& _rFullPath) +{ + int PanicCounter = 10; + + size_t Position = 0; + while(true) + { + // find next sub path + { + size_t nextPosition = _rFullPath.find('/', Position); + if (nextPosition == std::string::npos) + nextPosition = _rFullPath.find('\\', Position); + Position = nextPosition; + + if (Position == std::string::npos) + return true; + + Position++; + } + + // create next sub path + std::string SubPath = _rFullPath.substr(0, Position); + if (!SubPath.empty()) + { + if (!File::IsDirectory(SubPath.c_str())) + { + File::CreateDir(SubPath.c_str()); + LOG(WII_IPC_FILEIO, " CreateSubDir %s", SubPath.c_str()); + } + } + + // just a safty check... + PanicCounter--; + if (PanicCounter <= 0) + { + PanicAlert("CreateDirectoryStruct creates way to much dirs..."); + return false; + } + } +} + + bool DeleteDir(const char *filename) { diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index 9f19e0a404..610531ce16 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -41,6 +41,7 @@ void Launch(const char *filename); void Explore(const char *path); bool IsDirectory(const char *filename); bool CreateDir(const char *filename); +bool CreateDirectoryStructure(const std::string& _rFullPath); bool Delete(const char *filename); bool DeleteDir(const char *filename); bool Rename(const char *srcFilename, const char *destFilename); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp index af655e8bae..fd31f5057a 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE.cpp @@ -249,6 +249,10 @@ void CopySettingsFile(std::string DeviceName) std::string Target = "User/Wii" + DeviceName; + // Check if the target dir exists, otherwise create it + std::string TargetDir = Target.substr(0, Target.find_last_of("/")); + if(!File::IsDirectory(TargetDir.c_str())) File::CreateDirectoryStructure(Target.c_str()); + if (File::Copy(Source.c_str(), Target.c_str())) { LOG(WII_IPC_FILEIO, "FS: Copied %s to %s", Source.c_str(), Target.c_str()); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp index 2ff5057de5..2930345b94 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.cpp @@ -62,7 +62,7 @@ bool CWII_IPC_HLE_Device_fs::Open(u32 _CommandAddress, u32 _Mode) char Path[260+1]; sprintf(Path, FULL_WII_USER_DIR "title/00010000/%02x%02x%02x%02x/data/nocopy/", (u8)pTitleID[3], (u8)pTitleID[2], (u8)pTitleID[1], (u8)pTitleID[0]); - CreateDirectoryStruct(Path); + File::CreateDirectoryStructure(Path); } Memory::Write_U32(GetDeviceID(), _CommandAddress+4); @@ -241,7 +241,7 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B LOG(WII_IPC_FILEIO, "FS: CREATE_DIR %s", DirName.c_str()); DirName += "\\"; - CreateDirectoryStruct(DirName); + File::CreateDirectoryStructure(DirName); _dbg_assert_msg_(WII_IPC_FILEIO, File::IsDirectory(DirName.c_str()), "FS: CREATE_DIR %s failed", DirName.c_str()); return FS_RESULT_OK; @@ -330,7 +330,7 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B Offset += 64; // try to make the basis directory - CreateDirectoryStruct(Filename); + File::CreateDirectoryStructure(Filename); // if there is already a filedelete it if (File::Exists(FilenameRename.c_str())) @@ -385,7 +385,7 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B } // create the file - // F|RES: i think that we dont need this - CreateDirectoryStruct(Filename); + // F|RES: i think that we dont need this - File::CreateDirectoryStructure(Filename); bool Result = File::CreateEmptyFile(Filename.c_str()); if (!Result) { @@ -405,44 +405,3 @@ s32 CWII_IPC_HLE_Device_fs::ExecuteCommand(u32 _Parameter, u32 _BufferIn, u32 _B //LOGV(WII_IPC_FILEIO, 0, "=============================================================="); return FS_RESULT_FATAL; } - -void CWII_IPC_HLE_Device_fs::CreateDirectoryStruct(const std::string& _rFullPath) -{ - int PanicCounter = 10; - - size_t Position = 0; - while(true) - { - // find next sub path - { - size_t nextPosition = _rFullPath.find('/', Position); - if (nextPosition == std::string::npos) - nextPosition = _rFullPath.find('\\', Position); - Position = nextPosition; - - if (Position == std::string::npos) - break; - - Position++; - } - - // create next sub path - std::string SubPath = _rFullPath.substr(0, Position); - if (!SubPath.empty()) - { - if (!File::IsDirectory(SubPath.c_str())) - { - File::CreateDir(SubPath.c_str()); - LOG(WII_IPC_FILEIO, " CreateSubDir %s", SubPath.c_str()); - } - } - - // just a safty check... - PanicCounter--; - if (PanicCounter <= 0) - { - PanicAlert("CreateDirectoryStruct creates way to much dirs..."); - break; - } - } -} diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.h index 37708c841f..a7f44c6664 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_fs.h @@ -54,9 +54,6 @@ private: }; s32 ExecuteCommand(u32 Parameter, u32 _BufferIn, u32 _BufferInSize, u32 _BufferOut, u32 _BufferOutSize); - - void CreateDirectoryStruct(const std::string& _rFullPath); - }; #endif