Fix FixDatabase
This commit is contained in:
parent
3257169509
commit
754ea1c2b0
1 changed files with 38 additions and 24 deletions
|
@ -108,17 +108,19 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
|
||||||
|
|
||||||
public void Delete(int index)
|
public void Delete(int index)
|
||||||
{
|
{
|
||||||
|
int newCount = _figurineCount - 1;
|
||||||
|
|
||||||
// If this isn't the only element in the list, move the data in it.
|
// If this isn't the only element in the list, move the data in it.
|
||||||
if (_figurineCount - 1 > index)
|
if (index < newCount)
|
||||||
{
|
{
|
||||||
int targetLength = _figurineCount - index;
|
int targetLength = newCount - index;
|
||||||
int sourceIndex = index + 1;
|
int sourceIndex = index + 1;
|
||||||
int destinationIndex = index;
|
int destinationIndex = index;
|
||||||
|
|
||||||
Figurines.Slice(sourceIndex, targetLength).CopyTo(Figurines.Slice(destinationIndex, targetLength));
|
Figurines.Slice(sourceIndex, targetLength).CopyTo(Figurines.Slice(destinationIndex, targetLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
_figurineCount--;
|
_figurineCount = (byte)newCount;
|
||||||
|
|
||||||
UpdateCrc();
|
UpdateCrc();
|
||||||
}
|
}
|
||||||
|
@ -126,40 +128,52 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
|
||||||
public bool FixDatabase()
|
public bool FixDatabase()
|
||||||
{
|
{
|
||||||
bool isBroken = false;
|
bool isBroken = false;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
while (true)
|
while (i < Length)
|
||||||
{
|
{
|
||||||
int i;
|
ref StoreData figurine = ref Figurines[i];
|
||||||
|
|
||||||
for (i = 0; i < Length; i++)
|
if (!figurine.IsValid())
|
||||||
{
|
{
|
||||||
if (!Figurines[i].IsValid())
|
if (AcceptInvalidDeviceCrc && figurine.CoreData.IsValid() && figurine.IsValidDataCrc())
|
||||||
{
|
{
|
||||||
// If the device crc is the only part invalid, we fix it (This is useful to allow importing arbitrary database in Ryujinx)
|
figurine.UpdateCrc();
|
||||||
if (AcceptInvalidDeviceCrc && Figurines[i].CoreData.IsValid() && Figurines[i].IsValidDataCrc())
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Delete(i);
|
||||||
|
isBroken = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool hasDuplicate = false;
|
||||||
|
CreateId createId = figurine.CreateId;
|
||||||
|
|
||||||
|
for (int j = 0; j < i; j++)
|
||||||
|
{
|
||||||
|
if (Figurines[j].CreateId == createId)
|
||||||
{
|
{
|
||||||
Figurines[i].UpdateCrc();
|
hasDuplicate = true;
|
||||||
|
|
||||||
UpdateCrc();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Delete(i);
|
|
||||||
|
|
||||||
isBroken = true;
|
|
||||||
|
|
||||||
// As we removed an element, we need to restart the process from the beginning as indexes are now inconsistent.
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (i == Length)
|
if (hasDuplicate)
|
||||||
{
|
{
|
||||||
break;
|
Delete(i);
|
||||||
|
isBroken = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateCrc();
|
||||||
|
|
||||||
return isBroken;
|
return isBroken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue