2020-02-20 14:42:12 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os.path as path
|
|
|
|
from os import mkdir, rmdir
|
|
|
|
import json
|
|
|
|
|
|
|
|
import deemix.utils.localpaths as localpaths
|
|
|
|
|
|
|
|
settings = {}
|
2020-02-22 11:59:42 +00:00
|
|
|
defaultSettings = {}
|
2020-02-20 14:42:12 +00:00
|
|
|
|
|
|
|
def initSettings():
|
|
|
|
global settings
|
2020-02-22 11:59:42 +00:00
|
|
|
global defaultSettings
|
2020-02-20 14:42:12 +00:00
|
|
|
currentFolder = path.abspath(path.dirname(__file__))
|
|
|
|
configFolder = localpaths.getConfigFolder()
|
2020-02-22 11:59:42 +00:00
|
|
|
if not path.isdir(configFolder):
|
|
|
|
mkdir(configFolder)
|
|
|
|
with open(path.join(currentFolder, 'default.json'), 'r') as d:
|
|
|
|
defaultSettings = json.load(d)
|
2020-02-20 14:42:12 +00:00
|
|
|
if not path.isfile(path.join(configFolder, 'config.json')):
|
|
|
|
with open(path.join(configFolder, 'config.json'), 'w') as f:
|
2020-02-27 17:52:19 +00:00
|
|
|
json.dump(defaultSettings, f, indent=2)
|
2020-02-20 14:42:12 +00:00
|
|
|
with open(path.join(configFolder, 'config.json'), 'r') as configFile:
|
|
|
|
settings = json.load(configFile)
|
2020-02-22 11:59:42 +00:00
|
|
|
settingsCheck()
|
|
|
|
if settings['downloadLocation'] == "":
|
|
|
|
settings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music')
|
2020-02-20 14:42:12 +00:00
|
|
|
saveSettings(settings)
|
2020-02-22 11:59:42 +00:00
|
|
|
if not path.isdir(settings['downloadLocation']):
|
2020-02-22 14:52:36 +00:00
|
|
|
mkdir(settings['downloadLocation'])
|
2020-02-20 14:42:12 +00:00
|
|
|
return settings
|
|
|
|
|
|
|
|
def getSettings():
|
|
|
|
global settings
|
|
|
|
return settings
|
|
|
|
|
|
|
|
def saveSettings(newSettings):
|
|
|
|
global settings
|
|
|
|
settings = newSettings
|
|
|
|
with open(path.join(localpaths.getConfigFolder(), 'config.json'), 'w') as configFile:
|
2020-02-27 17:49:35 +00:00
|
|
|
json.dump(settings, configFile, indent=2)
|
2020-02-20 14:42:12 +00:00
|
|
|
return True
|
2020-02-22 11:59:42 +00:00
|
|
|
|
|
|
|
def settingsCheck():
|
|
|
|
global settings
|
|
|
|
global defaultSettings
|
|
|
|
changes = 0
|
|
|
|
for x in defaultSettings:
|
|
|
|
if not x in settings or type(settings[x]) != type(defaultSettings[x]):
|
|
|
|
settings[x] = defaultSettings[x]
|
|
|
|
changes+=1
|
|
|
|
for x in defaultSettings['tags']:
|
|
|
|
if not x in settings['tags'] or type(settings['tags'][x]) != type(defaultSettings['tags'][x]):
|
|
|
|
settings['tags'][x] = defaultSettings['tags'][x]
|
|
|
|
changes+=1
|
|
|
|
if changes > 0:
|
|
|
|
saveSettings(settings)
|