From 080a823cda1777e7ca27588aae78873b55e223d4 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:38:17 +1000 Subject: [PATCH] Merge 1.7.3 into main (#331) --- gaseous-server/Classes/Config.cs | 5 + gaseous-server/Classes/Database.cs | 32 +- gaseous-server/Classes/Metadata/Games.cs | 1 + gaseous-server/Classes/RomMediaGroup.cs | 122 ++++- .../Controllers/V1.0/SearchController.cs | 1 + .../Controllers/V1.1/GamesController.cs | 2 + .../wwwroot/emulators/EmulatorJS.html | 5 + .../wwwroot/pages/dialogs/librarynew.html | 48 +- .../wwwroot/pages/dialogs/rominfo.html | 15 +- .../wwwroot/pages/dialogs/userprofile.html | 3 +- gaseous-server/wwwroot/pages/emulator.html | 6 + gaseous-server/wwwroot/pages/game.html | 2 +- .../wwwroot/pages/settings/settings.html | 2 +- .../wwwroot/scripts/filterformating.js | 23 +- .../wwwroot/scripts/gamesformating.js | 467 ++++++++++-------- gaseous-server/wwwroot/styles/style.css | 24 +- 16 files changed, 519 insertions(+), 239 deletions(-) diff --git a/gaseous-server/Classes/Config.cs b/gaseous-server/Classes/Config.cs index 80eea28e..26f9963e 100644 --- a/gaseous-server/Classes/Config.cs +++ b/gaseous-server/Classes/Config.cs @@ -196,6 +196,11 @@ public static void InitSettings() { string SettingName = (string)dataRow["Setting"]; + if (SettingName.StartsWith("LastRun_")) + { + Console.WriteLine("Break"); + } + if (AppSettings.ContainsKey(SettingName)) { AppSettings.Remove(SettingName); diff --git a/gaseous-server/Classes/Database.cs b/gaseous-server/Classes/Database.cs index dcf44c57..555ef3ae 100644 --- a/gaseous-server/Classes/Database.cs +++ b/gaseous-server/Classes/Database.cs @@ -9,8 +9,21 @@ namespace gaseous_server.Classes { public class Database { - public static int schema_version = 0; - + private static int _schema_version { get; set; } = 0; + public static int schema_version + { + get + { + //Logging.Log(Logging.LogType.Information, "Database Schema", "Schema version is " + _schema_version); + return _schema_version; + } + set + { + //Logging.Log(Logging.LogType.Information, "Database Schema", "Setting schema version " + _schema_version); + _schema_version = value; + } + } + public Database() { @@ -80,7 +93,16 @@ public void InitDB() ExecuteCMD(sql, dbDict); } - for (int i = 1000; i < 10000; i++) + sql = "SELECT schema_version FROM schema_version;"; + dbDict = new Dictionary(); + DataTable SchemaVersion = ExecuteCMD(sql, dbDict); + int OuterSchemaVer = (int)SchemaVersion.Rows[0][0]; + if (OuterSchemaVer == 0) + { + OuterSchemaVer = 1000; + } + + for (int i = OuterSchemaVer; i < 10000; i++) { string resourceName = "gaseous_server.Support.Database.MySQL.gaseous-" + i + ".sql"; string dbScript = ""; @@ -96,7 +118,7 @@ public void InitDB() // apply script sql = "SELECT schema_version FROM schema_version;"; dbDict = new Dictionary(); - DataTable SchemaVersion = ExecuteCMD(sql, dbDict); + SchemaVersion = ExecuteCMD(sql, dbDict); if (SchemaVersion.Rows.Count == 0) { // something is broken here... where's the table? @@ -107,6 +129,8 @@ public void InitDB() { int SchemaVer = (int)SchemaVersion.Rows[0][0]; Logging.Log(Logging.LogType.Information, "Database", "Schema version is " + SchemaVer); + // update schema version variable + Database.schema_version = SchemaVer; if (SchemaVer < i) { try diff --git a/gaseous-server/Classes/Metadata/Games.cs b/gaseous-server/Classes/Metadata/Games.cs index 8476b6ab..18e4e2b0 100644 --- a/gaseous-server/Classes/Metadata/Games.cs +++ b/gaseous-server/Classes/Metadata/Games.cs @@ -561,6 +561,7 @@ public MinimalGameItem(Game gameObject) } public long? Id { get; set; } + public long Index { get; set; } public string Name { get; set; } public string Slug { get; set; } public double? TotalRating { get; set; } diff --git a/gaseous-server/Classes/RomMediaGroup.cs b/gaseous-server/Classes/RomMediaGroup.cs index b24c4b1a..5fb0f52d 100644 --- a/gaseous-server/Classes/RomMediaGroup.cs +++ b/gaseous-server/Classes/RomMediaGroup.cs @@ -5,6 +5,9 @@ using IGDB.Models; using gaseous_server.Classes.Metadata; using System.IO.Compression; +using SharpCompress.Archives; +using SharpCompress.Common; +using gaseous_server.Models; namespace gaseous_server.Classes { @@ -259,6 +262,7 @@ public static void CompileMediaGroup(long Id) { Game GameObject = Games.GetGame(mediaGroupItem.GameId, false, false, false); Platform PlatformObject = Platforms.GetPlatform(mediaGroupItem.PlatformId, false); + PlatformMapping.PlatformMapItem platformMapItem = PlatformMapping.GetPlatformMap(mediaGroupItem.PlatformId); Logging.Log(Logging.LogType.Information, "Media Group", "Beginning build of media group: " + GameObject.Name + " for platform " + PlatformObject.Name); @@ -293,10 +297,124 @@ public static void CompileMediaGroup(long Id) foreach (long RomId in mediaGroupItem.RomIds) { Roms.GameRomItem rom = Roms.GetRom(RomId); + bool fileNameFound = false; if (File.Exists(rom.Path)) { - Logging.Log(Logging.LogType.Information, "Media Group", "Copying ROM: " + rom.Name); - File.Copy(rom.Path, Path.Combine(ZipFileTempPath, Path.GetFileName(rom.Path))); + string romExt = Path.GetExtension(rom.Path); + if (new string[]{ ".zip", ".rar", ".7z" }.Contains(romExt)) + { + Logging.Log(Logging.LogType.Information, "Media Group", "Decompressing ROM: " + rom.Name); + + // is compressed + switch (romExt) + { + case ".zip": + try + { + using (var archive = SharpCompress.Archives.Zip.ZipArchive.Open(rom.Path)) + { + foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) + { + Logging.Log(Logging.LogType.Information, "Media Group", "Extracting file: " + entry.Key); + if (fileNameFound == false) + { + //check if extension is in valid extensions + if (platformMapItem.Extensions.SupportedFileExtensions.Contains(Path.GetExtension(entry.Key), StringComparer.InvariantCultureIgnoreCase)) + { + // update rom file name + rom.Name = entry.Key; + fileNameFound = true; + } + } + entry.WriteToDirectory(ZipFileTempPath, new ExtractionOptions() + { + ExtractFullPath = true, + Overwrite = true + }); + } + } + } + catch (Exception zipEx) + { + Logging.Log(Logging.LogType.Warning, "Media Group", "Unzip error", zipEx); + throw; + } + break; + + case ".rar": + try + { + using (var archive = SharpCompress.Archives.Rar.RarArchive.Open(rom.Path)) + { + foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) + { + Logging.Log(Logging.LogType.Information, "Media Group", "Extracting file: " + entry.Key); + if (fileNameFound == false) + { + //check if extension is in valid extensions + if (platformMapItem.Extensions.SupportedFileExtensions.Contains(Path.GetExtension(entry.Key), StringComparer.InvariantCultureIgnoreCase)) + { + // update rom file name + rom.Name = entry.Key; + fileNameFound = true; + } + } + entry.WriteToDirectory(ZipFileTempPath, new ExtractionOptions() + { + ExtractFullPath = true, + Overwrite = true + }); + } + } + } + catch (Exception zipEx) + { + Logging.Log(Logging.LogType.Warning, "Media Group", "Unrar error", zipEx); + throw; + } + break; + + case ".7z": + try + { + using (var archive = SharpCompress.Archives.SevenZip.SevenZipArchive.Open(rom.Path)) + { + foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) + { + Logging.Log(Logging.LogType.Information, "Media Group", "Extracting file: " + entry.Key); + if (fileNameFound == false) + { + //check if extension is in valid extensions + if (platformMapItem.Extensions.SupportedFileExtensions.Contains(Path.GetExtension(entry.Key), StringComparer.InvariantCultureIgnoreCase)) + { + // update rom file name + rom.Name = entry.Key; + fileNameFound = true; + } + } + entry.WriteToDirectory(ZipFileTempPath, new ExtractionOptions() + { + ExtractFullPath = true, + Overwrite = true + }); + } + } + } + catch (Exception zipEx) + { + Logging.Log(Logging.LogType.Warning, "Media Group", "7z error", zipEx); + throw; + } + break; + + } + } + else + { + // is uncompressed + Logging.Log(Logging.LogType.Information, "Media Group", "Copying ROM: " + rom.Name); + File.Copy(rom.Path, Path.Combine(ZipFileTempPath, Path.GetFileName(rom.Path))); + } romItems.Add(rom); } diff --git a/gaseous-server/Controllers/V1.0/SearchController.cs b/gaseous-server/Controllers/V1.0/SearchController.cs index a4766881..35894105 100644 --- a/gaseous-server/Controllers/V1.0/SearchController.cs +++ b/gaseous-server/Controllers/V1.0/SearchController.cs @@ -76,6 +76,7 @@ private static async Task> _SearchForGame(long PlatformId, str string searchFields = "fields cover,first_release_date,name,platforms,slug; "; searchBody += "search \"" + SearchString + "\";"; searchBody += "where platforms = (" + PlatformId + ");"; + searchBody += "limit 100;"; List? searchCache = Communications.GetSearchCache>(searchFields, searchBody); diff --git a/gaseous-server/Controllers/V1.1/GamesController.cs b/gaseous-server/Controllers/V1.1/GamesController.cs index 8bcc3f56..67ce3727 100644 --- a/gaseous-server/Controllers/V1.1/GamesController.cs +++ b/gaseous-server/Controllers/V1.1/GamesController.cs @@ -479,6 +479,7 @@ public static GameReturnPackage GetGames(GameSearchModel model, string userid, i Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); string sql = @" +SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); SELECT DISTINCT Game.Id, Game.`Name`, @@ -569,6 +570,7 @@ LEFT JOIN Game retGame = Storage.BuildCacheObject(new Game() , dbResponse.Rows[i]); Games.MinimalGameItem retMinGame = new Games.MinimalGameItem(retGame); + retMinGame.Index = i; if (dbResponse.Rows[i]["RomSaveCount"] != DBNull.Value || dbResponse.Rows[i]["MediaGroupSaveCount"] != DBNull.Value) { retMinGame.HasSavedGame = true; diff --git a/gaseous-server/wwwroot/emulators/EmulatorJS.html b/gaseous-server/wwwroot/emulators/EmulatorJS.html index 7baa7fcd..fa789b08 100644 --- a/gaseous-server/wwwroot/emulators/EmulatorJS.html +++ b/gaseous-server/wwwroot/emulators/EmulatorJS.html @@ -40,6 +40,11 @@ EJS_threads = false; + EJS_Buttons = { + saveSavFiles: false, + loadSavFiles: false + } + EJS_onSaveState = function(e) { var returnValue = { "ScreenshotByteArrayBase64": btoa(Uint8ToString(e.screenshot)), diff --git a/gaseous-server/wwwroot/pages/dialogs/librarynew.html b/gaseous-server/wwwroot/pages/dialogs/librarynew.html index 447a006e..0f9c6d91 100644 --- a/gaseous-server/wwwroot/pages/dialogs/librarynew.html +++ b/gaseous-server/wwwroot/pages/dialogs/librarynew.html @@ -1,34 +1,30 @@ -
- New Library -
- -
- - - - - - - - - - - - - -
Name
Default Platform
Path
+ + + + + + + + + + + + + +
Name
Default Platform
Path
-
-
- -
-
- -
+
+
+ +
+
+