Fix Plugin Admin installing plugins issues.

Fix Plugin Admin installing plugins bugs and check also wingup certificate before use it.
This commit is contained in:
Don HO 2018-08-12 15:21:21 +02:00
parent e75cf910bd
commit f3c17e9886
3 changed files with 61 additions and 32 deletions

View File

@ -536,7 +536,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
} }
//Plugin menu //Plugin menu
bool enablePluginAdmin = _pluginsAdminDlg.isListValide(); bool enablePluginAdmin = _pluginsAdminDlg.isValide();
_pluginsAdminDlg.setPluginsManager(&_pluginsManager); _pluginsAdminDlg.setPluginsManager(&_pluginsManager);
_pluginsManager.setMenu(_mainMenuHandle, NULL, enablePluginAdmin); _pluginsManager.setMenu(_mainMenuHandle, NULL, enablePluginAdmin);

View File

@ -352,22 +352,51 @@ vector<PluginUpdateInfo*> PluginViewList::fromUiIndexesToPluginInfos(const std::
return r; return r;
} }
PluginsAdminDlg::PluginsAdminDlg()
{
NppParameters *pNppParameters = NppParameters::getInstance();
_updaterDir = pNppParameters->getNppPath();
PathAppend(_updaterDir, TEXT("updater"));
_updaterFullPath = _updaterDir;
PathAppend(_updaterFullPath, TEXT("gup.exe"));
#ifdef DEBUG // if not debug, then it's release
// load from nppPluginList.json instead of nppPluginList.dll
_pluginListFullPath = TEXT("C:\\tmp\\nppPluginList.json");
#else //RELEASE
#ifdef _WIN64
_pluginListFullPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\x64\\Debug\\nppPluginList.dll");
#else
_pluginListFullPath = TEXT("C:\\sources\\nppPluginList\\vcxproj\\Debug\\nppPluginList.dll");
#endif
#endif
;
}
bool PluginsAdminDlg::installPlugins() bool PluginsAdminDlg::installPlugins()
{ {
vector<size_t> indexes = _availableList.getCheckedIndexes(); vector<size_t> indexes = _availableList.getCheckedIndexes();
vector<PluginUpdateInfo*> puis = _availableList.fromUiIndexesToPluginInfos(indexes); vector<PluginUpdateInfo*> puis = _availableList.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 "); generic_string updaterParams = TEXT("-unzipTo ");
generic_string nppPluginsDir = NppParameters::getInstance()->getUserPath();
PathAppend(nppPluginsDir, TEXT("plugins"));
if (!::PathFileExists(nppPluginsDir.c_str()))
{
::CreateDirectory(nppPluginsDir.c_str(), NULL);
}
for (auto i : puis) for (auto i : puis)
{ {
// add folder to operate // add folder to operate
generic_string destFolder = pNppParameters->getAppDataNppDir(); generic_string destFolder = nppPluginsDir;
PathAppend(destFolder, i->_folderName); PathAppend(destFolder, i->_folderName);
updaterParams += destFolder; updaterParams += destFolder;
@ -376,7 +405,10 @@ bool PluginsAdminDlg::installPlugins()
updaterParams += TEXT(" "); updaterParams += TEXT(" ");
updaterParams += i->_repository; updaterParams += i->_repository;
Process updater(updaterFullPath.c_str(), updaterParams.c_str(), updaterDir.c_str()); Process updater(_updaterFullPath.c_str(), updaterParams.c_str(), _updaterDir.c_str());
printStr(updaterParams.c_str());
printStr(_updaterDir.c_str());
int result = updater.runSync(); int result = updater.runSync();
if (result == 0) // wingup return 0 -> OK if (result == 0) // wingup return 0 -> OK
{ {
@ -584,9 +616,15 @@ PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const gen
typedef const char * (__cdecl * PFUNCGETPLUGINLIST)(); typedef const char * (__cdecl * PFUNCGETPLUGINLIST)();
bool PluginsAdminDlg::isListValide() bool PluginsAdminDlg::isValide()
{ {
if (!::PathFileExists(NPP_PLUGIN_LIST_PATH)) if (!::PathFileExists(_pluginListFullPath.c_str()))
{
return false;
}
generic_string gupPath;
if (!::PathFileExists(_updaterFullPath.c_str()))
{ {
return false; return false;
} }
@ -599,8 +637,11 @@ bool PluginsAdminDlg::isListValide()
// check the signature on default location : %APPDATA%\Notepad++\plugins\config\pl\nppPluginList.dll or NPP_INST_DIR\plugins\config\pl\nppPluginList.dll // check the signature on default location : %APPDATA%\Notepad++\plugins\config\pl\nppPluginList.dll or NPP_INST_DIR\plugins\config\pl\nppPluginList.dll
bool isOK = VerifySignedLibrary(NPP_PLUGIN_LIST_PATH, NPP_COMPONENT_SIGNER_KEY_ID, NPP_COMPONENT_SIGNER_SUBJECT, NPP_COMPONENT_SIGNER_DISPLAY_NAME, false, false, false); bool isOK = VerifySignedLibrary(_pluginListFullPath.c_str(), NPP_COMPONENT_SIGNER_KEY_ID, NPP_COMPONENT_SIGNER_SUBJECT, NPP_COMPONENT_SIGNER_DISPLAY_NAME, false, false, false);
if (!isOK)
return isOK;
isOK = VerifySignedLibrary(_updaterFullPath.c_str(), NPP_COMPONENT_SIGNER_KEY_ID, NPP_COMPONENT_SIGNER_SUBJECT, NPP_COMPONENT_SIGNER_DISPLAY_NAME, false, false, false);
return isOK; return isOK;
#endif #endif
} }
@ -608,7 +649,7 @@ bool PluginsAdminDlg::isListValide()
bool PluginsAdminDlg::updateListAndLoadFromJson() bool PluginsAdminDlg::updateListAndLoadFromJson()
{ {
try { try {
if (!isListValide()) if (!isValide())
return false; return false;
json j; json j;
@ -616,12 +657,12 @@ bool PluginsAdminDlg::updateListAndLoadFromJson()
#ifdef DEBUG // if not debug, then it's release #ifdef DEBUG // if not debug, then it's release
// load from nppPluginList.json instead of nppPluginList.dll // load from nppPluginList.json instead of nppPluginList.dll
ifstream nppPluginListJson(NPP_PLUGIN_LIST_PATH); ifstream nppPluginListJson(_pluginListFullPath);
nppPluginListJson >> j; nppPluginListJson >> j;
#else //RELEASE #else //RELEASE
HINSTANCE hLib = ::LoadLibrary(NPP_PLUGIN_LIST_PATH); HINSTANCE hLib = ::LoadLibrary(_pluginListFullPath.c_str());
if (!hLib) if (!hLib)
{ {
// Error treatment // Error treatment

View File

@ -25,24 +25,8 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once #pragma once
#ifdef DEBUG // if not debug, then it's release
// load from nppPluginList.json instead of nppPluginList.dll
#define NPP_PLUGIN_LIST_PATH TEXT("C:\\tmp\\nppPluginList.json")
#else //RELEASE
#ifdef _WIN64
#define NPP_PLUGIN_LIST_PATH TEXT("C:\\sources\\nppPluginList\\vcxproj\\x64\\Debug\\nppPluginList.dll")
#else
#define NPP_PLUGIN_LIST_PATH TEXT("C:\\sources\\nppPluginList\\vcxproj\\Debug\\nppPluginList.dll")
#endif
#endif
#include "StaticDialog.h" #include "StaticDialog.h"
#include "pluginsAdminRes.h" #include "pluginsAdminRes.h"
#include "TabBar.h" #include "TabBar.h"
@ -142,7 +126,7 @@ private:
class PluginsAdminDlg final : public StaticDialog class PluginsAdminDlg final : public StaticDialog
{ {
public : public :
PluginsAdminDlg() {}; PluginsAdminDlg();
~PluginsAdminDlg() {} ~PluginsAdminDlg() {}
void init(HINSTANCE hInst, HWND parent) { void init(HINSTANCE hInst, HWND parent) {
Window::init(hInst, parent); Window::init(hInst, parent);
@ -163,7 +147,7 @@ public :
display(); display();
}; };
bool isListValide(); bool isValide();
void switchDialog(int indexToSwitch); void switchDialog(int indexToSwitch);
void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; }; void setPluginsManager(PluginsManager *pluginsManager) { _pPluginsManager = pluginsManager; };
@ -179,6 +163,10 @@ protected:
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private : private :
generic_string _updaterDir;
generic_string _updaterFullPath;
generic_string _pluginListFullPath;
TabBar _tab; TabBar _tab;
PluginViewList _availableList; // A permanent list, once it's loaded (no removal - only hide or show) PluginViewList _availableList; // A permanent list, once it's loaded (no removal - only hide or show)