Пример #1
0
  /** Remove any temporary xml files produced while outputting characters. */
  static void removeTemporaryFiles() {
    final boolean cleanUp =
        UIPropertyContext.getInstance().initBoolean(UIPropertyContext.CLEANUP_TEMP_FILES, true);

    if (!cleanUp) {
      return;
    }

    final String aDirectory = SettingsHandler.getTempPath() + File.separator;
    new File(aDirectory)
        .list(
            new FilenameFilter() {
              @Override
              public boolean accept(File aFile, String aString) {
                try {
                  if (aString.startsWith(Constants.TEMPORARY_FILE_NAME)) {
                    final File tf = new File(aFile, aString);
                    tf.delete();
                  }
                } catch (Exception e) {
                  Logging.errorPrint("removeTemporaryFiles", e);
                }

                return false;
              }
            });
  }
Пример #2
0
  /**
   * Get a temporary file name for outputting a character using a particular output template.
   *
   * @param templateFile The output template that will be used.
   * @return The temporary file, or null if it could not be created.
   */
  public static File getTempOutputFilename(File templateFile) {
    String extension =
        ExportUtilities.getOutputExtension(
            templateFile.getName(), ExportUtilities.isPdfTemplate(templateFile));

    try {
      // create a temporary file to view the character output
      return File.createTempFile(
          Constants.TEMPORARY_FILE_NAME, "." + extension, SettingsHandler.getTempPath());
    } catch (IOException ioe) {
      ShowMessageDelegate.showMessageDialog(
          "Could not create temporary preview file.", "PCGen", MessageType.ERROR);
      Logging.errorPrint("Could not create temporary preview file.", ioe);
      return null;
    }
  }