diff --git a/DATabase/Core/Generate.cs b/DATabase/Core/Generate.cs index d2d41523..a42130e2 100644 --- a/DATabase/Core/Generate.cs +++ b/DATabase/Core/Generate.cs @@ -275,7 +275,7 @@ JOIN checksums (_systems != "" && _sources != "" ? " AND" : "") + (_systems != "" ? " systems.id in (" + _systems + ")" : "") + "\nORDER BY " + - (merged ? "checksums.size, checksums.crc, checksums.md5, checksums.sha1" + (merged ? "checksums.size, checksums.crc, systems.id, sources.id, checksums.md5, checksums.sha1" : "systems.id, sources.id, games.name, files.name"); using (SQLiteConnection dbc = new SQLiteConnection(_connectionString)) @@ -314,35 +314,41 @@ JOIN checksums if (merged) { - // Check if the rom is a duplicate - RomData last = (roms.Count == 0 ? new RomData() : roms[roms.Count - 1]); - bool shouldcont = false; - if (temp.Type == "rom" && last.Type == "rom") + // If it's the first rom in the list, don't touch it + if (roms.Count != 0) { - shouldcont = ((temp.Size != -1 && temp.Size == last.Size) && ( - (temp.CRC != "" && last.CRC != "" && temp.CRC == last.CRC) || - (temp.MD5 != "" && last.MD5 != "" && temp.MD5 == last.MD5) || - (temp.SHA1 != "" && last.SHA1 != "" && temp.SHA1 == last.SHA1) - ) - ); - } - else if (temp.Type == "disk" && last.Type == "disk") - { - shouldcont = ((temp.MD5 != "" && last.MD5 != "" && temp.MD5 == last.MD5) || - (temp.SHA1 != "" && last.SHA1 != "" && temp.SHA1 == last.SHA1) - ); - } + // Check if the rom is a duplicate + RomData last = roms[roms.Count - 1]; - // If it's a duplicate, skip adding it to the output but add any missing information - if (shouldcont) - { - last.CRC = (last.CRC == "" && temp.CRC != "" ? temp.CRC : last.CRC); - last.MD5 = (last.MD5 == "" && temp.MD5 != "" ? temp.MD5 : last.MD5); - last.SHA1 = (last.SHA1 == "" && temp.SHA1 != "" ? temp.SHA1 : last.SHA1); - roms.RemoveAt(roms.Count - 1); - roms.Insert(roms.Count - 1, last); + bool shouldcont = false; + if (temp.Type == "rom" && last.Type == "rom") + { + shouldcont = ((temp.Size != -1 && temp.Size == last.Size) && ( + (temp.CRC != "" && last.CRC != "" && temp.CRC == last.CRC) || + (temp.MD5 != "" && last.MD5 != "" && temp.MD5 == last.MD5) || + (temp.SHA1 != "" && last.SHA1 != "" && temp.SHA1 == last.SHA1) + ) + ); + } + else if (temp.Type == "disk" && last.Type == "disk") + { + shouldcont = ((temp.MD5 != "" && last.MD5 != "" && temp.MD5 == last.MD5) || + (temp.SHA1 != "" && last.SHA1 != "" && temp.SHA1 == last.SHA1) + ); + } - continue; + // If it's a duplicate, skip adding it to the output but add any missing information + if (shouldcont) + { + last.CRC = (last.CRC == "" && temp.CRC != "" ? temp.CRC : last.CRC); + last.MD5 = (last.MD5 == "" && temp.MD5 != "" ? temp.MD5 : last.MD5); + last.SHA1 = (last.SHA1 == "" && temp.SHA1 != "" ? temp.SHA1 : last.SHA1); + + roms.RemoveAt(roms.Count - 1); + roms.Insert(roms.Count, last); + + continue; + } } // Rename the game associated if it's still valid and we allow renames @@ -361,22 +367,25 @@ JOIN checksums } // If we're in a merged mode, resort by the correct parameters - roms.Sort(delegate (RomData x, RomData y) + if (merged) { - if (x.SystemID == y.SystemID) + roms.Sort(delegate (RomData x, RomData y) { - if (x.SourceID == y.SourceID) + if (x.SystemID == y.SystemID) { - if (x.Game == y.Game) + if (x.SourceID == y.SourceID) { - return String.Compare(x.Name, y.Name); + if (x.Game == y.Game) + { + return String.Compare(x.Name, y.Name); + } + return String.Compare(x.Game, y.Game); } - return String.Compare(x.Game, y.Game); + return (_norename ? String.Compare(x.Game, y.Game) : x.SourceID - y.SourceID); } - return (_norename ? String.Compare(x.Game, y.Game) : x.SourceID - y.SourceID); - } - return (_norename ? String.Compare(x.Game, y.Game) : x.SystemID - y.SystemID); - }); + return (_norename ? String.Compare(x.Game, y.Game) : x.SystemID - y.SystemID); + }); + } // Now check rename within games string lastname = "", lastgame = ""; diff --git a/DATabase/Core/Import.cs b/DATabase/Core/Import.cs index fc77f7fb..7a8757c0 100644 --- a/DATabase/Core/Import.cs +++ b/DATabase/Core/Import.cs @@ -333,9 +333,9 @@ namespace WoD child.Attributes["name"].Value, date, (child.Attributes["size"] != null ? Int32.Parse(child.Attributes["size"].Value) : -1), - (child.Attributes["crc"] != null ? child.Attributes["crc"].Value.ToLowerInvariant() : ""), - (child.Attributes["md5"] != null ? child.Attributes["md5"].Value.ToLowerInvariant() : ""), - (child.Attributes["sha1"] != null ? child.Attributes["sha1"].Value.ToLowerInvariant() : "") + (child.Attributes["crc"] != null ? child.Attributes["crc"].Value.ToLowerInvariant().Trim() : ""), + (child.Attributes["md5"] != null ? child.Attributes["md5"].Value.ToLowerInvariant().Trim() : ""), + (child.Attributes["sha1"] != null ? child.Attributes["sha1"].Value.ToLowerInvariant().Trim() : "") ); } // If we find the signs of a software list, traverse the children @@ -357,9 +357,9 @@ namespace WoD data.Attributes["name"].Value, date, (data.Attributes["size"] != null ? Int32.Parse(data.Attributes["size"].Value) : -1), - (data.Attributes["crc"] != null ? data.Attributes["crc"].Value.ToLowerInvariant() : ""), - (data.Attributes["md5"] != null ? data.Attributes["md5"].Value.ToLowerInvariant() : ""), - (data.Attributes["sha1"] != null ? data.Attributes["sha1"].Value.ToLowerInvariant() : "") + (data.Attributes["crc"] != null ? data.Attributes["crc"].Value.ToLowerInvariant().Trim() : ""), + (data.Attributes["md5"] != null ? data.Attributes["md5"].Value.ToLowerInvariant().Trim() : ""), + (data.Attributes["sha1"] != null ? data.Attributes["sha1"].Value.ToLowerInvariant().Trim() : "") ); } } diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 45c9411e..0809f48d 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -11,7 +11,7 @@ namespace WoD { private static string _dbName = "DATabase.sqlite"; private static string _connectionString = "Data Source=" + _dbName + ";Version = 3;"; - private static string _version = "0.0.6.0"; + private static string _version = "0.0.6.1"; private static string _header = @"+-----------------------------------------------------------------------------+ | DATabase " + _version + @" |