mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add file chooser for import
This commit is contained in:
80
SabreToolsUI/Helper.cs
Normal file
80
SabreToolsUI/Helper.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SabreTools
|
||||||
|
{
|
||||||
|
class Helper
|
||||||
|
{
|
||||||
|
private static string _dbName = "DATabase.sqlite";
|
||||||
|
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
||||||
|
|
||||||
|
public static object[] GetAllSystems()
|
||||||
|
{
|
||||||
|
List<object> objs = new List<object>();
|
||||||
|
|
||||||
|
Process.Start("DATabase.exe", "--skip");
|
||||||
|
|
||||||
|
string query = @"
|
||||||
|
SELECT DISTINCT systems.id, systems.manufacturer, systems.system
|
||||||
|
FROM systems JOIN games ON systems.id=games.system
|
||||||
|
ORDER BY systems.manufacturer, systems.system";
|
||||||
|
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
|
||||||
|
{
|
||||||
|
dbc.Open();
|
||||||
|
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
||||||
|
{
|
||||||
|
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
||||||
|
{
|
||||||
|
// If nothing is found, tell the user and exit
|
||||||
|
if (sldr.HasRows)
|
||||||
|
{
|
||||||
|
while (sldr.Read())
|
||||||
|
{
|
||||||
|
objs.Add(sldr.GetString(1) + " - " + sldr.GetString(2) + " (" + sldr.GetInt32(0) + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return objs.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object[] GetAllSources()
|
||||||
|
{
|
||||||
|
List<object> objs = new List<object>();
|
||||||
|
|
||||||
|
Process.Start("DATabase.exe", "--skip");
|
||||||
|
|
||||||
|
string query = @"
|
||||||
|
SELECT DISTINCT sources.id, sources.name
|
||||||
|
FROM sources JOIN games on sources.id=games.source
|
||||||
|
ORDER BY sources.name COLLATE NOCASE";
|
||||||
|
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
|
||||||
|
{
|
||||||
|
dbc.Open();
|
||||||
|
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
||||||
|
{
|
||||||
|
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
||||||
|
{
|
||||||
|
// If nothing is found, tell the user and exit
|
||||||
|
if (sldr.HasRows)
|
||||||
|
{
|
||||||
|
while (sldr.Read())
|
||||||
|
{
|
||||||
|
objs.Add(sldr.GetString(1) + " (" + sldr.GetInt32(0) + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return objs.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
86
SabreToolsUI/SabreToolsUI.Designer.cs
generated
86
SabreToolsUI/SabreToolsUI.Designer.cs
generated
@@ -43,6 +43,11 @@
|
|||||||
this.generateAllButton = new System.Windows.Forms.Button();
|
this.generateAllButton = new System.Windows.Forms.Button();
|
||||||
this.oldCheckBox = new System.Windows.Forms.CheckBox();
|
this.oldCheckBox = new System.Windows.Forms.CheckBox();
|
||||||
this.renameCheckBox = new System.Windows.Forms.CheckBox();
|
this.renameCheckBox = new System.Windows.Forms.CheckBox();
|
||||||
|
this.importDatLabel = new System.Windows.Forms.Label();
|
||||||
|
this.fileOrFolderLabel = new System.Windows.Forms.Label();
|
||||||
|
this.importTextBox = new System.Windows.Forms.TextBox();
|
||||||
|
this.exploreButton = new System.Windows.Forms.Button();
|
||||||
|
this.importButton = new System.Windows.Forms.Button();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -118,12 +123,19 @@
|
|||||||
// systemsCheckedListBox
|
// systemsCheckedListBox
|
||||||
//
|
//
|
||||||
this.systemsCheckedListBox.FormattingEnabled = true;
|
this.systemsCheckedListBox.FormattingEnabled = true;
|
||||||
this.systemsCheckedListBox.Items.AddRange(GetAllSystems());
|
|
||||||
this.systemsCheckedListBox.Location = new System.Drawing.Point(77, 65);
|
this.systemsCheckedListBox.Location = new System.Drawing.Point(77, 65);
|
||||||
this.systemsCheckedListBox.Name = "systemsCheckedListBox";
|
this.systemsCheckedListBox.Name = "systemsCheckedListBox";
|
||||||
this.systemsCheckedListBox.Size = new System.Drawing.Size(260, 34);
|
this.systemsCheckedListBox.Size = new System.Drawing.Size(260, 34);
|
||||||
this.systemsCheckedListBox.TabIndex = 4;
|
this.systemsCheckedListBox.TabIndex = 4;
|
||||||
//
|
//
|
||||||
|
// sourcesCheckedListBox
|
||||||
|
//
|
||||||
|
this.sourcesCheckedListBox.FormattingEnabled = true;
|
||||||
|
this.sourcesCheckedListBox.Location = new System.Drawing.Point(415, 65);
|
||||||
|
this.sourcesCheckedListBox.Name = "sourcesCheckedListBox";
|
||||||
|
this.sourcesCheckedListBox.Size = new System.Drawing.Size(244, 34);
|
||||||
|
this.sourcesCheckedListBox.TabIndex = 7;
|
||||||
|
//
|
||||||
// sourcesLabel
|
// sourcesLabel
|
||||||
//
|
//
|
||||||
this.sourcesLabel.AutoSize = true;
|
this.sourcesLabel.AutoSize = true;
|
||||||
@@ -134,34 +146,25 @@
|
|||||||
this.sourcesLabel.TabIndex = 6;
|
this.sourcesLabel.TabIndex = 6;
|
||||||
this.sourcesLabel.Text = "Sources:";
|
this.sourcesLabel.Text = "Sources:";
|
||||||
//
|
//
|
||||||
// sourcesCheckedListBox
|
|
||||||
//
|
|
||||||
this.sourcesCheckedListBox.FormattingEnabled = true;
|
|
||||||
this.sourcesCheckedListBox.Items.AddRange(GetAllSources());
|
|
||||||
this.sourcesCheckedListBox.Location = new System.Drawing.Point(415, 65);
|
|
||||||
this.sourcesCheckedListBox.Name = "sourcesCheckedListBox";
|
|
||||||
this.sourcesCheckedListBox.Size = new System.Drawing.Size(244, 34);
|
|
||||||
this.sourcesCheckedListBox.TabIndex = 7;
|
|
||||||
//
|
|
||||||
// generateButton
|
// generateButton
|
||||||
//
|
//
|
||||||
this.generateButton.Location = new System.Drawing.Point(18, 145);
|
this.generateButton.Location = new System.Drawing.Point(18, 128);
|
||||||
this.generateButton.Name = "generateButton";
|
this.generateButton.Name = "generateButton";
|
||||||
this.generateButton.Size = new System.Drawing.Size(75, 23);
|
this.generateButton.Size = new System.Drawing.Size(75, 23);
|
||||||
this.generateButton.TabIndex = 8;
|
this.generateButton.TabIndex = 8;
|
||||||
this.generateButton.Text = "Generate";
|
this.generateButton.Text = "Generate";
|
||||||
this.generateButton.UseVisualStyleBackColor = true;
|
this.generateButton.UseVisualStyleBackColor = true;
|
||||||
this.generateButton.Click += new System.EventHandler(this.button1_Click);
|
this.generateButton.Click += new System.EventHandler(this.generateButton_Click);
|
||||||
//
|
//
|
||||||
// generateAllButton
|
// generateAllButton
|
||||||
//
|
//
|
||||||
this.generateAllButton.Location = new System.Drawing.Point(100, 145);
|
this.generateAllButton.Location = new System.Drawing.Point(100, 128);
|
||||||
this.generateAllButton.Name = "generateAllButton";
|
this.generateAllButton.Name = "generateAllButton";
|
||||||
this.generateAllButton.Size = new System.Drawing.Size(97, 23);
|
this.generateAllButton.Size = new System.Drawing.Size(97, 23);
|
||||||
this.generateAllButton.TabIndex = 9;
|
this.generateAllButton.TabIndex = 9;
|
||||||
this.generateAllButton.Text = "Generate All";
|
this.generateAllButton.Text = "Generate All";
|
||||||
this.generateAllButton.UseVisualStyleBackColor = true;
|
this.generateAllButton.UseVisualStyleBackColor = true;
|
||||||
this.generateAllButton.Click += new System.EventHandler(this.button2_Click);
|
this.generateAllButton.Click += new System.EventHandler(this.generateAllButton_Click);
|
||||||
//
|
//
|
||||||
// oldCheckBox
|
// oldCheckBox
|
||||||
//
|
//
|
||||||
@@ -185,11 +188,61 @@
|
|||||||
this.renameCheckBox.Text = "Rename Games";
|
this.renameCheckBox.Text = "Rename Games";
|
||||||
this.renameCheckBox.UseVisualStyleBackColor = true;
|
this.renameCheckBox.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
|
// importDatLabel
|
||||||
|
//
|
||||||
|
this.importDatLabel.AutoSize = true;
|
||||||
|
this.importDatLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.importDatLabel.Location = new System.Drawing.Point(12, 168);
|
||||||
|
this.importDatLabel.Name = "importDatLabel";
|
||||||
|
this.importDatLabel.Size = new System.Drawing.Size(89, 17);
|
||||||
|
this.importDatLabel.TabIndex = 12;
|
||||||
|
this.importDatLabel.Text = "Import DAT";
|
||||||
|
//
|
||||||
|
// fileOrFolderLabel
|
||||||
|
//
|
||||||
|
this.fileOrFolderLabel.AutoSize = true;
|
||||||
|
this.fileOrFolderLabel.Location = new System.Drawing.Point(15, 197);
|
||||||
|
this.fileOrFolderLabel.Name = "fileOrFolderLabel";
|
||||||
|
this.fileOrFolderLabel.Size = new System.Drawing.Size(70, 13);
|
||||||
|
this.fileOrFolderLabel.TabIndex = 13;
|
||||||
|
this.fileOrFolderLabel.Text = "File or Folder:";
|
||||||
|
//
|
||||||
|
// importTextBox
|
||||||
|
//
|
||||||
|
this.importTextBox.Location = new System.Drawing.Point(91, 194);
|
||||||
|
this.importTextBox.Name = "importTextBox";
|
||||||
|
this.importTextBox.Size = new System.Drawing.Size(264, 20);
|
||||||
|
this.importTextBox.TabIndex = 14;
|
||||||
|
//
|
||||||
|
// exploreButton
|
||||||
|
//
|
||||||
|
this.exploreButton.Location = new System.Drawing.Point(361, 192);
|
||||||
|
this.exploreButton.Name = "exploreButton";
|
||||||
|
this.exploreButton.Size = new System.Drawing.Size(58, 23);
|
||||||
|
this.exploreButton.TabIndex = 15;
|
||||||
|
this.exploreButton.Text = "Explore";
|
||||||
|
this.exploreButton.UseVisualStyleBackColor = true;
|
||||||
|
this.exploreButton.Click += new System.EventHandler(this.exploreButton_Click);
|
||||||
|
//
|
||||||
|
// importButton
|
||||||
|
//
|
||||||
|
this.importButton.Location = new System.Drawing.Point(426, 192);
|
||||||
|
this.importButton.Name = "importButton";
|
||||||
|
this.importButton.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.importButton.TabIndex = 16;
|
||||||
|
this.importButton.Text = "Import";
|
||||||
|
this.importButton.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// SabreToolsUI
|
// SabreToolsUI
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(681, 477);
|
this.ClientSize = new System.Drawing.Size(681, 477);
|
||||||
|
this.Controls.Add(this.importButton);
|
||||||
|
this.Controls.Add(this.exploreButton);
|
||||||
|
this.Controls.Add(this.importTextBox);
|
||||||
|
this.Controls.Add(this.fileOrFolderLabel);
|
||||||
|
this.Controls.Add(this.importDatLabel);
|
||||||
this.Controls.Add(this.renameCheckBox);
|
this.Controls.Add(this.renameCheckBox);
|
||||||
this.Controls.Add(this.oldCheckBox);
|
this.Controls.Add(this.oldCheckBox);
|
||||||
this.Controls.Add(this.generateAllButton);
|
this.Controls.Add(this.generateAllButton);
|
||||||
@@ -227,6 +280,11 @@
|
|||||||
private System.Windows.Forms.Button generateAllButton;
|
private System.Windows.Forms.Button generateAllButton;
|
||||||
private System.Windows.Forms.CheckBox oldCheckBox;
|
private System.Windows.Forms.CheckBox oldCheckBox;
|
||||||
private System.Windows.Forms.CheckBox renameCheckBox;
|
private System.Windows.Forms.CheckBox renameCheckBox;
|
||||||
|
private System.Windows.Forms.Label importDatLabel;
|
||||||
|
private System.Windows.Forms.Label fileOrFolderLabel;
|
||||||
|
private System.Windows.Forms.TextBox importTextBox;
|
||||||
|
private System.Windows.Forms.Button exploreButton;
|
||||||
|
private System.Windows.Forms.Button importButton;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.SQLite;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -16,9 +16,6 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
public partial class SabreToolsUI : Form
|
public partial class SabreToolsUI : Form
|
||||||
{
|
{
|
||||||
private static string _dbName = "DATabase.sqlite";
|
|
||||||
private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;";
|
|
||||||
|
|
||||||
public SabreToolsUI()
|
public SabreToolsUI()
|
||||||
{
|
{
|
||||||
AllocConsole();
|
AllocConsole();
|
||||||
@@ -39,71 +36,7 @@ namespace SabreTools
|
|||||||
MessageBox.Show("SabreTools designed and coded by: Matt Nadareski (darksabre76)\nTested by: @tractivo", "About");
|
MessageBox.Show("SabreTools designed and coded by: Matt Nadareski (darksabre76)\nTested by: @tractivo", "About");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static object[] GetAllSystems()
|
private void generateButton_Click(object sender, EventArgs e)
|
||||||
{
|
|
||||||
List<object> objs = new List<object>();
|
|
||||||
|
|
||||||
Process.Start("DATabase.exe", "--skip");
|
|
||||||
|
|
||||||
string query = @"
|
|
||||||
SELECT DISTINCT systems.id, systems.manufacturer, systems.system
|
|
||||||
FROM systems JOIN games ON systems.id=games.system
|
|
||||||
ORDER BY systems.manufacturer, systems.system";
|
|
||||||
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
|
|
||||||
{
|
|
||||||
dbc.Open();
|
|
||||||
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
|
||||||
{
|
|
||||||
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
|
||||||
{
|
|
||||||
// If nothing is found, tell the user and exit
|
|
||||||
if (sldr.HasRows)
|
|
||||||
{
|
|
||||||
while (sldr.Read())
|
|
||||||
{
|
|
||||||
objs.Add(sldr.GetString(1) + " - " + sldr.GetString(2) + " (" + sldr.GetInt32(0) + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return objs.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static object[] GetAllSources()
|
|
||||||
{
|
|
||||||
List<object> objs = new List<object>();
|
|
||||||
|
|
||||||
Process.Start("DATabase.exe", "--skip");
|
|
||||||
|
|
||||||
string query = @"
|
|
||||||
SELECT DISTINCT sources.id, sources.name
|
|
||||||
FROM sources JOIN games on sources.id=games.source
|
|
||||||
ORDER BY sources.name COLLATE NOCASE";
|
|
||||||
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
|
|
||||||
{
|
|
||||||
dbc.Open();
|
|
||||||
using (SQLiteCommand slc = new SQLiteCommand(query, dbc))
|
|
||||||
{
|
|
||||||
using (SQLiteDataReader sldr = slc.ExecuteReader())
|
|
||||||
{
|
|
||||||
// If nothing is found, tell the user and exit
|
|
||||||
if (sldr.HasRows)
|
|
||||||
{
|
|
||||||
while (sldr.Read())
|
|
||||||
{
|
|
||||||
objs.Add(sldr.GetString(1) + " (" + sldr.GetInt32(0) + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return objs.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
string systems = "";
|
string systems = "";
|
||||||
string sources = "";
|
string sources = "";
|
||||||
@@ -136,9 +69,30 @@ ORDER BY sources.name COLLATE NOCASE";
|
|||||||
Process.Start("DATabase.exe", args);
|
Process.Start("DATabase.exe", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button2_Click(object sender, EventArgs e)
|
private void generateAllButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Process.Start("DATabase.exe", "-l -ga");
|
Process.Start("DATabase.exe", "-l -ga");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void exploreButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
|
|
||||||
|
// Set the proper starting folder
|
||||||
|
if (importTextBox.Text != "")
|
||||||
|
{
|
||||||
|
ofd.InitialDirectory = Path.GetDirectoryName(importTextBox.Text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ofd.InitialDirectory = Environment.CurrentDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the new folder, if applicable
|
||||||
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
importTextBox.Text = ofd.FileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Helper.cs" />
|
||||||
<Compile Include="SabreToolsUI.cs">
|
<Compile Include="SabreToolsUI.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
Reference in New Issue
Block a user