mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 23:00:06 +02:00
Merge pull request #265 from Paul-Licameli/migrate-old-chains
Migrate old chains...
This commit is contained in:
commit
b45b4c4a7a
@ -260,7 +260,13 @@ bool MacroCommands::DeleteMacro(const wxString & chain)
|
|||||||
wxFileName name(FileNames::MacroDir(), chain, wxT("txt"));
|
wxFileName name(FileNames::MacroDir(), chain, wxT("txt"));
|
||||||
|
|
||||||
// Delete it...wxRemoveFile will display errors
|
// 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)
|
bool MacroCommands::RenameMacro(const wxString & oldchain, const wxString & newchain)
|
||||||
@ -928,8 +934,43 @@ bool MacroCommands::ReportAndSkip(
|
|||||||
return true;
|
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()
|
wxArrayString MacroCommands::GetNames()
|
||||||
{
|
{
|
||||||
|
MigrateLegacyChains();
|
||||||
|
|
||||||
wxArrayString names;
|
wxArrayString names;
|
||||||
wxArrayString files;
|
wxArrayString files;
|
||||||
wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);
|
wxDir::GetAllFiles(FileNames::MacroDir(), &files, wxT("*.txt"), wxDIR_FILES);
|
||||||
|
@ -79,6 +79,7 @@ class MacroCommands final {
|
|||||||
bool IsMono();
|
bool IsMono();
|
||||||
|
|
||||||
// These commands do not depend on the command list.
|
// These commands do not depend on the command list.
|
||||||
|
static void MigrateLegacyChains();
|
||||||
static wxArrayString GetNames();
|
static wxArrayString GetNames();
|
||||||
static wxArrayString GetNamesOfDefaultMacros();
|
static wxArrayString GetNamesOfDefaultMacros();
|
||||||
|
|
||||||
|
@ -190,6 +190,12 @@ wxString FileNames::HtmlHelpDir()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString FileNames::LegacyChainDir()
|
||||||
|
{
|
||||||
|
// Don't force creation of it
|
||||||
|
return wxFileName{ DataDir(), wxT("Chains") }.GetFullPath();
|
||||||
|
}
|
||||||
|
|
||||||
wxString FileNames::MacroDir()
|
wxString FileNames::MacroDir()
|
||||||
{
|
{
|
||||||
return FileNames::MkDir( wxFileName( DataDir(), wxT("Macros") ).GetFullPath() );
|
return FileNames::MkDir( wxFileName( DataDir(), wxT("Macros") ).GetFullPath() );
|
||||||
|
@ -44,6 +44,7 @@ public:
|
|||||||
static wxString AutoSaveDir();
|
static wxString AutoSaveDir();
|
||||||
static wxString HtmlHelpDir();
|
static wxString HtmlHelpDir();
|
||||||
static wxString HtmlHelpIndexFile(bool quick);
|
static wxString HtmlHelpIndexFile(bool quick);
|
||||||
|
static wxString LegacyChainDir();
|
||||||
static wxString MacroDir();
|
static wxString MacroDir();
|
||||||
static wxString NRPDir();
|
static wxString NRPDir();
|
||||||
static wxString NRPFile();
|
static wxString NRPFile();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user