/** Saves the current Settings properties to the config file */
  public static void saveSettings() {
    if (!CONFIG_FILE_LOCATION.exists()) {
      try {
        LOGGER.debug(
            "Trying to create new settings file at {}", CONFIG_FILE_LOCATION.getAbsolutePath());
        CONFIG_FILE_LOCATION.createNewFile();
      } catch (IOException e) {
        LOGGER.error(
            "Could not create settings file at {}", CONFIG_FILE_LOCATION.getAbsolutePath(), e);
        throw ExceptionUtil.getRuntimeException(
            "exceptions.settings.create", e, CONFIG_FILE_LOCATION.getAbsolutePath());
      }
    }

    Properties properties = getAsProperties(settings);
    try {
      LOGGER.debug("Saving properties to settings file");
      properties.store(
          new FileOutputStream(CONFIG_FILE_LOCATION), "Settings file for YouTrack worklog viewer");
    } catch (IOException e) {
      LOGGER.error("Could not save settings to {}", CONFIG_FILE_LOCATION.getAbsolutePath(), e);
      throw ExceptionUtil.getRuntimeException(
          "exceptions.settings.write", e, CONFIG_FILE_LOCATION.getAbsolutePath());
    }
  }
  /**
   * Loads the user settings for the config file if present if not it returns the default settings
   *
   * @return the loaded Settings object
   */
  public static Settings loadSettings() {
    if (settings == null) {
      settings = new Settings();

      if (CONFIG_FILE_LOCATION.exists()) {
        LOGGER.debug("Loading configuration from {}", CONFIG_FILE_LOCATION.getAbsolutePath());
        Properties properties = new Properties();
        try {
          properties.load(new FileInputStream(CONFIG_FILE_LOCATION));
          applyFromPropertiesToSettings(settings, properties);
        } catch (IOException e) {
          LOGGER.error(
              "Could not read settings from {}", CONFIG_FILE_LOCATION.getAbsolutePath(), e);
          throw ExceptionUtil.getRuntimeException(
              "exceptions.settings.read", e, CONFIG_FILE_LOCATION.getAbsolutePath());
        }
      }
    }

    return settings;
  }