From 1d29204ae651c1d41b752914457904348319087c Mon Sep 17 00:00:00 2001 From: LPFaint99 Date: Sat, 11 Jun 2011 20:45:09 +0000 Subject: [PATCH] Windows: Sets the cwd to the folder that dolphin.exe resides in. Removes the ugliness that was the portable file, and now creating a shortcut or file association is less of a pain it is still necessary to modify the file association from ".../dolphin.exe" "%1" to ".../dolphin.exe" /e "%1" git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7593 8ced0084-cf51-0410-be5f-012b33b47a6e --- Data/User/Config/portable | 0 Source/Core/Common/Src/FileUtil.cpp | 16 ++++++++++ Source/Core/Common/Src/FileUtil.h | 4 +++ Source/Core/DolphinWX/Src/Main.cpp | 49 ++--------------------------- 4 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 Data/User/Config/portable diff --git a/Data/User/Config/portable b/Data/User/Config/portable deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index d68ee74eaf..6dd800b723 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -601,6 +601,21 @@ std::string GetBundleDirectory() } #endif +#ifdef _WIN32 +std::string &GetExeDirectory() +{ + static std::string DolphinPath; + if (DolphinPath.empty()) + { + char Dolphin_exe_Path[2048]; + GetModuleFileNameA(NULL, Dolphin_exe_Path, 2048); + DolphinPath = Dolphin_exe_Path; + DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\')); + } + return DolphinPath; +} +#endif + std::string GetSysDirectory() { std::string sysDir; @@ -628,6 +643,7 @@ std::string &GetUserPath(const unsigned int DirIDX, const std::string &newPath) if (paths[D_USER_IDX].empty()) { #ifdef _WIN32 + // TODO: use GetExeDirectory() here instead of ROOT_DIR so that if the cwd is changed we still have the correct paths? paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; #else if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index 642b5dd9e2..5c8ba2186e 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -139,6 +139,10 @@ std::string GetSysDirectory(); std::string GetBundleDirectory(); #endif +#ifdef _WIN32 +std::string &GetExeDirectory(); +#endif + bool WriteStringToFile(bool text_file, const std::string &str, const char *filename); bool ReadFileToString(bool text_file, const char *filename, std::string &str); diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index 4461fd4fd7..4d84ff239c 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -200,54 +200,9 @@ bool DolphinApp::OnInit() } #ifdef _WIN32 - // Keep the user config dir free unless user wants to save the working dir - if (!File::Exists(File::GetUserPath(D_CONFIG_IDX) + "portable")) + if (!wxSetWorkingDirectory(wxString(File::GetExeDirectory().c_str(), *wxConvCurrent))) { - char tmp[1024]; - sprintf(tmp, "%s/.dolphin%swd", (const char*)wxStandardPaths::Get().GetUserConfigDir().mb_str(), -#ifdef _M_IX86 - "x32"); -#else - "x64"); -#endif - std::ifstream workingDir(tmp); - if (!workingDir) - { - if (PanicYesNoT("Dolphin has not been configured with an install location,\nKeep Dolphin portable?")) - { - std::ofstream portable((File::GetUserPath(D_CONFIG_IDX) + "portable").c_str()); - if (!portable) - { - PanicAlertT("Portable Setting could not be saved\n Are you running Dolphin from read only media or from a directory that dolphin is not located in?"); - } - } - else - { - char CWD[1024]; - sprintf(CWD, "%s", (const char*)wxGetCwd().mb_str()); - if (PanicYesNoT("Set install location to:\n %s ?", CWD)) - { - std::ofstream workingDirF(tmp); - if (!workingDirF) - PanicAlertT("Install directory could not be saved"); - else - { - workingDirF << CWD << '\n'; - } - } - else - PanicAlertT("Relaunch Dolphin from the install directory and save from there"); - } - } - else - { - std::string tmpChar; - std::getline(workingDir, tmpChar); - if (!wxSetWorkingDirectory(wxString::From8BitData(tmpChar.c_str()))) - { - INFO_LOG(CONSOLE, "set working directory failed"); - } - } + INFO_LOG(CONSOLE, "set working directory failed"); } #else //create all necessary directories in user directory