-
Notifications
You must be signed in to change notification settings - Fork 22
Implement multi-branch handling #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,9 +24,10 @@ | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| import os | ||||||||||||||||||||||
| import functools | ||||||||||||||||||||||
| import shutil | ||||||||||||||||||||||
| import tempfile | ||||||||||||||||||||||
| import threading | ||||||||||||||||||||||
| from typing import Dict | ||||||||||||||||||||||
| from typing import Dict, List | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| from PySideWrapper import QtGui, QtCore, QtWidgets, QtSvg | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -45,7 +46,7 @@ | |||||||||||||||||||||
| from Widgets.addonmanager_widget_global_buttons import WidgetGlobalButtonBar | ||||||||||||||||||||||
| from Widgets.addonmanager_widget_progress_bar import Progress | ||||||||||||||||||||||
| from package_list import PackageListItemModel | ||||||||||||||||||||||
| from Addon import Addon | ||||||||||||||||||||||
| from Addon import Addon, cycle_to_sub_addon | ||||||||||||||||||||||
| from addonmanager_python_deps_gui import ( | ||||||||||||||||||||||
| PythonPackageManagerGui, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
@@ -298,7 +299,7 @@ def launch(self) -> None: | |||||||||||||||||||||
| self.composite_view.package_list.stop_loading.connect(self.stop_update) | ||||||||||||||||||||||
| self.composite_view.package_list.setEnabled(False) | ||||||||||||||||||||||
| self.composite_view.execute.connect(self.execute_macro) | ||||||||||||||||||||||
| self.composite_view.install.connect(self.launch_installer_gui) | ||||||||||||||||||||||
| self.composite_view.install.connect(self.update) | ||||||||||||||||||||||
| self.composite_view.uninstall.connect(self.remove) | ||||||||||||||||||||||
| self.composite_view.update.connect(self.update) | ||||||||||||||||||||||
| self.composite_view.update_status.connect(self.status_updated) | ||||||||||||||||||||||
|
|
@@ -440,6 +441,7 @@ def populate_packages_table(self) -> None: | |||||||||||||||||||||
| self.create_addon_list_worker = CreateAddonListWorker() | ||||||||||||||||||||||
| self.create_addon_list_worker.addon_repo.connect(self.add_addon_repo) | ||||||||||||||||||||||
| self.update_progress_bar(translate("AddonsInstaller", "Creating addon list"), 10, 100) | ||||||||||||||||||||||
| self.create_addon_list_worker.old_backups_found.connect(self.found_old_backups) | ||||||||||||||||||||||
| self.create_addon_list_worker.finished.connect(self.do_next_startup_phase) # Link to step 2 | ||||||||||||||||||||||
| self.create_addon_list_worker.start() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -600,6 +602,12 @@ def append_to_repos_list(self, repo: Addon) -> None: | |||||||||||||||||||||
| self.item_model.append_item(repo) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def update(self, repo: Addon) -> None: | ||||||||||||||||||||||
| try: | ||||||||||||||||||||||
| self.prep_for_install(repo) | ||||||||||||||||||||||
| except OSError as e: | ||||||||||||||||||||||
| fci.Console.PrintError(e) | ||||||||||||||||||||||
| fci.Console.PrintError("\n\nInstallation cancelled: out of disk space?\n") | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
| self.launch_installer_gui(repo) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def mark_repo_update_available(self, repo: Addon, available: bool) -> None: | ||||||||||||||||||||||
|
|
@@ -610,6 +618,19 @@ def mark_repo_update_available(self, repo: Addon, available: bool) -> None: | |||||||||||||||||||||
| self.item_model.reload_item(repo) | ||||||||||||||||||||||
| self.composite_view.package_details_controller.show_repo(repo) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def prep_for_install(self, installing_addon: Addon): | ||||||||||||||||||||||
| """To prepare for installing an addon, we need to see if this is the current active branch: | ||||||||||||||||||||||
| if it is not, then we need to cycle the addon's attached to this addon ID, making this one | ||||||||||||||||||||||
| active. We'll also remove any existing addon installed with this ID, making a backup | ||||||||||||||||||||||
| so that we can recover from a failed update/branch switch.""" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| for catalog_addon in self.item_model.repos: | ||||||||||||||||||||||
| if catalog_addon.name == installing_addon.name: | ||||||||||||||||||||||
| if catalog_addon != installing_addon: | ||||||||||||||||||||||
| cycle_to_sub_addon(catalog_addon, installing_addon, self.item_model) | ||||||||||||||||||||||
| break | ||||||||||||||||||||||
| make_backup(installing_addon) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def launch_installer_gui(self, addon: Addon) -> None: | ||||||||||||||||||||||
| if self.installer_gui is not None: | ||||||||||||||||||||||
| fci.Console.PrintError( | ||||||||||||||||||||||
|
|
@@ -624,6 +645,7 @@ def launch_installer_gui(self, addon: Addon) -> None: | |||||||||||||||||||||
| else: | ||||||||||||||||||||||
| self.installer_gui = AddonInstallerGUI(addon, self.item_model.repos) | ||||||||||||||||||||||
| self.installer_gui.success.connect(self.on_package_status_changed) | ||||||||||||||||||||||
| self.installer_gui.success.connect(cleanup_pre_installation_backup) | ||||||||||||||||||||||
| self.installer_gui.finished.connect(self.cleanup_installer) | ||||||||||||||||||||||
| self.installer_gui.run() # Does not block | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -743,5 +765,85 @@ def open_addons_folder(): | |||||||||||||||||||||
| QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(addons_folder)) | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||
| def found_old_backups(backups: List[str]): | ||||||||||||||||||||||
| handling = fci.Preferences().get("old_backup_handling") | ||||||||||||||||||||||
| if handling.lower().strip() == "never": | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
| if handling.lower().strip() == "always": | ||||||||||||||||||||||
| delete_old_backups(backups) | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| backup_string = ( | ||||||||||||||||||||||
| translate( | ||||||||||||||||||||||
| "AddonsInstaller", | ||||||||||||||||||||||
| f"The following auto-generated backups were found in your Mod directory:", | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| + "\n" | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| for backup in backups: | ||||||||||||||||||||||
| backup_string += "• " + str(backup) + "\n" | ||||||||||||||||||||||
| backup_string += translate("AddonsInstaller", "Do you want to delete them now?") | ||||||||||||||||||||||
| dlg = QtWidgets.QMessageBox() | ||||||||||||||||||||||
| dlg.setObjectName("AddonManager_FoundOldBackups") | ||||||||||||||||||||||
| dlg.setText(backup_string) | ||||||||||||||||||||||
| dlg.setStandardButtons( | ||||||||||||||||||||||
| QtWidgets.QMessageBox.YesToAll | ||||||||||||||||||||||
| | QtWidgets.QMessageBox.Yes | ||||||||||||||||||||||
| | QtWidgets.QMessageBox.No | ||||||||||||||||||||||
| | QtWidgets.QMessageBox.NoToAll | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| dlg.setDefaultButton(QtWidgets.QMessageBox.No) | ||||||||||||||||||||||
| dlg.button(QtWidgets.QMessageBox.YesToAll).setText( | ||||||||||||||||||||||
| translate("AddonsInstaller", "Always", "'Always' delete old backups") | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| dlg.button(QtWidgets.QMessageBox.NoToAll).setText( | ||||||||||||||||||||||
| translate("AddonsInstaller", "Never", "'Never' delete old backups") | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| result = dlg.exec_() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if result == QtWidgets.QMessageBox.NoToAll: | ||||||||||||||||||||||
| fci.Preferences().set("old_backup_handling", "never") | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
| if result == QtWidgets.QMessageBox.No: | ||||||||||||||||||||||
| return | ||||||||||||||||||||||
| if result == QtWidgets.QMessageBox.YesToAll: | ||||||||||||||||||||||
| fci.Preferences().set("old_backup_handling", "always") | ||||||||||||||||||||||
| delete_old_backups(backups) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Some utility functions | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def make_backup(addon: Addon) -> None: | ||||||||||||||||||||||
| """Make a backup of the addon's current installation directory, so that we can recover | ||||||||||||||||||||||
| from a failed update/branch switch.""" | ||||||||||||||||||||||
| original = str(os.path.join(fci.DataPaths().mod_dir, addon.name)) | ||||||||||||||||||||||
| if os.path.exists(original): | ||||||||||||||||||||||
| shutil.copytree(original, original + ".pre_update_backup", dirs_exist_ok=True) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
||||||||||||||||||||||
| backup_dir = original + ".pre_update_backup" | |
| if os.path.exists(original): | |
| if os.path.exists(backup_dir): | |
| # Warn the user and skip backup to avoid overwriting previous backup | |
| fci.Console.PrintError( | |
| f"Backup directory '{backup_dir}' already exists. Skipping backup to avoid overwriting previous backup." | |
| ) | |
| return | |
| shutil.copytree(original, backup_dir) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backup creation could fail due to permissions or disk space issues, but there's no error handling or user feedback. Consider adding try-catch and appropriate error messaging.