Enhance installed list in Plugin Admin

This commit is contained in:
Don HO 2018-06-13 04:15:21 +02:00
parent c30c0de0fc
commit c94319e863
3 changed files with 85 additions and 22 deletions

View File

@ -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<size_t> getCheckedIndexes() const;
virtual void init(HINSTANCE hInst, HWND hwnd);

View File

@ -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<LPARAM>(_list[index2remove]))
{
if (!_ui.removeFromIndex(i))
return false;
}
}
_list.erase(_list.begin() + index2remove);
return true;
}
bool PluginsAdminDlg::checkUpdates()
{
return true;

View File

@ -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<PluginUpdateInfo*>(_ui.getLParamFromIndex(index)); };
PluginUpdateInfo* findPluginInfoFromFolderName(const generic_string& folderName, int& index) const;
bool removeFromIndex(size_t index2remove);
private:
std::vector<PluginUpdateInfo*> _list;