From c94319e863e0f27e75a6e7999dd1fff9acac3d51 Mon Sep 17 00:00:00 2001 From: Don HO Date: Wed, 13 Jun 2018 04:15:21 +0200 Subject: [PATCH] Enhance installed list in Plugin Admin --- .../src/WinControls/AnsiCharPanel/ListView.h | 7 ++ .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 92 +++++++++++++++---- .../WinControls/PluginsAdmin/pluginsAdmin.h | 8 +- 3 files changed, 85 insertions(+), 22 deletions(-) diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/ListView.h b/PowerEditor/src/WinControls/AnsiCharPanel/ListView.h index 023a0af50..b0849bdc4 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/ListView.h +++ b/PowerEditor/src/WinControls/AnsiCharPanel/ListView.h @@ -74,6 +74,13 @@ public: LPARAM getLParamFromIndex(int itemIndex) const; + bool removeFromIndex(size_t i) { + if (i >= nbItem()) + return false; + + return (ListView_DeleteItem(_hSelf, i) == TRUE); + } + std::vector getCheckedIndexes() const; virtual void init(HINSTANCE hInst, HWND hwnd); diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index 20a5ab4da..97853852f 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -488,7 +488,22 @@ bool loadFromJson(PluginViewList & pl, const json& j) return true; } +PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const generic_string& filename) +{ + if (!::PathFileExists(fullFilePath.c_str())) + return; + _fullFilePath = fullFilePath; + _displayName = filename; + + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char *path = wmc->wchar2char(fullFilePath.c_str(), CP_ACP); + MD5 md5; + _id = wmc->char2wchar(md5.digestFile(path), CP_ACP); + + _version.setVersionFrom(fullFilePath); + +} bool PluginsAdminDlg::updateListAndLoadFromJson() { @@ -529,23 +544,6 @@ bool PluginsAdminDlg::updateListAndLoadFromJson() } -PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const generic_string& filename) -{ - if (!::PathFileExists(fullFilePath.c_str())) - return; - - _fullFilePath = fullFilePath; - _displayName = filename; - - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const char *path = wmc->wchar2char(fullFilePath.c_str(), CP_ACP); - MD5 md5; - _id = wmc->char2wchar(md5.digestFile(path), CP_ACP); - - _version.setVersionFrom(fullFilePath); - -} - bool PluginsAdminDlg::loadFromPluginInfos() { if (!_pPluginsManager) @@ -553,13 +551,69 @@ bool PluginsAdminDlg::loadFromPluginInfos() for (const auto& i : _pPluginsManager->_loadedDlls) { - PluginUpdateInfo* pui = new PluginUpdateInfo(i._fullFilePath, i._fileName); - _installedList.pushBack(pui); + if (i._fileName.length() >= MAX_PATH) + continue; + + // user file name (without ext. to find whole info in available list + TCHAR fnNoExt[MAX_PATH]; + lstrcpy(fnNoExt, i._fileName.c_str()); + ::PathRemoveExtension(fnNoExt); + + int index; + PluginUpdateInfo* foundInfo = _availableList.findPluginInfoFromFolderName(fnNoExt, index); + if (!foundInfo) + { + PluginUpdateInfo* pui = new PluginUpdateInfo(i._fullFilePath, i._fileName); + _installedList.pushBack(pui); + } + else + { + // add new updated info to installed list + PluginUpdateInfo* pui = new PluginUpdateInfo(*foundInfo); + pui->_fullFilePath = i._fullFilePath; + pui->_version.setVersionFrom(i._fullFilePath); + _installedList.pushBack(pui); + + // remove it from the available list + _availableList.removeFromIndex(index); + } } return true; } +PluginUpdateInfo* PluginViewList::findPluginInfoFromFolderName(const generic_string& folderName, int& index) const +{ + index = 0; + for (const auto& i : _list) + { + if (lstrcmpi(i->_folderName.c_str(), folderName.c_str()) == 0) + return i; + ++index; + } + index = -1; + return nullptr; +} + +bool PluginViewList::removeFromIndex(size_t index2remove) +{ + if (index2remove >= _list.size()) + return false; + + for (size_t i = 0; i < _ui.nbItem(); ++i) + { + if (_ui.getLParamFromIndex(i) == reinterpret_cast(_list[index2remove])) + { + if (!_ui.removeFromIndex(i)) + return false; + } + } + + _list.erase(_list.begin() + index2remove); + + return true; +} + bool PluginsAdminDlg::checkUpdates() { return true; diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h index 11352e596..3d8953c24 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h @@ -48,10 +48,10 @@ struct Version struct PluginUpdateInfo { - generic_string _fullFilePath; + generic_string _fullFilePath; // only for the installed Plugin - generic_string _folderName; - generic_string _displayName; + generic_string _folderName; // plugin folder name - should be the same name with plugin and should be uniq among the plugins + generic_string _displayName; // plugin description name Version _version; generic_string _homepage; generic_string _sourceUrl; @@ -108,6 +108,8 @@ public: void setViewStyleOption(int32_t extraStyle) { _ui.setStyleOption(extraStyle); }; size_t nbItem() const { return _ui.nbItem(); }; PluginUpdateInfo* getPluginInfoFromIndex(int index) const { return reinterpret_cast(_ui.getLParamFromIndex(index)); }; + PluginUpdateInfo* findPluginInfoFromFolderName(const generic_string& folderName, int& index) const; + bool removeFromIndex(size_t index2remove); private: std::vector _list;