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"
This commit is contained in:
parent
b48c086831
commit
71dd261a50
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
};
|
||||
|
|
|
@ -341,10 +341,11 @@ void PluginsAdminDlg::collectNppCurrentStatusInfos()
|
|||
vector<PluginUpdateInfo*> PluginViewList::fromUiIndexesToPluginInfos(const std::vector<size_t>& uiIndexes) const
|
||||
{
|
||||
std::vector<PluginUpdateInfo*> 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<size_t> indexes = _availableList.getCheckedIndexes();
|
||||
vector<PluginUpdateInfo*> 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<size_t> indexes = _availableList.getCheckedIndexes();
|
||||
vector<PluginUpdateInfo*> 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<PluginUpdateInfo*>& puis)
|
||||
{
|
||||
vector<size_t> indexes = _updateList.getCheckedIndexes();
|
||||
vector<PluginUpdateInfo*> 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<size_t> indexes = _installedList.getCheckedIndexes();
|
||||
vector<PluginUpdateInfo*> 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<size_t> indexes = _updateList.getCheckedIndexes();
|
||||
vector<PluginUpdateInfo*> puis = _updateList.fromUiIndexesToPluginInfos(indexes);
|
||||
|
||||
return exitToUpdateRemovePlugins(true, puis);
|
||||
}
|
||||
|
||||
bool PluginsAdminDlg::removePlugins()
|
||||
{
|
||||
// Need to exit Notepad++
|
||||
|
||||
vector<size_t> indexes = _installedList.getCheckedIndexes();
|
||||
vector<PluginUpdateInfo*> puis = _installedList.fromUiIndexesToPluginInfos(indexes);
|
||||
|
||||
return exitToUpdateRemovePlugins(false, puis);
|
||||
}
|
||||
|
||||
bool PluginViewList::removeFromFolderName(const generic_string& folderName)
|
||||
{
|
||||
|
||||
|
|
|
@ -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<PluginUpdateInfo*>& puis);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue