예제 #1
0
  protected void fileDirty(TranscodeFileImpl file, int type, Object data) {
    try {
      synchronized (this) {
        if (device_files == null) {

          loadDeviceFile();

        } else {

          device_files_last_mod = SystemTime.getMonotonousTime();
        }
      }

      device_files_dirty = true;

    } catch (Throwable e) {

      Debug.out("Failed to load device file", e);
    }

    for (TranscodeTargetListener l : listeners) {

      try {
        l.fileChanged(file, type, data);

      } catch (Throwable e) {

        Debug.out(e);
      }
    }
  }
예제 #2
0
  public TranscodeFileImpl allocateFile(
      TranscodeProfile profile, boolean no_xcode, DiskManagerFileInfo file, boolean for_job)
      throws TranscodeException {
    TranscodeFileImpl result = null;

    setError(KEY_FILE_ALLOC_ERROR, null);

    try {
      synchronized (this) {
        if (device_files == null) {

          loadDeviceFile();
        }

        String key =
            ByteFormatter.encodeString(file.getDownloadHash())
                + ":"
                + file.getIndex()
                + ":"
                + profile.getUID();

        if (device_files.containsKey(key)) {

          try {
            result = new TranscodeFileImpl(this, key, device_files);

          } catch (Throwable e) {

            device_files.remove(key);

            log("Failed to deserialise transcode file", e);
          }
        }

        if (result == null) {

          String ext = profile.getFileExtension();

          String target_file = file.getFile(true).getName();

          if (ext != null && !no_xcode) {

            int pos = target_file.lastIndexOf('.');

            if (pos != -1) {

              target_file = target_file.substring(0, pos);
            }

            target_file += ext;
          }

          target_file = allocateUniqueFileName(target_file);

          File output_file = getWorkingDirectory(true);

          if (!output_file.canWrite()) {

            throw (new TranscodeException(
                "Can't write to transcode folder '" + output_file.getAbsolutePath() + "'"));
          }

          output_file = new File(output_file.getAbsoluteFile(), target_file);

          result =
              new TranscodeFileImpl(
                  this, key, profile.getName(), device_files, output_file, for_job);

          result.setSourceFile(file);

          device_files_last_mod = SystemTime.getMonotonousTime();

          device_files_dirty = true;

        } else {

          result.setSourceFile(file);

          result.setProfileName(profile.getName());
        }
      }
    } catch (Throwable e) {

      setError(KEY_FILE_ALLOC_ERROR, Debug.getNestedExceptionMessage(e));

      throw (new TranscodeException("File allocation failed", e));
    }

    for (TranscodeTargetListener l : listeners) {

      try {
        l.fileAdded(result);

      } catch (Throwable e) {

        Debug.out(e);
      }
    }

    return (result);
  }
예제 #3
0
  protected void deleteFile(TranscodeFileImpl file, boolean delete_contents, boolean remove)
      throws TranscodeException {
    if (file.isDeleted()) {

      return;
    }

    if (delete_contents) {

      File f = file.getCacheFile();

      int time = 0;

      while (f.exists() && !f.delete()) {

        if (time > 3000) {

          log("Failed to remove file '" + f.getAbsolutePath() + "'");

          break;

        } else {

          try {
            Thread.sleep(500);

          } catch (Throwable e) {

          }

          time += 500;
        }
      }
    }

    if (remove) {

      try {
        // fire the listeners FIRST as this gives listeners a chance to extract data
        // from the file before it is deleted (otherwise operations fail with 'file has been
        // deleted'

        for (TranscodeTargetListener l : listeners) {

          try {
            l.fileRemoved(file);

          } catch (Throwable e) {

            Debug.out(e);
          }
        }

        synchronized (this) {
          if (device_files == null) {

            loadDeviceFile();

          } else {

            device_files_last_mod = SystemTime.getMonotonousTime();
          }

          device_files.remove(file.getKey());

          device_files_dirty = true;
        }

      } catch (Throwable e) {

        throw (new TranscodeException("Delete failed", e));
      }
    }
  }