1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-21 14:50:06 +02:00

Merge pull request #265 from Paul-Licameli/migrate-old-chains

Migrate old chains...
This commit is contained in:
James Crook 2018-03-15 12:19:27 +00:00 committed by GitHub
commit b45b4c4a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 1 deletions

View File

@ -260,7 +260,13 @@ bool MacroCommands::DeleteMacro(const wxString & chain)
wxFileName name(FileNames::MacroDir(), chain, wxT("txt"));
// Delete it...wxRemoveFile will display errors
return wxRemoveFile(name.GetFullPath());
auto result = wxRemoveFile(name.GetFullPath());
// Delete any legacy chain that it shadowed
auto oldPath = wxFileName{ FileNames::LegacyChainDir(), chain, wxT("txt") };
wxRemoveFile(oldPath.GetFullPath()); // Don't care about this return value
return result;
}
bool MacroCommands::RenameMacro(const wxString & oldchain, const wxString & newchain)
@ -928,8 +934,43 @@ bool MacroCommands::ReportAndSkip(
return true;
}
void MacroCommands::MigrateLegacyChains()
{
static bool done = false;
if (!done) {
// Check once per session at most
// Copy chain files from the old Chains into the new Macros directory,
// but only if like-named files are not already present in Macros.
// Leave the old copies in place, in case a user wants to go back to
// an old Audacity version. They will have their old chains intact, but
// won't have any edits they made to the copy that now lives in Macros
// which old Audacity will not read.
const auto oldDir = FileNames::LegacyChainDir();
wxArrayString files;
wxDir::GetAllFiles(oldDir, &files, wxT("*.txt"), wxDIR_FILES);
// add a dummy path component to be overwritten by SetFullName
wxFileName newDir{ FileNames::MacroDir(), wxT("x") };
for (const auto &file : files) {
auto name = wxFileName{file}.GetFullName();
newDir.SetFullName(name);
const auto newPath = newDir.GetFullPath();
if (!wxFileExists(newPath))
FileNames::CopyFile(file, newPath);
}
done = true;
}
// To do: use std::once
}
wxArrayString MacroCommands::GetNames()
{
MigrateLegacyChains();
wxArrayString names;
wxArrayString files;
wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);

View File

@ -79,6 +79,7 @@ class MacroCommands final {
bool IsMono();
// These commands do not depend on the command list.
static void MigrateLegacyChains();
static wxArrayString GetNames();
static wxArrayString GetNamesOfDefaultMacros();

View File

@ -190,6 +190,12 @@ wxString FileNames::HtmlHelpDir()
#endif
}
wxString FileNames::LegacyChainDir()
{
// Don't force creation of it
return wxFileName{ DataDir(), wxT("Chains") }.GetFullPath();
}
wxString FileNames::MacroDir()
{
return FileNames::MkDir( wxFileName( DataDir(), wxT("Macros") ).GetFullPath() );

View File

@ -44,6 +44,7 @@ public:
static wxString AutoSaveDir();
static wxString HtmlHelpDir();
static wxString HtmlHelpIndexFile(bool quick);
static wxString LegacyChainDir();
static wxString MacroDir();
static wxString NRPDir();
static wxString NRPFile();