commit aaff08bae49cde4873ce9178bb1849638ced95a4 Author: Dunestorm Date: Sat Jun 27 18:34:44 2020 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f375193 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vs +DevConsole/bin +DevConsole/obj +FireLance/bin +FireLance/obj diff --git a/DevConsole/DevConsole.csproj b/DevConsole/DevConsole.csproj new file mode 100644 index 0000000..0645bc9 --- /dev/null +++ b/DevConsole/DevConsole.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/DevConsole/DevConsole.csproj.user b/DevConsole/DevConsole.csproj.user new file mode 100644 index 0000000..724f1ea --- /dev/null +++ b/DevConsole/DevConsole.csproj.user @@ -0,0 +1,9 @@ + + + + ProjectDebugger + + + DevConsole + + \ No newline at end of file diff --git a/DevConsole/Program.cs b/DevConsole/Program.cs new file mode 100644 index 0000000..ac47ee3 --- /dev/null +++ b/DevConsole/Program.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; + +namespace DevConsole +{ + class Program + { + public static GSMParser parser = new GSMParser(); + + static void Main(string[] args) + { + while (true) + { + Console.WriteLine($"Connection State: {parser.GetConnectionState()}"); + CommandsMenu(); + } + } + + private static void CommandsMenu() + { + Console.WriteLine("Please select an option below:\n"); + Console.WriteLine("A. Database connection"); + Console.WriteLine("B. Query game by ID"); + Console.WriteLine("C. Query directory by ID"); + Console.WriteLine("D. Query game by NAME"); + Console.WriteLine("X. Exit application\n"); + Console.Write(":"); + + var userInput = Console.ReadKey(); + Console.Write("\n\n"); + + switch (userInput.Key) + { + case ConsoleKey.A: + OptionA(); + break; + case ConsoleKey.B: + OptionB(); + break; + case ConsoleKey.C: + OptionC(); + break; + case ConsoleKey.D: + OptionD(); + break; + case ConsoleKey.X: + Environment.Exit(0); + break; + default: + break; + } + } + + #region Command Options + private static void OptionA() + { + Console.WriteLine("A. Open DB"); + Console.WriteLine("B. Close DB"); + Console.Write(":"); + + var userInput = Console.ReadKey(); + Console.Write("\n\n"); + + switch (userInput.Key) + { + case ConsoleKey.A: + Console.WriteLine("Connect to database"); + parser.OpenConnection(@"C:\Users\Dunestorm\Projects\FireLance\FireLance\games.db"); + break; + case ConsoleKey.B: + parser.CloseCurrentConnection(); + break; + } + } + + private static void OptionB() + { + Console.WriteLine("Enter a Game ID (1043)"); + string r = Console.ReadLine(); + Console.Write("\n"); + + PrintGameEntries(parser.QueryGameById(r)); + } + + private static void OptionC() + { + Console.WriteLine("Enter a Game ID (1043)"); + string r = Console.ReadLine(); + Console.Write("\n"); + + PrintDirectories(parser.QueryDirectoryById(r)); + } + + private static void OptionD() + { + Console.WriteLine("Enter game to search"); + string r = Console.ReadLine(); + Console.Write("\n"); + + PrintGameEntries(parser.QueryGameByName(r)); + } + #endregion + + private static void PrintGameEntries(List gameEntries) + { + foreach (var game in gameEntries) + { + Console.WriteLine($"ID: {game.id}"); + Console.WriteLine($"GameName: {game.GameName}"); + Console.WriteLine($"BackupWarning: {game.BackupWarning}"); + Console.WriteLine($"RestoreWarning: {game.RestoreWarning}"); + Console.WriteLine($"LastModified: {game.LastModified}\n"); + } + } + + private static void PrintDirectories(List directoryEntries) + { + foreach (var directory in directoryEntries) + { + Console.WriteLine($"ID: {directory.id}"); + Console.WriteLine($"GameID: {directory.GameID}"); + Console.WriteLine($"SpecialPath: {directory.SpecialPath}"); + Console.WriteLine($"Path: {directory.Path}"); + Console.WriteLine($"RegHive: {directory.RegHive}"); + Console.WriteLine($"RegPath: {directory.RegPath}"); + Console.WriteLine($"RegValue: {directory.RegValue}"); + Console.WriteLine($"DefinedFiles: {directory.DefinedFiles}"); + Console.WriteLine($"ExcludedFiles: {directory.ExcludedFiles}"); + Console.WriteLine($"Recurse: {directory.Recurse}\n"); + } + } + } +} diff --git a/FireLance.sln b/FireLance.sln new file mode 100644 index 0000000..6bb9a5a --- /dev/null +++ b/FireLance.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GSMParser", "FireLance\GSMParser.csproj", "{7344FC11-3894-4393-A558-82E7D671372D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevConsole", "DevConsole\DevConsole.csproj", "{6B7A9B29-420B-4F58-975E-3D72A3D95314}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7344FC11-3894-4393-A558-82E7D671372D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7344FC11-3894-4393-A558-82E7D671372D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7344FC11-3894-4393-A558-82E7D671372D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7344FC11-3894-4393-A558-82E7D671372D}.Release|Any CPU.Build.0 = Release|Any CPU + {6B7A9B29-420B-4F58-975E-3D72A3D95314}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B7A9B29-420B-4F58-975E-3D72A3D95314}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B7A9B29-420B-4F58-975E-3D72A3D95314}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B7A9B29-420B-4F58-975E-3D72A3D95314}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {14C35A35-567D-434A-8D52-EFC955A5C57B} + EndGlobalSection +EndGlobal diff --git a/FireLance/GSMParser.csproj b/FireLance/GSMParser.csproj new file mode 100644 index 0000000..0eb011a --- /dev/null +++ b/FireLance/GSMParser.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp3.1 + + + + + + + + + + + Never + + + + diff --git a/FireLance/Main.cs b/FireLance/Main.cs new file mode 100644 index 0000000..153a2b5 --- /dev/null +++ b/FireLance/Main.cs @@ -0,0 +1,40 @@ +using Microsoft.Data.Sqlite; +using System; +using System.Collections.Generic; +using System.IO; +using Dapper; + +public class GSMParser +{ + private SqliteConnection DBConnection = new SqliteConnection(); + + public void OpenConnection(string dbLocation) + { + if (File.Exists(dbLocation) == false) + { + throw new FileNotFoundException(dbLocation); + } + + DBConnection = new SqliteConnection($"Data Source={dbLocation};Mode=ReadOnly"); + DBConnection.Open(); + } + + public void CloseCurrentConnection() { DBConnection.Close(); } + + public string GetConnectionState() { return Convert.ToString(DBConnection.State); } + + public List QueryGameById(string id) + { + return (List)DBConnection.Query(QueryBuilder.GameById(id), new DynamicParameters()); + } + + public List QueryDirectoryById(string id) + { + return (List)DBConnection.Query(QueryBuilder.DirectoryById(id), new DynamicParameters()); + } + + public List QueryGameByName(string name) + { + return (List) DBConnection.Query(QueryBuilder.GameByName(name), new DynamicParameters()); + } +} diff --git a/FireLance/Modals/Directories.cs b/FireLance/Modals/Directories.cs new file mode 100644 index 0000000..1b9504c --- /dev/null +++ b/FireLance/Modals/Directories.cs @@ -0,0 +1,13 @@ +public class Directories +{ + public int id { get; set; } + public int GameID { get; set; } + public string SpecialPath { get; set; } + public string Path { get; set; } + public string RegHive { get; set; } + public string RegPath { get; set; } + public string RegValue { get; set; } + public string DefinedFiles { get; set; } + public string ExcludedFiles { get; set; } + public bool Recurse { get; set; } +} diff --git a/FireLance/Modals/GameEntry.cs b/FireLance/Modals/GameEntry.cs new file mode 100644 index 0000000..2e3bf11 --- /dev/null +++ b/FireLance/Modals/GameEntry.cs @@ -0,0 +1,10 @@ +using System.Data.Common; + +public class GameEntry +{ + public int id { get; set; } + public string GameName { get; set; } + public string BackupWarning { get; set; } + public string RestoreWarning { get; set; } + public string LastModified { get; set; } +} \ No newline at end of file diff --git a/FireLance/QueryBuilder.cs b/FireLance/QueryBuilder.cs new file mode 100644 index 0000000..9870678 --- /dev/null +++ b/FireLance/QueryBuilder.cs @@ -0,0 +1,47 @@ +public static class QueryBuilder +{ + private static string NewQueryFromCommand(string select, string from, string where, string query, bool modalRecord, bool exactMatch) + { + string _query = string.Empty; + + _query += ($"SELECT \"{select}\""); + + if (modalRecord == true) + { + _query += ",* "; + } + else + { + _query += " "; + } + + _query += ($"FROM \"main\".\"{from}\"" + + $"WHERE \"{where}\" "); + + if (exactMatch == true) + { + _query += ($"LIKE '{query}'"); + } + else + { + _query += ($"LIKE '%{query}%'"); + } + + return _query; + } + + public static string GameByName(string name) + { + return NewQueryFromCommand("GameName", "GameEntry", "GameName", name, true, false); + } + + public static string GameById(string id) + { + return NewQueryFromCommand("GameName", "GameEntry", "id", id, true, true); + } + + public static string DirectoryById(string id) + { + return NewQueryFromCommand("Path", "Directories", "GameID", id, true, true); + } +} diff --git a/FireLance/games.db b/FireLance/games.db new file mode 100644 index 0000000..00be363 Binary files /dev/null and b/FireLance/games.db differ