// Path: src/main/java/org/gzipper/java/application/model/OperatingSystem.java
// public class OperatingSystem {
// 
//     /**
//      * The aggregated enumeration which represents the operating system.
//      */
//     protected final OS _operatingSystem;
// 
//     /**
//      * Constructs a new instance of this class using the specified enumeration.
//      *
//      * @param operatingSystem the operating system to be aggregated.
//      */
//     public OperatingSystem(OS operatingSystem) {
//         _operatingSystem = operatingSystem;
//     }
// 
//     /**
//      * Returns the default user directory of the system.
//      *
//      * @return the default user directory as string.
//      */
//     public String getDefaultUserDirectory() {
//         return System.getProperty("user.home");
//     }
// 
//     /**
//      * Returns the enumeration for the current operating system.
//      *
//      * @return the enumeration for the current operating system.
//      */
//     public OS getOsInfo() {
//         return _operatingSystem;
//     }
// }
// 
// Path: src/main/java/org/gzipper/java/application/util/StringUtils.java
// public final class StringUtils {
// 
//     /**
//      * An empty string.
//      */
//     public static final String EMPTY = "";
// 
//     private StringUtils() {
//         throw new AssertionError("Holds static members only");
//     }
// 
//     /**
//      * Checks whether the given string is {@code null} or empty.
//      *
//      * @param string the string to be checked.
//      * @return true if string is {@code null} or empty, false otherwise.
//      */
//     public static boolean isNullOrEmpty(String string) {
//         return string == null || string.isEmpty();
//     }
// }


import org.gzipper.java.application.model.OperatingSystem;
import org.gzipper.java.application.util.StringUtils;
import java.io.*;
import java.util.Properties;

/*
 * Copyright (C) 2018 Matthias Fussenegger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.gzipper.java.util;



/**
 * Singleton that provides convenience when working with {@link Properties} and
 * represents the settings file that can be used globally.
 *
 * @author Matthias Fussenegger
 */
public final class Settings {

    public static final String FALSE_STRING = "false";
    public static final String TRUE_STRING = "true";

    /**
     * The actual properties file. Required to store away changed properties.
     */
    private File _propsFile;

    /**
     * The properties read from the {@link #_propsFile};
     */
    private Properties _props;

    /**
     * The default properties values for restoration.
     */
    private final Properties _defaults;

    /**
     * The operating system the JVM runs on.
     */
    private OperatingSystem _os;

    private Settings() {
        _defaults = initDefaults();
    }

    /**
     * Initializes this singleton class. This may only be called once.
     *
     * @param props the properties file to initialize this class with.
     * @param os    the current operating system.
     */
    public void init(File props, OperatingSystem os) {
        if (_props == null) {
            _os = os; // to receive environment variables
            if (props != null) {
                _propsFile = props;
                _props = new Properties(_defaults);

                try (final FileInputStream fis = new FileInputStream(props);
                     final BufferedInputStream bis = new BufferedInputStream(fis)) {
                    _props.load(bis);
                } catch (IOException ex) {
                    Log.e(ex.getLocalizedMessage(), ex);
                }
            }
        }
    }

    /**
     * Initializes the default properties values.
     *
     * @return the default properties.
     */
    private Properties initDefaults() {

        final Properties defaults = new Properties();

        defaults.setProperty("loggingEnabled", FALSE_STRING);

// Path: src/main/java/org/gzipper/java/application/model/OperatingSystem.java
// public class OperatingSystem {
// 
//     /**
//      * The aggregated enumeration which represents the operating system.
//      */
//     protected final OS _operatingSystem;
// 
//     /**
//      * Constructs a new instance of this class using the specified enumeration.
//      *
//      * @param operatingSystem the operating system to be aggregated.
//      */
//     public OperatingSystem(OS operatingSystem) {
//         _operatingSystem = operatingSystem;
//     }
// 
//     /**
//      * Returns the default user directory of the system.
//      *
//      * @return the default user directory as string.
//      */
//     public String getDefaultUserDirectory() {
//         return System.getProperty("user.home");
//     }
// 
//     /**
//      * Returns the enumeration for the current operating system.
//      *
//      * @return the enumeration for the current operating system.
//      */
//     public OS getOsInfo() {
//         return _operatingSystem;
//     }
// }
// 
// Path: src/main/java/org/gzipper/java/application/util/StringUtils.java
// public final class StringUtils {
// 
//     /**
//      * An empty string.
//      */
//     public static final String EMPTY = "";
// 
//     private StringUtils() {
//         throw new AssertionError("Holds static members only");
//     }
// 
//     /**
//      * Checks whether the given string is {@code null} or empty.
//      *
//      * @param string the string to be checked.
//      * @return true if string is {@code null} or empty, false otherwise.
//      */
//     public static boolean isNullOrEmpty(String string) {
//         return string == null || string.isEmpty();
//     }
// }


// Path: src/main/java/org/gzipper/java/util/Settings.java
import org.gzipper.java.application.model.OperatingSystem;
import org.gzipper.java.application.util.StringUtils;
import java.io.*;
import java.util.Properties;

/*
 * Copyright (C) 2018 Matthias Fussenegger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.gzipper.java.util;



/**
 * Singleton that provides convenience when working with {@link Properties} and
 * represents the settings file that can be used globally.
 *
 * @author Matthias Fussenegger
 */
public final class Settings {

    public static final String FALSE_STRING = "false";
    public static final String TRUE_STRING = "true";

    /**
     * The actual properties file. Required to store away changed properties.
     */
    private File _propsFile;

    /**
     * The properties read from the {@link #_propsFile};
     */
    private Properties _props;

    /**
     * The default properties values for restoration.
     */
    private final Properties _defaults;

    /**
     * The operating system the JVM runs on.
     */
    private OperatingSystem _os;

    private Settings() {
        _defaults = initDefaults();
    }

    /**
     * Initializes this singleton class. This may only be called once.
     *
     * @param props the properties file to initialize this class with.
     * @param os    the current operating system.
     */
    public void init(File props, OperatingSystem os) {
        if (_props == null) {
            _os = os; // to receive environment variables
            if (props != null) {
                _propsFile = props;
                _props = new Properties(_defaults);

                try (final FileInputStream fis = new FileInputStream(props);
                     final BufferedInputStream bis = new BufferedInputStream(fis)) {
                    _props.load(bis);
                } catch (IOException ex) {
                    Log.e(ex.getLocalizedMessage(), ex);
                }
            }
        }
    }

    /**
     * Initializes the default properties values.
     *
     * @return the default properties.
     */
    private Properties initDefaults() {

        final Properties defaults = new Properties();

        defaults.setProperty("loggingEnabled", FALSE_STRING);

        defaults.setProperty("recentPath", StringUtils.EMPTY);
