diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index b94cb513..91c105d8 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -15,7 +15,7 @@ namespace SabreTools private static Logger logger; private static string _dbName = "DATabase.sqlite"; private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;"; - private static string _version = "0.2.4.0"; + private static string _version = "0.2.5.0"; private static string _header = @"+-----------------------------------------------------------------------------+ | DATabase " + _version + @" | diff --git a/Deheader/Headerer.cs b/Deheader/Headerer.cs index 19ff8ebd..b581fade 100644 --- a/Deheader/Headerer.cs +++ b/Deheader/Headerer.cs @@ -13,7 +13,7 @@ namespace SabreTools /// class Headerer { - private static string _version = "0.2.4.0"; + private static string _version = "0.2.5.0"; private static string _dbName = "Headerer.sqlite"; private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;"; private static Dictionary types; @@ -187,7 +187,7 @@ Options: sha1.ComputeHash(File.ReadAllBytes(file + ".new")); bool exists = false; - string query = @"SELECT * FROM data WHERE sha1='" + BitConverter.ToString(sha1.Hash) + "'"; + string query = @"SELECT * FROM data WHERE sha1='" + BitConverter.ToString(sha1.Hash) + "' AND header='" + realhead + "'"; using (SQLiteConnection dbc = new SQLiteConnection(_connectionString)) { dbc.Open(); @@ -220,7 +220,7 @@ Options: } /// - /// Detect and replace header to the given file + /// Detect and replace header(s) to the given file /// /// Name of the file to be parsed private static void ReplaceHeader(string file) @@ -230,7 +230,7 @@ Options: sha1.ComputeHash(File.ReadAllBytes(file)); string hash = BitConverter.ToString(sha1.Hash); - // Then try to pull the corresponding thing from the database + // Then try to pull the corresponding headers from the database string header = ""; string query = @"SELECT header, type FROM data WHERE sha1='" + hash + "'"; @@ -243,32 +243,33 @@ Options: { if (sldr.HasRows) { - sldr.Read(); - Console.WriteLine("Found match with rom type " + sldr.GetString(1)); - header = sldr.GetString(0); + int sub = 0; + while (sldr.Read()) + { + Console.WriteLine("Found match with rom type " + sldr.GetString(1)); + header = sldr.GetString(0); + + Console.WriteLine("Creating reheadered file: " + file + ".new" + sub); + BinaryWriter bw = new BinaryWriter(File.OpenWrite(file + ".new" + sub)); + + // Source: http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa + for (int i = 0; i < header.Length; i += 2) + { + bw.Write(Convert.ToByte(header.Substring(i, 2), 16)); + } + bw.Write(File.ReadAllBytes(file)); + bw.Close(); + Console.WriteLine("Reheadered file created!"); + } + } + else + { + Console.WriteLine("No matching header could be found!"); + return; } } } } - - // If the header isn't null, add it to the file. Otherwise tell the user - if (header == "") - { - Console.WriteLine("No matching header could be found!"); - return; - } - - Console.WriteLine("Creating reheadered file: " + file + ".new"); - BinaryWriter bw = new BinaryWriter(File.OpenWrite(file + ".new")); - - // Source: http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa - for (int i = 0; i < header.Length; i += 2) - { - bw.Write(Convert.ToByte(header.Substring(i, 2), 16)); - } - bw.Write(File.ReadAllBytes(file)); - bw.Close(); - Console.WriteLine("Reheadered file created!"); } /// @@ -292,9 +293,10 @@ Options: // Make sure the database has the correct schema string query = @" CREATE TABLE IF NOT EXISTS data ( - 'sha1' TEXT PRIMARY KEY NOT NULL, - 'header' TEXT NOT NULL, - 'type' TEXT NOT NULL + 'sha1' TEXT NOT NULL, + 'header' TEXT NOT NULL, + 'type' TEXT NOT NULL, + PRIMARY KEY (sha1, header, type) )"; SQLiteCommand slc = new SQLiteCommand(query, dbc); slc.ExecuteNonQuery(); diff --git a/README.MD b/README.MD index 6eeca911..8c5a5a6b 100644 --- a/README.MD +++ b/README.MD @@ -36,7 +36,7 @@ A simple auxilary tool that detects and removes headers and also restores header
  • Nintendo Entertainment System / Famicom
  • Super Nintendo Entertainment System
  • -The saved headers are currently stored in a database; one header per file. This restriction may be lifted in the future. +The saved headers are currently stored in a database; multiple headers allowed per file.

    Contributions

    diff --git a/SabreToolsUI/SabreToolsUI.Designer.cs b/SabreToolsUI/SabreToolsUI.Designer.cs index e5f5aed2..929848e0 100644 --- a/SabreToolsUI/SabreToolsUI.Designer.cs +++ b/SabreToolsUI/SabreToolsUI.Designer.cs @@ -261,7 +261,7 @@ this.MainMenuStrip = this.menuStrip1; this.Name = "SabreToolsUI"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "SabreTools UI 0.2.4.0"; + this.Text = "SabreTools UI 0.2.5.0"; this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false);