From 71dd261a50e17cad1142b6e1a8ea16e20a2d059e Mon Sep 17 00:00:00 2001 From: Don HO Date: Thu, 13 Sep 2018 23:07:22 +0200 Subject: [PATCH] Plugin Admin: Change the way to remove & update plugin uninstall: tell user to restart Notepad++ - Gup.exe remove all - clean in batch - relaunch Notepad++ gup.exe -clean "appPath2Launch" "dest_folder" "fold1" "a fold2" "fold3" gup.exe -clean "c:\npp\notepad++.exe" "c:\temp\" "toto" "ti ti" "tata" update: tell user to restart Notepad++ - Gup.exe download - remove all in directory - unzip/clean in batch - relaunch Notepad++ gup.exe -unzip -clean "appPath2Launch" "dest_folder" "toto http://toto" "titi http://titi" "tata http://tata" gup.exe -unzip -clean "c:\npp\notepad++.exe" c:\temp\ "toto http://toto" "ti et ti http://titi" "tata http://tata" Install: GUp.exe download - create directory - unzip: one by one, no relaunch gup.exe -unzipTo c:\donho\notepad++\plugins "https://github.com/npp-plugins/mimetools/releases/download/v2.1/mimetools.v2.1.zip" --- PowerEditor/src/NppBigSwitch.cpp | 7 + PowerEditor/src/Parameters.h | 14 ++ .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 154 ++++++++++-------- .../WinControls/PluginsAdmin/pluginsAdmin.h | 2 + 4 files changed, 105 insertions(+), 72 deletions(-) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index a24ed01bc..c9adcb21d 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1832,6 +1832,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa //Sends WM_DESTROY, Notepad++ will end if (message == WM_CLOSE) ::DestroyWindow(hwnd); + + generic_string updaterFullPath = pNppParam->getWingupFullPath(); + if (!updaterFullPath.empty()) + { + Process updater(updaterFullPath.c_str(), pNppParam->getWingupParams().c_str(), pNppParam->getWingupDir().c_str()); + updater.run(); + } } return TRUE; } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 251a95608..d1fbec616 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1745,6 +1745,19 @@ private: generic_string _initialCloudChoice; + generic_string _wingupFullPath; + generic_string _wingupParams; + generic_string _wingupDir; + +public: + generic_string getWingupFullPath() const { return _wingupFullPath; }; + generic_string getWingupParams() const { return _wingupParams; }; + generic_string getWingupDir() const { return _wingupDir; }; + void setWingupFullPath(const generic_string& val2set) { _wingupFullPath = val2set; }; + void setWingupParams(const generic_string& val2set) { _wingupParams = val2set; }; + void setWingupDir(const generic_string& val2set) { _wingupDir = val2set; }; + +private: void getLangKeywordsFromXmlTree(); bool getUserParametersFromXmlTree(); bool getUserStylersFromXmlTree(); @@ -1803,4 +1816,5 @@ private: int getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, generic_string menuEntryName, generic_string menuItemName); // return -1 if not found int getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, generic_string pluginName, generic_string pluginCmdName); // return -1 if not found winVer getWindowsVersion(); + }; diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index 4e7fdf9fc..f469e19c3 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -341,10 +341,11 @@ void PluginsAdminDlg::collectNppCurrentStatusInfos() vector PluginViewList::fromUiIndexesToPluginInfos(const std::vector& uiIndexes) const { std::vector r; + size_t nb = _ui.nbItem(); for (auto i : uiIndexes) { - if (i < _ui.nbItem()) + if (i < nb) { r.push_back(getPluginInfoFromUiIndex(i)); } @@ -378,12 +379,8 @@ PluginsAdminDlg::PluginsAdminDlg() ; } -bool PluginsAdminDlg::installPlugins() +generic_string PluginsAdminDlg::getPluginsPath() const { - vector indexes = _availableList.getCheckedIndexes(); - vector puis = _availableList.fromUiIndexesToPluginInfos(indexes); - - generic_string updaterParams = TEXT("-unzipTo "); NppParameters *pNppParameters = NppParameters::getInstance(); generic_string nppPluginsDir; @@ -403,6 +400,18 @@ bool PluginsAdminDlg::installPlugins() ::CreateDirectory(nppPluginsDir.c_str(), NULL); } + return nppPluginsDir; +} + +bool PluginsAdminDlg::installPlugins() +{ + vector indexes = _availableList.getCheckedIndexes(); + vector puis = _availableList.fromUiIndexesToPluginInfos(indexes); + + generic_string updaterParams = TEXT("-unzipTo "); + + generic_string nppPluginsDir = getPluginsPath(); + generic_string quoted_nppPluginsDir = TEXT("\""); quoted_nppPluginsDir += nppPluginsDir; quoted_nppPluginsDir += TEXT("\""); @@ -437,52 +446,8 @@ bool PluginsAdminDlg::installPlugins() return true; } -bool PluginsAdminDlg::updatePlugins() +bool PluginsAdminDlg::exitToUpdateRemovePlugins(bool isUpdate, const vector& puis) { - vector indexes = _updateList.getCheckedIndexes(); - vector puis = _updateList.fromUiIndexesToPluginInfos(indexes); - - NppParameters *pNppParameters = NppParameters::getInstance(); - generic_string updaterDir = pNppParameters->getNppPath(); - updaterDir += TEXT("\\updater\\"); - - generic_string updaterFullPath = updaterDir + TEXT("gup.exe"); - generic_string updaterParams = TEXT("-unzipTo "); - - for (auto i : puis) - { - // add folder to operate - generic_string destFolder = pNppParameters->getAppDataNppDir(); - PathAppend(destFolder, i->_folderName); - - updaterParams += destFolder; - - // add zipFile's url - updaterParams += TEXT(" "); - updaterParams += i->_repository; - - Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str()); - int result = updater.runSync(); - if (result == 0) // wingup return 0 -> OK - { - // Remove updated plugin from update list - _updateList.removeFromPluginInfoPtr(i); - - } - else // wingup return non-zero (-1) -> Not OK - { - // just move on - } - } - - return true; -} - -bool PluginsAdminDlg::removePlugins() -{ - vector indexes = _installedList.getCheckedIndexes(); - vector puis = _updateList.fromUiIndexesToPluginInfos(indexes); - NppParameters *pNppParameters = NppParameters::getInstance(); generic_string updaterDir = pNppParameters->getNppPath(); updaterDir += TEXT("\\updater\\"); @@ -490,38 +455,83 @@ bool PluginsAdminDlg::removePlugins() generic_string updaterFullPath = updaterDir + TEXT("gup.exe"); generic_string updaterParams = TEXT("-clean "); + if (isUpdate) // not clean + updaterParams += TEXT("-unzipTo "); + + TCHAR nppFullPath[MAX_PATH]; + ::GetModuleFileName(NULL, nppFullPath, MAX_PATH); + updaterParams += nppFullPath; + updaterParams += TEXT("\" "); + + updaterParams += TEXT("\""); + updaterParams += getPluginsPath(); + updaterParams += TEXT("\""); + for (auto i : puis) { - // add folder to operate - generic_string destFolder = pNppParameters->getAppDataNppDir(); - PathAppend(destFolder, i->_folderName); - - updaterParams += destFolder; - - Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str()); - int result = updater.runSync(); - if (result == 0) // wingup return 0 -> OK + if (isUpdate) { - // Remove removed plugin from installed list - _installedList.removeFromPluginInfoPtr(i); - - // Remove removed plugin from update list eventually - _updateList.removeFromFolderName(i->_folderName); - - // Add removed plugin back to available list (if available) - _availableList.restore(i->_folderName); - + // add folder to operate + updaterParams += TEXT(" \""); + updaterParams += i->_folderName; + updaterParams += TEXT(" "); + updaterParams += i->_repository; + updaterParams += TEXT("\""); } - else // wingup return non-zero (-1) -> Not OK + else // clean { - // just move on - + // add folder to operate + updaterParams += TEXT(" \""); + updaterParams += i->_folderName; + updaterParams += TEXT("\""); } } + // Ask user's confirmation + auto res = ::MessageBox(NULL, TEXT("If you click YES, you will quit Notepad++ to continue the operations.\nNotepad++ will be restarted after all the operations are terminated.\nContinue?"), TEXT("Notepad++ is about to exit"), MB_YESNO); + if (res == IDYES) + { + NppParameters *pNppParam = NppParameters::getInstance(); + + // gup path: makes trigger ready + pNppParam->setWingupFullPath(updaterFullPath); + + // op: -clean or "-clean -unzip" + // application path: Notepad++ path to be relaunched + // plugin global path + // plugin names or "plugin names + download url" + pNppParam->setWingupParams(updaterParams); + + // gup folder path + pNppParam->setWingupDir(updaterDir); + + // Quite Notepad++ so just before quitting Notepad++ launches gup with needed arguments + ::PostMessage(_hParent, WM_COMMAND, IDM_FILE_EXIT, 0); + } + return true; } +bool PluginsAdminDlg::updatePlugins() +{ + // Need to exit Notepad++ + + vector indexes = _updateList.getCheckedIndexes(); + vector puis = _updateList.fromUiIndexesToPluginInfos(indexes); + + return exitToUpdateRemovePlugins(true, puis); +} + +bool PluginsAdminDlg::removePlugins() +{ + // Need to exit Notepad++ + + vector indexes = _installedList.getCheckedIndexes(); + vector puis = _installedList.fromUiIndexesToPluginInfos(indexes); + + return exitToUpdateRemovePlugins(false, puis); +} + bool PluginViewList::removeFromFolderName(const generic_string& folderName) { diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h index a0af53879..ee11ed96f 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h @@ -154,6 +154,7 @@ public : bool updateListAndLoadFromJson(); void setAdminMode(bool isAdm) { _nppCurrentStatus._isAdminMode = isAdm; }; + generic_string getPluginsPath() const; bool installPlugins(); bool updatePlugins(); @@ -192,5 +193,6 @@ private : bool loadFromPluginInfos(); bool checkUpdates(); + bool exitToUpdateRemovePlugins(bool isUpdate, const std::vector& puis); };