Esempio n. 1
0
void File::list(FileVector& files, bool bRecursive) const
{
    files.clear();
    DirectoryIterator it(*this, bRecursive);
    while (it.hasNext())
    {
        files.push_back(it.next());
    }
}
bool Ini_UpdaterLists::readRollbackFileListFromSS(FileVector &changedFiles)
{
    const STRING section_name = SS_KEY_RollbackTree;
    
    STRING rollbackFileAndPath;
    if(!getProductFolder(m_useCurrentFolder, rollbackFileAndPath, pLog))
        return false;
    rollbackFileAndPath += UPDATER_LISTS_FILENEME;
    
    TCHAR childSectionName[MAX_PATH + 1];
    
    for(int _i = 0;; ++_i)
    {
        TCHAR szKeyName[MAX_PATH + 1];
        TCHAR fullSectionName[MAX_PATH + MAX_PATH + 1];
        
        memset(childSectionName, 0, (MAX_PATH + 1) * sizeof(TCHAR));
        memset(szKeyName, 0, (MAX_PATH + 1) * sizeof(TCHAR));
        memset(fullSectionName, 0, (MAX_PATH + MAX_PATH + 1) * sizeof(TCHAR));
        
        _stprintf(szKeyName, _T("entry%d"), _i);
        
        GetPrivateProfileString(section_name.c_str(), szKeyName, _T(""), childSectionName, MAX_PATH, rollbackFileAndPath.c_str());
        
        if(!childSectionName[0])
            break;
        
        _tcscpy(fullSectionName, section_name.c_str());
        _tcscat(fullSectionName, _T(":"));
        _tcscat(fullSectionName, childSectionName);
        
        FileInfo rec;
        if(!readSingleFileInfoRollback(rollbackFileAndPath.c_str(), fullSectionName, rec))
        {
            TRACE_MESSAGE2("Invalid content of '%s' section, skipping", fullSectionName);
            // ignore error, try next entry if any
            continue;
        }
        
        changedFiles.push_back(rec);
    }
    
    return true;
}
Esempio n. 3
0
//------------------------------------------------------------------------------
void DirectoryComparer::copy () {
   // variables
   FileCopier copier(safe_mode);
   FileVector& f0 = _uc[0].f;    // for convenience
   vector<path>& d0 = _uc[0].d;  // for convenience
   path fullpath0;               // convenience (updated in loops)
   path fullpath1;               // convenience (updated in loops)
   FileVector errors;            // holds files that we fail to copy
   
   // precompute total number of files and bytes to be transferred
   annotate0();

   // prepare batch, print totals
   unsigned totalFiles = _uc[0].files();
   FileSize totalBytes = _uc[0].bytes();
   copier.startBatch(totalFiles, totalBytes);
   cout << "========== Copying Files from A to B ==========\n";
   cout << "Copying " << totalFiles  << " files totaling " << totalBytes
        << " from " << workingPath(0) << " to " << workingPath(1) << ".\n";
   cout << "  Bytes Processed   |   Current File\n";

   // copy files from _uc[0].f
   for (unsigned i=0; i<f0.size(); ++i) {
      fullpath0 = groundPath(f0[i], 0);
      fullpath1 = groundPath(f0[i], 1);
      if (exists(fullpath1)) {
         // error!
         errors.push_back(f0[i], fullpath0);
         cout << "Warning: Cannot copy " << fullpath0 << " to " << fullpath1 << " because the latter already exists.\n";
      } else {
         copier.copy(fullpath0, fullpath1, f0[i]);
      }
   }

   // copy files from _uc[0].d
   recursive_directory_iterator end;
   unsigned depth = 0;
   path connector;
   path new_extension;
   for (unsigned i=0; i<d0.size(); ++i) {
      // initialize for recursive crawl of this directory
      recursive_directory_iterator itr(groundPath(d0[i], 0));
      depth = 0;
      connector = d0[i];
      cout << copier.status << "Creating directory " << connector << '.' << '\n';
      if (!safe_mode) create_directory(_p[1] / connector);

      while (itr != end) {
         // update connector
         if (depth < itr.level()) {
            connector /= new_extension;
            cout << copier.status << "Creating directory " << connector << '.' << '\n';
            if (!safe_mode) create_directory(_p[1] / connector);
            ++depth;  // this makes depth equal to itr.level()
         } else while (depth > itr.level()) {
            connector.remove_filename();
            --depth;
         }

         // copy file or save name of directory we may iterate into
         if (is_regular_file(itr->path())) {
            fullpath0 = itr->path();
            fullpath1 = _p[1] / connector / fullpath0.filename();
            if (exists(fullpath1)) {
               // error!
               errors.push_back(connector / fullpath0.filename(), fullpath0);
               cout << copier.status << "Warning: Cannot copy " << fullpath0 << " to " << fullpath1 << " because the latter already exists.\n";
            } else {
               copier.copy(fullpath0, fullpath1, connector / fullpath0.filename());
            }
         } else if (is_directory(itr->path())) {
            new_extension = itr->path().filename();
         }
         ++itr;
      }
   }

   // cleanup
   _uc[0].f.clear();
   _uc[0].d.clear();
   _annotations &= ~A0;

   // print outline
   cout << setw(9) << totalBytes << '/' << setw(9) << totalBytes << " | ";
   cout << totalFiles - errors.size() << " of " << totalFiles << " files were copied.\n";
   if (errors.size()) {
      cout << "The following files were not copied:\n";
      for (unsigned i=0; i<errors.size(); ++i) {
         cout << errors[i] << '\n';
      }
   }
   cout << '\n';
}
bool Ini_UpdaterLists::processChangedFiles(const STRING &rollbackFolder, const bool validLocalFilesForRollback)
{
    // Ini updater can not perform rollback in retranslation mode
    if(m_retranslation)
        return false;

    if(!validLocalFilesForRollback)
    {
        TRACE_MESSAGE("Rollback is not created, because inconsistent bases set was locally before update operation started");
        removeRollbackSection();
        return false;
    }
    
    TRACE_MESSAGE("Saving rollback file list");
    
    FileVector updateList;
    
    // set correct status for all entries that have changed
    std::string rollbackTrace;
    for(size_t index = 0; index < m_changedFiles.size(); ++index)
    {
        // entry copy, because size, signature, and hash tags are not valid here.
        //  There are values not for rollback, but values for new files
		FileInfo entryCopy;
        entryCopy.m_filename = m_changedFiles[index].m_filename;
        entryCopy.m_localPath = m_changedFiles[index].m_localPath;

		entryCopy.m_rollbackChange;
        switch(m_changedFiles[index].m_transactionInformation.m_changeStatus)
		{
		case FileInfo::added:
			entryCopy.m_rollbackChange = SS_KEY_RecentStatusAdded;
			break;

		case FileInfo::deleted:
			entryCopy.m_rollbackChange = SS_KEY_RecentStatusDeleted;
			break;
		
		case FileInfo::modified:
			entryCopy.m_rollbackChange = SS_KEY_RecentStatusModified;
			break;

		default:
            // do not write to rollback settings storage unchanged files
            continue;
		}

        // calculate MD5 for consistency check to restore changed and deleted files
        if((entryCopy.m_rollbackChange != SS_KEY_RecentStatusAdded)
            && !calcMD5Hash(STRING(rollbackFolder + entryCopy.m_filename).to_string().c_str(), entryCopy.m_md5))
        {
            TRACE_MESSAGE2("Rollback is not created, failed to calculate md5 for '%s'", (rollbackFolder + entryCopy.m_filename).to_string().c_str());
            return false;
        }
		updateList.push_back(entryCopy);

        if(index != 0)
            rollbackTrace += ", ";
        if(!(index % 15))
            rollbackTrace += "\n\t";
        rollbackTrace += entryCopy.m_filename.to_string() + " " + entryCopy.m_rollbackChange.to_string().c_str();
    }

    TRACE_MESSAGE2("Saving rollback files: %s", rollbackTrace.c_str());
    
    // saving rollback information
    if(!saveRollbackInfo(updateList))
    {
        TRACE_MESSAGE("Failed to save rollback file list");
        return false;
    }
    
    TRACE_MESSAGE("Rollback file list saved successfully");
    return true;
}