mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Start replacing more IDDB locations that use Source
This commit is contained in:
@@ -850,19 +850,14 @@ namespace SabreTools.DatFiles
|
||||
if (datItem == null)
|
||||
return string.Empty;
|
||||
|
||||
if (!_itemToMachineMapping.ContainsKey(itemIndex))
|
||||
var machine = GetMachineForItem(itemIndex);
|
||||
if (machine.Item2 == null)
|
||||
return string.Empty;
|
||||
|
||||
long machineIndex = _itemToMachineMapping[itemIndex];
|
||||
if (!_machines.ContainsKey(machineIndex))
|
||||
return string.Empty;
|
||||
var source = GetSourceForItem(itemIndex);
|
||||
|
||||
var machine = _machines[machineIndex];
|
||||
if (machine == null)
|
||||
return string.Empty;
|
||||
|
||||
string sourceKeyPadded = datItem.GetFieldValue<Source?>(DatItem.SourceKey)?.Index.ToString().PadLeft(10, '0') + '-';
|
||||
string machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? "Default";
|
||||
string sourceKeyPadded = source.Item2?.Index.ToString().PadLeft(10, '0') + '-';
|
||||
string machineName = machine.Item2.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? "Default";
|
||||
|
||||
string bucketKey = bucketBy switch
|
||||
{
|
||||
@@ -1116,8 +1111,8 @@ namespace SabreTools.DatFiles
|
||||
return nc.Compare(xName, yName);
|
||||
|
||||
// Otherwise, compare on machine or source, depending on the flag
|
||||
int? xSourceIndex = x.Item2.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
||||
int? ySourceIndex = y.Item2.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
||||
int? xSourceIndex = GetSourceForItem(x.Item1).Item2?.Index;
|
||||
int? ySourceIndex = GetSourceForItem(y.Item1).Item2?.Index;
|
||||
return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0);
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -118,15 +118,16 @@ namespace SabreTools.DatTools
|
||||
|
||||
foreach ((long, DatItem) item in items)
|
||||
{
|
||||
if (item.Item2.GetFieldValue<Source?>(DatItem.SourceKey) == null)
|
||||
var source = datFile.ItemsDB.GetSourceForItem(item.Item1);
|
||||
if (source.Item2 == null)
|
||||
continue;
|
||||
|
||||
var machine = datFile.ItemsDB.GetMachineForItem(item.Item1);
|
||||
if (machine.Item2 == null)
|
||||
continue;
|
||||
|
||||
string filename = inputs[item.Item2.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath;
|
||||
string? rootpath = inputs[item.Item2.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].ParentPath;
|
||||
string filename = inputs[source.Item2.Index].CurrentPath;
|
||||
string? rootpath = inputs[source.Item2.Index].ParentPath;
|
||||
|
||||
if (!string.IsNullOrEmpty(rootpath)
|
||||
#if NETFRAMEWORK
|
||||
@@ -913,7 +914,9 @@ namespace SabreTools.DatTools
|
||||
long machineIndex = itemMachineMappings[item.Key];
|
||||
long sourceIndex = itemSourceMappings[item.Key];
|
||||
|
||||
if (item.Value.GetFieldValue<Source?>(DatItem.SourceKey) == null)
|
||||
// Get the source associated with the item
|
||||
var source = datFile.ItemsDB.GetSource(sourceIndex);
|
||||
if (source == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
@@ -925,7 +928,7 @@ namespace SabreTools.DatTools
|
||||
#else
|
||||
if (item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
|
||||
#endif
|
||||
outDats[item.Value.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
|
||||
outDats[source.Index].ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
@@ -1105,14 +1108,13 @@ namespace SabreTools.DatTools
|
||||
if (item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
|
||||
#endif
|
||||
{
|
||||
if (item.Value.Clone() is not DatItem newrom || newrom.GetFieldValue<Source?>(DatItem.SourceKey) == null)
|
||||
if (item.Value.Clone() is not DatItem newrom || sourceIndex == -1)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
|
||||
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
|
||||
outerDiffData.ItemsDB.AddItem(newrom, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
@@ -1357,7 +1359,10 @@ namespace SabreTools.DatTools
|
||||
long machineIndex = itemMachineMappings[item.Key];
|
||||
long sourceIndex = itemSourceMappings[item.Key];
|
||||
|
||||
if (item.Value.GetFieldValue<Source?>(DatItem.SourceKey) != null && item.Value.GetFieldValue<Source?>(DatItem.SourceKey)!.Index == index)
|
||||
// Get the source associated with the item
|
||||
var source = datFile.ItemsDB.GetSource(sourceIndex);
|
||||
|
||||
if (source != null && source.Index == index)
|
||||
indexDat.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
|
||||
@@ -274,8 +274,11 @@ namespace SabreTools.DatTools
|
||||
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
// Get the source associated with the item
|
||||
var source = datFile.ItemsDB.GetSourceForItem(items[i].Item1);
|
||||
|
||||
// Unmatched items will have a source ID of int.MaxValue, remove all others
|
||||
if (items[i].Item2.GetFieldValue<Source?>(DatItem.SourceKey)?.Index != int.MaxValue)
|
||||
if (source.Item2?.Index != int.MaxValue)
|
||||
items[i].Item2.SetFieldValue<bool?>(DatItem.RemoveKey, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user