diff --git a/resources/lib/backup.py b/resources/lib/backup.py index d556442..1c7f313 100644 --- a/resources/lib/backup.py +++ b/resources/lib/backup.py @@ -27,6 +27,8 @@ class XbmcBackup: Backup = 0 Restore = 1 + ZIP_TEMP_PATH = None + # list of dirs for the "simple" file selection simple_directory_list = ['addons', 'addon_data', 'database', 'game_saves', 'playlists', 'profiles', 'thumbnails', 'config'] @@ -48,6 +50,7 @@ class XbmcBackup: def __init__(self): self.xbmc_vfs = XBMCFileSystem(xbmcvfs.translatePath('special://home')) + self.ZIP_TEMP_PATH = xbmcvfs.translatePath('special://temp') self.configureRemote() utils.log(utils.getString(30046)) @@ -181,13 +184,13 @@ class XbmcBackup: fileManager = FileManager(self.xbmc_vfs) # send the zip file to the real remote vfs - zip_name = self.remote_vfs.root_path[:-1] + ".zip" + zip_name = os.path.join(self.ZIP_TEMP_PATH, self.remote_vfs.root_path[:-1] + ".zip") self.remote_vfs.cleanup() - self.xbmc_vfs.rename(xbmcvfs.translatePath("special://temp/xbmc_backup_temp.zip"), xbmcvfs.translatePath("special://temp/" + zip_name)) - fileManager.addFile(xbmcvfs.translatePath("special://temp/" + zip_name)) + self.xbmc_vfs.rename(os.path.join(self.ZIP_TEMP_PATH, "xbmc_backup_temp.zip"), zip_name) + fileManager.addFile(zip_name) # set root to data dir home and reset remote - self.xbmc_vfs.set_root(xbmcvfs.translatePath("special://temp/")) + self.xbmc_vfs.set_root(self.ZIP_TEMP_PATH) self.remote_vfs = self.saved_remote_vfs # update the amount to transfer @@ -200,7 +203,7 @@ class XbmcBackup: shouldContinue = xbmcgui.Dialog().ok(utils.getString(30089), '%s\n%s' % (utils.getString(30090), utils.getString(30091))) # delete the temp zip file - self.xbmc_vfs.rmfile(xbmcvfs.translatePath("special://temp/" + zip_name)) + self.xbmc_vfs.rmfile(zip_name) # remove old backups self._rotateBackups() @@ -220,9 +223,9 @@ class XbmcBackup: utils.log("copying zip file: " + self.restore_point) # set root to data dir home - self.xbmc_vfs.set_root(xbmcvfs.translatePath("special://temp/")) - - if(not self.xbmc_vfs.exists(xbmcvfs.translatePath("special://temp/" + self.restore_point))): + self.xbmc_vfs.set_root(self.ZIP_TEMP_PATH) + restore_path = os.path.join(self.ZIP_TEMP_PATH, self.restore_point) + if(not self.xbmc_vfs.exists(restore_path)): # copy just this file from the remote vfs self.transferSize = self.remote_vfs.fileSize(self.remote_base_path + self.restore_point) zipFile = [] @@ -235,13 +238,13 @@ class XbmcBackup: utils.log("zip file exists already") # extract the zip file - zip_vfs = ZipFileSystem(xbmcvfs.translatePath("special://temp/" + self.restore_point), 'r') + zip_vfs = ZipFileSystem(restore_path, 'r') extractor = ZipExtractor() - if(not extractor.extract(zip_vfs, xbmcvfs.translatePath("special://temp/"), self.progressBar)): + if(not extractor.extract(zip_vfs, self.ZIP_TEMP_PATH, self.progressBar)): # we had a problem extracting the archive, delete everything zip_vfs.cleanup() - self.xbmc_vfs.rmfile(xbmcvfs.translatePath("special://temp/" + self.restore_point)) + self.xbmc_vfs.rmfile(restore_path) xbmcgui.Dialog().ok(utils.getString(30010), utils.getString(30101)) return @@ -250,7 +253,7 @@ class XbmcBackup: self.progressBar.updateProgress(0, utils.getString(30049) + "......") # set the new remote vfs and fix xbmc path - self.remote_vfs = XBMCFileSystem(xbmcvfs.translatePath("special://temp/" + self.restore_point.split(".")[0] + "/")) + self.remote_vfs = XBMCFileSystem(os.path.join(self.ZIP_TEMP_PATH, self.restore_point.split(".")[0])) self.xbmc_vfs.set_root(xbmcvfs.translatePath("special://home/")) # for restores remote path must exist @@ -335,7 +338,7 @@ class XbmcBackup: if(self.restore_point.split('.')[-1] == 'zip'): # delete the zip file and the extracted directory - self.xbmc_vfs.rmfile(xbmcvfs.translatePath("special://temp/" + self.restore_point)) + self.xbmc_vfs.rmfile(os.path.join(self.ZIP_TEMP_PATH, self.restore_point)) self.xbmc_vfs.rmdir(self.remote_vfs.root_path) # call update addons to refresh everything @@ -351,15 +354,16 @@ class XbmcBackup: if(mode == self.Backup and self.remote_vfs.root_path != ''): if(utils.getSettingBool("compress_backups")): # delete old temp file - if(self.xbmc_vfs.exists(xbmcvfs.translatePath('special://temp/xbmc_backup_temp.zip'))): - if(not self.xbmc_vfs.rmfile(xbmcvfs.translatePath('special://temp/xbmc_backup_temp.zip'))): + zip_path = os.path.join(self.ZIP_TEMP_PATH, 'xbmc_backup_temp.zip') + if(self.xbmc_vfs.exists(zip_path)): + if(not self.xbmc_vfs.rmfile(zip_path)): # we had some kind of error deleting the old file xbmcgui.Dialog().ok(utils.getString(30010), '%s\n%s' % (utils.getString(30096), utils.getString(30097))) return False # save the remote file system and use the zip vfs self.saved_remote_vfs = self.remote_vfs - self.remote_vfs = ZipFileSystem(xbmcvfs.translatePath("special://temp/xbmc_backup_temp.zip"), "w") + self.remote_vfs = ZipFileSystem(zip_path, "w") self.remote_vfs.set_root(self.remote_vfs.root_path + time.strftime("%Y%m%d%H%M") + "/") progressBarTitle = progressBarTitle + utils.getString(30023) + ": " + utils.getString(30016)