Initial commit
This commit is contained in:
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
.vs
|
||||||
|
DevConsole/bin
|
||||||
|
DevConsole/obj
|
||||||
|
FireLance/bin
|
||||||
|
FireLance/obj
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FireLance\GSMParser.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ActiveDebugProfile>DevConsole</ActiveDebugProfile>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -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<GameEntry> 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<Directories> 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.0.35" />
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.1.5" />
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="3.1.5" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="games.db">
|
||||||
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -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<GameEntry> QueryGameById(string id)
|
||||||
|
{
|
||||||
|
return (List<GameEntry>)DBConnection.Query<GameEntry>(QueryBuilder.GameById(id), new DynamicParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Directories> QueryDirectoryById(string id)
|
||||||
|
{
|
||||||
|
return (List<Directories>)DBConnection.Query<Directories>(QueryBuilder.DirectoryById(id), new DynamicParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GameEntry> QueryGameByName(string name)
|
||||||
|
{
|
||||||
|
return (List<GameEntry>) DBConnection.Query<GameEntry>(QueryBuilder.GameByName(name), new DynamicParameters());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user