From 10478e23f1dbc2fb581cd8e2cff722501577713e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 7 Aug 2022 10:36:52 +1000 Subject: [PATCH] Remove redundant dir exists checks --- src/BizHawk.Client.EmuHawk/MainForm.cs | 8 +++----- .../config/FirmwaresConfig.cs | 6 +----- src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 6 +----- .../movie/RecordMovie.cs | 5 +---- .../tools/Lua/LuaConsole.cs | 20 ++++++------------- .../tools/ToolFormBase.cs | 12 ++--------- 6 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index ab475a397f..187a2a61a9 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -1606,11 +1606,9 @@ namespace BizHawk.Client.EmuHawk } else { - ofd.InitialDirectory = Config.PathEntries.AbsolutePathForType(VSystemID.Raw.Libretro, "Cores"); - if (!Directory.Exists(ofd.InitialDirectory)) - { - Directory.CreateDirectory(ofd.InitialDirectory); - } + var initDir = Config.PathEntries.AbsolutePathForType(VSystemID.Raw.Libretro, "Cores"); + Directory.CreateDirectory(initDir); + ofd.InitialDirectory = initDir; } ofd.RestoreDirectory = true; diff --git a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs index b637df607d..e5e8149837 100644 --- a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs @@ -402,11 +402,7 @@ namespace BizHawk.Client.EmuHawk private void TbbOpenFolder_Click(object sender, EventArgs e) { var frmWares = _pathEntries.FirmwareAbsolutePath(); - if (!Directory.Exists(frmWares)) - { - Directory.CreateDirectory(frmWares); - } - + Directory.CreateDirectory(frmWares); System.Diagnostics.Process.Start(frmWares); } diff --git a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index 2581338ee3..cec5fe32e8 100644 --- a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -239,11 +239,7 @@ namespace BizHawk.Client.EmuHawk MovieView.Update(); var directory = _config.PathEntries.MovieAbsolutePath(); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - + Directory.CreateDirectory(directory); var dpTodo = new Queue(); var fpTodo = new List(); dpTodo.Enqueue(directory); diff --git a/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs b/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs index 9b567fda94..8838ff4161 100644 --- a/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs +++ b/src/BizHawk.Client.EmuHawk/movie/RecordMovie.cs @@ -185,10 +185,7 @@ namespace BizHawk.Client.EmuHawk // Create movie folder if it doesn't already exist try { - if (!Directory.Exists(movieFolderPath)) - { - Directory.CreateDirectory(movieFolderPath); - } + Directory.CreateDirectory(movieFolderPath); } catch (Exception movieDirException) { diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 92ced6a889..f3c74306d7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -785,19 +785,15 @@ namespace BizHawk.Client.EmuHawk private void OpenSessionMenuItem_Click(object sender, EventArgs e) { + var initDir = Config!.PathEntries.LuaAbsolutePath(); + Directory.CreateDirectory(initDir); var ofd = new OpenFileDialog { - InitialDirectory = Config.PathEntries.LuaAbsolutePath(), + InitialDirectory = initDir, Filter = SessionsFSFilterSet.ToString(), RestoreDirectory = true, Multiselect = false }; - - if (!Directory.Exists(ofd.InitialDirectory)) - { - Directory.CreateDirectory(ofd.InitialDirectory); - } - var result = this.ShowDialogWithTempMute(ofd); if (result.IsOk() && !string.IsNullOrWhiteSpace(ofd.FileName)) { @@ -871,19 +867,15 @@ namespace BizHawk.Client.EmuHawk private void OpenScriptMenuItem_Click(object sender, EventArgs e) { + var initDir = Config!.PathEntries.LuaAbsolutePath(); + Directory.CreateDirectory(initDir); var ofd = new OpenFileDialog { - InitialDirectory = Config.PathEntries.LuaAbsolutePath(), + InitialDirectory = initDir, Filter = new FilesystemFilterSet(FilesystemFilter.LuaScripts, FilesystemFilter.TextFiles).ToString(), RestoreDirectory = true, Multiselect = true }; - - if (!Directory.Exists(ofd.InitialDirectory)) - { - Directory.CreateDirectory(ofd.InitialDirectory); - } - var result = this.ShowDialogWithTempMute(ofd); if (result.IsOk() && ofd.FileNames != null) { diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs index db86533938..6418b1261c 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolFormBase.cs @@ -66,11 +66,7 @@ namespace BizHawk.Client.EmuHawk } public FileInfo OpenFileDialog(string currentFile, string path, FilesystemFilterSet filterSet) { - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - + Directory.CreateDirectory(path); using var ofd = new OpenFileDialog { FileName = !string.IsNullOrWhiteSpace(currentFile) @@ -91,11 +87,7 @@ namespace BizHawk.Client.EmuHawk } public static FileInfo SaveFileDialog(string currentFile, string path, FilesystemFilterSet filterSet, IDialogParent parent) { - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - + Directory.CreateDirectory(path); using var sfd = new SaveFileDialog { FileName = Path.GetFileName(currentFile),