All settings/files are now saved in Documents\Mesen

This commit is contained in:
Souryo 2015-07-05 19:21:49 -04:00
parent 6ab9f63476
commit c25ef7f07a
6 changed files with 48 additions and 35 deletions

View file

@ -36,16 +36,23 @@ namespace Mesen.GUI.Config
_config.Serialize(ConfigFile); _config.Serialize(ConfigFile);
} }
public static string HomeFolder
{
get
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.Create), "Mesen");
}
}
private static string ConfigFile private static string ConfigFile
{ {
get get
{ {
string configPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create), "Mesen"); if(!Directory.Exists(HomeFolder)) {
if(!Directory.Exists(configPath)) { Directory.CreateDirectory(HomeFolder);
Directory.CreateDirectory(configPath);
} }
return Path.Combine(configPath, "settings.xml"); return Path.Combine(HomeFolder, "settings.xml");
} }
} }

View file

@ -31,7 +31,7 @@ namespace Mesen.GUI.Forms
_notifListener = new InteropEmu.NotificationListener(); _notifListener = new InteropEmu.NotificationListener();
_notifListener.OnNotification += _notifListener_OnNotification; _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); InteropEmu.SetFlags((int)EmulationFlags.LimitFPS);
UpdateMenus(); UpdateMenus();

View file

@ -12,7 +12,7 @@ namespace Mesen.GUI
public class InteropEmu public class InteropEmu
{ {
private const string DLLPath = "WinMesen.dll"; 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 Release();
[DllImport(DLLPath)] public static extern void LoadROM([MarshalAs(UnmanagedType.LPWStr)]string filename); [DllImport(DLLPath)] public static extern void LoadROM([MarshalAs(UnmanagedType.LPWStr)]string filename);
[DllImport(DLLPath)] public static extern void Run(); [DllImport(DLLPath)] public static extern void Run();

View file

@ -37,8 +37,10 @@ namespace InteropEmu {
}; };
extern "C" { 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; _windowHandle = windowHandle;
_viewerHandle = dxViewerHandle; _viewerHandle = dxViewerHandle;

View file

@ -3,45 +3,46 @@
#include <shlobj.h> #include <shlobj.h>
#include "FolderUtilities.h" #include "FolderUtilities.h"
wstring FolderUtilities::_homeFolder = L"";
void FolderUtilities::SetHomeFolder(wstring homeFolder)
{
_homeFolder = homeFolder;
CreateDirectory(homeFolder.c_str(), nullptr);
}
wstring FolderUtilities::GetHomeFolder() wstring FolderUtilities::GetHomeFolder()
{ {
wstring folder; if(_homeFolder.size() == 0) {
PWSTR pathName; throw std::exception("Home folder not specified");
SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &pathName); }
folder = wstring((wchar_t*)pathName) + L"\\NesEMU\\"; return _homeFolder;
//Make sure it exists
CreateDirectory(folder.c_str(), nullptr);
CoTaskMemFree(pathName);
return folder;
} }
wstring FolderUtilities::GetSaveFolder() wstring FolderUtilities::GetSaveFolder()
{ {
wstring folder = GetHomeFolder() + L"Saves\\"; wstring folder = CombinePath(GetHomeFolder(), L"Saves\\");
CreateDirectory(folder.c_str(), nullptr); CreateDirectory(folder.c_str(), nullptr);
return folder; return folder;
} }
wstring FolderUtilities::GetSaveStateFolder() wstring FolderUtilities::GetSaveStateFolder()
{ {
wstring folder = GetHomeFolder() + L"SaveStates\\"; wstring folder = CombinePath(GetHomeFolder(), L"SaveStates\\");
CreateDirectory(folder.c_str(), nullptr); CreateDirectory(folder.c_str(), nullptr);
return folder; return folder;
} }
wstring FolderUtilities::GetMovieFolder() wstring FolderUtilities::GetMovieFolder()
{ {
wstring folder = GetHomeFolder() + L"Movies\\"; wstring folder = CombinePath(GetHomeFolder(), + L"Movies\\");
CreateDirectory(folder.c_str(), nullptr); CreateDirectory(folder.c_str(), nullptr);
return folder; return folder;
} }
wstring FolderUtilities::GetScreenshotFolder() wstring FolderUtilities::GetScreenshotFolder()
{ {
wstring folder = GetHomeFolder() + L"Screenshots\\"; wstring folder = CombinePath(GetHomeFolder(), L"Screenshots\\");
CreateDirectory(folder.c_str(), nullptr); CreateDirectory(folder.c_str(), nullptr);
return folder; return folder;
} }

View file

@ -4,7 +4,10 @@
class FolderUtilities class FolderUtilities
{ {
private:
static wstring _homeFolder;
public: public:
static void SetHomeFolder(wstring homeFolder);
static wstring GetHomeFolder(); static wstring GetHomeFolder();
static wstring GetSaveFolder(); static wstring GetSaveFolder();
static wstring GetSaveStateFolder(); static wstring GetSaveStateFolder();