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:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user