From 86b0ab50649436d8b44bcca8723c97f0de6e6473 Mon Sep 17 00:00:00 2001 From: Sour Date: Sat, 7 Jul 2018 18:29:42 -0400 Subject: [PATCH] UI: Fixed crash at startup if custom folders cannot be created --- GUI.NET/Config/ConfigManager.cs | 11 +++++++++-- GUI.NET/InteropEmu.cs | 1 + InteropDLL/ConsoleWrapper.cpp | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/GUI.NET/Config/ConfigManager.cs b/GUI.NET/Config/ConfigManager.cs index c14f417a..621728fd 100644 --- a/GUI.NET/Config/ConfigManager.cs +++ b/GUI.NET/Config/ConfigManager.cs @@ -201,8 +201,15 @@ namespace Mesen.GUI.Config } else { folder = defaultFolderName; } - if(!Directory.Exists(folder)) { - Directory.CreateDirectory(folder); + + try { + if(!Directory.Exists(folder)) { + Directory.CreateDirectory(folder); + } + } catch { + //If the folder doesn't exist and we couldn't create it, use the default folder + InteropEmu.WriteLogEntry("[UI] Folder could not be created: " + folder); + folder = defaultFolderName; } return folder; } diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 2d4e53d1..d29b3f06 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -100,6 +100,7 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void DisplayMessage([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string title, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string message, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string param1 = null); [DllImport(DLLPath, EntryPoint = "GetLog")] private static extern IntPtr GetLogWrapper(); + [DllImport(DLLPath)] public static extern void WriteLogEntry([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string message); [DllImport(DLLPath)] public static extern void MoviePlay([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string filename); [DllImport(DLLPath)] public static extern void MovieRecord(ref RecordMovieOptions options); diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index 9f20cbba..b8547f16 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -423,6 +423,8 @@ namespace InteropEmu { return _logString.c_str(); } + DllExport void __stdcall WriteLogEntry(char* message) { MessageManager::Log(message); } + DllExport void __stdcall SaveState(uint32_t stateIndex) { _console->GetSaveStateManager()->SaveState(stateIndex); } DllExport void __stdcall LoadState(uint32_t stateIndex) { _console->GetSaveStateManager()->LoadState(stateIndex); } DllExport void __stdcall SaveStateFile(char* filepath) { _console->GetSaveStateManager()->SaveState(filepath); }