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);
}
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");
}
}

View file

@ -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();

View file

@ -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();

View file

@ -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;

View file

@ -3,45 +3,46 @@
#include <shlobj.h>
#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;
}

View file

@ -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<wstring> GetFolders(wstring rootFolder);
static vector<wstring> GetFilesInFolder(wstring rootFolder, wstring mask, bool recursive);
static vector<wstring> GetFolders(wstring rootFolder);
static vector<wstring> 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);
};