mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-15 04:45:49 +01:00
ui settings restore update
This commit is contained in:
parent
adc6ee0c52
commit
49b3144baa
@ -556,3 +556,15 @@ msgstr ""
|
|||||||
msgctxt "#30141"
|
msgctxt "#30141"
|
||||||
msgid "This will erase any current Advanced Editor settings"
|
msgid "This will erase any current Advanced Editor settings"
|
||||||
msgstr ""
|
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))
|
xbmcgui.Dialog().ok(utils.getString(30077),utils.getString(30078))
|
||||||
return
|
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
|
#use a multiselect dialog to select sets to restore
|
||||||
restoreSets = [n['name'] for n in valFile['directories']]
|
restoreSets = [n['name'] for n in valFile['directories']]
|
||||||
|
|
||||||
@ -313,6 +319,12 @@ class XbmcBackup:
|
|||||||
self.xbmc_vfs.set_root(fileGroup['dest'])
|
self.xbmc_vfs.set_root(fileGroup['dest'])
|
||||||
self._copyFiles(fileGroup['files'],self.remote_vfs,self.xbmc_vfs)
|
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 .....")
|
self.progressBar.updateProgress(99,"Clean up operations .....")
|
||||||
|
|
||||||
if(self.restore_point.split('.')[-1] == 'zip'):
|
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.rmfile(xbmc.translatePath("special://temp/" + self.restore_point))
|
||||||
self.xbmc_vfs.rmdir(self.remote_vfs.root_path)
|
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
|
#call update addons to refresh everything
|
||||||
xbmc.executebuiltin('UpdateLocalAddons')
|
xbmc.executebuiltin('UpdateLocalAddons')
|
||||||
|
|
||||||
@ -468,13 +475,17 @@ class XbmcBackup:
|
|||||||
remove_num = remove_num + 1
|
remove_num = remove_num + 1
|
||||||
|
|
||||||
def _createValidationFile(self,dirList):
|
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 = []
|
valDirs = []
|
||||||
|
|
||||||
for aDir in dirList:
|
for aDir in dirList:
|
||||||
valDirs.append({"name":aDir['name'],"path":aDir['source']})
|
valDirs.append({"name":aDir['name'],"path":aDir['source']})
|
||||||
valInfo['directories'] = valDirs
|
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 = xbmcvfs.File(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),'w')
|
||||||
vFile.write(json.dumps(valInfo))
|
vFile.write(json.dumps(valInfo))
|
||||||
vFile.write("")
|
vFile.write("")
|
||||||
|
@ -1,73 +1,45 @@
|
|||||||
import json
|
import json
|
||||||
import xbmc,xbmcvfs
|
import xbmc,xbmcvfs
|
||||||
from . import utils as utils
|
from . import utils as utils
|
||||||
from xml.dom import minidom
|
|
||||||
from xml.parsers.expat import ExpatError
|
|
||||||
|
|
||||||
|
|
||||||
class GuiSettingsManager:
|
class GuiSettingsManager:
|
||||||
doc = None
|
systemSettings = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#first make a copy of the file
|
# get all of the current Kodi settings
|
||||||
xbmcvfs.copy(xbmc.translatePath('special://home/userdata/guisettings.xml'), xbmc.translatePath("special://home/userdata/guisettings.xml.restored"))
|
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.systemSettings = json_response['result']['settings']
|
||||||
self._readFile(xbmc.translatePath('special://home/userdata/guisettings.xml.restored'))
|
|
||||||
|
|
||||||
def run(self):
|
def backup(self):
|
||||||
#get a list of all the settings we can manipulate via json
|
utils.log('Backing up Kodi settings')
|
||||||
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}').decode('utf-8', errors="ignore"))
|
|
||||||
|
|
||||||
settings = json_response['result']['settings']
|
# return all current settings
|
||||||
currentSettings = {}
|
return self.systemSettings
|
||||||
|
|
||||||
for aSetting in settings:
|
def restore(self, restoreSettings):
|
||||||
if('value' in aSetting):
|
utils.log('Restoring Kodi settings')
|
||||||
currentSettings[aSetting['id']] = aSetting['value']
|
|
||||||
|
|
||||||
#parse the existing xml file and get all the settings we need to restore
|
updateJson = {"jsonrpc": "2.0", "id": 1, "method": "Settings.SetSettingValue", "params": {"setting": "", "value": ""}}
|
||||||
restoreSettings = self.__parseNodes(self.doc.getElementsByTagName('setting'))
|
|
||||||
|
|
||||||
#get a list where the restore setting value != the current value
|
# create a setting=value dict of the current settings
|
||||||
updateSettings = {k: v for k, v in list(restoreSettings.items()) if (k in currentSettings and currentSettings[k] != v)}
|
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
|
restoreCount = 0
|
||||||
jsonObj = {"jsonrpc":"2.0","id":1,"method":"Settings.SetSettingValue","params":{"setting":"","value":""}}
|
for aSetting in restoreSettings:
|
||||||
for anId, aValue in list(updateSettings.items()):
|
# only update a setting if its different than the current (action types have no value)
|
||||||
utils.log("updating: " + anId + ", value: " + str(aValue))
|
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
|
updateJson['params']['setting'] = aSetting['id']
|
||||||
jsonObj['params']['value'] = aValue
|
updateJson['params']['value'] = aSetting['value']
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
xbmc.executeJSONRPC(json.dumps(updateJson))
|
||||||
|
restoreCount = restoreCount + 1
|
||||||
|
|
||||||
|
utils.log('Update %d settings' % restoreCount)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<category id="general" label="30011">
|
<category id="general" label="30011">
|
||||||
<setting id="compress_backups" type="bool" label="30087" default="false" />
|
<setting id="compress_backups" type="bool" label="30087" default="false" />
|
||||||
<setting id="backup_rotation" type="number" label="30026" default="0" />
|
<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="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" />
|
<setting id="upgrade_notes" type="number" label="upgrade_notes" visible="false" default="1" />
|
||||||
</category>
|
</category>
|
||||||
|
Loading…
Reference in New Issue
Block a user