Example #1
0
func getRawMoonSettings() (rawMoonSettings *rawMoonSettingsStruct) {
	rawMoonSettings = &rawMoonSettingsStruct{
		BackgroundColor:  -1,
		ForegroundColor:  -1,
		LogMaxAgeInHours: defaultLogMaxAgeInHours,
	}

	userDir, err := caravel.GetUserDirectory()
	if err != nil {
		return rawMoonSettings
	}

	userSettingsPath := filepath.Join(userDir, userSettingsFileName)
	if !caravel.FileExists(userSettingsPath) {
		return rawMoonSettings
	}

	rawSettingsBytes, err := ioutil.ReadFile(userSettingsPath)
	if err != nil {
		return rawMoonSettings
	}

	err = json.Unmarshal(rawSettingsBytes, rawMoonSettings)
	if err != nil {
		return &rawMoonSettingsStruct{}
	}

	log.Debug("Settings file content: %#v", rawMoonSettings)

	return rawMoonSettings
}
Example #2
0
func getMoonSettings() *MoonSettings {
	if moonSettings != nil {
		return moonSettings
	}

	rawMoonSettings := getRawMoonSettings()

	moonSettings = &MoonSettings{}

	if rawMoonSettings.LocalDirectory != "" {
		moonSettings.localDirectory = rawMoonSettings.LocalDirectory
	} else {
		userDir, err := caravel.GetUserDirectory()
		if err != nil {
			log.Error("Cannot retrieve the user's directory")
			os.Exit(v3.ExitCodeError)
		}

		moonSettings.localDirectory = filepath.Join(userDir, defaultLocalDirName)
	}

	moonSettings.galleryDirectory = filepath.Join(moonSettings.localDirectory, galleryDirName)
	moonSettings.logsDirectory = filepath.Join(moonSettings.localDirectory, logsDirName)

	if rawMoonSettings.BufferSize > 0 {
		moonSettings.bufferSize = rawMoonSettings.BufferSize
	} else {
		moonSettings.bufferSize = defaultBufferSize
	}

	moonSettings.loggingLevel = parseLoggingLevel(rawMoonSettings.LoggingLevel)

	moonSettings.skipAppOutput = rawMoonSettings.SkipAppOutput

	if 0 <= rawMoonSettings.BackgroundColor && rawMoonSettings.BackgroundColor <= 255 {
		moonSettings.backgroundColor = rawMoonSettings.BackgroundColor
	} else {
		moonSettings.backgroundColor = defaultBackgroundColor
	}

	if 0 <= rawMoonSettings.ForegroundColor && rawMoonSettings.ForegroundColor <= 255 {
		moonSettings.foregroundColor = rawMoonSettings.ForegroundColor
	} else {
		moonSettings.foregroundColor = defaultForegroundColor
	}

	return moonSettings
}