mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Allow callers to set source and machine index
This commit is contained in:
@@ -23,9 +23,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
disk.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(disk, machineIndex, sourceIndex, statsOnly: false);
|
||||
disk.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(disk, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Disk? actualDisk = actual as Disk;
|
||||
@@ -42,9 +46,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem disk = new Disk { Name = "item" };
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
disk.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(disk, machineIndex, sourceIndex, statsOnly: false);
|
||||
disk.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(disk, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Disk? actualDisk = actual as Disk;
|
||||
@@ -61,9 +69,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
var file = new File { SHA1 = "deadbeef" };
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
file.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(file, machineIndex, sourceIndex, statsOnly: false);
|
||||
file.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(file, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Assert.True(actual is File);
|
||||
@@ -79,9 +91,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem file = new File();
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
file.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(file, machineIndex, sourceIndex, statsOnly: false);
|
||||
file.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(file, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Assert.True(actual is File);
|
||||
@@ -101,9 +117,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
media.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(media, machineIndex, sourceIndex, statsOnly: false);
|
||||
media.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(media, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Assert.True(actual is Media);
|
||||
@@ -122,9 +142,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
media.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(media, machineIndex, sourceIndex, statsOnly: false);
|
||||
media.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(media, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Assert.True(actual is Media);
|
||||
@@ -145,9 +169,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(rom, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(rom, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Rom? actualRom = actual as Rom;
|
||||
@@ -170,9 +198,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(rom, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(rom, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Rom? actualRom = actual as Rom;
|
||||
@@ -195,9 +227,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(rom, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(rom, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Rom? actualRom = actual as Rom;
|
||||
@@ -216,9 +252,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem rom = new Rom { Name = "item" };
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(rom, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(rom, statsOnly: false);
|
||||
|
||||
DatItem actual = Assert.Single(dict.GetItemsForBucket("default")).Value;
|
||||
Rom? actualRom = actual as Rom;
|
||||
@@ -237,9 +277,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom { Name = "item" };
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: true);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: true);
|
||||
|
||||
Assert.Empty(dict.GetItemsForBucket("default"));
|
||||
}
|
||||
@@ -253,9 +297,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom { Name = "item" };
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
Assert.Single(dict.GetItemsForBucket("default"));
|
||||
}
|
||||
@@ -322,9 +370,15 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
// Setup the dictionary
|
||||
var dict = new ItemDatabase();
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom1.SourceIndex = sourceIndex;
|
||||
rom2.SourceIndex = sourceIndex;
|
||||
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
dict.AddItem(rom1, machineIndex, sourceIndex, statsOnly: false);
|
||||
dict.AddItem(rom2, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom1.MachineIndex = machineIndex;
|
||||
rom2.MachineIndex = machineIndex;
|
||||
|
||||
dict.AddItem(rom1, statsOnly: false);
|
||||
dict.AddItem(rom2, statsOnly: false);
|
||||
|
||||
dict.ClearMarked();
|
||||
string key = Assert.Single(dict.SortedKeys);
|
||||
@@ -347,9 +401,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom();
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
var actual = dict.GetItemsForBucket(null, filter: false);
|
||||
|
||||
@@ -366,9 +424,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom();
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
var actual = dict.GetItemsForBucket("INVALID", filter: false);
|
||||
|
||||
@@ -385,9 +447,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom { RemoveFlag = true };
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
var actual = dict.GetItemsForBucket("machine", filter: true);
|
||||
|
||||
@@ -404,9 +470,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom { RemoveFlag = true };
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
var actual = dict.GetItemsForBucket("machine", filter: false);
|
||||
|
||||
@@ -423,9 +493,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom();
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
var actual = dict.GetItemsForBucket("machine", filter: false);
|
||||
|
||||
@@ -460,9 +534,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom();
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
long itemIndex = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
long itemIndex = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
var actual = dict.GetMachineForItem(itemIndex);
|
||||
Assert.Equal(0, actual.Key);
|
||||
@@ -497,9 +575,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
DatItem item = new Rom();
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
long itemIndex = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
long itemIndex = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
var actual = dict.GetSourceForItem(itemIndex);
|
||||
Assert.Equal(0, actual.Key);
|
||||
@@ -517,7 +599,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
Machine machine = new Machine { Name = "game-1" };
|
||||
|
||||
DatItem datItem = new Rom
|
||||
DatItem item = new Rom
|
||||
{
|
||||
Name = "rom-1",
|
||||
Size = 1024,
|
||||
@@ -526,9 +608,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
dict.AddItem(datItem, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
dict.AddItem(item, statsOnly: false);
|
||||
|
||||
dict.RemoveBucket("game-1");
|
||||
|
||||
@@ -546,7 +632,7 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
Machine machine = new Machine { Name = "game-1" };
|
||||
|
||||
DatItem datItem = new Rom
|
||||
DatItem item = new Rom
|
||||
{
|
||||
Name = "rom-1",
|
||||
Size = 1024,
|
||||
@@ -555,9 +641,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
long itemIndex = dict.AddItem(datItem, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
long itemIndex = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
dict.RemoveItem(itemIndex);
|
||||
|
||||
@@ -632,13 +722,25 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
// Setup the dictionary
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom1.SourceIndex = sourceIndex;
|
||||
rom2.SourceIndex = sourceIndex;
|
||||
rom3.SourceIndex = sourceIndex;
|
||||
rom4.SourceIndex = sourceIndex;
|
||||
|
||||
long machine1Index = dict.AddMachine(machine1);
|
||||
rom1.MachineIndex = machine1Index;
|
||||
rom2.MachineIndex = machine1Index;
|
||||
|
||||
long machine2Index = dict.AddMachine(machine2);
|
||||
dict.AddItem(rom1, machine1Index, sourceIndex, statsOnly: false);
|
||||
dict.AddItem(rom2, machine1Index, sourceIndex, statsOnly: false);
|
||||
dict.AddItem(rom3, machine2Index, sourceIndex, statsOnly: false);
|
||||
dict.AddItem(rom4, machine2Index, sourceIndex, statsOnly: false);
|
||||
rom3.MachineIndex = machine2Index;
|
||||
rom4.MachineIndex = machine2Index;
|
||||
|
||||
dict.AddItem(rom1, statsOnly: false);
|
||||
dict.AddItem(rom2, statsOnly: false);
|
||||
dict.AddItem(rom3, statsOnly: false);
|
||||
dict.AddItem(rom4, statsOnly: false);
|
||||
|
||||
dict.BucketBy(itemKey);
|
||||
Assert.Equal(expected, dict.SortedKeys.Length);
|
||||
@@ -672,10 +774,17 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
// Setup the dictionary
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom1.SourceIndex = sourceIndex;
|
||||
rom2.SourceIndex = sourceIndex;
|
||||
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
dict.AddItem(rom1, machineIndex, sourceIndex, statsOnly: false);
|
||||
dict.AddItem(rom2, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom1.MachineIndex = machineIndex;
|
||||
rom2.MachineIndex = machineIndex;
|
||||
|
||||
dict.AddItem(rom1, statsOnly: false);
|
||||
dict.AddItem(rom2, statsOnly: false);
|
||||
|
||||
dict.Deduplicate();
|
||||
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
||||
@@ -732,18 +841,22 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
var romA = new Rom
|
||||
{
|
||||
SourceIndex = sourceAIndex,
|
||||
MachineIndex = machineAIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "BEEFDEAD"
|
||||
};
|
||||
long romAIndex = dict.AddItem(romA, machineAIndex, sourceAIndex);
|
||||
long romAIndex = dict.AddItemInternal(romA);
|
||||
KeyValuePair<long, DatItem>? romAPair = new KeyValuePair<long, DatItem>(romAIndex, romA);
|
||||
|
||||
var romB = new Rom
|
||||
{
|
||||
SourceIndex = sourceBIndex,
|
||||
MachineIndex = machineBIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romBIndex = dict.AddItem(romB, machineBIndex, sourceBIndex);
|
||||
long romBIndex = dict.AddItemInternal(romB);
|
||||
KeyValuePair<long, DatItem>? romBPair = new KeyValuePair<long, DatItem>(romBIndex, romB);
|
||||
|
||||
var actual = dict.GetDuplicateStatus(romAPair, sourceA, romBPair, sourceB);
|
||||
@@ -768,18 +881,22 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
var romA = new Rom
|
||||
{
|
||||
SourceIndex = sourceAIndex,
|
||||
MachineIndex = machineAIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romAIndex = dict.AddItem(romA, machineAIndex, sourceAIndex);
|
||||
long romAIndex = dict.AddItemInternal(romA);
|
||||
KeyValuePair<long, DatItem>? romAPair = new KeyValuePair<long, DatItem>(romAIndex, romA);
|
||||
|
||||
var romB = new Rom
|
||||
{
|
||||
SourceIndex = sourceBIndex,
|
||||
MachineIndex = machineBIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romBIndex = dict.AddItem(romB, machineBIndex, sourceBIndex);
|
||||
long romBIndex = dict.AddItemInternal(romB);
|
||||
KeyValuePair<long, DatItem>? romBPair = new KeyValuePair<long, DatItem>(romBIndex, romB);
|
||||
|
||||
var actual = dict.GetDuplicateStatus(romAPair, sourceA, romBPair, sourceB);
|
||||
@@ -804,18 +921,22 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
var romA = new Rom
|
||||
{
|
||||
SourceIndex = sourceAIndex,
|
||||
MachineIndex = machineAIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romAIndex = dict.AddItem(romA, machineAIndex, sourceAIndex);
|
||||
long romAIndex = dict.AddItemInternal(romA);
|
||||
KeyValuePair<long, DatItem>? romAPair = new KeyValuePair<long, DatItem>(romAIndex, romA);
|
||||
|
||||
var romB = new Rom
|
||||
{
|
||||
SourceIndex = sourceBIndex,
|
||||
MachineIndex = machineBIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romBIndex = dict.AddItem(romB, machineBIndex, sourceBIndex);
|
||||
long romBIndex = dict.AddItemInternal(romB);
|
||||
KeyValuePair<long, DatItem>? romBPair = new KeyValuePair<long, DatItem>(romBIndex, romB);
|
||||
|
||||
var actual = dict.GetDuplicateStatus(romAPair, sourceA, romBPair, sourceB);
|
||||
@@ -840,18 +961,22 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
var romA = new Rom
|
||||
{
|
||||
SourceIndex = sourceAIndex,
|
||||
MachineIndex = machineAIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romAIndex = dict.AddItem(romA, machineAIndex, sourceAIndex);
|
||||
long romAIndex = dict.AddItemInternal(romA);
|
||||
KeyValuePair<long, DatItem>? romAPair = new KeyValuePair<long, DatItem>(romAIndex, romA);
|
||||
|
||||
var romB = new Rom
|
||||
{
|
||||
SourceIndex = sourceBIndex,
|
||||
MachineIndex = machineBIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romBIndex = dict.AddItem(romB, machineBIndex, sourceBIndex);
|
||||
long romBIndex = dict.AddItemInternal(romB);
|
||||
KeyValuePair<long, DatItem>? romBPair = new KeyValuePair<long, DatItem>(romBIndex, romB);
|
||||
|
||||
var actual = dict.GetDuplicateStatus(romAPair, sourceA, romBPair, sourceB);
|
||||
@@ -876,18 +1001,22 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
var romA = new Rom
|
||||
{
|
||||
SourceIndex = sourceAIndex,
|
||||
MachineIndex = machineAIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romAIndex = dict.AddItem(romA, machineAIndex, sourceAIndex);
|
||||
long romAIndex = dict.AddItemInternal(romA);
|
||||
KeyValuePair<long, DatItem>? romAPair = new KeyValuePair<long, DatItem>(romAIndex, romA);
|
||||
|
||||
var romB = new Rom
|
||||
{
|
||||
SourceIndex = sourceBIndex,
|
||||
MachineIndex = machineBIndex,
|
||||
Name = "same-name",
|
||||
CRC32 = "DEADBEEF"
|
||||
};
|
||||
long romBIndex = dict.AddItem(romB, machineBIndex, sourceBIndex);
|
||||
long romBIndex = dict.AddItemInternal(romB);
|
||||
KeyValuePair<long, DatItem>? romBPair = new KeyValuePair<long, DatItem>(romBIndex, romB);
|
||||
|
||||
var actual = dict.GetDuplicateStatus(romAPair, sourceA, romBPair, sourceB);
|
||||
@@ -924,10 +1053,17 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
// Setup the dictionary
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom1.SourceIndex = sourceIndex;
|
||||
rom2.SourceIndex = sourceIndex;
|
||||
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
dict.AddItem(rom1, machineIndex, sourceIndex, statsOnly: false);
|
||||
dict.AddItem(rom2, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom1.MachineIndex = machineIndex;
|
||||
rom2.MachineIndex = machineIndex;
|
||||
|
||||
dict.AddItem(rom1, statsOnly: false);
|
||||
dict.AddItem(rom2, statsOnly: false);
|
||||
|
||||
// Setup the test item
|
||||
DatItem rom = new Rom
|
||||
@@ -971,10 +1107,17 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
|
||||
// Setup the dictionary
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
rom1.SourceIndex = sourceIndex;
|
||||
rom2.SourceIndex = sourceIndex;
|
||||
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
dict.AddItem(rom1, machineIndex, sourceIndex, statsOnly: false);
|
||||
dict.AddItem(rom2, machineIndex, sourceIndex, statsOnly: false);
|
||||
rom1.MachineIndex = machineIndex;
|
||||
rom2.MachineIndex = machineIndex;
|
||||
|
||||
dict.AddItem(rom1, statsOnly: false);
|
||||
dict.AddItem(rom2, statsOnly: false);
|
||||
|
||||
// Setup the test item
|
||||
DatItem rom = new Rom
|
||||
@@ -1007,9 +1150,13 @@ namespace SabreTools.Metadata.DatFiles.Test
|
||||
};
|
||||
|
||||
var dict = new ItemDatabase();
|
||||
|
||||
long sourceIndex = dict.AddSource(source);
|
||||
item.SourceIndex = sourceIndex;
|
||||
long machineIndex = dict.AddMachine(machine);
|
||||
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||
item.MachineIndex = machineIndex;
|
||||
|
||||
_ = dict.AddItem(item, statsOnly: false);
|
||||
|
||||
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
||||
Assert.Equal(1, dict.DatStatistics.GetItemCount(Data.Models.Metadata.ItemType.Rom));
|
||||
|
||||
@@ -451,7 +451,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
.Contains(mergeTag))
|
||||
{
|
||||
item.Value.MachineIndex = cloneOfMachine.Key;
|
||||
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||
item.Value.SourceIndex = source.Key;
|
||||
ItemsDB.AddItemInternal(item.Value);
|
||||
}
|
||||
|
||||
// If there is no merge tag, add to parent
|
||||
@@ -461,7 +462,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
.Contains(disk.Name))
|
||||
{
|
||||
item.Value.MachineIndex = cloneOfMachine.Key;
|
||||
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||
item.Value.SourceIndex = source.Key;
|
||||
ItemsDB.AddItemInternal(item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +491,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
rom.Name = $"{machineName}\\{rom.Name}";
|
||||
|
||||
item.Value.MachineIndex = cloneOfMachine.Key;
|
||||
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||
item.Value.SourceIndex = source.Key;
|
||||
ItemsDB.AddItemInternal(item.Value);
|
||||
}
|
||||
|
||||
// If the parent doesn't already contain this item, add to subfolder of parent
|
||||
@@ -499,7 +502,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
rom.Name = $"{machineName}\\{rom.Name}";
|
||||
|
||||
item.Value.MachineIndex = cloneOfMachine.Key;
|
||||
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||
item.Value.SourceIndex = source.Key;
|
||||
ItemsDB.AddItemInternal(item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,7 +514,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
item.Value.SetName($"{machineName}\\{item.Value.GetName()}");
|
||||
|
||||
item.Value.MachineIndex = cloneOfMachine.Key;
|
||||
ItemsDB.AddItem(item.Value, cloneOfMachine.Key, source.Key);
|
||||
item.Value.SourceIndex = source.Key;
|
||||
ItemsDB.AddItemInternal(item.Value);
|
||||
}
|
||||
|
||||
// Remove the current item
|
||||
@@ -609,10 +614,13 @@ namespace SabreTools.Metadata.DatFiles
|
||||
foreach (var item in parentItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Value.Clone();
|
||||
datItem.MachineIndex = machine.Key;
|
||||
datItem.SourceIndex = source.Key;
|
||||
|
||||
if (items.Values.Any(i => i.GetName()?.ToLowerInvariant() == datItem.GetName()?.ToLowerInvariant())
|
||||
&& items.Values.Any(i => i == datItem))
|
||||
{
|
||||
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
||||
ItemsDB.AddItemInternal(datItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -874,7 +882,10 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
// Clone the item and then add it
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
||||
datItem.MachineIndex = machine.Key;
|
||||
datItem.SourceIndex = source.Key;
|
||||
|
||||
ItemsDB.AddItemInternal(datItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -884,8 +895,14 @@ namespace SabreTools.Metadata.DatFiles
|
||||
{
|
||||
if (!deviceReferences.Contains(deviceReference))
|
||||
{
|
||||
var deviceRef = new DeviceRef { Name = deviceReference };
|
||||
ItemsDB.AddItem(deviceRef, machine.Key, source.Key);
|
||||
var deviceRef = new DeviceRef
|
||||
{
|
||||
MachineIndex = machine.Key,
|
||||
SourceIndex = source.Key,
|
||||
Name = deviceReference,
|
||||
};
|
||||
|
||||
ItemsDB.AddItemInternal(deviceRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -929,7 +946,10 @@ namespace SabreTools.Metadata.DatFiles
|
||||
|
||||
// Clone the item and then add it
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
||||
datItem.MachineIndex = machine.Key;
|
||||
datItem.SourceIndex = source.Key;
|
||||
|
||||
ItemsDB.AddItemInternal(datItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -939,11 +959,21 @@ namespace SabreTools.Metadata.DatFiles
|
||||
{
|
||||
if (!slotOptions.Contains(slotOption))
|
||||
{
|
||||
var slotOptionItem = new SlotOption { DevName = slotOption };
|
||||
var slotOptionItem = new SlotOption
|
||||
{
|
||||
MachineIndex = machine.Key,
|
||||
SourceIndex = source.Key,
|
||||
DevName = slotOption,
|
||||
};
|
||||
|
||||
var slotItem = new Slot { SlotOption = [slotOptionItem] };
|
||||
var slotItem = new Slot
|
||||
{
|
||||
MachineIndex = machine.Key,
|
||||
SourceIndex = source.Key,
|
||||
SlotOption = [slotOptionItem],
|
||||
};
|
||||
|
||||
ItemsDB.AddItem(slotItem, machine.Key, source.Key);
|
||||
ItemsDB.AddItemInternal(slotItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1027,10 +1057,13 @@ namespace SabreTools.Metadata.DatFiles
|
||||
foreach (var item in parentItems)
|
||||
{
|
||||
DatItem datItem = (DatItem)item.Value.Clone();
|
||||
datItem.MachineIndex = machine.Key;
|
||||
datItem.SourceIndex = source.Key;
|
||||
|
||||
if (items.Any(i => i.Value.GetName() == datItem.GetName())
|
||||
&& items.Any(i => i.Value == datItem))
|
||||
{
|
||||
ItemsDB.AddItem(datItem, machine.Key, source.Key);
|
||||
ItemsDB.AddItemInternal(datItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,11 @@ namespace SabreTools.Metadata.DatFiles
|
||||
/// <returns>The index for the added item, -1 on error</returns>
|
||||
public long AddItemDB(DatItem item, long machineIndex, long sourceIndex, bool statsOnly)
|
||||
{
|
||||
return ItemsDB.AddItem(item, machineIndex, sourceIndex, statsOnly);
|
||||
// TODO: Have the callers of this method set them instead
|
||||
item.MachineIndex = machineIndex;
|
||||
item.SourceIndex = sourceIndex;
|
||||
|
||||
return ItemsDB.AddItem(item, statsOnly);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -157,11 +157,9 @@ namespace SabreTools.Metadata.DatFiles
|
||||
/// Add a DatItem to the dictionary after validation
|
||||
/// </summary>
|
||||
/// <param name="item">Item data to validate</param>
|
||||
/// <param name="machineIndex">Index of the machine related to the item</param>
|
||||
/// <param name="sourceIndex">Index of the source related to the item</param>
|
||||
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
||||
/// <returns>The index for the added item, -1 on error</returns>
|
||||
public long AddItem(DatItem item, long machineIndex, long sourceIndex, bool statsOnly)
|
||||
public long AddItem(DatItem item, bool statsOnly)
|
||||
{
|
||||
// If we have a Disk, File, Media, or Rom, clean the hash data
|
||||
if (item is Disk disk)
|
||||
@@ -261,7 +259,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
}
|
||||
else
|
||||
{
|
||||
return AddItem(item, machineIndex, sourceIndex);
|
||||
return AddItemInternal(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,12 +515,8 @@ namespace SabreTools.Metadata.DatFiles
|
||||
/// <summary>
|
||||
/// Add an item, returning the insert index
|
||||
/// </summary>
|
||||
internal long AddItem(DatItem item, long machineIndex, long sourceIndex)
|
||||
internal long AddItemInternal(DatItem item)
|
||||
{
|
||||
// Add the machine and source index
|
||||
item.MachineIndex = machineIndex;
|
||||
item.SourceIndex = sourceIndex;
|
||||
|
||||
#if NET40_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER
|
||||
// Add the item with a new index
|
||||
long index = Interlocked.Increment(ref _itemIndex) - 1;
|
||||
@@ -586,20 +580,9 @@ namespace SabreTools.Metadata.DatFiles
|
||||
Sort(ref sortedList, false);
|
||||
sortedList = Merge(sortedList);
|
||||
|
||||
// Get all existing mappings
|
||||
List<ItemMappings> currentMappings = sortedList.ConvertAll(item =>
|
||||
{
|
||||
return new ItemMappings(
|
||||
item.Value,
|
||||
GetMachineForItem(item.Key).Key,
|
||||
GetSourceForItem(item.Key).Key
|
||||
);
|
||||
});
|
||||
|
||||
// Add the list back to the dictionary
|
||||
RemoveBucket(key);
|
||||
currentMappings.ForEach(map =>
|
||||
AddItem(map.Item, map.MachineId, map.SourceId));
|
||||
sortedList.ForEach(item => AddItemInternal(item.Value));
|
||||
#if NET40_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER
|
||||
});
|
||||
#else
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace SabreTools.Metadata.DatFiles
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used during deduplication
|
||||
/// </summary>
|
||||
public struct ItemMappings(DatItems.DatItem item, long machineId, long sourceId)
|
||||
{
|
||||
public DatItems.DatItem Item = item;
|
||||
public long MachineId = machineId;
|
||||
public long SourceId = sourceId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user