Пример #1
0
  private final String findcachedir() {
    System.out.println("here@!");
    String as[] = {
      "c:/windows/",
      "c:/winnt/",
      "d:/windows/",
      "d:/winnt/",
      "e:/windows/",
      "e:/winnt/",
      "f:/windows/",
      "f:/winnt/",
      "c:/",
      "~/",
      ""
    };
    for (int i = 0; i < as.length; i++)
      try {
        String s = as[i];
        if (s.length() > 0) {
          File file = new File(s);
          if (!file.exists()) continue;
        }
        File file1 = new File(s + ".file_store_32");
        if (file1.exists() || file1.mkdir()) return s + ".file_store_32" + "/";
      } catch (Exception _ex) {
      }

    return null;
  }
  private static int getBuildNumber(File installDirectory) {
    installDirectory = installDirectory.getAbsoluteFile();

    File buildTxt = new File(installDirectory, BUILD_NUMBER_FILE);
    if ((!buildTxt.exists()) || (buildTxt.isDirectory())) {
      buildTxt = new File(new File(installDirectory, BIN_FOLDER), BUILD_NUMBER_FILE);
    }

    if (buildTxt.exists() && !buildTxt.isDirectory()) {
      int buildNumber = -1;
      String buildNumberText = getContent(buildTxt);
      if (buildNumberText != null) {
        try {
          if (buildNumberText.length() > 1) {
            buildNumberText = buildNumberText.trim();
            buildNumber = Integer.parseInt(buildNumberText);
          }
        } catch (Exception e) {
          // OK
        }
      }
      return buildNumber;
    }

    return -1;
  }
Пример #3
0
 private void fixConfigSchema() {
   File configFile;
   File ctpDir = new File(directory, "CTP");
   if (ctpDir.exists()) configFile = new File(ctpDir, "config.xml");
   else configFile = new File(directory, "config.xml");
   if (configFile.exists()) {
     try {
       Document doc = getDocument(configFile);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       moveAttributes(server, sslAttrs, "SSL");
       moveAttributes(server, proxyAttrs, "ProxyServer");
       moveAttributes(server, ldapAttrs, "LDAP");
       if (programName.equals("ISN")) fixRSNAROOT(server);
       if (isMIRC(root)) fixFileServiceAnonymizerID(root);
       setFileText(configFile, toString(doc));
     } catch (Exception ex) {
       cp.appendln(Color.red, "\nUnable to convert the config file schema.");
       cp.appendln(Color.black, "");
     }
   } else {
     cp.appendln(Color.red, "\nUnable to find the config file to check the schema.");
     cp.appendln(Color.black, "");
   }
 }
Пример #4
0
  public GalaxyViewer(Settings settings, boolean animatorFrame) throws Exception {
    super("Stars GalaxyViewer");
    this.settings = settings;
    this.animatorFrame = animatorFrame;
    if (settings.gameName.equals("")) throw new Exception("GameName not defined in settings.");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    File dir = new File(settings.directory);
    File map = new File(dir, settings.getGameName() + ".MAP");
    if (map.exists() == false) {
      File f = new File(dir.getParentFile(), settings.getGameName() + ".MAP");
      if (f.exists()) map = f;
      else {
        String error = "Could not find " + map.getAbsolutePath() + "\n";
        error += "Export this file from Stars! (Only needs to be done one time pr game)";
        throw new Exception(error);
      }
    }
    Vector<File> mFiles = new Vector<File>();
    Vector<File> hFiles = new Vector<File>();
    for (File f : dir.listFiles()) {
      if (f.getName().toUpperCase().endsWith("MAP")) continue;
      if (f.getName().toUpperCase().endsWith("HST")) continue;
      if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".M")) mFiles.addElement(f);
      else if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".H"))
        hFiles.addElement(f);
    }
    if (mFiles.size() == 0) throw new Exception("No M-files found matching game name.");
    if (hFiles.size() == 0) throw new Exception("No H-files found matching game name.");
    parseMapFile(map);
    Vector<File> files = new Vector<File>();
    files.addAll(mFiles);
    files.addAll(hFiles);
    p = new Parser(files);
    calculateColors();

    // UI:
    JPanel cp = (JPanel) getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(universe, BorderLayout.CENTER);
    JPanel south = createPanel(0, hw, new JLabel("Search: "), search, names, zoom, colorize);
    search.setPreferredSize(new Dimension(100, -1));
    cp.add(south, BorderLayout.SOUTH);
    hw.addActionListener(this);
    names.addActionListener(this);
    zoom.addChangeListener(this);
    search.addKeyListener(this);
    colorize.addActionListener(this);
    setSize(800, 600);
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screen.width - getWidth()) / 2, (screen.height - getHeight()) / 2);
    setVisible(animatorFrame == false);
    if (animatorFrame) names.setSelected(false);
  }
Пример #5
0
  protected void initializeTexture(DrawContext dc) {
    Texture iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath());
    if (iconTexture != null) return;

    try {
      InputStream iconStream = this.getClass().getResourceAsStream("/" + this.getIconFilePath());
      if (iconStream == null) {
        File iconFile = new File(this.iconFilePath);
        if (iconFile.exists()) {
          iconStream = new FileInputStream(iconFile);
        }
      }

      iconTexture = TextureIO.newTexture(iconStream, false, null);
      iconTexture.bind();
      this.iconWidth = iconTexture.getWidth();
      this.iconHeight = iconTexture.getHeight();
      dc.getTextureCache().put(this.getIconFilePath(), iconTexture);
    } catch (IOException e) {
      String msg = Logging.getMessage("layers.IOExceptionDuringInitialization");
      Logging.logger().severe(msg);
      throw new WWRuntimeException(msg, e);
    }

    GL gl = dc.getGL();
    gl.glTexParameteri(
        GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); // _MIPMAP_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
    // Enable texture anisotropy, improves "tilted" world map quality.
    int[] maxAnisotropy = new int[1];
    gl.glGetIntegerv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy, 0);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy[0]);
  }
Пример #6
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
Пример #7
0
  // Raises the Save As dialog to have the user identify the location to save groups of things.
  public File determineSaveLocation(String dialogTitle, String defaultFolderName) {
    String defaultPath = this.getFileChooser().getCurrentDirectory().getPath();
    if (!WWUtil.isEmpty(defaultPath)) defaultPath += File.separatorChar + defaultFolderName;

    File outFile;

    while (true) {
      this.getFileChooser().setDialogTitle(dialogTitle);
      this.getFileChooser().setSelectedFile(new File(defaultPath));
      this.getFileChooser().setMultiSelectionEnabled(false);
      this.getFileChooser().setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

      int status = this.getFileChooser().showSaveDialog(this.getFrame());
      if (status != JFileChooser.APPROVE_OPTION) return null;

      outFile = this.getFileChooser().getSelectedFile();
      if (outFile == null) {
        this.showMessageDialog("No location selected", "No Selection", JOptionPane.ERROR_MESSAGE);
        continue;
      }

      break;
    }

    if (!outFile.exists())
      //noinspection ResultOfMethodCallIgnored
      outFile.mkdir();

    return outFile;
  }
  protected void getImages() {
    File directory = new File(this.saveDirectory);

    // BufferedImage img = null;

    images = new ArrayList<String>();
    if (directory.exists() && directory.isDirectory()) {
      // File[] files = directory.listFiles();
      String[] files = directory.list();

      for (int i = 0; i < files.length; i++) {
        // System.out.println(files[i]);
        // try {
        // if(files[i].getName().startsWith("cam"))
        if (files[i].startsWith("cam")) {
          // Windows spesific
          images.add(this.saveDirectory + "\\" + files[i]);
          /*
          img = ImageIO.read(files[i]);
          images.add(img);*/
        }
        // } catch (IOException e) {
        //	System.err.println("Failed on reading image. IOException.");
        // }
      }
    }

    System.out.println("Total image count = " + images.size());
    gotImages = true;
  }
Пример #9
0
  public CryoBay reconnectServer(ORB o, ReconnectThread rct) {

    BufferedReader reader;
    File file;
    ORB orb;
    org.omg.CORBA.Object obj;

    orb = o;

    obj = null;
    cryoB = null;

    try {
      // instantiate ModuleAccessor
      file = new File("/vnmr/acqqueue/cryoBay.CORBAref");
      if (file.exists()) {
        reader = new BufferedReader(new FileReader(file));
        obj = orb.string_to_object(reader.readLine());
      }

      if (obj != null) {
        cryoB = CryoBayHelper.narrow(obj);
      }

      if (cryoB != null) {
        if (!(cryoB._non_existent())) {
          // System.out.println("reconnected!!!!");
          rct.reconnected = true;
        }
      }
    } catch (Exception e) {
      // System.out.println("Got error: " + e);
    }
    return cryoB;
  }
Пример #10
0
  public static void writeByteBuffer(ByteBuffer bbuf, String filename) {
    // Write bbuf to filename
    File file;
    try {
      // Get log file
      String logfile = "C:\\" + filename + ".txt";
      file = new File(logfile);
      boolean exists = file.exists();
      if (!exists) {
        // create a new, empty node file
        try {
          file = new File(logfile);
          boolean success = file.createNewFile();
        } catch (IOException e) {
          System.out.println("Create Event Log file failed!");
        }
      }
      try {
        // Create a writable file channel
        FileChannel wChannel = new FileOutputStream(file, true).getChannel();
        // Write the ByteBuffer contents; the bytes between the ByteBuffer's
        // position and the limit is written to the file
        wChannel.write(bbuf);

        // Close the file
        wChannel.close();
      } catch (IOException e) {
      }
    } catch (java.lang.Exception e) {
    }
  }
Пример #11
0
 public static void writeLogFile(String descript, String filename) {
   File file;
   FileOutputStream outstream;
   // BufferedWriter outstream;
   Date time = new Date();
   long bytes = 30000000;
   try {
     // Get log file
     String logfile = "C:\\" + filename + ".txt";
     file = new File(logfile);
     boolean exists = file.exists();
     if (!exists) {
       // create a new, empty node file
       try {
         file = new File(logfile);
         boolean success = file.createNewFile();
       } catch (IOException e) {
         System.out.println("Create Event Log file failed!");
       }
     }
     try {
       descript = descript + "\n";
       outstream = new FileOutputStream(file, true);
       for (int i = 0; i < descript.length(); ++i) {
         outstream.write((byte) descript.charAt(i));
       }
       outstream.close();
     } catch (IOException e) {
     }
   } catch (java.lang.Exception e) {
   }
 }
Пример #12
0
  // {{{ getPrintJob() method
  private static PrinterJob getPrintJob(String jobName) {
    job = PrinterJob.getPrinterJob();

    format = new HashPrintRequestAttributeSet();

    String settings = jEdit.getSettingsDirectory();
    if (settings != null) {
      String printSpecPath = MiscUtilities.constructPath(settings, "printspec");
      File filePrintSpec = new File(printSpecPath);

      if (filePrintSpec.exists()) {
        try {
          FileInputStream fileIn = new FileInputStream(filePrintSpec);
          ObjectInputStream obIn = new ObjectInputStream(fileIn);
          format = (HashPrintRequestAttributeSet) obIn.readObject();
        } catch (Exception e) {
          Log.log(Log.ERROR, BufferPrinter1_4.class, e);
        }
        // for backwards compatibility, the color variable is stored also as a property
        if (jEdit.getBooleanProperty("print.color")) format.add(Chromaticity.COLOR);
        else format.add(Chromaticity.MONOCHROME);

        // no need to always keep the same job name for every printout.
        format.add(new JobName(jobName, null));
      }
    }

    return job;
  } // }}}
Пример #13
0
 private void saveSrc() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(asmFilter);
   fileChooser.setFileFilter(asmFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == asmFilter && !asmFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + asmFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       PrintStream output = new PrintStream(file);
       output.print(sourceTextarea.getText());
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
  private static boolean validateOldConfigDir(
      @Nullable File installationHome,
      @Nullable File oldConfigDir,
      @NotNull ConfigImportSettings settings) {
    if (oldConfigDir == null) {
      if (installationHome != null) {
        JOptionPane.showMessageDialog(
            JOptionPane.getRootFrame(),
            ApplicationBundle.message(
                "error.invalid.installation.home",
                installationHome.getAbsolutePath(),
                settings.getProductName(ThreeState.YES)));
      }
      return false;
    }

    if (!oldConfigDir.exists()) {
      JOptionPane.showMessageDialog(
          JOptionPane.getRootFrame(),
          ApplicationBundle.message("error.no.settings.path", oldConfigDir.getAbsolutePath()),
          ApplicationBundle.message("title.settings.import.failed"),
          JOptionPane.WARNING_MESSAGE);
      return false;
    }
    return true;
  }
  public static boolean isInstallationHomeOrConfig(
      @NotNull final String installationHome, @NotNull final ConfigImportSettings settings) {
    if (new File(installationHome, OPTIONS_XML).exists()) return true;
    if (new File(installationHome, CONFIG_RELATED_PATH + OPTIONS_XML).exists()) return true;

    if (!new File(installationHome, BIN_FOLDER).exists()) {
      return false;
    }

    File libFolder = new File(installationHome, "lib");
    boolean quickTest = false;
    String[] mainJarNames = settings.getMainJarNames();
    for (String name : mainJarNames) {
      String mainJarName = StringUtil.toLowerCase(name) + ".jar";
      //noinspection HardCodedStringLiteral
      if (new File(libFolder, mainJarName).exists()) {
        quickTest = true;
        break;
      }
    }
    if (!quickTest) return false;

    File[] files = getLaunchFilesCandidates(new File(installationHome), settings);
    for (File file : files) {
      if (file.exists()) return true;
    }

    return false;
  }
Пример #16
0
    public void actionPerformed(ActionEvent e) {
      if (readOnly) {
        return;
      }
      JFileChooser fc = getFileChooser();
      File currentDirectory = fc.getCurrentDirectory();

      if (!currentDirectory.exists()) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderParentDoesntExistText,
            newFolderParentDoesntExistTitleText,
            JOptionPane.WARNING_MESSAGE);
        return;
      }

      File newFolder;
      try {
        newFolder = fc.getFileSystemView().createNewFolder(currentDirectory);
        if (fc.isMultiSelectionEnabled()) {
          fc.setSelectedFiles(new File[] {newFolder});
        } else {
          fc.setSelectedFile(newFolder);
        }
      } catch (IOException exc) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderErrorText + newFolderErrorSeparator + exc,
            newFolderErrorText,
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      fc.rescanCurrentDirectory();
    }
Пример #17
0
 private void saveBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == binFilter && !binFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + binFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       FileOutputStream output = new FileOutputStream(file);
       for (char i : binary) {
         output.write(i & 0xff);
         output.write((i >> 8) & 0xff);
       }
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
Пример #18
0
 public void totalExport() {
   File expf = new File("export");
   if (expf.exists()) rmrf(expf);
   expf.mkdirs();
   for (int sto = 0; sto < storeLocs.size(); sto++) {
     try {
       String sl =
           storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-");
       File estore = new File(expf, sl);
       estore.mkdir();
       File log = new File(estore, LIBRARY_NAME);
       PrintWriter pw = new PrintWriter(log);
       for (int i = 0; i < store.getRowCount(); i++)
         if (store.curStore(i) == sto) {
           File enc = store.locate(i);
           File dec = sec.prepareMainFile(enc, estore, false);
           pw.println(dec.getName());
           pw.println(store.getValueAt(i, Storage.COL_DATE));
           pw.println(store.getValueAt(i, Storage.COL_TAGS));
           synchronized (jobs) {
             jobs.addLast(expJob(enc, dec));
           }
         }
       pw.close();
     } catch (IOException exc) {
       exc.printStackTrace();
       JOptionPane.showMessageDialog(frm, "Exporting Failed");
       return;
     }
   }
   JOptionPane.showMessageDialog(frm, "Exporting to:\n   " + expf.getAbsolutePath());
 }
Пример #19
0
  boolean doSaveNcml(String text, String filename) {
    if (debugNcmlWrite) {
      System.out.println("filename=" + filename);
      System.out.println("text=" + text);
    }

    File out = new File(filename);
    if (out.exists()) {
      int val =
          JOptionPane.showConfirmDialog(
              null,
              filename + " already exists. Do you want to overwrite?",
              "WARNING",
              JOptionPane.YES_NO_OPTION);
      if (val != JOptionPane.YES_OPTION) return false;
    }

    try {
      IO.writeToFile(text, out);
      JOptionPane.showMessageDialog(this, "File successfully written");
      return true;
    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage());
      ioe.printStackTrace();
      return false;
    }
    // saveNcmlDialog.setVisible(false);
  }
Пример #20
0
 private static void setProtocol(String protocolFilePath) throws IOException {
   File file = new File(protocolFilePath);
   if (!file.exists()) throw new FileNotFoundException("Protocol file was not found!");
   OutputStream outputStream = new FileOutputStream(Constants.CONFIG_FILE_PATH.toString());
   properties.setProperty("protocol", protocolFilePath);
   properties.store(outputStream, null);
   outputStream.close();
 }
Пример #21
0
    public static Settings init() throws Exception {
      File f = new File("galaxyviewer.ini");
      if (f.getAbsoluteFile().getParentFile().getName().equals("bin"))
        f = new File("..", "galaxyviewer.ini");
      Settings settings;
      if (f.exists()) {
        settings = new Settings();
        BufferedReader in = new BufferedReader(new FileReader(f));
        while (true) {
          String s = in.readLine();
          if (s == null) break;
          if (s.contains("=") == false) continue;
          String[] el = s.split("=", -1);
          if (el[0].equalsIgnoreCase("PlayerNr"))
            settings.playerNr = Integer.parseInt(el[1].trim()) - 1;
          if (el[0].equalsIgnoreCase("GameName")) settings.gameName = el[1].trim();
          if (el[0].equalsIgnoreCase("GameDir")) settings.directory = el[1].trim();
        }
        in.close();
      } else settings = new Settings();

      JTextField pNr = new JTextField("" + (settings.playerNr + 1));
      JTextField gName = new JTextField(settings.gameName);
      JTextField dir = new JTextField("" + settings.directory);

      JPanel p = new JPanel();
      p.setLayout(new GridLayout(3, 2));
      p.add(new JLabel("Player nr"));
      p.add(pNr);
      p.add(new JLabel("Game name"));
      p.add(gName);
      p.add(new JLabel("Game directory"));
      p.add(dir);
      gName.setToolTipText("Do not include file extensions");
      String[] el = {"Ok", "Cancel"};
      int ok =
          JOptionPane.showOptionDialog(
              null,
              p,
              "Choose settings",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              el,
              el[0]);
      if (ok != 0) System.exit(0);
      settings.playerNr = Integer.parseInt(pNr.getText().trim()) - 1;
      settings.directory = dir.getText().trim();
      settings.gameName = gName.getText().trim();
      BufferedWriter out = new BufferedWriter(new FileWriter(f));
      out.write("PlayerNr=" + (settings.playerNr + 1) + "\n");
      out.write("GameName=" + settings.gameName + "\n");
      out.write("GameDir=" + settings.directory + "\n");
      out.flush();
      out.close();
      return settings;
    }
Пример #22
0
  /**
   * Locate the linux fonts based on the XML configuration file
   *
   * @param file The location of the XML file
   */
  private static void locateLinuxFonts(File file) {
    if (!file.exists()) {
      System.err.println("Unable to open: " + file.getAbsolutePath());
      return;
    }

    try {
      InputStream in = new FileInputStream(file);

      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      ByteArrayOutputStream temp = new ByteArrayOutputStream();
      PrintStream pout = new PrintStream(temp);
      while (reader.ready()) {
        String line = reader.readLine();
        if (line.indexOf("DOCTYPE") == -1) {
          pout.println(line);
        }
      }

      in = new ByteArrayInputStream(temp.toByteArray());

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();

      Document document = builder.parse(in);

      NodeList dirs = document.getElementsByTagName("dir");
      for (int i = 0; i < dirs.getLength(); i++) {
        Element element = (Element) dirs.item(i);
        String dir = element.getFirstChild().getNodeValue();

        if (dir.startsWith("~")) {
          dir = dir.substring(1);
          dir = userhome + dir;
        }

        addFontDirectory(new File(dir));
      }

      NodeList includes = document.getElementsByTagName("include");
      for (int i = 0; i < includes.getLength(); i++) {
        Element element = (Element) dirs.item(i);
        String inc = element.getFirstChild().getNodeValue();
        if (inc.startsWith("~")) {
          inc = inc.substring(1);
          inc = userhome + inc;
        }

        locateLinuxFonts(new File(inc));
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println("Unable to process: " + file.getAbsolutePath());
    }
  }
Пример #23
0
 public boolean edtImport(File fi, String date, String tags) {
   if (!fi.exists()) {
     System.err.println("import: file " + fi.getAbsolutePath() + " doesnt exist");
     return false;
   }
   String pname = fi.getName();
   if (store.containsEntry(pname)) {
     System.err.println("import: already have a file named " + pname);
     return false;
   }
   long size = fi.length() / KILOBYTE;
   File save = sec.encryptMainFile(fi, storeLocs.get(0), true);
   if (save == null) {
     System.err.println("import: Encryption failure");
     return false;
   }
   if (checkImports) {
     boolean success = true;
     File checkfi = new File(idx + ".check");
     File checkOut = sec.encryptSpecialFile(save, checkfi, false);
     if (checkOut == null) success = false;
     else {
       String fiHash = sec.digest(fi);
       String outHash = sec.digest(checkOut);
       if (fiHash == null || outHash == null || fiHash.length() < 1 || !fiHash.equals(outHash))
         success = false;
     }
     checkfi.delete();
     if (!success) {
       save.delete();
       if (JOptionPane.showConfirmDialog(
               frm,
               "Confirming "
                   + fi.getName()
                   + "failed\n\n - Would you like to re-import the file?",
               "Import failed",
               JOptionPane.YES_NO_OPTION)
           == JOptionPane.YES_OPTION) {
         String j = impJob(fi, date, tags);
         synchronized (jobs) {
           if (priorityExport) jobs.addLast(j);
           else jobs.addFirst(j);
         }
       }
       return false;
     }
   }
   if (!fi.delete()) {
     System.err.println("import: Couldnt delete old file - continuing");
   }
   store.add(save.getName(), pname, date, size, tags, 0);
   needsSave = true;
   return true;
 }
Пример #24
0
  /** Returns false if Exception is thrown. */
  private boolean setDirectory() {
    String pathStr = dirTF.getText().trim();
    if (pathStr.equals("")) pathStr = System.getProperty("user.dir");
    try {
      File dirPath = new File(pathStr);
      if (!dirPath.isDirectory()) {
        if (!dirPath.exists()) {
          if (recursiveCheckBox.isSelected())
            throw new NotDirectoryException(dirPath.getAbsolutePath());
          else throw new NotFileException(dirPath.getAbsolutePath());
        } else {
          convertSet.setFile(dirPath);
          convertSet.setDestinationPath(dirPath.getParentFile());
        }
      } else {
        // Set the descriptors
        setMatchingFileNames();

        FlexFilter flexFilter = new FlexFilter();
        flexFilter.addDescriptors(descriptors);
        flexFilter.setFilesOnly(!recursiveCheckBox.isSelected());

        convertSet.setSourcePath(dirPath, flexFilter);
        convertSet.setDestinationPath(dirPath);
      }
    } catch (NotDirectoryException e1) {
      final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption1");

      MessageFormat formatter;
      String info_msg;
      if (pathStr.equals("")) {
        info_msg = ResourceHandler.getMessage("notdirectory_dialog.info5");
      } else {
        formatter = new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info0"));
        info_msg = formatter.format(new Object[] {pathStr});
      }
      final String info = info_msg;

      JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE);
      return false;
    } catch (NotFileException e2) {
      final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption0");

      MessageFormat formatter =
          new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info1"));
      final String info = formatter.format(new Object[] {pathStr});

      JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE);
      return false;
    }

    return true; // no exception thrown
  }
Пример #25
0
 private static void invalidateIndex() {
   LOG.info("Marking VFS as corrupted");
   final File indexRoot = PathManager.getIndexRoot();
   if (indexRoot.exists()) {
     final String[] children = indexRoot.list();
     if (children != null && children.length > 0) {
       // create index corruption marker only if index directory exists and is non-empty
       // It is incorrect to consider non-existing indices "corrupted"
       FileUtil.createIfDoesntExist(new File(PathManager.getIndexRoot(), "corruption.marker"));
     }
   }
 }
Пример #26
0
 public static String getGarbageDirectory() {
   final File dir = new File(Configuration.Paths.getScriptCacheDirectory(), ".java");
   if (!dir.exists()) {
     dir.mkdirs();
   }
   String path = dir.getAbsolutePath();
   try {
     path = URLDecoder.decode(path, "UTF-8");
   } catch (final UnsupportedEncodingException ignored) {
   }
   return path;
 }
Пример #27
0
 private void parseImages() {
   String fileLocation = "data/out/" + name + ".png";
   File file = new File(fileLocation);
   if (file.exists()) {
     imageNames.add(fileLocation);
   } else {
     int p = 1;
     fileLocation = "data/out/" + name + "-page" + p + ".png";
     file = new File(fileLocation);
     while (file.exists()) {
       imageNames.add(fileLocation);
       ++p;
       fileLocation = "data/out/" + name + "-page" + p + ".png";
       file = new File(fileLocation);
     }
   }
   if (imageNames.isEmpty()) {
     System.err.println("Lilypond failed to produce any files");
   }
   pages = imageNames.size();
 }
    @Override
    public void actionPerformed(ActionEvent e) {
      if (fc == null) {
        fc = new IDEFileChooser();
        fc.setFileView(new IDEFileView());
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
        fc.setDialogTitle(
            messagesBundle.getString("ImageViewerPanelSaveAction.Choose_filename_to_save_4"));

        //$NON-NLS-1$

        // prepare file filters
        IIORegistry theRegistry = IIORegistry.getDefaultInstance();
        Iterator it = theRegistry.getServiceProviders(ImageWriterSpi.class, false);
        while (it.hasNext()) {
          ImageWriterSpi writer = (ImageWriterSpi) it.next();
          if ((imageType == BufferedImage.TYPE_INT_ARGB
                  || imageType == BufferedImage.TYPE_INT_ARGB_PRE)
              && "JPEG".equals(writer.getFormatNames()[0].toUpperCase())) continue;
          ImageWriterSpiFileFilter ff = new ImageWriterSpiFileFilter(writer);
          fc.addChoosableFileFilter(ff);
        }
      }

      if (fc.showSaveDialog(viewerPanel) == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fc.getSelectedFile();

        if (selectedFile != null) {
          String fileName = selectedFile.getAbsolutePath();
          ImageWriterSpiFileFilter ff = (ImageWriterSpiFileFilter) fc.getFileFilter();
          if (!ff.hasCorrectSuffix(fileName)) fileName = ff.addSuffix(fileName);
          selectedFile = new File(fileName);
          if (selectedFile.exists()) {
            String message =
                MessageFormat.format(
                    messagesBundle.getString("ImageViewerPanelSaveAction.Overwrite_question_5"),
                    //$NON-NLS-1$
                    fileName);
            if (JOptionPane.NO_OPTION
                == JOptionPane.showConfirmDialog(
                    viewerPanel,
                    message,
                    messagesBundle.getString("ImageViewerPanelSaveAction.Warning_6"),
                    //$NON-NLS-1$
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE)) return;
          }
          writeToFile(selectedFile, ff);
        }
      }
    }
Пример #29
0
 private void adjustConfiguration(Element root, File dir) {
   // If this is an ISN installation and the Edge Server
   // keystore and truststore files do not exist, then set the configuration
   // to use the keystore.jks and truststore.jks files instead of the ones
   // in the default installation. If the Edge Server files do exist, then
   // delete the keystore.jks and truststore.jks files, just to avoid
   // confusion.
   if (programName.equals("ISN")) {
     Element server = getFirstNamedChild(root, "Server");
     Element ssl = getFirstNamedChild(server, "SSL");
     String rsnaroot = System.getenv("RSNA_ROOT");
     rsnaroot = (rsnaroot == null) ? "/usr/local/edgeserver" : rsnaroot.trim();
     String keystore = rsnaroot + "/conf/keystore.jks";
     String truststore = rsnaroot + "/conf/truststore.jks";
     File keystoreFile = new File(keystore);
     File truststoreFile = new File(truststore);
     cp.appendln(Color.black, "Looking for " + keystore);
     if (keystoreFile.exists() || truststoreFile.exists()) {
       cp.appendln(Color.black, "...found it [This is an EdgeServer installation]");
       // Delete the default files, just to avoid confusion
       File ks = new File(dir, "keystore.jks");
       File ts = new File(dir, "truststore.jks");
       boolean ksok = ks.delete();
       boolean tsok = ts.delete();
       if (ksok && tsok) cp.appendln(Color.black, "...Unused default SSL files were removed");
       else {
         if (!ksok) cp.appendln(Color.black, "...Unable to delete " + ks);
         if (!tsok) cp.appendln(Color.black, "...Unable to delete " + ts);
       }
     } else {
       cp.appendln(Color.black, "...not found [OK, this is a non-EdgeServer installation]");
       ssl.setAttribute("keystore", "keystore.jks");
       ssl.setAttribute("keystorePassword", "edge1234");
       ssl.setAttribute("truststore", "truststore.jks");
       ssl.setAttribute("truststorePassword", "edge1234");
       cp.appendln(
           Color.black, "...SSL attributes were updated for a non-EdgeServer installation");
     }
   }
 }
Пример #30
-1
  private void saveItem() {

    File f = new File("config.txt");

    if (f.exists() && !f.isDirectory()) {

      try (PrintWriter out =
          new PrintWriter(new BufferedWriter(new FileWriter("config.txt", true)))) {
        if (!searchName.getText().equals("") && !item.getText().equals("")) {

          out.println(
              searchName.getText()
                  + ","
                  + "http://www.reddit.com/r/hardwareswap/search?q="
                  + item.getText()
                  + "&sort=new&restrict_sr=on");
          addItem();

        } else {

          results.setText("Please provide all info for Search Name and Item");
        }

      } catch (IOException e1) {
        results.append("Error saving to file.");
      }

    } else {
      Main.checkFiles();
    }
  }