Say why the folders cannot be made instead of dying
Something already sitting where Documents/N1MM Logger+ should go — a file, or a link to somewhere that is not there — threw out of Directory.CreateDirectory before the program had a window, so the operator got a stack trace and nothing else. CreateFolders answers with what stopped it, and the program shows it in a window naming the path and stops there. NONEMM_HOME moves the whole lot somewhere else, for a station that keeps its files off the Documents folder. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
This commit is contained in:
@@ -20,7 +20,7 @@ public class UserPathsTests : IDisposable
|
||||
{
|
||||
UserPaths paths = new(root);
|
||||
|
||||
paths.CreateFolders();
|
||||
Assert.Null(paths.CreateFolders());
|
||||
|
||||
string[] made = [.. Directory.GetDirectories(root).Select(Path.GetFileName).OfType<string>().Order()];
|
||||
Assert.Equal(
|
||||
@@ -62,4 +62,32 @@ public class UserPathsTests : IDisposable
|
||||
|
||||
Assert.Equal(Path.Combine(root, "Nonemm", "settings.json"), paths.SettingsFile);
|
||||
}
|
||||
|
||||
/// A file where the folder should be stops the program starting, so it says
|
||||
/// so rather than throwing at an operator who has no window to read it in.
|
||||
[Fact]
|
||||
public void AFileWhereTheFolderShouldBeIsReported()
|
||||
{
|
||||
Directory.CreateDirectory(root);
|
||||
string inTheWay = Path.Combine(root, "N1MM Logger+");
|
||||
File.WriteAllText(inTheWay, "not a folder");
|
||||
UserPaths paths = new(inTheWay);
|
||||
|
||||
string? problem = paths.CreateFolders();
|
||||
|
||||
Assert.NotNull(problem);
|
||||
Assert.Contains(inTheWay, problem);
|
||||
Assert.Contains("is a file", problem);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FoldersThatAreAlreadyThereAreLeftAlone()
|
||||
{
|
||||
UserPaths paths = new(root);
|
||||
paths.CreateFolders();
|
||||
File.WriteAllText(Path.Combine(paths.Databases, "om5m.s3db"), "log");
|
||||
|
||||
Assert.Null(paths.CreateFolders());
|
||||
Assert.Equal("log", File.ReadAllText(Path.Combine(paths.Databases, "om5m.s3db")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user