mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 15:49:36 +02:00
Migrate old chains...
... Copy old Chains files to Macros, once only per session, never overwriting. Leave old files in place in case the user downgrades their Audacity. When removing a Macro, remove also any like-named legacy chain.
This commit is contained in:
parent
6fe494df51
commit
cc7bf5c328
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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() );
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user