Example #1
0
static void rm_dash_rf_execute(wxArrayString &fList, 
                               int count, int files_p, int dirs_p,
                               const wxChar *prompt){

   AudacityProject *p = GetActiveProject();

   if (prompt && p)
      p->ProgressShow(_("Progress"), prompt);
  
   for (int i = 0; i < count; i++) {
      const wxChar *file = fList[i].c_str();
      if(files_p){
         wxRemoveFile(file);
      }
      if(dirs_p){
         wxRmdir(file);
      }

      if (prompt && p)
         p->ProgressUpdate(int ((i * 1000.0) / count));
   }
   
   if (prompt && p)
      p->ProgressHide();
}
Example #2
0
void DirManager::FillBlockfilesCache()
{
   bool cacheBlockFiles = false;
   gPrefs->Read(wxT("/Directories/CacheBlockFiles"), &cacheBlockFiles);

   if (!cacheBlockFiles)
      return; // user opted not to cache block files

   BlockHash::iterator i;
   int numNeed = 0;

   i = blockFileHash.begin();
   while (i != blockFileHash.end())
   {
      BlockFile *b = i->second;
      if (b->GetNeedFillCache())
         numNeed++;
      i++;
   }
   
   if (numNeed == 0)
      return;
      
   AudacityProject *p = GetActiveProject();
   
   p->ProgressShow(_("Caching audio"),
      _("Caching audio into memory..."));

   i = blockFileHash.begin();
   int current = 0;
   while (i != blockFileHash.end())
   {
      BlockFile *b = i->second;
      if (b->GetNeedFillCache())
         b->FillCache();
      if (!p->ProgressUpdate((int)((current * 1000.0) / numNeed)))
         break; // user cancelled progress dialog, stop caching
      i++;
      current++;
   }
   
   p->ProgressHide();
}
Example #3
0
static int rm_dash_rf_enumerate_prompt(wxString dirpath,
                                       wxArrayString &flist, 
                                       wxString dirspec,
                                       int files_p,int dirs_p,
                                       int progress_count,
                                       const wxChar *prompt){
   AudacityProject *p = GetActiveProject();

   if (p)
      p->ProgressShow(_("Progress"), prompt);

   int count=rm_dash_rf_enumerate_i(dirpath, flist, dirspec, files_p,dirs_p,
                                    progress_count,0,
                                    prompt);

   if (p)
      p->ProgressHide();

   return count;
}
Example #4
0
void DirManager::WriteCacheToDisk()
{
   BlockHash::iterator i;
   int numNeed = 0;

   i = blockFileHash.begin();
   while (i != blockFileHash.end())
   {
      BlockFile *b = i->second;
      if (b->GetNeedWriteCacheToDisk())
         numNeed++;
      i++;
   }
   
   if (numNeed == 0)
      return;
      
   AudacityProject *p = GetActiveProject();
   
   p->ProgressShow(_("Saving recorded audio"),
      _("Saving recorded audio to disk..."));

   i = blockFileHash.begin();
   int current = 0;
   while (i != blockFileHash.end())
   {
      BlockFile *b = i->second;
      if (b->GetNeedWriteCacheToDisk())
      {
         b->WriteCacheToDisk();
         p->ProgressUpdate((int)((current * 1000.0) / numNeed));
      }
      i++;
      current++;
   }
   
   p->ProgressHide();
}
Example #5
0
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;
}