From 49af21a67e8556bc32bfc2a1e74807eba0e7d727 Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Thu, 22 Aug 2019 13:23:41 -0500 Subject: [PATCH] cannot have duplicate set names or rules regarding folders within a set --- resources/lib/advanced_editor.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/resources/lib/advanced_editor.py b/resources/lib/advanced_editor.py index 968c300..1272145 100644 --- a/resources/lib/advanced_editor.py +++ b/resources/lib/advanced_editor.py @@ -49,6 +49,9 @@ class BackupSetManager: #return the set at this index return {'name':keys[index],'set':self.paths[keys[index]]} + def validateSetName(self,name): + return (name not in self.getSets()) + def _writeFile(self): #create the custom file aFile = xbmcvfs.File(self.jsonFile,'w') @@ -131,12 +134,17 @@ class AdvancedBackupEditor: addFolder = self.dialog.browse(type=0,heading=utils.getString(30120),shares='files',defaultt=backupSet['root']) if(addFolder.startswith(rootPath)): - #cannot add root as an exclusion - if(optionSelected == 0 and addFolder != backupSet['root']): - backupSet['dirs'].append({"path":addFolder,"type":"exclude"}) - elif(optionSelected == 1): - #can add root as inclusion - backupSet['dirs'].append({"path":addFolder,"type":"include","recurse":True}) + + if(not any(addFolder == aDir['path'] for aDir in backupSet['dirs'])): + #cannot add root as an exclusion + if(optionSelected == 0 and addFolder != backupSet['root']): + backupSet['dirs'].append({"path":addFolder,"type":"exclude"}) + elif(optionSelected == 1): + #can add root as inclusion + backupSet['dirs'].append({"path":addFolder,"type":"include","recurse":True}) + else: + #this path is already part of another include/exclude rule + self.dialog.ok(utils.getString(30117),utils.getString(30137),addFolder) else: #folder must be under root folder self.dialog.ok(utils.getString(30117), utils.getString(30136),rootPath) @@ -173,7 +181,11 @@ class AdvancedBackupEditor: if(exitCondition == 0): newSet = self.createSet() - customPaths.addSet(newSet) + #check that the name is unique + if(customPaths.validateSetName(newSet['name'])): + customPaths.addSet(newSet) + else: + self.dialog.ok(utils.getString(30117), utils.getString(30138),newSet['name']) else: #bring up a context menu menuOption = self.dialog.select(heading=utils.getString(30124),list=[utils.getString(30122),utils.getString(30123)],preselect=0)