Skip to content

Commit

Permalink
Code clean up and API versioning (#178)
Browse files Browse the repository at this point in the history
* Merged tools project into main project

* Applied API versioning
  • Loading branch information
michael-j-green authored Oct 30, 2023
1 parent 1cc7eb2 commit 2ade60c
Show file tree
Hide file tree
Showing 85 changed files with 338 additions and 297 deletions.
6 changes: 0 additions & 6 deletions Gaseous.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1704.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gaseous-tools", "gaseous-tools\gaseous-tools.csproj", "{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gaseous-server", "gaseous-server\gaseous-server.csproj", "{A01D2EFF-C82E-473B-84D7-7C25E736F5D2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{17FA6F12-8532-420C-9489-CB8FDE42137C}"
Expand Down Expand Up @@ -37,10 +35,6 @@ Global
{FFCEC386-033F-4772-A45B-D33579F2E5EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFCEC386-033F-4772-A45B-D33579F2E5EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFCEC386-033F-4772-A45B-D33579F2E5EE}.Release|Any CPU.Build.0 = Release|Any CPU
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08FE408A-5EC1-4110-ABD8-D19A1155B8CE}.Release|Any CPU.Build.0 = Release|Any CPU
{A01D2EFF-C82E-473B-84D7-7C25E736F5D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A01D2EFF-C82E-473B-84D7-7C25E736F5D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A01D2EFF-C82E-473B-84D7-7C25E736F5D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
1 change: 0 additions & 1 deletion gaseous-server/Classes/Bios.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using gaseous_tools;

namespace gaseous_server.Classes
{
Expand Down
15 changes: 7 additions & 8 deletions gaseous-server/Classes/Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using gaseous_server.Classes.Metadata;
using gaseous_server.Controllers;
using gaseous_server.Models;
using gaseous_tools;
using IGDB.Models;
using Newtonsoft.Json;

Expand All @@ -21,7 +20,7 @@ public Collections()
}

public static List<CollectionItem> GetCollections() {
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM RomCollections ORDER BY `Name`";

DataTable data = db.ExecuteCMD(sql);
Expand All @@ -36,7 +35,7 @@ public static List<CollectionItem> GetCollections() {
}

public static CollectionItem GetCollection(long Id) {
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM RomCollections WHERE Id = @id ORDER BY `Name`";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", Id);
Expand All @@ -57,7 +56,7 @@ public static CollectionItem GetCollection(long Id) {

public static CollectionItem NewCollection(CollectionItem item)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "INSERT INTO RomCollections (`Name`, Description, Platforms, Genres, Players, PlayerPerspectives, Themes, MinimumRating, MaximumRating, MaximumRomsPerPlatform, MaximumBytesPerPlatform, MaximumCollectionSizeInBytes, FolderStructure, IncludeBIOSFiles, AlwaysInclude, BuiltStatus) VALUES (@name, @description, @platforms, @genres, @players, @playerperspectives, @themes, @minimumrating, @maximumrating, @maximumromsperplatform, @maximumbytesperplatform, @maximumcollectionsizeinbytes, @folderstructure, @includebiosfiles, @alwaysinclude, @builtstatus); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("name", item.Name);
Expand Down Expand Up @@ -88,7 +87,7 @@ public static CollectionItem NewCollection(CollectionItem item)

public static CollectionItem EditCollection(long Id, CollectionItem item, bool ForceRebuild = true)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "UPDATE RomCollections SET `Name`=@name, Description=@description, Platforms=@platforms, Genres=@genres, Players=@players, PlayerPerspectives=@playerperspectives, Themes=@themes, MinimumRating=@minimumrating, MaximumRating=@maximumrating, MaximumRomsPerPlatform=@maximumromsperplatform, MaximumBytesPerPlatform=@maximumbytesperplatform, MaximumCollectionSizeInBytes=@maximumcollectionsizeinbytes, FolderStructure=@folderstructure, IncludeBIOSFiles=@includebiosfiles, AlwaysInclude=@alwaysinclude, BuiltStatus=@builtstatus WHERE Id=@id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", Id);
Expand Down Expand Up @@ -143,7 +142,7 @@ public static CollectionItem EditCollection(long Id, CollectionItem item, bool F

public static void DeleteCollection(long Id)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "DELETE FROM RomCollections WHERE Id=@id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", Id);
Expand All @@ -163,7 +162,7 @@ public static void StartCollectionItemBuild(long Id)
if (collectionItem.BuildStatus != CollectionItem.CollectionBuildStatus.Building)
{
// set collection item to waitingforbuild
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "UPDATE RomCollections SET BuiltStatus=@bs WHERE Id=@id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", Id);
Expand Down Expand Up @@ -363,7 +362,7 @@ public static CollectionContents GetCollectionContent(CollectionItem collectionI

public static void CompileCollections(long CollectionId)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);

CollectionItem collectionItem = GetCollection(CollectionId);
if (collectionItem.BuildStatus == CollectionItem.CollectionBuildStatus.WaitingForBuild)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Security.Cryptography;

namespace gaseous_tools
namespace gaseous_server.Classes
{
public class Common
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Newtonsoft.Json;
using IGDB.Models;

namespace gaseous_tools
namespace gaseous_server.Classes
{
public static class Config
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using System.Diagnostics;
using System.Reflection;
using MySqlConnector;
using static gaseous_tools.Database;

namespace gaseous_tools
namespace gaseous_server.Classes
{
public class Database
{
Expand Down Expand Up @@ -81,7 +80,7 @@ public void InitDB()

for (int i = 1000; i < 10000; i++)
{
string resourceName = "gaseous_tools.Database.MySQL.gaseous-" + i + ".sql";
string resourceName = "gaseous_server.Support.Database.MySQL.gaseous-" + i + ".sql";
string dbScript = "";

string[] resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
Expand Down Expand Up @@ -109,7 +108,7 @@ public void InitDB()
if (SchemaVer < i)
{
// run pre-upgrade code
gaseous_tools.DatabaseMigration.PreUpgradeScript(i, _ConnectorType);
DatabaseMigration.PreUpgradeScript(i, _ConnectorType);

// apply schema!
Logging.Log(Logging.LogType.Information, "Database", "Updating schema to version " + i);
Expand All @@ -121,7 +120,7 @@ public void InitDB()
ExecuteCMD(sql, dbDict);

// run post-upgrade code
gaseous_tools.DatabaseMigration.PostUpgradeScript(i, _ConnectorType);
DatabaseMigration.PostUpgradeScript(i, _ConnectorType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using System;
using System.Data;

namespace gaseous_tools
namespace gaseous_server.Classes
{
public static class DatabaseMigration
{
public static List<int> BackgroundUpgradeTargetSchemaVersions = new List<int>();

public static void PreUpgradeScript(int TargetSchemaVersion, gaseous_tools.Database.databaseType? DatabaseType)
public static void PreUpgradeScript(int TargetSchemaVersion, Database.databaseType? DatabaseType)
{

}

public static void PostUpgradeScript(int TargetSchemaVersion, gaseous_tools.Database.databaseType? DatabaseType)
public static void PostUpgradeScript(int TargetSchemaVersion, Database.databaseType? DatabaseType)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Dictionary<string, object> dbDict = new Dictionary<string, object>();

switch(DatabaseType)
Expand Down Expand Up @@ -65,7 +65,7 @@ public static void UpgradeScriptBackgroundTasks()
}

public static void MySql_1002_MigrateMetadataVersion() {
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "";
Dictionary<string, object> dbDict = new Dictionary<string, object>();

Expand Down
12 changes: 6 additions & 6 deletions gaseous-server/Classes/GameLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Data;
using gaseous_server.Classes;
using gaseous_server.Classes.Metadata;
using gaseous_tools;
using IGDB.Models;
using Microsoft.CodeAnalysis.FlowAnalysis.DataFlow;

Expand Down Expand Up @@ -39,7 +39,7 @@ public static LibraryItem GetDefaultLibrary
{
get
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM GameLibraries WHERE DefaultLibrary=1 LIMIT 1";
DataTable data = db.ExecuteCMD(sql);
DataRow row = data.Rows[0];
Expand All @@ -54,7 +54,7 @@ public static List<LibraryItem> GetLibraries
get
{
List<LibraryItem> libraryItems = new List<LibraryItem>();
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM GameLibraries";
DataTable data = db.ExecuteCMD(sql);
foreach (DataRow row in data.Rows)
Expand Down Expand Up @@ -86,7 +86,7 @@ public static LibraryItem AddLibrary(string Name, string Path, long DefaultPlatf
throw new PathNotFound(PathName);
}

Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "INSERT INTO GameLibraries (Name, Path, DefaultPlatform, DefaultLibrary) VALUES (@name, @path, @defaultplatform, 0); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("name", Name);
Expand All @@ -103,7 +103,7 @@ public static void DeleteLibrary(int LibraryId)
{
if (GetLibrary(LibraryId).IsDefaultLibrary == false)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "DELETE FROM Games_Roms WHERE LibraryId=@id; DELETE FROM GameLibraries WHERE Id=@id;";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", LibraryId);
Expand All @@ -117,7 +117,7 @@ public static void DeleteLibrary(int LibraryId)

public static LibraryItem GetLibrary(int LibraryId)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM GameLibraries WHERE Id=@id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", LibraryId);
Expand Down
9 changes: 4 additions & 5 deletions gaseous-server/Classes/ImportGames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using gaseous_server.Classes.Metadata;
using gaseous_tools;
using IGDB.Models;
using NuGet.Common;
using static gaseous_server.Classes.Metadata.Games;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class ImportGame
{
public static void ImportGameFile(string GameFileImportPath, IGDB.Models.Platform? OverridePlatform)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "";
Dictionary<string, object> dbDict = new Dictionary<string, object>();

Expand Down Expand Up @@ -418,7 +417,7 @@ private static List<string> GetSearchCandidates(string GameName)

public static long StoreROM(GameLibrary.LibraryItem library, Common.hashObject hash, IGDB.Models.Game determinedGame, IGDB.Models.Platform determinedPlatform, Models.Signatures_Games discoveredSignature, string GameFileImportPath, long UpdateId = 0)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);

string sql = "";

Expand Down Expand Up @@ -541,7 +540,7 @@ public static bool MoveGameFile(long RomId)
File.Move(romPath, DestinationPath);

// update the db
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "UPDATE Games_Roms SET Path=@path WHERE Id=@id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", RomId);
Expand All @@ -566,7 +565,7 @@ public static void OrganiseLibrary()
GameLibrary.LibraryItem library = GameLibrary.GetDefaultLibrary;

// move rom files to their new location
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM Games_Roms WHERE LibraryId = @libraryid";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("libraryid", library.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Metadata.Ecma335;
namespace gaseous_tools
namespace gaseous_server.Classes
{
public class Logging
{
Expand Down Expand Up @@ -69,7 +69,7 @@ static public void Log(LogType EventType, string ServerProcess, string Message,

if (LogToDiskOnly == false)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "DELETE FROM ServerLogs WHERE EventTime < @EventRententionDate; INSERT INTO ServerLogs (EventTime, EventType, Process, Message, Exception) VALUES (@EventTime, @EventType, @Process, @Message, @Exception);";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("EventRententionDate", DateTime.UtcNow.AddDays(Config.LoggingConfiguration.LogRetention * -1));
Expand Down Expand Up @@ -112,7 +112,7 @@ static void LogToDisk(LogItem logItem, string TraceOutput, Exception? exception)

static public List<LogItem> GetLogs(long? StartIndex, int PageNumber = 1, int PageSize = 100)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "";
if (StartIndex == null)
{
Expand Down
3 changes: 1 addition & 2 deletions gaseous-server/Classes/Maintenance.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Data;
using gaseous_server.Models;
using gaseous_tools;
using Microsoft.VisualStudio.Web.CodeGeneration;

namespace gaseous_server.Classes
Expand Down Expand Up @@ -46,7 +45,7 @@ public static void RunMaintenance()
}

Logging.Log(Logging.LogType.Information, "Maintenance", "Optimising database tables");
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SHOW TABLES;";
DataTable tables = db.ExecuteCMD(sql);

Expand Down
4 changes: 1 addition & 3 deletions gaseous-server/Classes/Metadata/AgeRating.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Reflection;
using gaseous_tools;
using IGDB;
using IGDB.Models;
using static gaseous_tools.Config.ConfigFile;

namespace gaseous_server.Classes.Metadata
{
Expand Down Expand Up @@ -83,7 +81,7 @@ private static async Task<AgeRating> _GetAgeRatings(SearchUsing searchUsing, obj
}
catch (Exception ex)
{
gaseous_tools.Logging.Log(gaseous_tools.Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
returnValue = Storage.GetCacheValue<AgeRating>(returnValue, "id", (long)searchValue);
}
break;
Expand Down
Loading

0 comments on commit 2ade60c

Please sign in to comment.