Skip to content

Commit

Permalink
Fix broken migration on Windows (#86)
Browse files Browse the repository at this point in the history
* Ensure that the migration is also executed on Windows.

* Increase version.
  • Loading branch information
chkr1011 authored Feb 21, 2024
1 parent 99f4725 commit 55efe61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:

env:
VERSION: "1.8.0.${{github.run_number}}"
VERSION: "1.8.1.${{github.run_number}}"

jobs:
build:
Expand Down
24 changes: 12 additions & 12 deletions Source/Services/State/StateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ static string GeneratePath()
path = GeneratePathForWindows();
}

path = Path.Combine(path, "State");
Migrate(path);

path = Path.Combine(path, "State");
Directory.CreateDirectory(path);

return path;
Expand Down Expand Up @@ -124,8 +125,6 @@ static string GeneratePathForLinux()

path = Path.Combine(path, "mqtt-multimeter");

Migrate(path);

return path;
}

Expand Down Expand Up @@ -161,21 +160,22 @@ static void Migrate(string destinationPath)
{
try
{
if (Directory.Exists(destinationPath))
// The first version of the app was named "MQTTnetApp". That is the reason for the different name.
var legacyPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".MQTTnetApp");

if (!Directory.Exists(legacyPath))
{
// If the new directory exist we stop the migration to prevent data loss.
// This requires that the user will delete/move the old variant of the directory
// on it's own.
// There is nothing to migrate...
return;
}

// The first version of the app was named "MQTTnetApp". That is the reason for the different name.
var legacyPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".MQTTnetApp");

if (Directory.Exists(legacyPath))
if (Directory.Exists(destinationPath))
{
Directory.Move(legacyPath, destinationPath);
// If the new directory exist we create a backup of the data so that the user can manually restore the data.
Directory.Move(destinationPath, destinationPath + "-backup-" + Guid.NewGuid());
}

Directory.Move(legacyPath, destinationPath);
}
catch (Exception exception)
{
Expand Down

0 comments on commit 55efe61

Please sign in to comment.