diff --git a/src/app/commands/cmd_options.cpp b/src/app/commands/cmd_options.cpp index 80f0ce451..4ce87bd19 100644 --- a/src/app/commands/cmd_options.cpp +++ b/src/app/commands/cmd_options.cpp @@ -182,7 +182,8 @@ class OptionsWindow : public app::gen::Options { void uninstall() { ASSERT(m_extension); ASSERT(canBeUninstalled()); - App::instance()->extensions().uninstallExtension(m_extension); + App::instance()->extensions().uninstallExtension(m_extension, + DeletePluginPref::kYes); m_extension = nullptr; } @@ -1445,7 +1446,7 @@ private: // Uninstall old version if (ext->canBeUninstalled()) { - exts.uninstallExtension(ext); + exts.uninstallExtension(ext, DeletePluginPref::kNo); ExtensionItem* item = getItemByExtension(ext); if (item) diff --git a/src/app/extensions.cpp b/src/app/extensions.cpp index e97febdcd..5874c4287 100644 --- a/src/app/extensions.cpp +++ b/src/app/extensions.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2022 Igara Studio S.A. // Copyright (C) 2017-2018 David Capello // // This program is distributed under the terms of @@ -353,7 +353,7 @@ void Extension::enable(const bool state) #endif // ENABLE_SCRIPTING } -void Extension::uninstall() +void Extension::uninstall(const DeletePluginPref delPref) { if (!m_isInstalled) return; @@ -366,14 +366,15 @@ void Extension::uninstall() m_name.c_str(), m_path.c_str()); // Remove all files inside the extension path - uninstallFiles(m_path); - ASSERT(!base::is_directory(m_path)); + uninstallFiles(m_path, delPref); + ASSERT(!base::is_directory(m_path) || delPref == DeletePluginPref::kNo); m_isEnabled = false; m_isInstalled = false; } -void Extension::uninstallFiles(const std::string& path) +void Extension::uninstallFiles(const std::string& path, + const DeletePluginPref delPref) { #if 1 // Read the list of files to be uninstalled from __info.json file @@ -398,11 +399,17 @@ void Extension::uninstallFiles(const std::string& path) } } - // Delete __pref.lua file + // Delete __pref.lua file (only if specified, e.g. if the user is + // updating the extension, the preferences should be kept). + bool hasPrefFile = false; { std::string fn = base::join_path(path, kPrefLua); - if (base::is_file(fn)) - base::delete_file(fn); + if (base::is_file(fn)) { + if (delPref == DeletePluginPref::kYes) + base::delete_file(fn); + else + hasPrefFile = true; + } } std::sort(installedDirs.begin(), @@ -427,7 +434,8 @@ void Extension::uninstallFiles(const std::string& path) } TRACE("EXT: Deleting extension directory '%s'\n", path.c_str()); - base::remove_directory(path); + if (!hasPrefFile) + base::remove_directory(path); #else // The following code delete the whole "path", // we prefer the __info.json approach. @@ -439,7 +447,7 @@ void Extension::uninstallFiles(const std::string& path) base::delete_file(fn); } else if (base::is_directory(fn)) { - uninstallFiles(fn); + uninstallFiles(fn, deleteUserPref); } } @@ -860,9 +868,10 @@ void Extensions::enableExtension(Extension* extension, const bool state) generateExtensionSignals(extension); } -void Extensions::uninstallExtension(Extension* extension) +void Extensions::uninstallExtension(Extension* extension, + const DeletePluginPref delPref) { - extension->uninstall(); + extension->uninstall(delPref); generateExtensionSignals(extension); auto it = std::find(m_extensions.begin(), diff --git a/src/app/extensions.h b/src/app/extensions.h index 00b222d27..3561b0c6f 100644 --- a/src/app/extensions.h +++ b/src/app/extensions.h @@ -31,6 +31,8 @@ namespace app { std::string commonPath; }; + enum DeletePluginPref { kNo, kYes }; + class Extension { friend class Extensions; public: @@ -113,8 +115,9 @@ namespace app { private: void enable(const bool state); - void uninstall(); - void uninstallFiles(const std::string& path); + void uninstall(const DeletePluginPref delPref); + void uninstallFiles(const std::string& path, + const DeletePluginPref delPref); bool isCurrentTheme() const; bool isDefaultTheme() const; void updateCategory(const Category newCategory); @@ -172,7 +175,8 @@ namespace app { iterator end() { return m_extensions.end(); } void enableExtension(Extension* extension, const bool state); - void uninstallExtension(Extension* extension); + void uninstallExtension(Extension* extension, + const DeletePluginPref delPref); ExtensionInfo getCompressedExtensionInfo(const std::string& zipFn); Extension* installCompressedExtension(const std::string& zipFn, const ExtensionInfo& info);