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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
This commit is contained in:
@@ -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
|
On a system that does not say where Documents is — most Linux systems, until
|
||||||
someone sets `XDG_DOCUMENTS_DIR` — it is `~/Documents/N1MM Logger+`.
|
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
|
### Operators
|
||||||
|
|
||||||
**Ctrl+O**, or **Config → Change Operator…**, asks who is at the radio. The
|
**Ctrl+O**, or **Config → Change Operator…**, asks who is at the radio. The
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ public partial class App : Application
|
|||||||
{
|
{
|
||||||
UserPaths paths = UserPaths.Default();
|
UserPaths paths = UserPaths.Default();
|
||||||
paths.CreateFolders();
|
paths.CreateFolders();
|
||||||
paths.AdoptOlderFiles();
|
|
||||||
Settings settings = Settings.Load(paths.SettingsFile);
|
Settings settings = Settings.Load(paths.SettingsFile);
|
||||||
Themes.Use(settings.Theme);
|
Themes.Use(settings.Theme);
|
||||||
Themes.Changed += (_, _) => ApplyTheme();
|
Themes.Changed += (_, _) => ApplyTheme();
|
||||||
|
|||||||
@@ -143,78 +143,4 @@ public sealed class UserPaths
|
|||||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
||||||
"Documents");
|
"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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,36 +62,4 @@ public class UserPathsTests : IDisposable
|
|||||||
|
|
||||||
Assert.Equal(Path.Combine(root, "Nonemm", "settings.json"), paths.SettingsFile);
|
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")));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user