From d5b5233ab8bd1efafc8fb36e677bbc54f528753c Mon Sep 17 00:00:00 2001 From: ericek111 Date: Mon, 31 Aug 2026 23:09:01 +0000 Subject: [PATCH] Drop the migration from the older folder Nothing has shipped, so there is nothing to migrate: the program makes Documents/N1MM Logger+ and starts there. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD --- README.md | 6 -- src/Nonemm.App/App.axaml.cs | 1 - src/Nonemm.App/Configuration/UserPaths.cs | 74 ----------------------- tests/Nonemm.App.Tests/UserPathsTests.cs | 32 ---------- 4 files changed, 113 deletions(-) diff --git a/README.md b/README.md index 7d55d79..db71eae 100644 --- a/README.md +++ b/README.md @@ -425,12 +425,6 @@ and neither has anything to do with a log. On a system that does not say where Documents is — most Linux systems, until someone sets `XDG_DOCUMENTS_DIR` — it is `~/Documents/N1MM Logger+`. -A version before this one kept everything in `Documents\Nonemm` or -`~/.config/nonemm`. Those files are copied into N1MM's folders the first time -this version runs, and the log and call history paths in the settings are moved -with them, so the copy that opens is the copy that came over. The older folder -is left as it was. - ### Operators **Ctrl+O**, or **Config → Change Operator…**, asks who is at the radio. The diff --git a/src/Nonemm.App/App.axaml.cs b/src/Nonemm.App/App.axaml.cs index 1f0c6f8..d1c5a40 100644 --- a/src/Nonemm.App/App.axaml.cs +++ b/src/Nonemm.App/App.axaml.cs @@ -18,7 +18,6 @@ public partial class App : Application { UserPaths paths = UserPaths.Default(); paths.CreateFolders(); - paths.AdoptOlderFiles(); Settings settings = Settings.Load(paths.SettingsFile); Themes.Use(settings.Theme); Themes.Changed += (_, _) => ApplyTheme(); diff --git a/src/Nonemm.App/Configuration/UserPaths.cs b/src/Nonemm.App/Configuration/UserPaths.cs index 0fbdc73..11c85d3 100644 --- a/src/Nonemm.App/Configuration/UserPaths.cs +++ b/src/Nonemm.App/Configuration/UserPaths.cs @@ -143,78 +143,4 @@ public sealed class UserPaths Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Documents"); } - - /// Where versions before this one kept everything. Their files are copied - /// into N1MM's folders the first time this one runs. - public static string LegacyRoot() => - OperatingSystem.IsWindows() - ? Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), - "Nonemm") - : Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "nonemm"); - - /// Copies what an older version kept into these folders, once: it runs only - /// while there is no settings file here and there is one there. The older - /// folder is left as it was, so nothing is lost if the operator goes back - /// to the older version. - /// - /// Paths inside the settings that pointed into the older folder — the log - /// database and the call history file — are moved with it, so the copy that - /// is opened is the copy that was brought over. - public bool AdoptOlderFiles(string? legacyRoot = null) - { - string older = legacyRoot ?? LegacyRoot(); - string olderSettings = Path.Combine(older, "settings.json"); - if (File.Exists(SettingsFile) || !File.Exists(olderSettings) || SameFolder(older, Root)) - { - return false; - } - Copy(older, Root); - Settings settings = Settings.Load(olderSettings); - settings = settings with - { - DatabasePath = Brought(settings.DatabasePath, older), - CallHistoryFile = Brought(settings.CallHistoryFile, older), - }; - settings.Save(SettingsFile); - return true; - } - - /// A file that was inside the older folder is now inside this one, in the - /// same place under it. A file kept anywhere else is left where it is. - private string Brought(string path, string older) - { - if (path.Trim().Length == 0 - || !path.StartsWith(older + Path.DirectorySeparatorChar, StringComparison.Ordinal)) - { - return path; - } - return Path.Combine(Root, path[(older.Length + 1)..]); - } - - private static void Copy(string from, string to) - { - Directory.CreateDirectory(to); - foreach (string file in Directory.GetFiles(from)) - { - // the settings file is written again afterwards, with the paths - // inside it moved - if (!Path.GetFileName(file).Equals("settings.json", StringComparison.OrdinalIgnoreCase)) - { - File.Copy(file, Path.Combine(to, Path.GetFileName(file)), overwrite: false); - } - } - foreach (string folder in Directory.GetDirectories(from)) - { - Copy(folder, Path.Combine(to, Path.GetFileName(folder))); - } - } - - private static bool SameFolder(string one, string other) => - string.Equals( - Path.TrimEndingDirectorySeparator(Path.GetFullPath(one)), - Path.TrimEndingDirectorySeparator(Path.GetFullPath(other)), - StringComparison.Ordinal); } diff --git a/tests/Nonemm.App.Tests/UserPathsTests.cs b/tests/Nonemm.App.Tests/UserPathsTests.cs index 34455d3..5b6a800 100644 --- a/tests/Nonemm.App.Tests/UserPathsTests.cs +++ b/tests/Nonemm.App.Tests/UserPathsTests.cs @@ -62,36 +62,4 @@ public class UserPathsTests : IDisposable Assert.Equal(Path.Combine(root, "Nonemm", "settings.json"), paths.SettingsFile); } - - [Fact] - public void AnOlderVersionsFilesAreCopiedInOnce() - { - string older = Path.Combine(root, "older"); - Directory.CreateDirectory(Path.Combine(older, "Databases")); - File.WriteAllText(Path.Combine(older, "Databases", "om5m.s3db"), "log"); - string database = Path.Combine(older, "Databases", "om5m.s3db"); - new Settings { DatabasePath = database }.Save(Path.Combine(older, "settings.json")); - UserPaths paths = new(Path.Combine(root, "new")); - paths.CreateFolders(); - - Assert.True(paths.AdoptOlderFiles(older)); - - Assert.Equal("log", File.ReadAllText(Path.Combine(paths.Databases, "om5m.s3db"))); - // the log that was opened is the log that was brought over - Assert.Equal( - Path.Combine(paths.Databases, "om5m.s3db"), - Settings.Load(paths.SettingsFile).DatabasePath); - Assert.False(paths.AdoptOlderFiles(older)); - // the older folder is left as it was - Assert.True(File.Exists(database)); - } - - [Fact] - public void NothingIsCopiedWhenThereIsNoOlderFolder() - { - UserPaths paths = new(root); - paths.CreateFolders(); - - Assert.False(paths.AdoptOlderFiles(Path.Combine(root, "nowhere"))); - } }