mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-12-22 14:05:23 +01:00
Guisettings fix (#156)
fix guisettings restore issues - thanks Bluerayx
This commit is contained in:
parent
b34e538d6b
commit
5d9d8a1820
@ -321,10 +321,10 @@ 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)
|
||||||
|
|
||||||
if(utils.getSetting("backup_config") == "true"):
|
|
||||||
#update the guisettings information (or what we can from it)
|
#update the guisettings information (or what we can from it)
|
||||||
gui_settings = GuiSettingsManager('special://home/userdata/guisettings.xml')
|
gui_settings = GuiSettingsManager('special://home/userdata/guisettings.xml')
|
||||||
gui_settings.run()
|
gui_settings.run()
|
||||||
|
|
||||||
#call update addons to refresh everything
|
#call update addons to refresh everything
|
||||||
xbmc.executebuiltin('UpdateLocalAddons')
|
xbmc.executebuiltin('UpdateLocalAddons')
|
||||||
|
@ -8,8 +8,6 @@ import xbmc,xbmcvfs
|
|||||||
class GuiSettingsManager:
|
class GuiSettingsManager:
|
||||||
settingsFile = None
|
settingsFile = None
|
||||||
doc = None
|
doc = None
|
||||||
settings_allowed = list()
|
|
||||||
found_settings = list()
|
|
||||||
|
|
||||||
def __init__(self,settingsFile):
|
def __init__(self,settingsFile):
|
||||||
self._readFile(xbmc.translatePath(settingsFile))
|
self._readFile(xbmc.translatePath(settingsFile))
|
||||||
@ -19,32 +17,24 @@ class GuiSettingsManager:
|
|||||||
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}'))
|
json_response = json.loads(xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.GetSettings","params":{"level":"advanced"}}'))
|
||||||
|
|
||||||
settings = json_response['result']['settings']
|
settings = json_response['result']['settings']
|
||||||
|
settingsAllowed = []
|
||||||
for aSetting in settings:
|
|
||||||
self.settings_allowed.append(aSetting['id'])
|
|
||||||
|
|
||||||
#parse the existing xml file and get all the settings
|
|
||||||
root_nodes = self.__parseNodes(self.doc.documentElement)
|
|
||||||
|
|
||||||
for aNode in root_nodes:
|
for aSetting in settings:
|
||||||
secondary_list = self.__parseNodes(self.doc.getElementsByTagName(aNode.name)[0])
|
settingsAllowed.append(aSetting['id'])
|
||||||
|
|
||||||
for secondNode in secondary_list:
|
#parse the existing xml file and get all the settings we need to update
|
||||||
#if the node does not have children and is not default
|
updateSettings = self.__parseNodes(self.doc.getElementsByTagName('setting'))
|
||||||
if(not secondNode.hasChildren and not secondNode.isDefault):
|
|
||||||
|
|
||||||
if(secondNode.json_name() in self.settings_allowed):
|
|
||||||
self.found_settings.append(secondNode)
|
|
||||||
|
|
||||||
#go through all the found settings and update them
|
#go through all the found settings and update them
|
||||||
for aSetting in self.found_settings:
|
for aSetting in updateSettings:
|
||||||
utils.log("updating: " + aSetting.json_name() + ", value: " + aSetting.value)
|
if(aSetting.name in settingsAllowed):
|
||||||
|
utils.log("updating: " + aSetting.name + ", value: " + aSetting.value)
|
||||||
|
|
||||||
#check for boolean and numeric values
|
#check for boolean and numeric values
|
||||||
if(aSetting.value.isdigit() or (aSetting.value == 'true' or aSetting.value == 'false')):
|
if(aSetting.value.isdigit() or (aSetting.value == 'true' or aSetting.value == 'false')):
|
||||||
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.SetSettingValue","params":{"setting":"' + aSetting.json_name() + '","value":' + aSetting.value + '}}')
|
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.SetSettingValue","params":{"setting":"' + aSetting.name + '","value":' + aSetting.value + '}}')
|
||||||
else:
|
else:
|
||||||
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.SetSettingValue","params":{"setting":"' + aSetting.json_name() + '","value":"' + utils.encode(aSetting.value) + '"}}')
|
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "id":1, "method":"Settings.SetSettingValue","params":{"setting":"' + aSetting.name + '","value":"' + utils.encode(aSetting.value) + '"}}')
|
||||||
|
|
||||||
#make a copy of the guisettings file to make user based restores easier
|
#make a copy of the guisettings file to make user based restores easier
|
||||||
xbmcvfs.copy(self.settingsFile, xbmc.translatePath("special://home/userdata/guisettings.xml.restored"))
|
xbmcvfs.copy(self.settingsFile, xbmc.translatePath("special://home/userdata/guisettings.xml.restored"))
|
||||||
@ -52,28 +42,16 @@ class GuiSettingsManager:
|
|||||||
def __parseNodes(self,nodeList):
|
def __parseNodes(self,nodeList):
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
for node in nodeList.childNodes:
|
for node in nodeList:
|
||||||
if(node.nodeType == self.doc.ELEMENT_NODE):
|
#only add if it's not a default setting
|
||||||
aSetting = SettingNode(node.nodeName)
|
if('default' not in node.attributes.keys()):
|
||||||
|
aSetting = SettingNode(node.getAttribute('id'),node.firstChild.nodeValue)
|
||||||
|
aSetting.isDefault = False
|
||||||
|
|
||||||
#detect if there are any element nodes
|
|
||||||
if(len(node.childNodes) > 0):
|
|
||||||
for child_node in node.childNodes:
|
|
||||||
if(child_node.nodeType == self.doc.ELEMENT_NODE):
|
|
||||||
aSetting.hasChildren = True
|
|
||||||
|
|
||||||
if(not aSetting.hasChildren and len(node.childNodes) > 0):
|
|
||||||
aSetting.value = node.firstChild.nodeValue
|
|
||||||
|
|
||||||
if('default' not in node.attributes.keys()):
|
|
||||||
aSetting.isDefault = False
|
|
||||||
|
|
||||||
aSetting.parent = node.parentNode.nodeName
|
|
||||||
|
|
||||||
result.append(aSetting)
|
result.append(aSetting)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _readFile(self,fileLoc):
|
def _readFile(self,fileLoc):
|
||||||
|
|
||||||
if(xbmcvfs.exists(fileLoc)):
|
if(xbmcvfs.exists(fileLoc)):
|
||||||
@ -86,14 +64,16 @@ class GuiSettingsManager:
|
|||||||
class SettingNode:
|
class SettingNode:
|
||||||
name = ''
|
name = ''
|
||||||
value = ''
|
value = ''
|
||||||
hasChildren = False
|
|
||||||
isDefault = True
|
isDefault = True
|
||||||
parent = ''
|
|
||||||
|
|
||||||
def __init__(self,name):
|
def __init__(self,name,value):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.value= value
|
||||||
|
|
||||||
def json_name(self):
|
def __str__(self):
|
||||||
return self.parent + "." + self.name
|
return "%s : %s" % (self.name,self.value)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self.__str__()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user