diff --git a/SabreTools.Helper/Dats/DatItem.cs b/SabreTools.Helper/Dats/DatItem.cs index b188accc..7f696790 100644 --- a/SabreTools.Helper/Dats/DatItem.cs +++ b/SabreTools.Helper/Dats/DatItem.cs @@ -545,7 +545,8 @@ namespace SabreTools.Helper.Dats // Now we want to loop through and check names string last = null; - int lastid = 1; + string lastrenamed = null; + int lastid = 0; for (int i = 0; i < infiles.Count; i++) { DatItem datItem = infiles[i]; @@ -558,17 +559,30 @@ namespace SabreTools.Helper.Dats Disk disk = (Disk)datItem; disk.Name += "_" + (!String.IsNullOrEmpty(disk.MD5) ? disk.MD5 : disk.SHA1); datItem = disk; + lastrenamed = lastrenamed == null ? datItem.Name : lastrenamed; } else if (datItem.Type == ItemType.Rom) { Rom rom = (Rom)datItem; - rom.Name += "_" + (!String.IsNullOrEmpty(rom.CRC) ? rom.CRC : !String.IsNullOrEmpty(rom.MD5) ? rom.MD5 : rom.SHA1); + rom.Name += "_" + (!String.IsNullOrEmpty(rom.CRC) ? rom.CRC : + !String.IsNullOrEmpty(rom.MD5) ? rom.MD5 : + !String.IsNullOrEmpty(rom.SHA1) ? rom.SHA1 : "(alt)"); datItem = rom; + lastrenamed = lastrenamed == null ? datItem.Name : lastrenamed; } + + // If we have a conflict with the last renamed item, do the right thing + if (datItem.Name == lastrenamed) + { + lastrenamed = datItem.Name; + datItem.Name += (lastid == 0 ? "" : "_" + lastid); + lastid++; + } + // If we have no conflict, then we want to reset the lastrenamed and id else { - datItem.Name += "_" + lastid; - lastid++; + lastrenamed = null; + lastid = 0; } output.Add(datItem); @@ -579,7 +593,8 @@ namespace SabreTools.Helper.Dats { output.Add(datItem); last = datItem.Name; - lastid = 1; + lastrenamed = null; + lastid = 0; } } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs index b2faf356..2f66050b 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs @@ -139,11 +139,13 @@ namespace SabreTools.Helper.Dats sortable.Add(newkey, new List()); } + /* // Here, we want to see if there is a duplicate-named file already in the game if (sortable[newkey].Where(i => i.Name == rom.Name).Count() > 0) { logger.Error("Duplicate named-file '" + rom.Name + "' detected in machine '" + newkey + "'"); } + */ sortable[newkey].Add(rom); }