From c25ef7f07a3822ca040bfbde43451a83a47b5c82 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sun, 5 Jul 2015 19:21:49 -0400 Subject: [PATCH] All settings/files are now saved in Documents\Mesen --- GUI.NET/Config/ConfigManager.cs | 15 +++++++++++---- GUI.NET/Forms/frmMain.cs | 2 +- GUI.NET/InteropEmu.cs | 2 +- InteropDLL/ConsoleWrapper.cpp | 4 +++- Utilities/FolderUtilities.cpp | 31 ++++++++++++++++--------------- Utilities/FolderUtilities.h | 29 ++++++++++++++++------------- 6 files changed, 48 insertions(+), 35 deletions(-) diff --git a/GUI.NET/Config/ConfigManager.cs b/GUI.NET/Config/ConfigManager.cs index a49ed6a0..001c3b93 100644 --- a/GUI.NET/Config/ConfigManager.cs +++ b/GUI.NET/Config/ConfigManager.cs @@ -36,16 +36,23 @@ namespace Mesen.GUI.Config _config.Serialize(ConfigFile); } + public static string HomeFolder + { + get + { + return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.Create), "Mesen"); + } + } + private static string ConfigFile { get { - string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create), "Mesen"); - if(!Directory.Exists(configPath)) { - Directory.CreateDirectory(configPath); + if(!Directory.Exists(HomeFolder)) { + Directory.CreateDirectory(HomeFolder); } - return Path.Combine(configPath, "settings.xml"); + return Path.Combine(HomeFolder, "settings.xml"); } } diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 80075619..17f5e87f 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -31,7 +31,7 @@ namespace Mesen.GUI.Forms _notifListener = new InteropEmu.NotificationListener(); _notifListener.OnNotification += _notifListener_OnNotification; - InteropEmu.InitializeEmu(this.Handle, this.dxViewer.Handle); + InteropEmu.InitializeEmu(ConfigManager.HomeFolder, this.Handle, this.dxViewer.Handle); InteropEmu.SetFlags((int)EmulationFlags.LimitFPS); UpdateMenus(); diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 889c7a04..92055de8 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -12,7 +12,7 @@ namespace Mesen.GUI public class InteropEmu { private const string DLLPath = "WinMesen.dll"; - [DllImport(DLLPath)] public static extern void InitializeEmu(IntPtr windowHandle, IntPtr dxViewerHandle); + [DllImport(DLLPath)] public static extern void InitializeEmu([MarshalAs(UnmanagedType.LPWStr)]string homeFolder, IntPtr windowHandle, IntPtr dxViewerHandle); [DllImport(DLLPath)] public static extern void Release(); [DllImport(DLLPath)] public static extern void LoadROM([MarshalAs(UnmanagedType.LPWStr)]string filename); [DllImport(DLLPath)] public static extern void Run(); diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index ceca8516..65d0c9e0 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -37,8 +37,10 @@ namespace InteropEmu { }; extern "C" { - DllExport void __stdcall InitializeEmu(HWND windowHandle, HWND dxViewerHandle) + DllExport void __stdcall InitializeEmu(wchar_t* homeFolder, HWND windowHandle, HWND dxViewerHandle) { + FolderUtilities::SetHomeFolder(homeFolder); + _windowHandle = windowHandle; _viewerHandle = dxViewerHandle; diff --git a/Utilities/FolderUtilities.cpp b/Utilities/FolderUtilities.cpp index 292568fd..c525e611 100644 --- a/Utilities/FolderUtilities.cpp +++ b/Utilities/FolderUtilities.cpp @@ -3,45 +3,46 @@ #include #include "FolderUtilities.h" +wstring FolderUtilities::_homeFolder = L""; + +void FolderUtilities::SetHomeFolder(wstring homeFolder) +{ + _homeFolder = homeFolder; + CreateDirectory(homeFolder.c_str(), nullptr); +} + wstring FolderUtilities::GetHomeFolder() { - wstring folder; - PWSTR pathName; - SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &pathName); - folder = wstring((wchar_t*)pathName) + L"\\NesEMU\\"; - - //Make sure it exists - CreateDirectory(folder.c_str(), nullptr); - - CoTaskMemFree(pathName); - - return folder; + if(_homeFolder.size() == 0) { + throw std::exception("Home folder not specified"); + } + return _homeFolder; } wstring FolderUtilities::GetSaveFolder() { - wstring folder = GetHomeFolder() + L"Saves\\"; + wstring folder = CombinePath(GetHomeFolder(), L"Saves\\"); CreateDirectory(folder.c_str(), nullptr); return folder; } wstring FolderUtilities::GetSaveStateFolder() { - wstring folder = GetHomeFolder() + L"SaveStates\\"; + wstring folder = CombinePath(GetHomeFolder(), L"SaveStates\\"); CreateDirectory(folder.c_str(), nullptr); return folder; } wstring FolderUtilities::GetMovieFolder() { - wstring folder = GetHomeFolder() + L"Movies\\"; + wstring folder = CombinePath(GetHomeFolder(), + L"Movies\\"); CreateDirectory(folder.c_str(), nullptr); return folder; } wstring FolderUtilities::GetScreenshotFolder() { - wstring folder = GetHomeFolder() + L"Screenshots\\"; + wstring folder = CombinePath(GetHomeFolder(), L"Screenshots\\"); CreateDirectory(folder.c_str(), nullptr); return folder; } diff --git a/Utilities/FolderUtilities.h b/Utilities/FolderUtilities.h index 755e0082..593b0423 100644 --- a/Utilities/FolderUtilities.h +++ b/Utilities/FolderUtilities.h @@ -4,20 +4,23 @@ class FolderUtilities { - public: - static wstring GetHomeFolder(); - static wstring GetSaveFolder(); - static wstring GetSaveStateFolder(); - static wstring GetMovieFolder(); - static wstring GetScreenshotFolder(); +private: + static wstring _homeFolder; +public: + static void SetHomeFolder(wstring homeFolder); + static wstring GetHomeFolder(); + static wstring GetSaveFolder(); + static wstring GetSaveStateFolder(); + static wstring GetMovieFolder(); + static wstring GetScreenshotFolder(); - static vector GetFolders(wstring rootFolder); - static vector GetFilesInFolder(wstring rootFolder, wstring mask, bool recursive); + static vector GetFolders(wstring rootFolder); + static vector GetFilesInFolder(wstring rootFolder, wstring mask, bool recursive); - static wstring GetFilename(wstring filepath, bool includeExtension); - static wstring GetFolderName(wstring filepath); - - static int64_t GetFileModificationTime(wstring filepath); + static wstring GetFilename(wstring filepath, bool includeExtension); + static wstring GetFolderName(wstring filepath); - static wstring CombinePath(wstring folder, wstring filename); + static int64_t GetFileModificationTime(wstring filepath); + + static wstring CombinePath(wstring folder, wstring filename); }; \ No newline at end of file