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)
|
if (datItem == null)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
if (!_itemToMachineMapping.ContainsKey(itemIndex))
|
var machine = GetMachineForItem(itemIndex);
|
||||||
|
if (machine.Item2 == null)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
long machineIndex = _itemToMachineMapping[itemIndex];
|
var source = GetSourceForItem(itemIndex);
|
||||||
if (!_machines.ContainsKey(machineIndex))
|
|
||||||
return string.Empty;
|
|
||||||
|
|
||||||
var machine = _machines[machineIndex];
|
string sourceKeyPadded = source.Item2?.Index.ToString().PadLeft(10, '0') + '-';
|
||||||
if (machine == null)
|
string machineName = machine.Item2.GetStringFieldValue(Models.Metadata.Machine.NameKey) ?? "Default";
|
||||||
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 bucketKey = bucketBy switch
|
string bucketKey = bucketBy switch
|
||||||
{
|
{
|
||||||
@@ -1116,8 +1111,8 @@ namespace SabreTools.DatFiles
|
|||||||
return nc.Compare(xName, yName);
|
return nc.Compare(xName, yName);
|
||||||
|
|
||||||
// Otherwise, compare on machine or source, depending on the flag
|
// Otherwise, compare on machine or source, depending on the flag
|
||||||
int? xSourceIndex = x.Item2.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
int? xSourceIndex = GetSourceForItem(x.Item1).Item2?.Index;
|
||||||
int? ySourceIndex = y.Item2.GetFieldValue<Source?>(DatItem.SourceKey)?.Index;
|
int? ySourceIndex = GetSourceForItem(y.Item1).Item2?.Index;
|
||||||
return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0);
|
return (norename ? nc.Compare(xMachineName, yMachineName) : (xSourceIndex - ySourceIndex) ?? 0);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -118,15 +118,16 @@ namespace SabreTools.DatTools
|
|||||||
|
|
||||||
foreach ((long, DatItem) item in items)
|
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;
|
continue;
|
||||||
|
|
||||||
var machine = datFile.ItemsDB.GetMachineForItem(item.Item1);
|
var machine = datFile.ItemsDB.GetMachineForItem(item.Item1);
|
||||||
if (machine.Item2 == null)
|
if (machine.Item2 == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string filename = inputs[item.Item2.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath;
|
string filename = inputs[source.Item2.Index].CurrentPath;
|
||||||
string? rootpath = inputs[item.Item2.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].ParentPath;
|
string? rootpath = inputs[source.Item2.Index].ParentPath;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(rootpath)
|
if (!string.IsNullOrEmpty(rootpath)
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
@@ -913,7 +914,9 @@ namespace SabreTools.DatTools
|
|||||||
long machineIndex = itemMachineMappings[item.Key];
|
long machineIndex = itemMachineMappings[item.Key];
|
||||||
long sourceIndex = itemSourceMappings[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
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
@@ -925,7 +928,7 @@ namespace SabreTools.DatTools
|
|||||||
#else
|
#else
|
||||||
if (item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
|
if (item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
|
||||||
#endif
|
#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
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
});
|
});
|
||||||
#else
|
#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)
|
if (item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.Value.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
|
||||||
#endif
|
#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
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#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);
|
outerDiffData.ItemsDB.AddItem(newrom, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
|
||||||
}
|
}
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
@@ -1357,7 +1359,10 @@ namespace SabreTools.DatTools
|
|||||||
long machineIndex = itemMachineMappings[item.Key];
|
long machineIndex = itemMachineMappings[item.Key];
|
||||||
long sourceIndex = itemSourceMappings[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);
|
indexDat.ItemsDB.AddItem(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -274,8 +274,11 @@ namespace SabreTools.DatTools
|
|||||||
|
|
||||||
for (int i = 0; i < items.Length; i++)
|
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
|
// 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);
|
items[i].Item2.SetFieldValue<bool?>(DatItem.RemoveKey, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user