mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
ui settings restore update
This commit is contained in:
parent
adc6ee0c52
commit
49b3144baa
@ -556,3 +556,15 @@ msgstr ""
|
||||
msgctxt "#30141"
|
||||
msgid "This will erase any current Advanced Editor settings"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30148"
|
||||
msgid "Ask before restoring Kodi UI settings"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30149"
|
||||
msgid "Restore Kodi UI Settings"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30150"
|
||||
msgid "Restore saved Kodi system settings from backup?"
|
||||
msgstr ""
|
||||
|
@ -280,6 +280,12 @@ class XbmcBackup:
|
||||
xbmcgui.Dialog().ok(utils.getString(30077),utils.getString(30078))
|
||||
return
|
||||
|
||||
# check if settings should be restored from this backup
|
||||
restoreSettings = utils.getSetting('always_prompt_restore_settings') == 'false'
|
||||
if(not restoreSettings and 'system_settings' in valFile):
|
||||
# prompt the user to restore settings yes/no
|
||||
restoreSettings = xbmcgui.Dialog().yesno(utils.getString(30149), utils.getString(30150))
|
||||
|
||||
#use a multiselect dialog to select sets to restore
|
||||
restoreSets = [n['name'] for n in valFile['directories']]
|
||||
|
||||
@ -313,6 +319,12 @@ class XbmcBackup:
|
||||
self.xbmc_vfs.set_root(fileGroup['dest'])
|
||||
self._copyFiles(fileGroup['files'],self.remote_vfs,self.xbmc_vfs)
|
||||
|
||||
# update the Kodi settings - if we can
|
||||
if('system_settings' in valFile and restoreSettings):
|
||||
self.progressBar.updateProgress(98, "Restoring Kodi settings")
|
||||
gui_settings = GuiSettingsManager()
|
||||
gui_settings.restore(valFile['system_settings'])
|
||||
|
||||
self.progressBar.updateProgress(99,"Clean up operations .....")
|
||||
|
||||
if(self.restore_point.split('.')[-1] == 'zip'):
|
||||
@ -320,11 +332,6 @@ class XbmcBackup:
|
||||
self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + self.restore_point))
|
||||
self.xbmc_vfs.rmdir(self.remote_vfs.root_path)
|
||||
|
||||
|
||||
#update the guisettings information (or what we can from it)
|
||||
gui_settings = GuiSettingsManager()
|
||||
gui_settings.run()
|
||||
|
||||
#call update addons to refresh everything
|
||||
xbmc.executebuiltin('UpdateLocalAddons')
|
||||
|
||||
@ -468,13 +475,17 @@ class XbmcBackup:
|
||||
remove_num = remove_num + 1
|
||||
|
||||
def _createValidationFile(self,dirList):
|
||||
valInfo = {"name":"XBMC Backup Validation File","xbmc_version":xbmc.getInfoLabel('System.BuildVersion'),"type":0}
|
||||
valInfo = {"name":"XBMC Backup Validation File","xbmc_version":xbmc.getInfoLabel('System.BuildVersion'),"type":0, "system_settings": []}
|
||||
valDirs = []
|
||||
|
||||
for aDir in dirList:
|
||||
valDirs.append({"name":aDir['name'],"path":aDir['source']})
|
||||
valInfo['directories'] = valDirs
|
||||
|
||||
# dump all current Kodi settings
|
||||
gui_settings = GuiSettingsManager()
|
||||
valInfo['system_settings'] = gui_settings.backup()
|
||||
|
||||
vFile = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),'w')
|
||||
vFile.write(json.dumps(valInfo))
|
||||
vFile.write("")
|
||||
|
@ -1,73 +1,45 @@
|
||||
import json
|
||||
import xbmc,xbmcvfs
|
||||
from . import utils as utils
|
||||
from xml.dom import minidom
|
||||
from xml.parsers.expat import ExpatError
|
||||
|
||||
|
||||
class GuiSettingsManager:
|
||||
doc = None
|
||||
systemSettings = None
|
||||
|
||||
def __init__(self):
|
||||
#first make a copy of the file
|
||||
xbmcvfs.copy(xbmc.translatePath('special://home/userdata/guisettings.xml'), xbmc.translatePath("special://home/userdata/guisettings.xml.restored"))
|
||||
# get all of the current Kodi settings
|
||||
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"expert"}}').decode('utf-8', errors="ignore"))
|
||||
|
||||
#read in the copy
|
||||
self._readFile(xbmc.translatePath('special://home/userdata/guisettings.xml.restored'))
|
||||
self.systemSettings = json_response['result']['settings']
|
||||
|
||||
def run(self):
|
||||
#get a list of all the settings we can manipulate via json
|
||||
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}').decode('utf-8', errors="ignore"))
|
||||
def backup(self):
|
||||
utils.log('Backing up Kodi settings')
|
||||
|
||||
settings = json_response['result']['settings']
|
||||
currentSettings = {}
|
||||
# return all current settings
|
||||
return self.systemSettings
|
||||
|
||||
for aSetting in settings:
|
||||
if('value' in aSetting):
|
||||
currentSettings[aSetting['id']] = aSetting['value']
|
||||
def restore(self, restoreSettings):
|
||||
utils.log('Restoring Kodi settings')
|
||||
|
||||
#parse the existing xml file and get all the settings we need to restore
|
||||
restoreSettings = self.__parseNodes(self.doc.getElementsByTagName('setting'))
|
||||
updateJson = {"jsonrpc": "2.0", "id": 1, "method": "Settings.SetSettingValue", "params": {"setting": "", "value": ""}}
|
||||
|
||||
#get a list where the restore setting value != the current value
|
||||
updateSettings = {k: v for k, v in list(restoreSettings.items()) if (k in currentSettings and currentSettings[k] != v)}
|
||||
# create a setting=value dict of the current settings
|
||||
settingsDict = {}
|
||||
for aSetting in self.systemSettings:
|
||||
# ignore action types, no value
|
||||
if(aSetting['type'] != 'action'):
|
||||
settingsDict[aSetting['id']] = aSetting['value']
|
||||
|
||||
#go through all the found settings and update them
|
||||
jsonObj = {"jsonrpc":"2.0","id":1,"method":"Settings.SetSettingValue","params":{"setting":"","value":""}}
|
||||
for anId, aValue in list(updateSettings.items()):
|
||||
utils.log("updating: " + anId + ", value: " + str(aValue))
|
||||
restoreCount = 0
|
||||
for aSetting in restoreSettings:
|
||||
# only update a setting if its different than the current (action types have no value)
|
||||
if(aSetting['type'] != 'action' and settingsDict[aSetting['id']] != aSetting['value']):
|
||||
utils.log('%s different than current: %s' % (aSetting['id'], str(aSetting['value'])), xbmc.LOGDEBUG)
|
||||
|
||||
jsonObj['params']['setting'] = anId
|
||||
jsonObj['params']['value'] = aValue
|
||||
|
||||
xbmc.executeJSONRPC(json.dumps(jsonObj))
|
||||
|
||||
def __parseNodes(self,nodeList):
|
||||
result = {}
|
||||
|
||||
for node in nodeList:
|
||||
nodeValue = ''
|
||||
if(node.firstChild != None):
|
||||
nodeValue = node.firstChild.nodeValue
|
||||
|
||||
#check for numbers and booleans
|
||||
if(nodeValue.isdigit()):
|
||||
nodeValue = int(nodeValue)
|
||||
elif(nodeValue == 'true'):
|
||||
nodeValue = True
|
||||
elif(nodeValue == 'false'):
|
||||
nodeValue = False
|
||||
|
||||
result[node.getAttribute('id')] = nodeValue
|
||||
|
||||
return result
|
||||
|
||||
def _readFile(self,fileLoc):
|
||||
|
||||
if(xbmcvfs.exists(fileLoc)):
|
||||
try:
|
||||
self.doc = minidom.parse(fileLoc)
|
||||
except ExpatError:
|
||||
utils.log("Can't read " + fileLoc)
|
||||
updateJson['params']['setting'] = aSetting['id']
|
||||
updateJson['params']['value'] = aSetting['value']
|
||||
|
||||
xbmc.executeJSONRPC(json.dumps(updateJson))
|
||||
restoreCount = restoreCount + 1
|
||||
|
||||
utils.log('Update %d settings' % restoreCount)
|
||||
|
@ -3,6 +3,7 @@
|
||||
<category id="general" label="30011">
|
||||
<setting id="compress_backups" type="bool" label="30087" default="false" />
|
||||
<setting id="backup_rotation" type="number" label="30026" default="0" />
|
||||
<setting id="always_prompt_restore_settings" type="bool" label="30148" default="false" />
|
||||
<setting id="progress_mode" type="enum" label="30022" lvalues="30082|30083|30084" default="0" />
|
||||
<setting id="upgrade_notes" type="number" label="upgrade_notes" visible="false" default="1" />
|
||||
</category>
|
||||
|
Loading…
Reference in New Issue
Block a user