bool DirManager::SetProject(wxString & projPath, wxString & projName, bool create) { wxString oldPath = projPath; wxString oldName = projName; wxString oldFull = projFull; wxString oldLoc = projFull; if (oldLoc == "") oldLoc = temp; lastProject = projPath; if (projPath == "") projPath =::wxGetCwd(); this->projPath = projPath; this->projName = projName; this->projFull = projPath + wxFILE_SEP_PATH + projName; if (create) { if (!wxPathExists(projFull)) if (!wxMkdir(projFull)) return false; #ifdef __UNIX__ chmod(projFull, 0775); #endif } else { #ifndef __WXMAC__ if (!wxPathExists(projFull)) return false; #endif } /* Move all files into this new directory. Files which are "locked" get copied instead of moved. (This happens when we perform a Save As - the files which belonged to the last saved version of the old project must not be moved, otherwise the old project would not be safe. */ blockFileHash->BeginFind(); wxNode *n = blockFileHash->Next(); bool success = true; while(n && success) { BlockFile *b = (BlockFile *)n->GetData(); if (b->IsLocked()) success = CopyToNewProjectDirectory(b); else success = MoveToNewProjectDirectory(b); n = blockFileHash->Next(); } if (!success) { // If the move failed, we try to move/copy as many files // back as possible so that no damage was done. (No sense // in checking for errors this time around - there's nothing // that could be done about it.) // Likely causes: directory was not writeable, disk was full projFull = oldLoc; blockFileHash->BeginFind(); wxNode *n = blockFileHash->Next(); while(n) { BlockFile *b = (BlockFile *)n->GetData(); MoveToNewProjectDirectory(b); n = blockFileHash->Next(); } projFull = oldFull; projPath = oldPath; projName = oldName; return false; } return true; }
bool DirManager::SetProject(wxString & projPath, wxString & projName, bool create) { wxString oldPath = this->projPath; wxString oldName = this->projName; wxString oldFull = projFull; wxString oldLoc = projFull; if (oldLoc == wxT("")) oldLoc = mytemp; if (projPath == wxT("")) projPath = ::wxGetCwd(); this->projPath = projPath; this->projName = projName; this->projFull = projPath + wxFILE_SEP_PATH + projName; wxString cleanupLoc1=oldLoc; wxString cleanupLoc2=projFull; if (create) { if (!wxDirExists(projFull)) if (!wxMkdir(projFull)) return false; #ifdef __UNIX__ chmod(OSFILENAME(projFull), 0775); #endif } else { #ifndef __WXMAC__ if (!wxDirExists(projFull)) return false; #endif } /* Move all files into this new directory. Files which are "locked" get copied instead of moved. (This happens when we perform a Save As - the files which belonged to the last saved version of the old project must not be moved, otherwise the old project would not be safe. */ AudacityProject *p = GetActiveProject(); if (p) p->ProgressShow(_("Progress"), _("Saving project data files")); int total=blockFileHash.size(); int count=0; BlockHash::iterator i=blockFileHash.begin(); bool success = true; while(i != blockFileHash.end() && success) { BlockFile *b = i->second; if (b->IsLocked()) success = CopyToNewProjectDirectory(b); else{ success = MoveToNewProjectDirectory(b); } if (p) p->ProgressUpdate(int ((count * 1000.0) / total)); i++; count++; } if (!success) { // If the move failed, we try to move/copy as many files // back as possible so that no damage was done. (No sense // in checking for errors this time around - there's nothing // that could be done about it.) // Likely causes: directory was not writeable, disk was full projFull = oldLoc; BlockHash::iterator i=blockFileHash.begin(); while(i != blockFileHash.end()) { BlockFile *b = i->second; MoveToNewProjectDirectory(b); if (count>=0 && p) p->ProgressUpdate(int ((count * 1000.0) / total)); i++; count--; } this->projFull = oldFull; this->projPath = oldPath; this->projName = oldName; if (p) p->ProgressHide(); return false; } if (p) p->ProgressHide(); // Some subtlety; SetProject is used both to move a temp project // into a permanent home as well as just set up path variables when // loading a project; in this latter case, the movement code does // nothing because SetProject is called before there are any // blockfiles. Cleanup code trigger is the same if(blockFileHash.size()>0){ // Clean up after ourselves; look for empty directories in the old // and new project directories. The easiest way to do this is to // recurse depth-first and rmdir every directory seen in old and // new; rmdir will fail on non-empty dirs. wxArrayString dirlist; count=rm_dash_rf_enumerate(cleanupLoc1,dirlist,wxEmptyString,0,1); count+=rm_dash_rf_enumerate(cleanupLoc2,dirlist,wxEmptyString,0,1); if(count) rm_dash_rf_execute(dirlist,count,0,1,_("Cleaning up cache directories")); } return true; }