From 8ce403dab232419283721d18d0fc98d9718eecec Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 30 Nov 2019 23:18:26 +1000 Subject: [PATCH] Mirror cleanup from 7aa170283 onto the C# APIs also fixed VS' stupid comma placement and added a "using" in SqlLuaLibrary --- BizHawk.Client.Common/Api/Classes/EmuApi.cs | 19 +++++-------- .../Api/Classes/GameInfoApi.cs | 28 +++---------------- BizHawk.Client.Common/Api/Classes/MovieApi.cs | 4 +-- BizHawk.Client.Common/Api/Classes/SqlApi.cs | 2 +- .../lua/EmuLuaLibrary.SQL.cs | 12 ++++---- 5 files changed, 20 insertions(+), 45 deletions(-) diff --git a/BizHawk.Client.Common/Api/Classes/EmuApi.cs b/BizHawk.Client.Common/Api/Classes/EmuApi.cs index ea5524e1af..4e5dbf7029 100644 --- a/BizHawk.Client.Common/Api/Classes/EmuApi.cs +++ b/BizHawk.Client.Common/Api/Classes/EmuApi.cs @@ -377,22 +377,22 @@ namespace BizHawk.Client.Common s.DispBackground = luaParam[1]; nes.PutSettings(s); } - else if (Emulator is QuickNES quickNes) + else if (Emulator is QuickNES quicknes) { - var s = quickNes.GetSettings(); + var s = quicknes.GetSettings(); // this core doesn't support disabling BG - bool showsp = GetSetting(0, luaParam); - if (showsp && s.NumSprites == 0) + bool showSp = GetSetting(0, luaParam); + if (showSp && s.NumSprites == 0) { s.NumSprites = 8; } - else if (!showsp && s.NumSprites > 0) + else if (!showSp && s.NumSprites > 0) { s.NumSprites = 0; } - quickNes.PutSettings(s); + quicknes.PutSettings(s); } else if (Emulator is PCEngine pce) { @@ -426,12 +426,7 @@ namespace BizHawk.Client.Common private static bool GetSetting(int index, bool[] settings) { - if (index < settings.Length) - { - return settings[index]; - } - - return true; + return index >= settings.Length || settings[index]; } } } diff --git a/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs b/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs index f6bd4848df..52c8b017a5 100644 --- a/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs +++ b/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs @@ -12,22 +12,12 @@ namespace BizHawk.Client.Common public string GetRomName() { - if (Global.Game != null) - { - return Global.Game.Name ?? ""; - } - - return ""; + return Global.Game?.Name ?? ""; } public string GetRomHash() { - if (Global.Game != null) - { - return Global.Game.Hash ?? ""; - } - - return ""; + return Global.Game?.Hash ?? ""; } public bool InDatabase() @@ -42,22 +32,12 @@ namespace BizHawk.Client.Common public string GetStatus() { - if (Global.Game != null) - { - return Global.Game.Status.ToString(); - } - - return ""; + return Global.Game?.Status.ToString(); } public bool IsStatusBad() { - if (Global.Game != null) - { - return Global.Game.IsRomStatusBad(); - } - - return true; + return Global.Game?.IsRomStatusBad() ?? true; } public string GetBoardType() diff --git a/BizHawk.Client.Common/Api/Classes/MovieApi.cs b/BizHawk.Client.Common/Api/Classes/MovieApi.cs index 1463b0d498..a876ebca16 100644 --- a/BizHawk.Client.Common/Api/Classes/MovieApi.cs +++ b/BizHawk.Client.Common/Api/Classes/MovieApi.cs @@ -95,8 +95,8 @@ namespace BizHawk.Client.Common { var movie = Global.MovieSession.Movie; var system = movie.HeaderEntries[HeaderKeys.PLATFORM]; - var pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL) && - movie.HeaderEntries[HeaderKeys.PAL] == "1"; + var pal = movie.HeaderEntries.ContainsKey(HeaderKeys.PAL) + && movie.HeaderEntries[HeaderKeys.PAL] == "1"; return new PlatformFrameRates()[system, pal]; } diff --git a/BizHawk.Client.Common/Api/Classes/SqlApi.cs b/BizHawk.Client.Common/Api/Classes/SqlApi.cs index 069c4dcf26..0df1e1f18b 100644 --- a/BizHawk.Client.Common/Api/Classes/SqlApi.cs +++ b/BizHawk.Client.Common/Api/Classes/SqlApi.cs @@ -29,7 +29,7 @@ namespace BizHawk.Client.Common { DataSource = name, Version = 3, - JournalMode = SQLiteJournalModeEnum.Wal, // Allows for reads and writes to happen at the same time + JournalMode = SQLiteJournalModeEnum.Wal, // Allows for reads and writes to happen at the same time DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted, // This only helps make the database lock left. May be pointless now SyncMode = SynchronizationModes.Off // This shortens the delay for do synchronous calls. }; diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs index 6afde80435..0969c2502f 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.SQL.cs @@ -44,11 +44,11 @@ namespace BizHawk.Client.Common { var connBuilder = new SQLiteConnectionStringBuilder { - DataSource = name - , Version = 3 // SQLite version - , JournalMode = SQLiteJournalModeEnum.Wal // Allows for reads and writes to happen at the same time - , DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted // This only helps make the database lock left. May be pointless now - , SyncMode = SynchronizationModes.Off // This shortens the delay for do synchronous calls. + DataSource = name, + Version = 3, + JournalMode = SQLiteJournalModeEnum.Wal, // Allows for reads and writes to happen at the same time + DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted, // This only helps make the database lock left. May be pointless now + SyncMode = SynchronizationModes.Off, // This shortens the delay for do synchronous calls. }; _mDBConnection = new SQLiteConnection(connBuilder.ToString()); @@ -107,7 +107,7 @@ namespace BizHawk.Client.Common var table = Lua.NewTable(); _mDBConnection.Open(); string sql = $"PRAGMA read_uncommitted =1;{query}"; - var command = new SQLiteCommand(sql, _mDBConnection); + using var command = new SQLiteCommand(sql, _mDBConnection); SQLiteDataReader reader = command.ExecuteReader(); bool rows = reader.HasRows; long rowCount = 0;