def enable_mod(sim_folder, mod_folder, update_func=None): """Copies mod folder into flight sim install.""" logger.debug("Enabling mod {}".format(mod_folder)) src_folder = os.path.join(files.MOD_CACHE_FOLDER, mod_folder) dest_folder = os.path.join(sim_mod_folder(sim_folder), mod_folder) # move mod to sim files.move_folder(src_folder, dest_folder, update_func=update_func) return True
def disable_mod(sim_folder, mod_folder, update_func=None): """Copies mod folder into mod cache.""" logger.debug("Disabling mod {}".format(mod_folder)) files.create_mod_cache_folder() src_folder = os.path.join(sim_mod_folder(sim_folder), mod_folder) dest_folder = os.path.join(files.MOD_CACHE_FOLDER, mod_folder) # move mod to mod cache files.move_folder(src_folder, dest_folder, update_func=update_func) return True
def disable_mod(self, folder, update_func=None): """Deletes symlink/dopies mod folder into mod install location.""" logger.debug("Disabling mod {}".format(folder)) src_folder = self.get_mod_folder(folder, enabled=True) dest_folder = self.get_mod_folder(folder, enabled=False) if files.is_symlink(src_folder): # delete symlink files.delete_symlink(src_folder, update_func=update_func) else: # move mod to mod install location files.move_folder(src_folder, dest_folder, update_func=update_func) return True
def install_mods(self, folder, update_func=None, delete=False, percent_func=None): """Extracts and installs a new mod.""" logger.debug("Installing mod {}".format(folder)) # determine the mods inside the extracted archive mod_folders = self.determine_mod_folders(folder, update_func=update_func) installed_mods = [] for i, mod_folder in enumerate(mod_folders): # get the base folder name base_mod_folder = os.path.basename(mod_folder) install_folder = os.path.join(files.get_mod_install_folder(), base_mod_folder) dest_folder = os.path.join(self.get_sim_mod_folder(), base_mod_folder) # copy mod to install dir if delete: files.move_folder(mod_folder, install_folder, update_func=update_func) else: files.copy_folder(mod_folder, install_folder, update_func=update_func) # create the symlink to the sim files.create_symlink(install_folder, dest_folder) if percent_func: percent_func((i, len(mod_folders))) installed_mods.append(base_mod_folder) # clear the cache of the mod function self.clear_mod_cache() # return installed mods list return installed_mods
def install_mods(sim_folder, extracted_archive, update_func=None): """Extracts and installs a new mod.""" logger.debug("Installing mod {}".format(extracted_archive)) # determine the mods inside the extracted archive mod_folders = determine_mod_folders(extracted_archive, update_func=update_func) installed_mods = [] for mod_folder in mod_folders: # get the base folder name base_mod_folder = os.path.basename(mod_folder) dest_folder = os.path.join(sim_mod_folder(sim_folder), base_mod_folder) # move mod to sim files.move_folder(mod_folder, dest_folder, update_func=update_func) installed_mods.append(base_mod_folder) # return installed mods list return installed_mods
def move_mod_install_folder( self, src: str, dest: str, update_func: Callable = None ) -> None: """Moves the mod install folder.""" logger.debug("Moving mod install folder from {} to {}".format(src, dest)) # first, build a list of the currently enabled mods enabled_mod_folders = files.listdir_dirs(self.get_sim_mod_folder()) # move the install folder files.move_folder(src, dest, update_func=update_func) # set new config value config.set_key_value(config.MOD_INSTALL_FOLDER_KEY, dest, path=True) # clear the cache self.clear_mod_cache() config.get_key_value.cache_clear() # now, go through mods in the install folder and re-enable them # if they were enabled before. moved_mod_folders = files.listdir_dirs(dest) for mod_folder in moved_mod_folders: if mod_folder in enabled_mod_folders: self.enable_mod(mod_folder, update_func=update_func)