mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-31 01:34:58 +02:00
Change Plugins Admin installation behaviour
Old installation behaviour is loading installed plugins without restart Notepad++, which could make some plugins loading uncomplete. New behaviour use the same implementation of plugin updating, witch quit notepad++ for plugin installation then restart Notepad++.
This commit is contained in:
parent
fdf954f714
commit
ee763ca0ad
@ -486,129 +486,25 @@ generic_string PluginsAdminDlg::getPluginsPath() const
|
|||||||
return nppPluginsDir;
|
return nppPluginsDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PluginsAdminDlg::exitToInstallRemovePlugins(Operation op, const vector<PluginUpdateInfo*>& puis)
|
||||||
DWORD WINAPI PluginsAdminDlg::launchPluginInstallerThread(void* params)
|
|
||||||
{
|
{
|
||||||
auto lwp = static_cast<LaunchWingupParams*>(params);
|
generic_string opStr;
|
||||||
|
if (op == pa_install)
|
||||||
|
opStr = TEXT("-unzipTo ");
|
||||||
|
else if (op == pa_update)
|
||||||
|
opStr = TEXT("-unzipTo -clean ");
|
||||||
|
else if (op == pa_remove)
|
||||||
|
opStr = TEXT("-clean ");
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
Process updater(lwp->_updaterFullPath.c_str(), lwp->_updaterParams.c_str(), lwp->_updaterDir.c_str());
|
|
||||||
|
|
||||||
int result = updater.runSync();
|
|
||||||
|
|
||||||
if (result == 0) // wingup return 0 -> OK
|
|
||||||
{
|
|
||||||
generic_string installedPluginPath = lwp->_nppPluginsDir;
|
|
||||||
PathAppend(installedPluginPath, lwp->_pluginUpdateInfo->_folderName + TEXT(".dll"));
|
|
||||||
|
|
||||||
// check installed dll
|
|
||||||
if (!::PathFileExists(installedPluginPath.c_str()))
|
|
||||||
{
|
|
||||||
// Problem: Remove installed plugin
|
|
||||||
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
|
|
||||||
pNativeSpeaker->messageBox("PluginBuiltWronglyCannotFound",
|
|
||||||
NULL,
|
|
||||||
TEXT("The plugin package is built wrongly. This plugin will be uninstalled."),
|
|
||||||
TEXT("Plugin cannot be found"),
|
|
||||||
MB_OK | MB_APPLMODAL,
|
|
||||||
0,
|
|
||||||
lwp->_pluginUpdateInfo->_displayName.c_str());
|
|
||||||
|
|
||||||
deleteFileOrFolder(lwp->_nppPluginsDir);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Critical section
|
|
||||||
WaitForSingleObject(lwp->_mutex, INFINITE);
|
|
||||||
|
|
||||||
// Remove (Hide) installed plugin from available list
|
|
||||||
lwp->_uiAvailableList->hideFromPluginInfoPtr(lwp->_pluginUpdateInfo);
|
|
||||||
|
|
||||||
// Add installed plugin into insttalled list
|
|
||||||
PluginUpdateInfo* installedPui = new PluginUpdateInfo(*(lwp->_pluginUpdateInfo));
|
|
||||||
installedPui->_isVisible = true;
|
|
||||||
lwp->_uiInstalledList->pushBack(installedPui);
|
|
||||||
|
|
||||||
// Load installed plugin
|
|
||||||
vector<generic_string> dll2Remove;
|
|
||||||
int index = lwp->_pPluginsManager->loadPlugin(installedPluginPath.c_str(), dll2Remove);
|
|
||||||
lwp->_pPluginsManager->addInMenuFromPMIndex(index);
|
|
||||||
|
|
||||||
// Notify plugin that Notepad++ is ready
|
|
||||||
SCNotification scnN;
|
|
||||||
scnN.nmhdr.code = NPPN_READY;
|
|
||||||
scnN.nmhdr.hwndFrom = lwp->_hwnd;
|
|
||||||
scnN.nmhdr.idFrom = 0;
|
|
||||||
lwp->_pPluginsManager->notify(index, &scnN);
|
|
||||||
|
|
||||||
// End of Critical section
|
|
||||||
ReleaseMutex(lwp->_mutex);
|
|
||||||
}
|
|
||||||
else // wingup return non-zero (-1) -> Not OK
|
|
||||||
{
|
|
||||||
// just move on
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PluginsAdminDlg::installPlugins()
|
|
||||||
{
|
|
||||||
vector<size_t> indexes = _availableList.getCheckedIndexes();
|
|
||||||
vector<PluginUpdateInfo*> puis = _availableList.fromUiIndexesToPluginInfos(indexes);
|
|
||||||
|
|
||||||
generic_string nppPluginsHome = getPluginsPath();
|
|
||||||
|
|
||||||
HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppPluginInstaller"));
|
|
||||||
|
|
||||||
for (auto i : puis)
|
|
||||||
{
|
|
||||||
generic_string updaterParams = TEXT("-unzipTo ");
|
|
||||||
generic_string nppPluginsDir = nppPluginsHome;
|
|
||||||
PathAppend(nppPluginsDir, i->_folderName);
|
|
||||||
generic_string quoted_nppPluginsDir = TEXT("\"");
|
|
||||||
quoted_nppPluginsDir += nppPluginsDir;
|
|
||||||
quoted_nppPluginsDir += TEXT("\"");
|
|
||||||
updaterParams += quoted_nppPluginsDir;
|
|
||||||
|
|
||||||
// add zipFile's url
|
|
||||||
updaterParams += TEXT(" ");
|
|
||||||
updaterParams += i->_repository;
|
|
||||||
|
|
||||||
// add zipFile's SHA-256 for checking
|
|
||||||
updaterParams += TEXT(" ");
|
|
||||||
updaterParams += i->_id;
|
|
||||||
|
|
||||||
LaunchWingupParams* lwp = new LaunchWingupParams;
|
|
||||||
lwp->_nppPluginsDir = nppPluginsDir;
|
|
||||||
lwp->_pluginUpdateInfo = i;
|
|
||||||
lwp->_pPluginsManager = _pPluginsManager;
|
|
||||||
lwp->_uiAvailableList = &_availableList;
|
|
||||||
lwp->_uiInstalledList = &_installedList;
|
|
||||||
lwp->_updaterDir = _updaterDir;
|
|
||||||
lwp->_updaterFullPath = _updaterFullPath;
|
|
||||||
lwp->_updaterParams = updaterParams;
|
|
||||||
lwp->_hwnd = _hSelf;
|
|
||||||
lwp->_mutex = mutex;
|
|
||||||
|
|
||||||
_lwps.push_back(lwp);
|
|
||||||
|
|
||||||
HANDLE hThread = ::CreateThread(NULL, 0, launchPluginInstallerThread, lwp, 0, NULL);
|
|
||||||
::CloseHandle(hThread);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PluginsAdminDlg::exitToUpdateRemovePlugins(bool isUpdate, const vector<PluginUpdateInfo*>& puis)
|
|
||||||
{
|
|
||||||
NppParameters *pNppParameters = NppParameters::getInstance();
|
NppParameters *pNppParameters = NppParameters::getInstance();
|
||||||
generic_string updaterDir = pNppParameters->getNppPath();
|
generic_string updaterDir = pNppParameters->getNppPath();
|
||||||
updaterDir += TEXT("\\updater\\");
|
updaterDir += TEXT("\\updater\\");
|
||||||
|
|
||||||
generic_string updaterFullPath = updaterDir + TEXT("gup.exe");
|
generic_string updaterFullPath = updaterDir + TEXT("gup.exe");
|
||||||
generic_string updaterParams = TEXT("-clean ");
|
|
||||||
|
|
||||||
if (isUpdate) // not clean
|
generic_string updaterParams = opStr;
|
||||||
updaterParams += TEXT("-unzipTo ");
|
|
||||||
|
|
||||||
TCHAR nppFullPath[MAX_PATH];
|
TCHAR nppFullPath[MAX_PATH];
|
||||||
::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
|
::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
|
||||||
@ -622,7 +518,7 @@ bool PluginsAdminDlg::exitToUpdateRemovePlugins(bool isUpdate, const vector<Plug
|
|||||||
|
|
||||||
for (auto i : puis)
|
for (auto i : puis)
|
||||||
{
|
{
|
||||||
if (isUpdate)
|
if (op == pa_install || op == pa_update)
|
||||||
{
|
{
|
||||||
// add folder to operate
|
// add folder to operate
|
||||||
updaterParams += TEXT(" \"");
|
updaterParams += TEXT(" \"");
|
||||||
@ -633,7 +529,7 @@ bool PluginsAdminDlg::exitToUpdateRemovePlugins(bool isUpdate, const vector<Plug
|
|||||||
updaterParams += i->_id;
|
updaterParams += i->_id;
|
||||||
updaterParams += TEXT("\"");
|
updaterParams += TEXT("\"");
|
||||||
}
|
}
|
||||||
else // clean
|
else // op == pa_remove
|
||||||
{
|
{
|
||||||
// add folder to operate
|
// add folder to operate
|
||||||
updaterParams += TEXT(" \"");
|
updaterParams += TEXT(" \"");
|
||||||
@ -643,7 +539,13 @@ bool PluginsAdminDlg::exitToUpdateRemovePlugins(bool isUpdate, const vector<Plug
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ask user's confirmation
|
// 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);
|
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
|
||||||
|
auto res = pNativeSpeaker->messageBox("ExitToUpdatePlugins",
|
||||||
|
_hSelf,
|
||||||
|
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 | MB_APPLMODAL);
|
||||||
|
|
||||||
if (res == IDYES)
|
if (res == IDYES)
|
||||||
{
|
{
|
||||||
NppParameters *pNppParam = NppParameters::getInstance();
|
NppParameters *pNppParam = NppParameters::getInstance();
|
||||||
@ -667,6 +569,16 @@ bool PluginsAdminDlg::exitToUpdateRemovePlugins(bool isUpdate, const vector<Plug
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PluginsAdminDlg::installPlugins()
|
||||||
|
{
|
||||||
|
// Need to exit Notepad++
|
||||||
|
|
||||||
|
vector<size_t> indexes = _availableList.getCheckedIndexes();
|
||||||
|
vector<PluginUpdateInfo*> puis = _availableList.fromUiIndexesToPluginInfos(indexes);
|
||||||
|
|
||||||
|
return exitToInstallRemovePlugins(pa_install, puis);
|
||||||
|
}
|
||||||
|
|
||||||
bool PluginsAdminDlg::updatePlugins()
|
bool PluginsAdminDlg::updatePlugins()
|
||||||
{
|
{
|
||||||
// Need to exit Notepad++
|
// Need to exit Notepad++
|
||||||
@ -674,7 +586,7 @@ bool PluginsAdminDlg::updatePlugins()
|
|||||||
vector<size_t> indexes = _updateList.getCheckedIndexes();
|
vector<size_t> indexes = _updateList.getCheckedIndexes();
|
||||||
vector<PluginUpdateInfo*> puis = _updateList.fromUiIndexesToPluginInfos(indexes);
|
vector<PluginUpdateInfo*> puis = _updateList.fromUiIndexesToPluginInfos(indexes);
|
||||||
|
|
||||||
return exitToUpdateRemovePlugins(true, puis);
|
return exitToInstallRemovePlugins(pa_update, puis);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluginsAdminDlg::removePlugins()
|
bool PluginsAdminDlg::removePlugins()
|
||||||
@ -684,7 +596,7 @@ bool PluginsAdminDlg::removePlugins()
|
|||||||
vector<size_t> indexes = _installedList.getCheckedIndexes();
|
vector<size_t> indexes = _installedList.getCheckedIndexes();
|
||||||
vector<PluginUpdateInfo*> puis = _installedList.fromUiIndexesToPluginInfos(indexes);
|
vector<PluginUpdateInfo*> puis = _installedList.fromUiIndexesToPluginInfos(indexes);
|
||||||
|
|
||||||
return exitToUpdateRemovePlugins(false, puis);
|
return exitToInstallRemovePlugins(pa_remove, puis);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluginViewList::removeFromFolderName(const generic_string& folderName)
|
bool PluginViewList::removeFromFolderName(const generic_string& folderName)
|
||||||
|
@ -150,35 +150,11 @@ private:
|
|||||||
ListView _ui;
|
ListView _ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
|
||||||
// The parameters used for plugin installer thread
|
|
||||||
//
|
|
||||||
struct LaunchWingupParams
|
|
||||||
{
|
|
||||||
generic_string _updaterFullPath;
|
|
||||||
generic_string _updaterDir;
|
|
||||||
generic_string _updaterParams;
|
|
||||||
|
|
||||||
generic_string _nppPluginsDir;
|
|
||||||
PluginUpdateInfo* _pluginUpdateInfo;
|
|
||||||
|
|
||||||
PluginViewList* _uiAvailableList;
|
|
||||||
PluginViewList* _uiInstalledList;
|
|
||||||
|
|
||||||
PluginsManager *_pPluginsManager;
|
|
||||||
|
|
||||||
HWND _hwnd = nullptr;
|
|
||||||
HANDLE _mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PluginsAdminDlg final : public StaticDialog
|
class PluginsAdminDlg final : public StaticDialog
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
PluginsAdminDlg();
|
PluginsAdminDlg();
|
||||||
~PluginsAdminDlg() {
|
~PluginsAdminDlg() {};
|
||||||
for (auto i : _lwps)
|
|
||||||
delete i;
|
|
||||||
};
|
|
||||||
|
|
||||||
void init(HINSTANCE hInst, HWND parent) {
|
void init(HINSTANCE hInst, HWND parent) {
|
||||||
Window::init(hInst, parent);
|
Window::init(hInst, parent);
|
||||||
@ -230,8 +206,6 @@ private :
|
|||||||
PluginsManager *_pPluginsManager = nullptr;
|
PluginsManager *_pPluginsManager = nullptr;
|
||||||
NppCurrentStatus _nppCurrentStatus;
|
NppCurrentStatus _nppCurrentStatus;
|
||||||
|
|
||||||
std::vector<LaunchWingupParams*> _lwps; // Add each new instanciate plugin installer parameter object of the thread for cleaning up afterward
|
|
||||||
|
|
||||||
void collectNppCurrentStatusInfos();
|
void collectNppCurrentStatusInfos();
|
||||||
bool searchInPlugins(bool isNextMode) const;
|
bool searchInPlugins(bool isNextMode) const;
|
||||||
const bool _inNames = true;
|
const bool _inNames = true;
|
||||||
@ -246,10 +220,14 @@ private :
|
|||||||
return searchFromCurrentSel(str2search, _inDescs, isNextMode);
|
return searchFromCurrentSel(str2search, _inDescs, isNextMode);
|
||||||
};
|
};
|
||||||
|
|
||||||
static DWORD WINAPI launchPluginInstallerThread(void *params);
|
|
||||||
|
|
||||||
bool loadFromPluginInfos();
|
bool loadFromPluginInfos();
|
||||||
bool checkUpdates();
|
bool checkUpdates();
|
||||||
bool exitToUpdateRemovePlugins(bool isUpdate, const std::vector<PluginUpdateInfo*>& puis);
|
|
||||||
|
enum Operation {
|
||||||
|
pa_install = 0,
|
||||||
|
pa_update = 1,
|
||||||
|
pa_remove = 2
|
||||||
|
};
|
||||||
|
bool exitToInstallRemovePlugins(Operation op, const std::vector<PluginUpdateInfo*>& puis);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user