Esempio n. 1
0
void MLPluginController::doFileQueueAction(FileAction a)
{
	File newPresetsFolder = getDefaultFileLocation(kPresetFiles);
	File destRoot(newPresetsFolder);
	
	// get name relative to collection root.
	const std::string& relativeName = a.mCollection->getRelativePathFromName(a.mFile.getLongName());
	
	// If file at destination does not exist, or is older than the source, convert
	// source and overwrite destination.
	File destFile = destRoot.getChildFile(String(relativeName)).withFileExtension("mlpreset");
	bool destinationExists = destFile.exists();
	bool destinationIsOlder =  destFile.getLastModificationTime() < a.mFile.getJuceFile().getLastModificationTime();
	if((!destinationExists) || (destinationIsOlder))
	{
		mpProcessor->loadPatchStateFromFile(a.mFile);
		mpProcessor->saveStateToRelativePath(relativeName);
		mFilesConverted++;
	}

	mFilesProcessed++;
}
Esempio n. 2
0
static void
ImportMailThread(void *stuff)
{
  ImportThreadData *pData = (ImportThreadData *)stuff;

  IMPORT_LOG0("ImportMailThread: Starting...");

  nsresult rv = NS_OK;

  nsCOMPtr<nsIMsgFolder>    destRoot(pData->destRoot);

  uint32_t  count = 0;
  rv = pData->boxes->Count(&count);

  uint32_t    i;
  bool        import;
  uint32_t    size;
  uint32_t    depth = 1;
  uint32_t    newDepth;
  nsString    lastName;
  PRUnichar *    pName;

  nsCOMPtr<nsIMsgFolder>    curFolder(destRoot);

  nsCOMPtr<nsIMsgFolder>          newFolder;
  nsCOMPtr<nsIMsgFolder>          subFolder;
  nsCOMPtr<nsISimpleEnumerator>   enumerator;

  bool              exists;

  nsString  success;
  nsString  error;

  // GetSubFolders() will initialize folders if they are not already initialized.
  ProxyGetSubFolders(curFolder, getter_AddRefs(enumerator));

  IMPORT_LOG1("ImportMailThread: Total number of folders to import = %d.", count);

  // Note that the front-end js script only displays one import result string so
  // we combine both good and bad import status into one string (in var 'success').

  for (i = 0; (i < count) && !(pData->abort); i++) {
    nsCOMPtr<nsIImportMailboxDescriptor> box =
      do_QueryElementAt(pData->boxes, i);
    if (box) {
      pData->currentMailbox = i;

      import = false;
      size = 0;
      rv = box->GetImport(&import);
      if (import)
        rv = box->GetSize(&size);
      rv = box->GetDepth(&newDepth);
      if (newDepth > depth) {
          // OK, we are going to add a subfolder under the last/previous folder we processed, so
          // find this folder (stored in 'lastName') who is going to be the new parent folder.
        IMPORT_LOG1("ImportMailThread: Processing child folder '%s'.", NS_ConvertUTF16toUTF8(lastName).get());
        rv = ProxyGetChildNamed(curFolder, lastName, getter_AddRefs(subFolder));
        if (NS_FAILED(rv)) {
          IMPORT_LOG1("*** ImportMailThread: Failed to get the interface for child folder '%s'.", NS_ConvertUTF16toUTF8(lastName).get());
          nsImportGenericMail::ReportError(IMPORT_ERROR_MB_FINDCHILD,
                                           lastName.get(),
                                           &error, pData->stringBundle);
          pData->fatalError = true;
          break;
        }
        curFolder = subFolder;
        // Make sure this new parent folder obj has the correct subfolder list so far.
        rv = ProxyGetSubFolders(curFolder, getter_AddRefs(enumerator));
      }
      else if (newDepth < depth) {
        rv = NS_OK;
        while ((newDepth < depth) && NS_SUCCEEDED(rv)) {
          rv = curFolder->GetParent(getter_AddRefs(curFolder));
          if (NS_FAILED(rv)) {
            IMPORT_LOG1("*** ImportMailThread: Failed to get the interface for parent folder '%s'.", lastName.get());
            nsImportGenericMail::ReportError(IMPORT_ERROR_MB_FINDCHILD,
                                             lastName.get(), &error,
                                             pData->stringBundle);
            pData->fatalError = true;
            break;
          }
          depth--;
        }
        if (NS_FAILED(rv)) {
          IMPORT_LOG1("*** ImportMailThread: Failed to get the proxy interface for parent folder '%s'.", lastName.get());
          nsImportStringBundle::GetStringByID(IMPORT_ERROR_MB_NOPROXY,
                                              pData->stringBundle, error);
          pData->fatalError = true;
          break;
        }
      }
      depth = newDepth;
      pName = nullptr;
      box->GetDisplayName(&pName);
      if (pName) {
        lastName = pName;
        NS_Free(pName);
      }
      else
        lastName.AssignLiteral("Unknown!");

      // translate the folder name if we are doing migration, but
      // only for special folders which are at the root level
      if (pData->performingMigration && depth == 1)
        pData->mailImport->TranslateFolderName(lastName, lastName);

      exists = false;
      rv = ProxyContainsChildNamed(curFolder, lastName, &exists);

      // If we are performing profile migration (as opposed to importing) then we are starting
      // with empty local folders. In that case, always choose to over-write the existing local folder
      // with this name. Don't create a unique subfolder name. Otherwise you end up with "Inbox, Inbox0"
      // or "Unsent Folders, UnsentFolders0"
      if (exists && !pData->performingMigration) {
        nsString subName;
        ProxyGenerateUniqueSubfolderName(curFolder, lastName, nullptr, subName);
        if (!subName.IsEmpty())
          lastName.Assign(subName);
      }

      IMPORT_LOG1("ImportMailThread: Creating new import folder '%s'.", NS_ConvertUTF16toUTF8(lastName).get());
      ProxyCreateSubfolder(curFolder, lastName); // this may fail if the folder already exists..that's ok

      rv = ProxyGetChildNamed(curFolder, lastName, getter_AddRefs(newFolder));
      if (NS_FAILED(rv)) {
        IMPORT_LOG1("*** ImportMailThread: Failed to locate subfolder '%s' after it's been created.", lastName.get());
        nsImportGenericMail::ReportError(IMPORT_ERROR_MB_CREATE, lastName.get(),
                                         &error, pData->stringBundle);
      }

      if (size && import && newFolder && NS_SUCCEEDED(rv)) {
        bool fatalError = false;
        pData->currentSize = size;
        PRUnichar *pSuccess = nullptr;
        PRUnichar *pError = nullptr;
        rv = pData->mailImport->ImportMailbox(box, newFolder, &pError, &pSuccess, &fatalError);
        if (pError) {
          error.Append(pError);
          NS_Free(pError);
        }
        if (pSuccess) {
          success.Append(pSuccess);
          NS_Free(pSuccess);
        }

        pData->currentSize = 0;
        pData->currentTotal += size;
        
        // commit to the db synchronously, but using a proxy since it doesn't like being used
        // elsewhere than from the main thread.
        // OK, we've copied the actual folder/file over if the folder size is not 0
        // (ie, the msg summary is no longer valid) so close the msg database so that
        // when the folder is reopened the folder db can be reconstructed (which
        // validates msg summary and forces folder to be reparsed).
        rv = ProxyForceDBClosed(newFolder);
        fatalError = NS_FAILED(rv);

        if (fatalError) {
          IMPORT_LOG1("*** ImportMailThread: ImportMailbox returned fatalError, mailbox #%d\n", (int) i);
          pData->fatalError = true;
          break;
        }
      }
    }
  }

  // Now save the new acct info to pref file.
  nsCOMPtr <nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
        if (NS_SUCCEEDED(rv) && accMgr) {
    rv = accMgr->SaveAccountInfo();
    NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file");
  }

  nsImportGenericMail::SetLogs(success, error, pData->successLog, pData->errorLog);

  if (pData->abort || pData->fatalError) {
    IMPORT_LOG0("*** ImportMailThread: Abort or fatalError flag was set\n");
    if (pData->ownsDestRoot) {
      IMPORT_LOG0("Calling destRoot->RecursiveDelete\n");
      destRoot->RecursiveDelete(true, nullptr);
    }
    else {
      // FIXME: just delete the stuff we created?
    }
  }

  IMPORT_LOG1("Import mailbox thread done: %d\n", (int) pData->currentTotal);

  pData->ThreadDelete();

}