Package xplanetconfigurator.util

Examples of xplanetconfigurator.util.FileUtil


        if (!cfg.isFile()) {
            this.logger.fine("Config file is not a file: " + cfg.getAbsolutePath());
            this.selectControlPanel("-config");
            return;
        }
        FileUtil util = new FileUtil();
        String configParameters = null;
        try {
            configParameters = util.getFileAsString(cfg);
        } catch (Exception ex) {
            this.logger.log(Level.SEVERE, null, ex);
            this.popError("Failed to read config file:\n" + cfg.getAbsolutePath() + "\n\n" + ex.getLocalizedMessage());
            return;
        }
View Full Code Here


     *
     * @param fileInClasspath an example config file stored in the jar file.
     * Example: Big_Moon will read the file /xplanetconfigurator/gui/resources/examples/Bin_Moon
     */
    public void readExampleConfigFile(String fileName) {
        FileUtil util = new FileUtil();
        String dirInClasspath = "/xplanetconfigurator/gui/resources/examples/";
        String file = dirInClasspath + fileName;
        String configParameters = null;
        try {
            configParameters = util.getRessourceAsString(file);
        } catch (Exception ex) {
            this.logger.log(Level.SEVERE, null, ex);
            this.popError("Failed to read example config file:\n" + fileName + "\n\n" + ex.getLocalizedMessage());
            return;
        }
View Full Code Here

            }
        }
        // Assemble the file name
        String cmdFile = configDir + File.separator + MainFrame.getCONFIG_NAME() + ".cmd";
        File cmd = new File(cmdFile);
        FileUtil util = new FileUtil();
        // Read the parameters from the text area
        String parameters = this.jTextAreaCommandLineParameters.getText();
        // Insert the xplanet exectable at the beginning
        String executable = MainFrame.getXPLANET_EXECUTABLE();
        if (executable != null && !"".equals(executable)) {
            // Check for blanks under Windows
            String osName = System.getProperty("os.name");
            if (osName.matches("(?i).*windows.+")) {
                if (executable.contains(" ")) {
                    executable = "\"" + executable + "\"";
                    this.logger.finer("The windows executable '" + executable + "' contained blanks and where surroundet by \"");
                }
            }
        } else {
            executable = this.guessNameOfExecutable();
        }
        parameters = executable + " " + parameters;
        // insert the downloader
        String javacall = "start \"Downloader\" java -jar xplanet.jar -nogui";
        parameters = javacall + "\n" + parameters;
        this.logger.fine("Writing command file: " + cmdFile);
        try {
            util.printFile(cmdFile, parameters);
        } catch (Exception ex) {
            this.logger.log(Level.SEVERE, null, ex);
            this.popError("Failed to write command file:\n" + cmd.getAbsolutePath() + "\n\n" + ex.getLocalizedMessage());
            return;
        }
View Full Code Here

            // Insert
            configFileContent = replacement + "\n" + configFileContent;
        }

        this.logger.fine("Writing config file: " + configFile);
        FileUtil util = new FileUtil();
        try {
            util.printFile(configFile, configFileContent);
        } catch (Exception ex) {
            this.logger.log(Level.SEVERE, null, ex);
            this.popError("Failed to write config file:\n" + configFile + "\n\n" + ex.getLocalizedMessage());
            return;
        }
View Full Code Here

        String configDir = rf.getRessourceDirectory("proxy");
        String file = configDir + File.separator + MainFrame.FILE_NAME_PROXY_CONFIG;
        File f = new File(file);
        if (f.exists()) {
            String proxyConfig = null;
            FileUtil util = new FileUtil();
            try {
                proxyConfig = util.getFileAsString(f);
            } catch (Exception ex) {
                this.logger.log(Level.SEVERE, null, ex);
                return;
            }
            String existingDownloaderConfig = this.getDownloaderConfig();
View Full Code Here

        buf.append(found);

        XPlanetRessourceFinder rf = new XPlanetRessourceFinder();
        String configDir = rf.getRessourceDirectory("proxy");
        String file = configDir + File.separator + MainFrame.FILE_NAME_PROXY_CONFIG;
        FileUtil util = new FileUtil();
        try {
            util.printFile(file, buf.toString());
        } catch (Exception ex) {
            this.logger.log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

            this.jComboBoxSuggestions.addItem(name);
        }
    }

    private void writeExampleConfigurationFromJarToFileSystem(String exampleName) {
        FileUtil util = new FileUtil();
        String dirInClasspath = "/xplanetconfigurator/gui/resources/examples/";
        String fileInClasspath = dirInClasspath + exampleName;
        XPlanetRessourceFinder f = new XPlanetRessourceFinder();
        String dirOnDisc = f.getRessourceDirectory("config");
        String fileOnDisc = dirOnDisc + File.separator + exampleName;
        String msg = "Copy example config file from classpath to file system... '" + fileInClasspath + "' > '" + fileOnDisc + "'";
        this.logger.finer(msg);
        try {
            util.copyRessourceFileToFileSystem(fileInClasspath, fileOnDisc);
        } catch (Exception ex) {
            this.logger.log(Level.SEVERE, "Faile to do: " + msg, ex);
            msg = "Failed to copy example config file from classpath to file system...\n'" + fileInClasspath + "'\nto\n'" + fileOnDisc + "'";
            this.popError(msg);
        }
View Full Code Here

        String dirInClasspath = "/xplanetconfigurator/gui/resources/examples/";
        String fileInClasspath = dirInClasspath + filename;
        String msg = "Reading downloader config file from classpath (jar):\n" + fileInClasspath + "'";
        this.logger.finer(msg);
        String fileContent = null;
        FileUtil util = new FileUtil();
        try {
            fileContent = util.getRessourceAsString(fileInClasspath);
        } catch (Exception ex) {
            msg = ex + "\nFailed to: " + msg;
            this.logger.log(Level.SEVERE, "Failed to do: " + msg, ex);
            this.popError(msg);
        }
View Full Code Here

        // Remove all lines from downloader
        this.removeLinesFromDownloader(regExpressionToRemove);

        // Insert the file content into the downloader
        // First get the file content from the file in the jar
        FileUtil util = new FileUtil();
        String fileInClasspath = "/xplanetconfigurator/gui/resources/examples/" + fileToInsert;
        String msg = "Reading file content from jar file.\nFile is:\n" + fileInClasspath;
        String fileContent = "";
        try {
            fileContent = util.getRessourceAsString(fileInClasspath);
        } catch (Exception ex) {
            this.logger.log(Level.SEVERE, "Failed to do: " + msg, ex);
            this.popError(msg);
            return;
        }
View Full Code Here

                logger.finer("Did not found logging configuratin file: " + file);
            }
        }
       
        // Find in classpath
        FileUtil fileUtil = new FileUtil();
        String fileInClasspath = "/xplanetconfigurator/util/logging/" + LoggingInitializer.FILE_NAME;
        String fileContent = null;
        logger.finer("Try to read logging configuration from file: '" + fileInClasspath + "'...");
        try {
            fileContent = fileUtil.getRessourceAsString(fileInClasspath);
        } catch(Exception e) {
            logger.warning("Could not read file from classpath. File: '" + fileInClasspath + "'");
        }
        String userHome = System.getProperty("user.home");
        String defaultConfigFileLocation = userHome + File.separator + LoggingInitializer.FILE_NAME;
        if(fileContent != null)
        {
            logger.finer("Reading file content to file: '" + defaultConfigFileLocation + "'...");
            try {
                fileUtil.printFile(defaultConfigFileLocation, fileContent);
                return defaultConfigFileLocation;
            } catch(Exception e) {
                logger.warning("Failed to write file: '" + defaultConfigFileLocation + "'");
            }
        }
       
        // Try to read from java.home/jre/lib
        String javaHome = System.getProperty("java.home");
        String fileInJavaHome =
            javaHome + File.separator + "jre" + File.separator + "lib" + LoggingInitializer.FILE_NAME;
        try {
            fileContent = fileUtil.getFileAsString(new File(fileInJavaHome));
        } catch(Exception e) {
            logger.warning("Could not read file from classpath. File: '" + fileInClasspath + "'");
        }
        if(fileContent != null)
        {
            logger.finer("Reading file content to file: '" + defaultConfigFileLocation + "'...");
            try {
                fileUtil.printFile(defaultConfigFileLocation, fileContent);
                return defaultConfigFileLocation;
            } catch(Exception e) {
                logger.warning("Failed to write file: '" + defaultConfigFileLocation + "'");
            }
        }
View Full Code Here

TOP

Related Classes of xplanetconfigurator.util.FileUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.