def restore_colortheme(self): '''restore zipbackup of colortheme to colorthemes folder''' zip_path = xbmcgui.Dialog().browse( 1, self.addon.getLocalizedString(32030), "files", ".zip") if zip_path and zip_path.endswith(".zip"): # create temp path temp_path = try_encode('special://temp/skinbackup/') temp_zip = try_encode("special://temp/colortheme.zip") if xbmcvfs.exists(temp_path): recursive_delete_dir(temp_path) xbmcvfs.mkdir(temp_path) # unzip to temp xbmcvfs.copy(zip_path, temp_zip) unzip_fromfile(temp_zip, temp_path) for filename in xbmcvfs.listdir(temp_path)[1]: filename = filename.decode("utf-8") sourcefile = os.path.join(temp_path, filename) destfile = os.path.join(self.userthemes_path, filename) xbmcvfs.copy(sourcefile, destfile) # cleanup temp xbmcvfs.delete(temp_zip) recursive_delete_dir(temp_path) xbmcgui.Dialog().ok(self.addon.getLocalizedString(32026), self.addon.getLocalizedString(32027))
def restore(self, filename="", silent=False): '''restore skin settings from file''' if not filename: filename = self.get_restorefilename() #skip if filename is not a zip file if not filename.endswith("zip"): return progressdialog = None if not silent: progressdialog = xbmcgui.DialogProgress( self.addon.getLocalizedString(32006)) progressdialog.create(self.addon.getLocalizedString(32007)) if filename and xbmcvfs.exists(filename): # create temp path temp_path = self.create_temp() if not filename.endswith("zip"): # assume that passed filename is actually a skinsettings file skinsettingsfile = filename else: # copy zip to temp directory and unzip skinsettingsfile = temp_path + "guisettings.txt" if progressdialog: progressdialog.update(0, "unpacking backup...") zip_temp = try_encode( '%sskinbackup-%s.zip' % (ADDON_DATA, datetime.now().strftime('%Y-%m-%d-%H-%M'))) copy_file(filename, zip_temp, True) unzip_fromfile(zip_temp, temp_path) delete_file(zip_temp) # copy skinshortcuts preferences self.restore_skinshortcuts(temp_path) # restore any custom skin images or themes for directory in ["custom_images/", "themes/"]: custom_images_folder = try_encode( "special://profile/addon_data/%s/%s" % (xbmc.getSkinDir(), directory)) custom_images_folder_temp = temp_path + directory if xbmcvfs.exists(custom_images_folder_temp): for file in xbmcvfs.listdir( custom_images_folder_temp)[1]: xbmcvfs.copy(custom_images_folder_temp + file, custom_images_folder + file) # restore guisettings if xbmcvfs.exists(skinsettingsfile): self.restore_guisettings(skinsettingsfile, progressdialog) # cleanup temp recursive_delete_dir(temp_path) progressdialog.close() if not silent: xbmcgui.Dialog().ok(self.addon.getLocalizedString(32006), self.addon.getLocalizedString(32009))
def create_temp(): temp_path = u'%stemp/' % ADDON_DATA # workaround weird slashes behaviour on some platforms. temp_path = temp_path.replace("//","/").replace("special:/","special://") if xbmcvfs.exists(temp_path): recursive_delete_dir(temp_path) xbmc.sleep(2000) xbmcvfs.mkdirs(temp_path) xbmcvfs.mkdirs(temp_path + "skinbackup/") return temp_path
def backup(self, filters=None, backup_file="", silent=False): '''create skin backup''' if not filters: filters = [] if not backup_file: return # create temp path temp_path = self.create_temp() zip_temp = try_encode( '%sskinbackup-%s.zip' % (temp_path, datetime.now().strftime('%Y-%m-%d %H.%M'))) temp_path = temp_path + "skinbackup/" # backup skinshortcuts preferences if not filters or (filters and "skinshortcuts" in filters): self.backup_skinshortcuts(temp_path + "skinshortcuts/") # backup skin settings if "skinshortcutsonly" not in filters: skinsettings_path = os.path.join(temp_path, try_encode("guisettings.txt")) self.backup_skinsettings(skinsettings_path, filters, temp_path) # zip the backup if sys.version_info.major == 3: zip_temp = try_decode(xbmcvfs.translatePath(zip_temp)) else: zip_temp = try_decode(xbmc.translatePath(zip_temp)) zip_tofile(temp_path, zip_temp) # copy file to destination - wait until it's really copied xbmc.log("Skin Helper Backup --> Saving Backup to %s" % backup_file, level=xbmc.LOGINFO) copy_file(zip_temp, backup_file, True) if not xbmcvfs.exists(backup_file): if not silent: raise IOError('Failed to copy ' + zip_temp + " to " + backup_file) # cleanup temp recursive_delete_dir(temp_path) xbmcvfs.delete(zip_temp) # clean old backups self.clean_oldbackups() self.create_temp() # show success message if not silent: xbmcgui.Dialog().ok(self.addon.getLocalizedString(32004), self.addon.getLocalizedString(32005))
def backup(self, filters=None, backup_file="", silent=False): '''create skin backup''' if not filters: filters = [] if not backup_file: return # create temp path temp_path = self.create_temp() zip_temp = '%s/skinbackup-%s.zip' % ( temp_path, datetime.now().strftime('%Y-%m-%d %H.%M')) temp_path = temp_path + "skinbackup/" # backup skinshortcuts preferences if not filters or (filters and "skinshortcuts" in filters): self.backup_skinshortcuts(temp_path + "skinshortcuts/") # backup skin settings if "skinshortcutsonly" not in filters: skinsettings_path = os.path.join(temp_path, "guisettings.txt") self.backup_skinsettings(skinsettings_path, filters, temp_path) # zip the backup zip_temp = xbmcvfs.translatePath(zip_temp) zip_tofile(temp_path, zip_temp) # copy file to destination - wait untill it's really copied copy_file(zip_temp, backup_file, True) # cleanup temp recursive_delete_dir(temp_path) xbmcvfs.delete(zip_temp) # show success message if not silent: xbmcgui.Dialog().ok(self.addon.getLocalizedString(32004), self.addon.getLocalizedString(32005))
def deletedir(self): '''helper to delete a directory, input can be normal filesystem path or vfs''' del_path = self.params.get("path") if del_path: ret = xbmcgui.Dialog().yesno(heading=xbmc.getLocalizedString(122), line1="%s[CR]%s" % (xbmc.getLocalizedString(125), del_path)) if ret: success = recursive_delete_dir(del_path) if success: xbmcgui.Dialog().ok(heading=xbmc.getLocalizedString(19179), line1=self.addon.getLocalizedString(32014)) else: xbmcgui.Dialog().ok(heading=xbmc.getLocalizedString(16205), line1=xbmc.getLocalizedString(32015))