Compare commits

...

6 Commits

Author SHA1 Message Date
Michael Green
e4cffb6fb4 Revert "Added a check for the DB and a delay at start up if the database is not available (#148)"
This reverts commit f9d6cc4bdc.
2023-10-11 16:09:55 +11:00
Michael Green
0e125d42ec Revert "Create libraries based on external unmanaged directories (#147)"
This reverts commit 1934558595.
2023-10-11 16:09:34 +11:00
Michael Green
6d110731c4 Merge branch 'main' into branch-v1.6.0 2023-10-10 22:04:59 -07:00
Michael Green
de628e6766 Check for null during cache clean (#153) 2023-10-11 16:02:34 +11:00
Michael Green
308338580d Cache objects from database in memory to improve performance (#151)
* IGDB objects are now cached in memory

* Completed caching of PlatformMaps
2023-10-10 23:59:52 +11:00
Michael Green
49784dc325 Removed import block from LibraryScan (#150) 2023-10-10 11:00:13 +11:00
23 changed files with 273 additions and 769 deletions

View File

@@ -1,176 +0,0 @@
using System;
using System.Data;
using gaseous_server.Classes.Metadata;
using gaseous_tools;
using IGDB.Models;
using Microsoft.CodeAnalysis.FlowAnalysis.DataFlow;
namespace gaseous_server
{
public static class GameLibrary
{
// exceptions
public class PathExists : Exception
{
public PathExists(string path) : base("The library path " + path + " already exists.")
{}
}
public class PathNotFound : Exception
{
public PathNotFound(string path) : base("The path " + path + " does not exist.")
{}
}
public class LibraryNotFound : Exception
{
public LibraryNotFound(int LibraryId) : base("Library id " + LibraryId + " does not exist.")
{}
}
public class CannotDeleteDefaultLibrary : Exception
{
public CannotDeleteDefaultLibrary() : base("Unable to delete the default library.")
{}
}
// code
public static LibraryItem GetDefaultLibrary
{
get
{
Database db = new gaseous_tools.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];
LibraryItem library = new LibraryItem((int)row["Id"], (string)row["Name"], (string)row["Path"], (long)row["DefaultPlatform"], Convert.ToBoolean((int)row["DefaultLibrary"]));
return library;
}
}
public static List<LibraryItem> GetLibraries
{
get
{
List<LibraryItem> libraryItems = new List<LibraryItem>();
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM GameLibraries";
DataTable data = db.ExecuteCMD(sql);
foreach (DataRow row in data.Rows)
{
LibraryItem library = new LibraryItem((int)row["Id"], (string)row["Name"], (string)row["Path"], (long)row["DefaultPlatform"], Convert.ToBoolean((int)row["DefaultLibrary"]));
libraryItems.Add(library);
}
return libraryItems;
}
}
public static LibraryItem AddLibrary(string Name, string Path, long DefaultPlatformId)
{
string PathName = Common.NormalizePath(Path);
// check path isn't already in place
foreach (LibraryItem item in GetLibraries)
{
if (Common.NormalizePath(PathName) == Common.NormalizePath(item.Path))
{
// already existing path!
throw new PathExists(PathName);
}
}
if (!System.IO.Path.Exists(PathName))
{
throw new PathNotFound(PathName);
}
Database db = new gaseous_tools.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);
dbDict.Add("path", PathName);
dbDict.Add("defaultplatform", DefaultPlatformId);
DataTable data = db.ExecuteCMD(sql, dbDict);
int newLibraryId = (int)(long)data.Rows[0][0];
return GetLibrary(newLibraryId);
}
public static void DeleteLibrary(int LibraryId)
{
if (GetLibrary(LibraryId).IsDefaultLibrary == false)
{
Database db = new gaseous_tools.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);
db.ExecuteCMD(sql, dbDict);
}
else
{
throw new CannotDeleteDefaultLibrary();
}
}
public static LibraryItem GetLibrary(int LibraryId)
{
Database db = new gaseous_tools.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);
DataTable data = db.ExecuteCMD(sql, dbDict);
if (data.Rows.Count > 0)
{
DataRow row = data.Rows[0];
LibraryItem library = new LibraryItem((int)row["Id"], (string)row["Name"], (string)row["Path"], (long)row["DefaultPlatform"], Convert.ToBoolean((int)row["DefaultLibrary"]));
return library;
}
else
{
throw new LibraryNotFound(LibraryId);
}
}
public class LibraryItem
{
public LibraryItem(int Id, string Name, string Path, long DefaultPlatformId, bool IsDefaultLibrary)
{
_Id = Id;
_Name = Name;
_Path = Path;
_DefaultPlatformId = DefaultPlatformId;
_IsDefaultLibrary = IsDefaultLibrary;
}
int _Id = 0;
string _Name = "";
string _Path = "";
long _DefaultPlatformId = 0;
bool _IsDefaultLibrary = false;
public int Id => _Id;
public string Name => _Name;
public string Path => _Path;
public long DefaultPlatformId => _DefaultPlatformId;
public string? DefaultPlatformName
{
get
{
if (_DefaultPlatformId != 0)
{
Platform platform = Platforms.GetPlatform(_DefaultPlatformId);
return platform.Name;
}
else
{
return "";
}
}
}
public bool IsDefaultLibrary => _IsDefaultLibrary;
}
}
}

View File

@@ -4,7 +4,6 @@ using System.IO.Compression;
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using gaseous_server.Classes.Metadata;
using gaseous_tools;
using IGDB.Models;
using MySqlX.XDevAPI;
@@ -99,7 +98,7 @@ namespace gaseous_server.Classes
IGDB.Models.Game determinedGame = SearchForGame(discoveredSignature.Game.Name, discoveredSignature.Flags.IGDBPlatformId);
// add to database
StoreROM(GameLibrary.GetDefaultLibrary, hash, determinedGame, determinedPlatform, discoveredSignature, GameFileImportPath);
StoreROM(hash, determinedGame, determinedPlatform, discoveredSignature, GameFileImportPath);
}
}
else
@@ -392,7 +391,7 @@ namespace gaseous_server.Classes
return SearchCandidates;
}
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)
public static long StoreROM(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);
@@ -402,7 +401,7 @@ namespace gaseous_server.Classes
if (UpdateId == 0)
{
sql = "INSERT INTO Games_Roms (PlatformId, GameId, Name, Size, CRC, MD5, SHA1, DevelopmentStatus, Attributes, RomType, RomTypeMedia, MediaLabel, Path, MetadataSource, MetadataGameName, MetadataVersion, LibraryId) VALUES (@platformid, @gameid, @name, @size, @crc, @md5, @sha1, @developmentstatus, @Attributes, @romtype, @romtypemedia, @medialabel, @path, @metadatasource, @metadatagamename, @metadataversion, @libraryid); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
sql = "INSERT INTO Games_Roms (PlatformId, GameId, Name, Size, CRC, MD5, SHA1, DevelopmentStatus, Attributes, RomType, RomTypeMedia, MediaLabel, Path, MetadataSource, MetadataGameName, MetadataVersion) VALUES (@platformid, @gameid, @name, @size, @crc, @md5, @sha1, @developmentstatus, @Attributes, @romtype, @romtypemedia, @medialabel, @path, @metadatasource, @metadatagamename, @metadataversion); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
} else
{
sql = "UPDATE Games_Roms SET PlatformId=platformid, GameId=@gameid, Name=@name, Size=@size, DevelopmentStatus=@developmentstatus, Attributes=@Attributes, RomType=@romtype, RomTypeMedia=@romtypemedia, MediaLabel=@medialabel, MetadataSource=@metadatasource, MetadataGameName=@metadatagamename, MetadataVersion=@metadataversion WHERE Id=@id;";
@@ -419,7 +418,6 @@ namespace gaseous_server.Classes
dbDict.Add("metadatasource", discoveredSignature.Rom.SignatureSource);
dbDict.Add("metadatagamename", discoveredSignature.Game.Name);
dbDict.Add("metadataversion", 2);
dbDict.Add("libraryid", library.Id);
if (discoveredSignature.Rom.Attributes != null)
{
@@ -452,10 +450,7 @@ namespace gaseous_server.Classes
}
// move to destination
if (library.IsDefaultLibrary == true)
{
MoveGameFile(romId);
}
MoveGameFile(romId);
return romId;
}
@@ -479,7 +474,7 @@ namespace gaseous_server.Classes
{
gameSlug = game.Slug;
}
string DestinationPath = Path.Combine(GameLibrary.GetDefaultLibrary.Path, gameSlug, platformSlug);
string DestinationPath = Path.Combine(Config.LibraryConfiguration.LibraryDataDirectory, gameSlug, platformSlug);
if (!Directory.Exists(DestinationPath))
{
Directory.CreateDirectory(DestinationPath);
@@ -537,16 +532,12 @@ namespace gaseous_server.Classes
public static void OrganiseLibrary()
{
Logging.Log(Logging.LogType.Information, "Organise Library", "Starting default library organisation");
GameLibrary.LibraryItem library = GameLibrary.GetDefaultLibrary;
Logging.Log(Logging.LogType.Information, "Organise Library", "Starting library organisation");
// move rom files to their new location
Database db = new gaseous_tools.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);
DataTable romDT = db.ExecuteCMD(sql, dbDict);
string sql = "SELECT * FROM Games_Roms";
DataTable romDT = db.ExecuteCMD(sql);
if (romDT.Rows.Count > 0)
{
@@ -559,9 +550,9 @@ namespace gaseous_server.Classes
}
// clean up empty directories
DeleteOrphanedDirectories(GameLibrary.GetDefaultLibrary.Path);
DeleteOrphanedDirectories(Config.LibraryConfiguration.LibraryDataDirectory);
Logging.Log(Logging.LogType.Information, "Organise Library", "Finsihed default library organisation");
Logging.Log(Logging.LogType.Information, "Organise Library", "Finsihed library organisation");
}
private static void DeleteOrphanedDirectories(string startLocation)
@@ -579,179 +570,154 @@ namespace gaseous_server.Classes
public static void LibraryScan()
{
foreach (GameLibrary.LibraryItem library in GameLibrary.GetLibraries)
Logging.Log(Logging.LogType.Information, "Library Scan", "Starting library scan");
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Logging.Log(Logging.LogType.Information, "Library Scan", "Looking for duplicate library files to clean up");
string duplicateSql = "DELETE r1 FROM Games_Roms r1 INNER JOIN Games_Roms r2 WHERE r1.Id > r2.Id AND r1.MD5 = r2.MD5;";
db.ExecuteCMD(duplicateSql);
string sql = "SELECT * FROM Games_Roms ORDER BY `name`";
DataTable dtRoms = db.ExecuteCMD(sql);
// clean out database entries in the import folder
if (dtRoms.Rows.Count > 0)
{
Logging.Log(Logging.LogType.Information, "Library Scan", "Starting library scan. Library " + library.Name);
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Logging.Log(Logging.LogType.Information, "Library Scan", "Looking for duplicate library files to clean up");
string duplicateSql = "DELETE r1 FROM Games_Roms r1 INNER JOIN Games_Roms r2 WHERE r1.Id > r2.Id AND r1.MD5 = r2.MD5 AND r1.LibraryId=@libraryid AND r2.LibraryId=@libraryid;";
Dictionary<string, object> dupDict = new Dictionary<string, object>();
dupDict.Add("libraryid", library.Id);
db.ExecuteCMD(duplicateSql, dupDict);
string sql = "SELECT * FROM Games_Roms WHERE LibraryId=@libraryid ORDER BY `name`";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("libraryid", library.Id);
DataTable dtRoms = db.ExecuteCMD(sql, dbDict);
// clean out database entries in the import folder
if (dtRoms.Rows.Count > 0)
for (var i = 0; i < dtRoms.Rows.Count; i++)
{
long romId = (long)dtRoms.Rows[i]["Id"];
string romPath = (string)dtRoms.Rows[i]["Path"];
if (!romPath.StartsWith(Config.LibraryConfiguration.LibraryDataDirectory))
{
Logging.Log(Logging.LogType.Information, "Library Scan", " Deleting database entry for files with incorrect directory " + romPath);
string deleteSql = "DELETE FROM Games_Roms WHERE Id=@id";
Dictionary<string, object> deleteDict = new Dictionary<string, object>();
deleteDict.Add("Id", romId);
db.ExecuteCMD(deleteSql, deleteDict);
}
}
}
sql = "SELECT * FROM Games_Roms ORDER BY `name`";
dtRoms = db.ExecuteCMD(sql);
// search for files in the library that aren't in the database
Logging.Log(Logging.LogType.Information, "Library Scan", "Looking for orphaned library files to add");
string[] LibraryFiles = Directory.GetFiles(Config.LibraryConfiguration.LibraryDataDirectory, "*.*", SearchOption.AllDirectories);
foreach (string LibraryFile in LibraryFiles)
{
if (!Common.SkippableFiles.Contains<string>(Path.GetFileName(LibraryFile), StringComparer.OrdinalIgnoreCase))
{
Common.hashObject LibraryFileHash = new Common.hashObject(LibraryFile);
// check if file is in database
bool romFound = false;
for (var i = 0; i < dtRoms.Rows.Count; i++)
{
long romId = (long)dtRoms.Rows[i]["Id"];
string romPath = (string)dtRoms.Rows[i]["Path"];
string romMd5 = (string)dtRoms.Rows[i]["MD5"];
if (!romPath.StartsWith(library.Path))
if ((LibraryFile == romPath) || (LibraryFileHash.md5hash == romMd5))
{
Logging.Log(Logging.LogType.Information, "Library Scan", " Deleting database entry for files with incorrect directory " + romPath);
string deleteSql = "DELETE FROM Games_Roms WHERE Id=@id AND LibraryId=@libraryid";
Dictionary<string, object> deleteDict = new Dictionary<string, object>();
deleteDict.Add("Id", romId);
deleteDict.Add("libraryid", library.Id);
db.ExecuteCMD(deleteSql, deleteDict);
romFound = true;
break;
}
}
}
sql = "SELECT * FROM Games_Roms ORDER BY `name`";
dtRoms = db.ExecuteCMD(sql, dbDict);
// search for files in the library that aren't in the database
Logging.Log(Logging.LogType.Information, "Library Scan", "Looking for orphaned library files to add");
string[] LibraryFiles = Directory.GetFiles(library.Path, "*.*", SearchOption.AllDirectories);
foreach (string LibraryFile in LibraryFiles)
{
if (!Common.SkippableFiles.Contains<string>(Path.GetFileName(LibraryFile), StringComparer.OrdinalIgnoreCase))
if (romFound == false)
{
Common.hashObject LibraryFileHash = new Common.hashObject(LibraryFile);
// file is not in database - process it
Common.hashObject hash = new Common.hashObject(LibraryFile);
FileInfo fi = new FileInfo(LibraryFile);
// check if file is in database
bool romFound = false;
for (var i = 0; i < dtRoms.Rows.Count; i++)
Models.Signatures_Games sig = GetFileSignature(hash, fi, LibraryFile);
Logging.Log(Logging.LogType.Information, "Library Scan", " Orphaned file found in library: " + LibraryFile);
// get discovered platform
IGDB.Models.Platform determinedPlatform = Metadata.Platforms.GetPlatform(sig.Flags.IGDBPlatformId);
if (determinedPlatform == null)
{
long romId = (long)dtRoms.Rows[i]["Id"];
string romPath = (string)dtRoms.Rows[i]["Path"];
string romMd5 = (string)dtRoms.Rows[i]["MD5"];
if ((LibraryFile == romPath) || (LibraryFileHash.md5hash == romMd5))
{
romFound = true;
break;
}
determinedPlatform = new IGDB.Models.Platform();
}
if (romFound == false)
IGDB.Models.Game determinedGame = SearchForGame(sig.Game.Name, sig.Flags.IGDBPlatformId);
StoreROM(hash, determinedGame, determinedPlatform, sig, LibraryFile);
}
}
}
sql = "SELECT * FROM Games_Roms ORDER BY `name`";
dtRoms = db.ExecuteCMD(sql);
// check all roms to see if their local file still exists
Logging.Log(Logging.LogType.Information, "Library Scan", "Checking library files exist on disk");
if (dtRoms.Rows.Count > 0)
{
for (var i = 0; i < dtRoms.Rows.Count; i++)
{
long romId = (long)dtRoms.Rows[i]["Id"];
string romPath = (string)dtRoms.Rows[i]["Path"];
gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType romMetadataSource = (gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType)(int)dtRoms.Rows[i]["MetadataSource"];
Logging.Log(Logging.LogType.Information, "Library Scan", " Processing ROM at path " + romPath);
if (File.Exists(romPath))
{
// file exists, so lets check to make sure the signature was matched, and update if a signature can be found
if (
romMetadataSource == gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType.None ||
(int)dtRoms.Rows[i]["MetadataVersion"] == 1
)
{
// file is not in database - process it
Common.hashObject hash = new Common.hashObject(LibraryFile);
FileInfo fi = new FileInfo(LibraryFile);
Models.Signatures_Games sig = GetFileSignature(hash, fi, LibraryFile);
Logging.Log(Logging.LogType.Information, "Library Scan", " Orphaned file found in library: " + LibraryFile);
// get discovered platform
IGDB.Models.Platform determinedPlatform = Metadata.Platforms.GetPlatform(sig.Flags.IGDBPlatformId);
IGDB.Models.Game determinedGame = new Game();
if (determinedPlatform == null)
Common.hashObject hash = new Common.hashObject
{
if (library.DefaultPlatformId == 0)
md5hash = (string)dtRoms.Rows[i]["MD5"],
sha1hash = (string)dtRoms.Rows[i]["SHA1"]
};
FileInfo fi = new FileInfo(romPath);
Models.Signatures_Games sig = GetFileSignature(hash, fi, romPath);
if (sig.Rom.SignatureSource != gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType.None)
{
Logging.Log(Logging.LogType.Information, "Library Scan", " Update signature found for " + romPath);
// get discovered platform
IGDB.Models.Platform determinedPlatform = Metadata.Platforms.GetPlatform(sig.Flags.IGDBPlatformId);
if (determinedPlatform == null)
{
determinedPlatform = new IGDB.Models.Platform();
determinedGame = SearchForGame(sig.Game.Name, sig.Flags.IGDBPlatformId);
}
else
{
determinedPlatform = Platforms.GetPlatform(library.DefaultPlatformId);
determinedGame = SearchForGame(sig.Game.Name, library.DefaultPlatformId);
}
}
else
{
determinedGame = SearchForGame(sig.Game.Name, (long)determinedPlatform.Id);
}
StoreROM(library, hash, determinedGame, determinedPlatform, sig, LibraryFile);
IGDB.Models.Game determinedGame = SearchForGame(sig.Game.Name, sig.Flags.IGDBPlatformId);
StoreROM(hash, determinedGame, determinedPlatform, sig, romPath, romId);
}
}
if (romPath != ComputeROMPath(romId))
{
MoveGameFile(romId);
}
}
}
sql = "SELECT * FROM Games_Roms WHERE LibraryId=@libraryid ORDER BY `name`";
dtRoms = db.ExecuteCMD(sql, dbDict);
// check all roms to see if their local file still exists
Logging.Log(Logging.LogType.Information, "Library Scan", "Checking library files exist on disk");
if (dtRoms.Rows.Count > 0)
{
for (var i = 0; i < dtRoms.Rows.Count; i++)
else
{
long romId = (long)dtRoms.Rows[i]["Id"];
string romPath = (string)dtRoms.Rows[i]["Path"];
gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType romMetadataSource = (gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType)(int)dtRoms.Rows[i]["MetadataSource"];
// file doesn't exist where it's supposed to be! delete it from the db
Logging.Log(Logging.LogType.Warning, "Library Scan", " Deleting orphaned database entry for " + romPath);
Logging.Log(Logging.LogType.Information, "Library Scan", " Processing ROM at path " + romPath);
if (File.Exists(romPath))
{
// file exists, so lets check to make sure the signature was matched, and update if a signature can be found
if (
romMetadataSource == gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType.None ||
(int)dtRoms.Rows[i]["MetadataVersion"] == 1
)
{
Common.hashObject hash = new Common.hashObject
{
md5hash = (string)dtRoms.Rows[i]["MD5"],
sha1hash = (string)dtRoms.Rows[i]["SHA1"]
};
FileInfo fi = new FileInfo(romPath);
Models.Signatures_Games sig = GetFileSignature(hash, fi, romPath);
if (sig.Rom.SignatureSource != gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType.None)
{
Logging.Log(Logging.LogType.Information, "Library Scan", " Update signature found for " + romPath);
// get discovered platform
IGDB.Models.Platform determinedPlatform = Metadata.Platforms.GetPlatform(sig.Flags.IGDBPlatformId);
if (determinedPlatform == null)
{
determinedPlatform = new IGDB.Models.Platform();
}
IGDB.Models.Game determinedGame = SearchForGame(sig.Game.Name, sig.Flags.IGDBPlatformId);
StoreROM(library, hash, determinedGame, determinedPlatform, sig, romPath, romId);
}
}
if (library.IsDefaultLibrary == true)
{
if (romPath != ComputeROMPath(romId))
{
MoveGameFile(romId);
}
}
}
else
{
// file doesn't exist where it's supposed to be! delete it from the db
Logging.Log(Logging.LogType.Warning, "Library Scan", " Deleting orphaned database entry for " + romPath);
string deleteSql = "DELETE FROM Games_Roms WHERE Id = @id AND LibraryId = @libraryid";
Dictionary<string, object> deleteDict = new Dictionary<string, object>();
deleteDict.Add("id", romId);
deleteDict.Add("libraryid", library.Id);
db.ExecuteCMD(deleteSql, deleteDict);
}
string deleteSql = "DELETE FROM Games_Roms WHERE Id = @id";
Dictionary<string, object> deleteDict = new Dictionary<string, object>();
deleteDict.Add("id", romId);
db.ExecuteCMD(deleteSql, deleteDict);
}
}
Logging.Log(Logging.LogType.Information, "Library Scan", "Library scan completed");
}
Logging.Log(Logging.LogType.Information, "Library Scan", "Library scan completed");
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Reflection;
using gaseous_tools;
using IGDB;
using IGDB.Models;
using Microsoft.Extensions.Caching.Memory;
namespace gaseous_server.Classes.Metadata
{
@@ -16,14 +17,32 @@ namespace gaseous_server.Classes.Metadata
Expired
}
private static Dictionary<string, MemoryCacheObject> ObjectCache = new Dictionary<string, MemoryCacheObject>();
public static CacheStatus GetCacheStatus(string Endpoint, string Slug)
{
return _GetCacheStatus(Endpoint, "slug", Slug);
CacheClean();
if (ObjectCache.ContainsKey(Endpoint + Slug))
{
return CacheStatus.Current;
}
else
{
return _GetCacheStatus(Endpoint, "slug", Slug);
}
}
public static CacheStatus GetCacheStatus(string Endpoint, long Id)
{
return _GetCacheStatus(Endpoint, "id", Id);
CacheClean();
if (ObjectCache.ContainsKey(Endpoint + Id))
{
return CacheStatus.Current;
}
else
{
return _GetCacheStatus(Endpoint, "id", Id);
}
}
public static CacheStatus GetCacheStatus(DataRow Row)
@@ -164,6 +183,21 @@ namespace gaseous_server.Classes.Metadata
{
string Endpoint = EndpointType.GetType().Name;
if (ObjectCache.ContainsKey(Endpoint + SearchValue))
{
MemoryCacheObject cacheObject = ObjectCache[Endpoint + SearchValue];
if (cacheObject.ExpiryTime < DateTime.UtcNow)
{
// object has expired, remove it
ObjectCache.Remove(Endpoint + SearchValue);
}
else
{
// object is valid, return it
return (T)cacheObject.Object;
}
}
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM " + Endpoint + " WHERE " + SearchField + " = @" + SearchField;
@@ -181,7 +215,11 @@ namespace gaseous_server.Classes.Metadata
else
{
DataRow dataRow = dt.Rows[0];
return BuildCacheObject<T>(EndpointType, dataRow);
object returnObject = BuildCacheObject<T>(EndpointType, dataRow);
ObjectCache.Add(Endpoint + SearchValue, new MemoryCacheObject{
Object = returnObject
});
return (T)returnObject;
}
}
@@ -380,6 +418,35 @@ namespace gaseous_server.Classes.Metadata
return EndpointType;
}
private static void CacheClean()
{
if (ObjectCache == null)
{
ObjectCache = new Dictionary<string, MemoryCacheObject>();
}
Dictionary<string, MemoryCacheObject> workCache = ObjectCache;
foreach (KeyValuePair<string, MemoryCacheObject> objectCache in workCache)
{
if (objectCache.Value.ExpiryTime < DateTime.UtcNow)
{
ObjectCache.Remove(objectCache.Key);
}
}
}
private class MemoryCacheObject
{
public object Object { get; set; }
public DateTime CreationTime { get; } = DateTime.UtcNow;
public DateTime ExpiryTime
{
get
{
return CreationTime.AddMinutes(60);
}
}
}
}
}

View File

@@ -81,19 +81,16 @@ namespace gaseous_server.Classes
public static void DeleteRom(long RomId)
{
GameRomItem rom = GetRom(RomId);
if (rom.Library.IsDefaultLibrary == true)
if (File.Exists(rom.Path))
{
if (File.Exists(rom.Path))
{
File.Delete(rom.Path);
}
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "DELETE FROM Games_Roms WHERE Id = @id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", RomId);
db.ExecuteCMD(sql, dbDict);
File.Delete(rom.Path);
}
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "DELETE FROM Games_Roms WHERE Id = @id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("id", RomId);
db.ExecuteCMD(sql, dbDict);
}
private static GameRomItem BuildRom(DataRow romDR)
@@ -116,8 +113,7 @@ namespace gaseous_server.Classes
MediaLabel = (string)romDR["medialabel"],
Path = (string)romDR["path"],
Source = (gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType)(Int32)romDR["metadatasource"],
SignatureSourceGameTitle = (string)Common.ReturnValueIfNull(romDR["MetadataGameName"], ""),
Library = GameLibrary.GetLibrary((int)romDR["LibraryId"])
SignatureSourceGameTitle = (string)Common.ReturnValueIfNull(romDR["MetadataGameName"], "")
};
// check for a web emulator and update the romItem
@@ -157,7 +153,6 @@ namespace gaseous_server.Classes
public string? Path { get; set; }
public gaseous_signature_parser.models.RomSignatureObject.RomSignatureObject.Game.Rom.SignatureSourceType Source { get; set; }
public string? SignatureSourceGameTitle { get; set;}
public GameLibrary.LibraryItem Library { get; set; }
}
}
}

View File

@@ -212,13 +212,12 @@ namespace gaseous_server.SignatureIngestors.XML
dbDict.Add("romtypemedia", Common.ReturnValueIfNull(romObject.RomTypeMedia, ""));
dbDict.Add("medialabel", Common.ReturnValueIfNull(romObject.MediaLabel, ""));
dbDict.Add("metadatasource", romObject.SignatureSource);
dbDict.Add("ingestorversion", 2);
sigDB = db.ExecuteCMD(sql, dbDict);
if (sigDB.Rows.Count == 0)
{
// entry not present, insert it
sql = "INSERT INTO Signatures_Roms (GameId, Name, Size, CRC, MD5, SHA1, DevelopmentStatus, Attributes, RomType, RomTypeMedia, MediaLabel, MetadataSource, IngestorVersion) VALUES (@gameid, @name, @size, @crc, @md5, @sha1, @developmentstatus, @attributes, @romtype, @romtypemedia, @medialabel, @metadatasource, @ingestorversion); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
sql = "INSERT INTO Signatures_Roms (GameId, Name, Size, CRC, MD5, SHA1, DevelopmentStatus, Attributes, RomType, RomTypeMedia, MediaLabel, MetadataSource) VALUES (@gameid, @name, @size, @crc, @md5, @sha1, @developmentstatus, @attributes, @romtype, @romtypemedia, @medialabel, @metadatasource); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
sigDB = db.ExecuteCMD(sql, dbDict);

View File

@@ -1,77 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace gaseous_server.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class LibraryController : Controller
{
[HttpGet]
[ProducesResponseType(typeof(List<GameLibrary.LibraryItem>), StatusCodes.Status200OK)]
public ActionResult GetLibraries()
{
return Ok(GameLibrary.GetLibraries);
}
[HttpGet("{LibraryId}")]
[ProducesResponseType(typeof(GameLibrary.LibraryItem), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult GetLibrary(int LibraryId)
{
try
{
return Ok(GameLibrary.GetLibrary(LibraryId));
}
catch
{
return NotFound();
}
}
[HttpPost]
[ProducesResponseType(typeof(GameLibrary.LibraryItem), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
public ActionResult AddLibrary(string Name, string Path, long DefaultPlatformId)
{
try
{
return Ok(GameLibrary.AddLibrary(Name, Path, DefaultPlatformId));
}
catch (GameLibrary.PathExists exPE)
{
return Conflict("Path already used in another library");
}
catch (GameLibrary.PathNotFound exPNF)
{
return NotFound("Path not found");
}
}
[HttpDelete("{LibraryId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult DelLibrary(int LibraryId)
{
try
{
GameLibrary.DeleteLibrary(LibraryId);
return Ok();
}
catch (GameLibrary.CannotDeleteDefaultLibrary exCDDL)
{
return BadRequest(exCDDL.ToString());
}
catch (GameLibrary.LibraryNotFound exLNF)
{
return NotFound(exLNF.ToString());
}
}
}
}

View File

@@ -24,10 +24,8 @@ namespace gaseous_server.Controllers
// disk size
List<SystemInfo.PathItem> Disks = new List<SystemInfo.PathItem>();
foreach (GameLibrary.LibraryItem libraryItem in GameLibrary.GetLibraries)
{
Disks.Add(GetDisk(libraryItem.Path));
}
//Disks.Add(GetDisk(gaseous_tools.Config.ConfigurationPath));
Disks.Add(GetDisk(gaseous_tools.Config.LibraryConfiguration.LibraryRootDirectory));
ReturnValue.Paths = Disks;
// database size

View File

@@ -15,6 +15,8 @@ namespace gaseous_server.Models
{
public class PlatformMapping
{
private static Dictionary<string, PlatformMapItem> PlatformMapCache = new Dictionary<string, PlatformMapItem>();
/// <summary>
/// Updates the platform map from the embedded platform map resource
/// </summary>
@@ -98,7 +100,15 @@ namespace gaseous_server.Models
List<PlatformMapItem> platformMaps = new List<PlatformMapItem>();
foreach (DataRow row in data.Rows)
{
platformMaps.Add(BuildPlatformMapItem(row));
long mapId = (long)row["Id"];
if (PlatformMapCache.ContainsKey(mapId.ToString()))
{
platformMaps.Add(PlatformMapCache[mapId.ToString()]);
}
else
{
platformMaps.Add(BuildPlatformMapItem(row));
}
}
platformMaps.Sort((x, y) => x.IGDBName.CompareTo(y.IGDBName));
@@ -109,23 +119,30 @@ namespace gaseous_server.Models
public static PlatformMapItem GetPlatformMap(long Id)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM PlatformMap WHERE Id = @Id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("Id", Id);
DataTable data = db.ExecuteCMD(sql, dbDict);
if (data.Rows.Count > 0)
if (PlatformMapCache.ContainsKey(Id.ToString()))
{
PlatformMapItem platformMap = BuildPlatformMapItem(data.Rows[0]);
return platformMap;
return PlatformMapCache[Id.ToString()];
}
else
{
Exception exception = new Exception("Platform Map Id " + Id + " does not exist.");
Logging.Log(Logging.LogType.Critical, "Platform Map", "Platform Map Id " + Id + " does not exist.", exception);
throw exception;
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT * FROM PlatformMap WHERE Id = @Id";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("Id", Id);
DataTable data = db.ExecuteCMD(sql, dbDict);
if (data.Rows.Count > 0)
{
PlatformMapItem platformMap = BuildPlatformMapItem(data.Rows[0]);
return platformMap;
}
else
{
Exception exception = new Exception("Platform Map Id " + Id + " does not exist.");
Logging.Log(Logging.LogType.Critical, "Platform Map", "Platform Map Id " + Id + " does not exist.", exception);
throw exception;
}
}
}
@@ -218,6 +235,11 @@ namespace gaseous_server.Models
db.ExecuteCMD(sql, dbDict);
}
}
if (PlatformMapCache.ContainsKey(item.IGDBId.ToString()))
{
PlatformMapCache.Remove(item.IGDBId.ToString());
}
}
static PlatformMapItem BuildPlatformMapItem(DataRow row)
@@ -321,6 +343,15 @@ namespace gaseous_server.Models
};
mapItem.Bios = bioss;
if (PlatformMapCache.ContainsKey(IGDBId.ToString()))
{
PlatformMapCache[IGDBId.ToString()] = mapItem;
}
else
{
PlatformMapCache.Add(IGDBId.ToString(), mapItem);
}
return mapItem;
}

View File

@@ -12,24 +12,8 @@ using Microsoft.OpenApi.Models;
Logging.WriteToDiskOnly = true;
Logging.Log(Logging.LogType.Information, "Startup", "Starting Gaseous Server " + Assembly.GetExecutingAssembly().GetName().Version);
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
// check db availability
bool dbOnline = false;
do
{
Logging.Log(Logging.LogType.Information, "Startup", "Waiting for database...");
if (db.TestConnection() == true)
{
dbOnline = true;
}
else
{
Thread.Sleep(30000);
}
} while (dbOnline == true);
// set up db
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
db.InitDB();
// load app settings
@@ -198,9 +182,8 @@ ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
})
);
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
ProcessQueue.QueueItemType.LibraryScan, 30, new List<ProcessQueue.QueueItemType>
ProcessQueue.QueueItemType.LibraryScan, 1440, new List<ProcessQueue.QueueItemType>
{
ProcessQueue.QueueItemType.TitleIngestor,
ProcessQueue.QueueItemType.OrganiseLibrary
})
);

View File

@@ -120,20 +120,8 @@
},
"retroPieDirectoryName": "amiga",
"webEmulator": {
"type": "EmulatorJS",
"core": "amiga",
"availableWebEmulators": [
{
"emulatorType": "EmulatorJS",
"availableWebEmulatorCores": [
{
"core": "amiga",
"alternateCoreName": "puae",
"default": true
}
]
}
]
"type": "",
"core": ""
},
"bios": [
{
@@ -582,20 +570,8 @@
},
"retroPieDirectoryName": "c64",
"webEmulator": {
"type": "EmulatorJS",
"core": "vice_x64",
"availableWebEmulators": [
{
"emulatorType": "EmulatorJS",
"availableWebEmulatorCores": [
{
"core": "c64",
"alternateCoreName": "vice_x64",
"default": true
}
]
}
]
"type": "",
"core": ""
},
"bios": [
{

View File

@@ -80,7 +80,7 @@ namespace gaseous_server
qi.Blocks.Contains(ProcessQueue.QueueItemType.All)
)
{
//Console.WriteLine(queueItem.ItemType.ToString() + " is blocked by " + qi.ItemType.ToString());
Console.WriteLine(queueItem.ItemType.ToString() + " is blocked by " + qi.ItemType.ToString());
return true;
}
}

View File

@@ -1,27 +0,0 @@
<p>Are you sure you want to delete this library?</p>
<p><strong>Warning:</strong> This cannot be undone!</p>
<div style="width: 100%; text-align: center;">
<div style="display: inline-block; margin-right: 20px;">
<button class="redbutton" value="Delete" onclick="deleteLibrary();">Delete</button>
</div>
<div style="display: inline-block; margin-left: 20px;">
<button value="Cancel" onclick="closeSubDialog();">Cancel</button>
</div>
</div>
<script type="text/javascript">
function deleteLibrary() {
ajaxCall(
'/api/v1/Library/' + subModalVariables,
'DELETE',
function (result) {
drawLibrary();
closeSubDialog();
},
function (error) {
drawLibrary();
closeSubDialog();
}
);
}
</script>

View File

@@ -1,91 +0,0 @@
<div style="padding-top: 5px;">
<strong>New Library</strong>
</div>
<div style="width: 300px;">
<table style="width: 98%; margin-top: 15px; margin-bottom: 15px;">
<tr>
<th>Name</th>
<td><input type="text" id="newlibrary_name" style="width: 95%;" /></td>
</tr>
<tr>
<th>Default Platform</th>
<td><select id="newlibrary_defaultplatform" style="width: 100%;"></select></td>
</tr>
<tr>
<th>Path</th>
<td><input type="text" id="newlibrary_path" style="width: 95%;" /></td>
</tr>
</table>
<div style="width: 100%; text-align: right;">
<div style="display: inline-block; margin-right: 20px;">
<button value="OK" onclick="newLibrary();">OK</button>
</div>
<div style="display: inline-block;">
<button value="Cancel" onclick="closeSubDialog();">Cancel</button>
</div>
</div>
</div>
<script type="text/javascript">
$('#newlibrary_defaultplatform').select2({
minimumInputLength: 3,
ajax: {
url: '/api/v1/Search/Platform',
data: function (params) {
var query = {
SearchString: params.term
}
// Query parameters will be ?SearchString=[term]
return query;
},
processResults: function (data) {
var arr = [];
arr.push({
id: 0,
text: 'Any'
});
for (var i = 0; i < data.length; i++) {
arr.push({
id: data[i].id,
text: data[i].name
});
}
return {
results: arr
};
}
}
});
document.getElementById('newlibrary_defaultplatform').innerHTML = "<option value='" + 0 + "' selected='selected'>Any</option>";
function newLibrary() {
var libName = document.getElementById('newlibrary_name').value;
var libPlatform = $('#newlibrary_defaultplatform').select2('data');
var libPath = document.getElementById('newlibrary_path').value;
if (libName.length == 0) {
alert("A library name must be provided.")
} else if (libPath.length == 0) {
alert("A path must be provided.");
} else {
ajaxCall(
'/api/v1/Library?Name=' + encodeURIComponent(libName) + '&DefaultPlatformId=' + libPlatform[0].id + '&Path=' + encodeURIComponent(libPath),
'POST',
function(result) {
drawLibrary();
closeSubDialog();
},
function(error) {
alert('An error occurred while creating the library:\n\n' + JSON.stringify(error.responseText));
}
);
}
}
</script>

View File

@@ -7,10 +7,6 @@
<div id="properties_bodypanel">
<div id="properties_bodypanel_general" name="properties_tab" style="display: none;">
<table cellspacing="0" style="width: 100%;">
<tr>
<th>Library</th>
<td id="rominfo_library"></td>
</tr>
<tr>
<th>Platform</th>
<td id="rominfo_platform"></td>
@@ -121,7 +117,6 @@
ajaxCall('/api/v1/Games/' + gameId + '/roms/' + modalVariables, 'GET', function (result) {
romData = result;
document.getElementById('modal-heading').innerHTML = result.name;
document.getElementById('rominfo_library').innerHTML = result.library.name;
document.getElementById('rominfo_platform').innerHTML = result.platform.name;
document.getElementById('rominfo_size').innerHTML = formatBytes(result.size, 2);
document.getElementById('rominfo_type').innerHTML = getRomType(result.romType);
@@ -135,10 +130,6 @@
document.getElementById('properties_fixplatform').innerHTML = "<option value='" + result.platform.id + "' selected='selected'>" + result.platform.name + "</option>";
document.getElementById('properties_fixgame').innerHTML = "<option value='" + gameData.id + "' selected='selected'>" + gameData.name + "</option>";
if (result.library.isDefaultLibrary == false) {
document.getElementById('romDelete').style.display = 'none';
}
if (result.attributes.length > 0) {
document.getElementById('properties_bodypanel_attributes').appendChild(BuildAttributesTable(result.attributes, result.source));
} else {

View File

@@ -6,7 +6,6 @@
<div id="properties_toc" class="settings_toc">
<div class="filter_header">Settings</div>
<div id="properties_toc_system" name="properties_toc_item" onclick="SelectTab('system');">System</div>
<div id="properties_toc_settings" name="properties_toc_item" onclick="SelectTab('settings');">Settings</div>
<div id="properties_toc_mapping" name="properties_toc_item" onclick="SelectTab('mapping');">Platform Mapping</div>
<div id="properties_toc_bios" name="properties_toc_item" onclick="SelectTab('bios');">Firmware</div>
<div id="properties_toc_logs" name="properties_toc_item" onclick="SelectTab('logs');">Logs</div>

View File

@@ -1,63 +0,0 @@
<div id="gametitle">
<h1 id="gametitle_label">Settings</h1>
</div>
<h3>Libraries</h3>
<table id="settings_libraries" class="romtable" style="width: 100%;" cellspacing="0">
</table>
<div style="text-align: right;"><button id="settings_newlibrary" onclick="showSubDialog('librarynew');">New Library</button></div>
<script type="text/javascript">
function drawLibrary() {
ajaxCall(
'/api/v1/Library',
'GET',
function (result) {
var newTable = document.getElementById('settings_libraries');
newTable.innerHTML = '';
newTable.appendChild(createTableRow(true, ['Name', 'Path', 'Default Platform', 'Default Library', '']));
for (var i = 0; i < result.length; i++) {
var platformName = '';
if (result[i].defaultPlatformId == 0) {
if (result[i].isDefaultLibrary == true) {
platformName = "n/a";
} else {
platformName = "";
}
} else {
platformName = result[i].defaultPlatformName;
}
var defaultLibrary = '';
if (result[i].isDefaultLibrary == true) {
defaultLibrary = "Yes";
} else {
defaultLibrary = "";
}
var deleteButton = '';
if (result[i].isDefaultLibrary == false) {
var deleteButton = '<a href="#" onclick="showSubDialog(\'librarydelete\', ' + result[i].id + ');" class="romlink"><img src="/images/delete.svg" class="banner_button_image" alt="Delete" title="Delete" /></a>';
}
newTable.appendChild(createTableRow(
false,
[
result[i].name,
result[i].path,
platformName,
defaultLibrary,
'<div style="text-align: right;">' + deleteButton + '</div>'
],
'romrow',
'romcell'
));
}
}
);
}
drawLibrary();
</script>

View File

@@ -104,12 +104,6 @@ namespace gaseous_tools
".DS_STORE",
"desktop.ini"
};
public static string NormalizePath(string path)
{
return Path.GetFullPath(new Uri(path).LocalPath)
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}
}
}

View File

@@ -183,7 +183,7 @@ namespace gaseous_tools
else
{
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT Value FROM Settings WHERE Setting = @SettingName";
string sql = "SELECT * FROM Settings WHERE Setting = @SettingName";
Dictionary<string, object> dbDict = new Dictionary<string, object>();
dbDict.Add("SettingName", SettingName);
dbDict.Add("Value", DefaultValue);
@@ -337,13 +337,13 @@ namespace gaseous_tools
}
}
// public string LibraryDataDirectory
// {
// get
// {
// return Path.Combine(LibraryRootDirectory, "Library");
// }
// }
public string LibraryDataDirectory
{
get
{
return Path.Combine(LibraryRootDirectory, "Library");
}
}
public string LibraryBIOSDirectory
{
@@ -418,6 +418,7 @@ namespace gaseous_tools
{
if (!Directory.Exists(LibraryRootDirectory)) { Directory.CreateDirectory(LibraryRootDirectory); }
if (!Directory.Exists(LibraryImportDirectory)) { Directory.CreateDirectory(LibraryImportDirectory); }
if (!Directory.Exists(LibraryDataDirectory)) { Directory.CreateDirectory(LibraryDataDirectory); }
if (!Directory.Exists(LibraryBIOSDirectory)) { Directory.CreateDirectory(LibraryBIOSDirectory); }
if (!Directory.Exists(LibraryUploadDirectory)) { Directory.CreateDirectory(LibraryUploadDirectory); }
if (!Directory.Exists(LibraryMetadataDirectory)) { Directory.CreateDirectory(LibraryMetadataDirectory); }

View File

@@ -206,18 +206,6 @@ namespace gaseous_tools
}
}
public bool TestConnection()
{
switch (_ConnectorType)
{
case databaseType.MySql:
MySQLServerConnector conn = new MySQLServerConnector(_ConnectionString);
return conn.TestConnection();
default:
return false;
}
}
public class SQLTransactionItem
{
public SQLTransactionItem()
@@ -326,20 +314,6 @@ namespace gaseous_tools
return cmd;
}
public bool TestConnection()
{
MySqlConnection conn = new MySqlConnection(DBConn);
try
{
conn.Open();
conn.Close();
return true;
}
catch
{
return false;
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
CREATE TABLE `GameLibraries` (
`Id` int NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) NOT NULL,
`Path` longtext NOT NULL,
`DefaultLibrary` int NOT NULL DEFAULT '0',
`DefaultPlatform` bigint NOT NULL DEFAULT '0',
PRIMARY KEY (`Id`)
);
ALTER TABLE `Games_Roms`
ADD COLUMN `LibraryId` INT NULL DEFAULT 0 AFTER `MetadataVersion`;

View File

@@ -14,9 +14,6 @@ namespace gaseous_tools
public static void PostUpgradeScript(int TargetSchemaVersion, gaseous_tools.Database.databaseType? DatabaseType)
{
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Dictionary<string, object> dbDict = new Dictionary<string, object>();
switch(DatabaseType)
{
case Database.databaseType.MySql:
@@ -26,26 +23,6 @@ namespace gaseous_tools
// this is a safe background task
BackgroundUpgradeTargetSchemaVersions.Add(1002);
break;
case 1004:
// needs to run on start up
// copy root path to new libraries format
string oldRoot = Path.Combine(Config.LibraryConfiguration.LibraryRootDirectory, "Library");
string sql = "INSERT INTO GameLibraries (Name, Path, DefaultLibrary, DefaultPlatform) VALUES (@name, @path, @defaultlibrary, @defaultplatform); SELECT CAST(LAST_INSERT_ID() AS SIGNED);";
dbDict.Add("name", "Default");
dbDict.Add("path", oldRoot);
dbDict.Add("defaultlibrary", 1);
dbDict.Add("defaultplatform", 0);
DataTable data = db.ExecuteCMD(sql, dbDict);
// apply the new library id to the existing roms
sql = "UPDATE Games_Roms SET LibraryId=@libraryid;";
dbDict.Clear();
dbDict.Add("libraryid", data.Rows[0][0]);
db.ExecuteCMD(sql, dbDict);
break;
}
break;
}

View File

@@ -19,7 +19,6 @@
<None Remove="Database\MySQL\gaseous-1001.sql" />
<None Remove="Database\MySQL\gaseous-1002.sql" />
<None Remove="Database\MySQL\gaseous-1003.sql" />
<None Remove="Database\MySQL\gaseous-1004.sql" />
</ItemGroup>
<ItemGroup>
<Folder Include="Database\" />
@@ -30,6 +29,5 @@
<EmbeddedResource Include="Database\MySQL\gaseous-1001.sql" />
<EmbeddedResource Include="Database\MySQL\gaseous-1002.sql" />
<EmbeddedResource Include="Database\MySQL\gaseous-1003.sql" />
<EmbeddedResource Include="Database\MySQL\gaseous-1004.sql" />
</ItemGroup>
</Project>