mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-12 07:36:24 +01:00
This commit is contained in:
@@ -176,7 +176,7 @@ DirManager::~DirManager()
|
|||||||
// subdirs of subdirs. Files in the passed-in directory will not be
|
// subdirs of subdirs. Files in the passed-in directory will not be
|
||||||
// enumerated. Also, the passed-in directory is the last entry added
|
// enumerated. Also, the passed-in directory is the last entry added
|
||||||
// to the list.
|
// to the list.
|
||||||
static int RecursivelyEnumerate(wxString dirpath,
|
static int RecursivelyEnumerate(wxString dirPath,
|
||||||
wxArrayString& flist,
|
wxArrayString& flist,
|
||||||
wxString dirspec,
|
wxString dirspec,
|
||||||
bool bFiles, bool bDirs,
|
bool bFiles, bool bDirs,
|
||||||
@@ -187,14 +187,14 @@ static int RecursivelyEnumerate(wxString dirpath,
|
|||||||
int count=0;
|
int count=0;
|
||||||
bool cont;
|
bool cont;
|
||||||
|
|
||||||
wxDir dir(dirpath);
|
wxDir dir(dirPath);
|
||||||
if(dir.IsOpened()){
|
if(dir.IsOpened()){
|
||||||
wxString name;
|
wxString name;
|
||||||
|
|
||||||
if (bFiles){
|
if (bFiles){
|
||||||
cont= dir.GetFirst(&name, dirspec, wxDIR_FILES);
|
cont= dir.GetFirst(&name, dirspec, wxDIR_FILES);
|
||||||
while ( cont ){
|
while ( cont ){
|
||||||
wxString filepath=dirpath + wxFILE_SEP_PATH + name;
|
wxString filepath = dirPath + wxFILE_SEP_PATH + name;
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
flist.Add(filepath);
|
flist.Add(filepath);
|
||||||
@@ -209,9 +209,9 @@ static int RecursivelyEnumerate(wxString dirpath,
|
|||||||
|
|
||||||
cont= dir.GetFirst(&name, dirspec, wxDIR_DIRS);
|
cont= dir.GetFirst(&name, dirspec, wxDIR_DIRS);
|
||||||
while ( cont ){
|
while ( cont ){
|
||||||
wxString subdirpath=dirpath + wxFILE_SEP_PATH + name;
|
wxString subdirPath = dirPath + wxFILE_SEP_PATH + name;
|
||||||
count += RecursivelyEnumerate(
|
count += RecursivelyEnumerate(
|
||||||
subdirpath, flist, wxEmptyString,
|
subdirPath, flist, wxEmptyString,
|
||||||
bFiles, bDirs,
|
bFiles, bDirs,
|
||||||
progress_count, count + progress_bias,
|
progress_count, count + progress_bias,
|
||||||
progress);
|
progress);
|
||||||
@@ -220,7 +220,7 @@ static int RecursivelyEnumerate(wxString dirpath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bDirs) {
|
if (bDirs) {
|
||||||
flist.Add(dirpath);
|
flist.Add(dirPath);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ static int RecursivelyEnumerate(wxString dirpath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int RecursivelyEnumerateWithProgress(wxString dirpath,
|
static int RecursivelyEnumerateWithProgress(wxString dirPath,
|
||||||
wxArrayString &flist,
|
wxArrayString &flist,
|
||||||
wxString dirspec,
|
wxString dirspec,
|
||||||
bool bFiles, bool bDirs,
|
bool bFiles, bool bDirs,
|
||||||
@@ -241,7 +241,7 @@ static int RecursivelyEnumerateWithProgress(wxString dirpath,
|
|||||||
progress = new ProgressDialog(_("Progress"), message);
|
progress = new ProgressDialog(_("Progress"), message);
|
||||||
|
|
||||||
int count = RecursivelyEnumerate(
|
int count = RecursivelyEnumerate(
|
||||||
dirpath, flist, dirspec,
|
dirPath, flist, dirspec,
|
||||||
bFiles, bDirs,
|
bFiles, bDirs,
|
||||||
progress_count, 0,
|
progress_count, 0,
|
||||||
progress);
|
progress);
|
||||||
@@ -252,6 +252,71 @@ static int RecursivelyEnumerateWithProgress(wxString dirpath,
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int RecursivelyCountSubdirs(wxString dirPath)
|
||||||
|
{
|
||||||
|
bool bContinue;
|
||||||
|
int nCount = 0;
|
||||||
|
wxDir dir(dirPath);
|
||||||
|
if (dir.IsOpened() && dir.HasSubDirs())
|
||||||
|
{
|
||||||
|
wxString name;
|
||||||
|
bContinue = dir.GetFirst(&name, wxEmptyString, wxDIR_DIRS);
|
||||||
|
while (bContinue)
|
||||||
|
{
|
||||||
|
nCount++;
|
||||||
|
wxString subdirPath = dirPath + wxFILE_SEP_PATH + name;
|
||||||
|
nCount += RecursivelyCountSubdirs(subdirPath);
|
||||||
|
bContinue = dir.GetNext(&name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int RecursivelyRemoveEmptyDirs(wxString dirPath,
|
||||||
|
int nDirCount = 0,
|
||||||
|
ProgressDialog* pProgress = NULL)
|
||||||
|
{
|
||||||
|
bool bContinue;
|
||||||
|
wxDir dir(dirPath);
|
||||||
|
int nCount = 0;
|
||||||
|
if (dir.IsOpened())
|
||||||
|
{
|
||||||
|
if (dir.HasSubDirs())
|
||||||
|
{
|
||||||
|
wxString name;
|
||||||
|
bContinue = dir.GetFirst(&name, wxEmptyString, wxDIR_DIRS);
|
||||||
|
while (bContinue)
|
||||||
|
{
|
||||||
|
wxString subdirPath = dirPath + wxFILE_SEP_PATH + name;
|
||||||
|
nCount += RecursivelyRemoveEmptyDirs(subdirPath, nDirCount, pProgress);
|
||||||
|
bContinue = dir.GetNext(&name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Have to recheck dir.HasSubDirs() again, in case they all were deleted in recursive calls.
|
||||||
|
if (!dir.HasSubDirs() && !dir.HasFiles())
|
||||||
|
{
|
||||||
|
// No subdirs or files. It's empty so delete it.
|
||||||
|
// Vaughan, 2010-07-07:
|
||||||
|
// Note that, per http://src.chromium.org/svn/trunk/src/base/file_util_win.cc, among others,
|
||||||
|
// "Some versions of Windows return ERROR_FILE_NOT_FOUND (0x2) when deleting
|
||||||
|
// an empty directory..." Supposedly fixed in Vista and up.
|
||||||
|
// I discovered this on WinXP. I tried several other Windows SDK functions (e.g., _rmdir
|
||||||
|
// and RemoveDirectory), and they all give same results.
|
||||||
|
// I noticed dirs get deleted in RecursivelyRemove, maybe because it doesn't
|
||||||
|
// consider whether the path is a directory or a file and wxRemoveFile()'s it first.
|
||||||
|
// Tried it here, but no joy!
|
||||||
|
// #ifdef __WXMSW__
|
||||||
|
// ::wxRemoveFile(dirPath);
|
||||||
|
// #endif
|
||||||
|
::wxRmdir(dirPath);
|
||||||
|
}
|
||||||
|
nCount++; // Count dirPath in progress.
|
||||||
|
if (pProgress)
|
||||||
|
pProgress->Update(nCount, nDirCount);
|
||||||
|
}
|
||||||
|
return nCount;
|
||||||
|
}
|
||||||
|
|
||||||
static void RecursivelyRemove(wxArrayString &fList, int count,
|
static void RecursivelyRemove(wxArrayString &fList, int count,
|
||||||
bool bFiles, bool bDirs,
|
bool bFiles, bool bDirs,
|
||||||
const wxChar* message = NULL)
|
const wxChar* message = NULL)
|
||||||
@@ -264,9 +329,9 @@ static void RecursivelyRemove(wxArrayString &fList, int count,
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
const wxChar *file = fList[i].c_str();
|
const wxChar *file = fList[i].c_str();
|
||||||
if (bFiles)
|
if (bFiles)
|
||||||
wxRemoveFile(file);
|
::wxRemoveFile(file);
|
||||||
if (bDirs)
|
if (bDirs)
|
||||||
wxRmdir(file);
|
::wxRmdir(file); // See note above about wxRmdir sometimes incorrectly failing on Windows.
|
||||||
if (progress)
|
if (progress)
|
||||||
progress->Update(i, count);
|
progress->Update(i, count);
|
||||||
}
|
}
|
||||||
@@ -1320,12 +1385,12 @@ int DirManager::ProjectFSCK(bool forceerror, bool silentlycorrect, bool bIgnoreN
|
|||||||
BlockHash missingSummaryList;
|
BlockHash missingSummaryList;
|
||||||
BlockHash missingDataList;
|
BlockHash missingDataList;
|
||||||
|
|
||||||
|
wxString dirPath = (projFull != wxT("") ? projFull: mytemp);
|
||||||
int count =
|
int count =
|
||||||
RecursivelyEnumerateWithProgress(
|
RecursivelyEnumerateWithProgress(
|
||||||
(projFull != wxT("")? projFull: mytemp),
|
dirPath, fnameList, wxEmptyString,
|
||||||
fnameList, wxEmptyString,
|
|
||||||
true, false,
|
true, false,
|
||||||
blockcount, _("Inspecting project file data..."));
|
blockcount, _("Inspecting project file data"));
|
||||||
|
|
||||||
// enumerate orphaned blockfiles
|
// enumerate orphaned blockfiles
|
||||||
BlockHash diskFileHash;
|
BlockHash diskFileHash;
|
||||||
@@ -1438,7 +1503,7 @@ int DirManager::ProjectFSCK(bool forceerror, bool silentlycorrect, bool bIgnoreN
|
|||||||
prompt.Printf(promptA,(int)orphanList.GetCount());
|
prompt.Printf(promptA,(int)orphanList.GetCount());
|
||||||
|
|
||||||
const wxChar *buttons[]={_("Delete orphaned files [safe and recommended]"),
|
const wxChar *buttons[]={_("Delete orphaned files [safe and recommended]"),
|
||||||
_("Continue without deleting; silently work around the extra files"),
|
_("Continue without deleting; ignore the extra files this session"),
|
||||||
_("Close project immediately with no changes"),NULL};
|
_("Close project immediately with no changes"),NULL};
|
||||||
int action = ShowMultiDialog(prompt,
|
int action = ShowMultiDialog(prompt,
|
||||||
_("Warning"),
|
_("Warning"),
|
||||||
@@ -1584,18 +1649,14 @@ int DirManager::ProjectFSCK(bool forceerror, bool silentlycorrect, bool bIgnoreN
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up any empty directories
|
// Remove any empty directories.
|
||||||
fnameList.Clear();
|
ProgressDialog* pProgress =
|
||||||
//vvvvv Why ignore enumeration before deleting?!
|
new ProgressDialog(_("Progress"),
|
||||||
//vvvvv Anyway, this enumeration call does not return
|
_("Cleaning up unused directories in project data"));
|
||||||
// empty directories, it returns all subdirs. Need to fix it.
|
// nDirCount is for updating pProgress. +1 because we may delete dirPath.
|
||||||
count =
|
int nDirCount = RecursivelyCountSubdirs(dirPath) + 1;
|
||||||
RecursivelyEnumerateWithProgress(
|
RecursivelyRemoveEmptyDirs(dirPath, nDirCount, pProgress);
|
||||||
(projFull != wxT("")? projFull: mytemp),
|
delete pProgress;
|
||||||
fnameList, wxEmptyString,
|
|
||||||
false, true,
|
|
||||||
blockcount, _("Cleaning up unused directories in project data..."));
|
|
||||||
RecursivelyRemove(fnameList, 0, false, true);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -1622,7 +1683,7 @@ void DirManager::RemoveOrphanedBlockfiles()
|
|||||||
(projFull != wxT("") ? projFull: mytemp),
|
(projFull != wxT("") ? projFull: mytemp),
|
||||||
fnameList, wxEmptyString,
|
fnameList, wxEmptyString,
|
||||||
true, false,
|
true, false,
|
||||||
blockcount, _("Inspecting project file data..."));
|
blockcount, _("Inspecting project file data"));
|
||||||
|
|
||||||
// enumerate orphaned blockfiles
|
// enumerate orphaned blockfiles
|
||||||
wxArrayString orphanList;
|
wxArrayString orphanList;
|
||||||
@@ -1672,7 +1733,7 @@ void DirManager::FillBlockfilesCache()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ProgressDialog progress(_("Caching audio"),
|
ProgressDialog progress(_("Caching audio"),
|
||||||
_("Caching audio into memory..."));
|
_("Caching audio into memory"));
|
||||||
|
|
||||||
i = blockFileHash.begin();
|
i = blockFileHash.begin();
|
||||||
int current = 0;
|
int current = 0;
|
||||||
@@ -1708,7 +1769,7 @@ void DirManager::WriteCacheToDisk()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ProgressDialog progress(_("Saving recorded audio"),
|
ProgressDialog progress(_("Saving recorded audio"),
|
||||||
_("Saving recorded audio to disk..."));
|
_("Saving recorded audio to disk"));
|
||||||
|
|
||||||
i = blockFileHash.begin();
|
i = blockFileHash.begin();
|
||||||
int current = 0;
|
int current = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user