From c09b0f511ea9dc4b075e76ccc28365b9c7c6deeb Mon Sep 17 00:00:00 2001 From: Sacha Date: Sat, 12 Jul 2014 03:06:59 +1000 Subject: [PATCH] More header changes. --- Utilities/Log.cpp | 2 +- Utilities/rFile.cpp | 49 +++++++++++++----- Utilities/rFile.h | 8 ++- Utilities/rMsgBox.cpp | 25 +-------- Utilities/rMsgBox.h | 53 ++++++++------------ rpcs3/Emu/FS/vfsLocalDir.cpp | 2 +- rpcs3/Emu/GS/GCM.h | 6 ++- rpcs3/Emu/SysCalls/Modules/cellGame.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp | 8 ++- rpcs3/Gui/CompilerELF.cpp | 2 +- rpcs3/Gui/GameViewer.cpp | 5 +- rpcs3/rpcs3.h | 1 + rpcs3/stdafx.h | 6 --- 13 files changed, 79 insertions(+), 90 deletions(-) diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 8361dcbf9d..4613e39e8a 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -104,7 +104,7 @@ struct FileListener : LogListener { if (!mFile.IsOpened()) { - rMessageBox("Can't create log file! (" + name + ".log)", rMessageBoxCaptionStr, rICON_ERROR); + rMessageBox("Can't create log file! (" + name + ".log)", "Error", rICON_ERROR); } } diff --git a/Utilities/rFile.cpp b/Utilities/rFile.cpp index 40cd2e0c49..0973fae502 100644 --- a/Utilities/rFile.cpp +++ b/Utilities/rFile.cpp @@ -1,6 +1,19 @@ #include "stdafx.h" +#include -const int rPATH_MKDIR_FULL = wxPATH_MKDIR_FULL; +#ifdef _WIN32 +// Maybe in StrFmt? +std::wstring ConvertUTF8ToWString(const std::string &source) { + int len = (int)source.size(); + int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, NULL, 0); + std::wstring str; + str.resize(size); + if (size > 0) { + MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, &str[0], size); + } + return str; +} +#endif wxFile::OpenMode convertOpenMode(rFile::OpenMode open) { @@ -140,7 +153,13 @@ bool rFile::Open(const std::string &filename, rFile::OpenMode mode, int access) bool rFile::Exists(const std::string &file) { - return wxFile::Exists(fmt::FromUTF8(file)); +#ifdef _WIN32 + std::wstring wstr = ConvertUTF8ToWString(filename); + return GetFileAttributes(wstr.c_str()) != 0xFFFFFFFF; +#else + struct stat buffer; + return (stat (file.c_str(), &buffer) == 0); +#endif } bool rFile::IsOpened() const @@ -173,14 +192,25 @@ std::string rGetCwd() return fmt::ToUTF8(wxGetCwd()); } -bool rMkdir(const std::string &path) +bool rMkdir(const std::string &dir) { - return wxMkdir(fmt::FromUTF8(path)); + return mkdir(dir.c_str()); } -bool rRmdir(const std::string &path) +bool rMkpath(const std::string& path) { - return wxRmdir(fmt::FromUTF8(path)); + return wxFileName::Mkdir(fmt::FromUTF8(path), 0777, wxPATH_MKDIR_FULL); +} + +bool rRmdir(const std::string &dir) +{ +#ifdef _WIN32 + if (!RemoveDirectory(ConvertUTF8ToWString(dir).c_str())) { + ELOG("Error deleting directory %s: %i", dir, GetLastError()); + } +#else + rmdir(dir.c_str()); +#endif } bool rDirExists(const std::string &path) @@ -235,7 +265,7 @@ bool rDir::Open(const std::string& path) bool rDir::Exists(const std::string &path) { - return wxDir::Exists(fmt::FromUTF8(path)); + return rFile::Exists(path); } bool rDir::GetFirst(std::string *filename) const @@ -299,11 +329,6 @@ std::string rFileName::GetFullName() return fmt::ToUTF8(reinterpret_cast(handle)->GetFullName()); } -bool rFileName::Mkdir(const std::string& name, int permissions , int flags ) -{ - return wxFileName::Mkdir(fmt::FromUTF8(name), permissions, flags); -} - bool rFileName::Normalize() { return reinterpret_cast(handle)->Normalize(); diff --git a/Utilities/rFile.h b/Utilities/rFile.h index cf4da0c284..35cb332661 100644 --- a/Utilities/rFile.h +++ b/Utilities/rFile.h @@ -2,8 +2,6 @@ #include -extern const int rPATH_MKDIR_FULL; - enum rSeekMode { rFromStart, @@ -44,8 +42,9 @@ public: }; std::string rGetCwd(); -bool rMkdir(const std::string &path); -bool rRmdir(const std::string &path); +bool rRmdir(const std::string& dir); +bool rMkdir(const std::string& dir); +bool rMkpath(const std::string& path); bool rDirExists(const std::string &path); bool rFileExists(const std::string &path); bool rRemoveFile(const std::string &path); @@ -77,7 +76,6 @@ struct rFileName std::string GetPath(); std::string GetName(); std::string GetFullName(); - static bool Mkdir(const std::string& name, int permissions=0777, int flags=0); bool Normalize(); void *handle; diff --git a/Utilities/rMsgBox.cpp b/Utilities/rMsgBox.cpp index bdc9fa4b07..716464a156 100644 --- a/Utilities/rMsgBox.cpp +++ b/Utilities/rMsgBox.cpp @@ -1,8 +1,6 @@ #include "stdafx.h" - -std::string rMessageBoxCaptionStr = "Message"; - +#ifndef QT_UI rMessageDialog::rMessageDialog(void *parent, const std::string& msg, const std::string& title , long style ) { handle = reinterpret_cast(new wxMessageDialog( @@ -28,24 +26,5 @@ long rMessageBox(const std::string& message, const std::string& title, long styl return wxMessageBox(fmt::FromUTF8(message), fmt::FromUTF8(title),style); } -std::string dummyApp::GetAppName() -{ - if (handle) - { - return fmt::ToUTF8(reinterpret_cast(handle)->GetAppName()); - } - else - { - return "NULL"; - } -} -dummyApp::dummyApp() : handle(nullptr) -{ +#endif -} -static dummyApp app; - -dummyApp& rGetApp() -{ - return app; -} \ No newline at end of file diff --git a/Utilities/rMsgBox.h b/Utilities/rMsgBox.h index 354c850141..f19081fe5c 100644 --- a/Utilities/rMsgBox.h +++ b/Utilities/rMsgBox.h @@ -1,34 +1,33 @@ #pragma once -extern std::string rMessageBoxCaptionStr;// = "Message"; - enum MsgBoxParams : unsigned long { - rOK = 0x4 - , rYES =0x2//res - , rNO = 0x8 //res - , rID_YES = 5103 //resDialog - , rCANCEL = 0x10 - , rYES_NO = 0xA - , rHELP = 0x1000 - , rNO_DEFAULT = 0x80 - , rCANCEL_DEFAULT = 0x80000000 - , rYES_DEFAULT = 0x0 - , rOK_DEFAULT = 0x0 - , rICON_NONE = 0x40000 - , rICON_EXCLAMATION = 0x100 - , rICON_ERROR = 0x200 - , rICON_HAND = 0x200 - , rICON_QUESTION = 0x400 - , rICON_INFORMATION = 0x800 - , rICON_AUTH_NEEDED = 0x80000 - , rSTAY_ON_TOP = 0x8000 - , rCENTRE = 0x1 + rYES_DEFAULT = 0x0, + rOK_DEFAULT = 0x0, + rCENTRE = 0x1, + rYES = 0x2, //res + rOK = 0x4, + rNO = 0x8, //res + rCANCEL = 0x10, + rYES_NO = 0xA, + rNO_DEFAULT = 0x80, + rICON_EXCLAMATION = 0x100, + rICON_ERROR = 0x200, + rICON_HAND = 0x200, + rICON_QUESTION = 0x400, + rICON_INFORMATION = 0x800, + rHELP = 0x1000, + rID_CANCEL = 0x13ED, + rID_YES = 0x13EF, //resDialog + rSTAY_ON_TOP = 0x8000, + rICON_NONE = 0x40000, + rICON_AUTH_NEEDED = 0x80000, + rCANCEL_DEFAULT = 0x80000000, }; struct rMessageDialog { - rMessageDialog(void *parent, const std::string& msg, const std::string& title = rMessageBoxCaptionStr, long style = rOK | rCENTRE); + rMessageDialog(void *parent, const std::string& msg, const std::string& title = "RPCS3", long style = rOK | rCENTRE); rMessageDialog(const rMessageDialog& other) = delete; ~rMessageDialog(); long ShowModal(); @@ -37,11 +36,3 @@ struct rMessageDialog long rMessageBox(const std::string& message, const std::string& title,long style); -struct dummyApp -{ - dummyApp(); - std::string GetAppName(); - void* handle; -}; - -dummyApp& rGetApp(); \ No newline at end of file diff --git a/rpcs3/Emu/FS/vfsLocalDir.cpp b/rpcs3/Emu/FS/vfsLocalDir.cpp index 349923e749..e97f9a5ad7 100644 --- a/rpcs3/Emu/FS/vfsLocalDir.cpp +++ b/rpcs3/Emu/FS/vfsLocalDir.cpp @@ -40,7 +40,7 @@ bool vfsLocalDir::Open(const std::string& path) bool vfsLocalDir::Create(const std::string& path) { - return rFileName::Mkdir(path, 0777, rPATH_MKDIR_FULL); + return rMkpath(path); } bool vfsLocalDir::Rename(const std::string& from, const std::string& to) diff --git a/rpcs3/Emu/GS/GCM.h b/rpcs3/Emu/GS/GCM.h index 5c766ebf46..9f56cb2bab 100644 --- a/rpcs3/Emu/GS/GCM.h +++ b/rpcs3/Emu/GS/GCM.h @@ -1330,8 +1330,10 @@ static const std::string GetMethodName(const u32 id) { NV4097_SET_TRANSFORM_BRANCH_BITS, "SetTransformBranchBits" } , }; - for(auto& s: METHOD_NAME_LIST) - if(s.id == id) return "cellGcm" + s.name; + for(auto& s: METHOD_NAME_LIST) { + if(s.id == id) + return "cellGcm" + s.name; + } return fmt::Format("unknown/illegal method [0x%08x]", id); } diff --git a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp index d693772ff2..24c0ba865a 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp @@ -456,7 +456,7 @@ int cellGameContentErrorDialog(s32 type, s32 errNeedSizeKB, u32 dirName_addr) std::string errorMsg = fmt::Format("%s\nSpace needed: %d KB\nDirectory name: %s", errorName.c_str(), errNeedSizeKB, dirName); - rMessageBox(errorMsg, rGetApp().GetAppName(), rICON_ERROR | rOK); + rMessageBox(errorMsg, "Error", rICON_ERROR | rOK); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp b/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp index 7fcc039748..7869c80ff5 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp @@ -287,14 +287,12 @@ int cellMsgDialogOpenErrorCode(u32 errorCode, mem_func_ptr_t static const std::string m_class_name = "GameViewer"; @@ -238,9 +239,9 @@ void GameViewer::RemoveGame(wxCommandEvent& event) Emu.GetVFS().UnMountAll(); - //TODO: Replace wxWidgetsSpecific filesystem stuff? - if (!wxDirExists(fmt::FromUTF8(localPath))) + if (!rFile::Exists(localPath)) return; + //TODO: Replace wxWidgetsSpecific filesystem stuff? WxDirDeleteTraverser deleter; wxDir localDir(localPath); localDir.Traverse(deleter); diff --git a/rpcs3/rpcs3.h b/rpcs3/rpcs3.h index 6ee25f0455..77b35aa7fc 100644 --- a/rpcs3/rpcs3.h +++ b/rpcs3/rpcs3.h @@ -2,6 +2,7 @@ #include "Gui/MainFrame.h" #include "Emu/DbgCommand.h" #include "Utilities/Thread.h" +#include class CPUThread; diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index 8aaceab5d0..cfb31964fc 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -12,13 +12,9 @@ #include #include #include -#include -#include -#include #include #include -#include #include #include #include @@ -32,8 +28,6 @@ #include #include #include -#include -#include #include #include #endif