Change order of application to use original `client.realm` last

This commit is contained in:
Dean Herbert 2022-08-05 17:48:51 +09:00
parent 84a3fbd25c
commit 3c84b1a389
1 changed files with 15 additions and 17 deletions

View File

@ -173,7 +173,7 @@ public RealmAccess(Storage storage, string filename, GameThread? updateThread =
Filename += realm_extension;
#if DEBUG
Filename = applyFilenameSchemaSuffix(Filename);
applyFilenameSchemaSuffix(ref Filename);
#endif
string newerVersionFilename = $"{Filename.Replace(realm_extension, string.Empty)}_newer_version{realm_extension}";
@ -221,24 +221,17 @@ public RealmAccess(Storage storage, string filename, GameThread? updateThread =
/// To get around this, store development databases against their realm version.
/// Note that this means changes made on newer realm versions will disappear.
/// </summary>
private string applyFilenameSchemaSuffix(string filename)
private void applyFilenameSchemaSuffix(ref string filename)
{
string proposedFilename = getVersionedFilename(schema_version);
string originalFilename = filename;
filename = getVersionedFilename(schema_version);
// First check if the current realm version already exists...
if (storage.Exists(proposedFilename))
return proposedFilename;
// If a non-versioned file exists (aka before this method was added), move it to the new versioned
// format.
if (storage.Exists(filename))
{
Logger.Log(@$"Moving non-versioned realm file {filename} to {proposedFilename}");
storage.Move(filename, proposedFilename);
return proposedFilename;
}
return;
// If it doesn't, check for a previous version we can use as a base database to migrate from...
// Check for a previous version we can use as a base database to migrate from...
for (int i = schema_version - 1; i >= 0; i--)
{
string iFilename = getVersionedFilename(i);
@ -246,7 +239,7 @@ private string applyFilenameSchemaSuffix(string filename)
if (storage.Exists(iFilename))
{
using (var previous = storage.GetStream(iFilename))
using (var current = storage.CreateFileSafely(proposedFilename))
using (var current = storage.CreateFileSafely(filename))
{
Logger.Log(@$"Using previous realm database {iFilename} to migrate new schema version {schema_version}");
previous.CopyTo(current);
@ -254,9 +247,14 @@ private string applyFilenameSchemaSuffix(string filename)
}
}
return proposedFilename;
// Finally, check for a non-versioned file exists (aka before this method was added)...
if (storage.Exists(originalFilename))
{
Logger.Log(@$"Moving non-versioned realm file {filename} to {filename}");
storage.Move(filename, filename);
}
string getVersionedFilename(int version) => filename.Replace(realm_extension, $"_{version}{realm_extension}");
string getVersionedFilename(int version) => originalFilename.Replace(realm_extension, $"_{version}{realm_extension}");
}
private void attemptRecoverFromFile(string recoveryFilename)