Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions WheelWizard.Test/Features/Settings/PathManagerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using WheelWizard.Services;

namespace WheelWizard.Test.Features.Settings;

[Collection("SettingsFeature")]
public class PathManagerTests
{
[Fact]
public void TrySetWheelWizardAppdataPath_ReturnsFalse_WhenTargetPathIsUnavailable()
{
if (!OperatingSystem.IsWindows())
return;

var unavailablePath = GetUnavailableWindowsPath();
var result = PathManager.TrySetWheelWizardAppdataPath(unavailablePath, out var errorMessage, out _);

Assert.False(result);
Assert.False(string.IsNullOrWhiteSpace(errorMessage));
}

private static string GetUnavailableWindowsPath()
{
var used = DriveInfo.GetDrives().Select(d => char.ToUpperInvariant(d.Name[0])).ToHashSet();
var drive = "ZYXWVUTSRQPONMLKJIHGFEDCBA".FirstOrDefault(letter => !used.Contains(letter), 'Z');
return $@"{drive}:\WheelWizardTests\{Guid.NewGuid():N}";
}
Comment thread
nickogl marked this conversation as resolved.
}
23 changes: 22 additions & 1 deletion WheelWizard/Services/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,35 @@ public static bool IsUsingCustomWheelWizardAppdataPath
return null;

var normalized = FileHelper.NormalizePath(storedPath);
return FileHelper.PathsEqual(normalized, DefaultWheelWizardAppdataPath) ? null : normalized;
if (FileHelper.PathsEqual(normalized, DefaultWheelWizardAppdataPath))
return null;

// If a previously selected custom location is no longer available (for example,
// when an external drive letter changes), fall back to the default path.
if (!TryEnsureWheelWizardAppdataPathAccessible(normalized))
return null;

return normalized;
}
catch
{
return null;
}
}

private static bool TryEnsureWheelWizardAppdataPathAccessible(string normalizedPath)
{
try
{
FileHelper.EnsureDirectory(normalizedPath);
return true;
}
catch
{
return false;
}
}

private static string? LoadPersistedWheelWizardAppdataOverride()
{
#if WINDOWS
Expand Down
Loading