Add version management for Plugins update in Plugin Admin
This commit is contained in:
parent
74e89bdf5f
commit
6510889ba0
|
@ -45,6 +45,36 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
Version::Version(const generic_string& versionStr)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
auto ss = tokenizeString(versionStr, '.');
|
||||||
|
|
||||||
|
if (ss.size() > 4)
|
||||||
|
throw generic_string(TEXT("The string to parse is not a valid version format. Let's make it default value in catch block."));
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
vector<unsigned long*> v = {&_major, &_minor, &_patch, &_build};
|
||||||
|
for (const auto& s : ss)
|
||||||
|
{
|
||||||
|
if (!isNumber(s))
|
||||||
|
{
|
||||||
|
throw generic_string(TEXT("The string to parse is not a valid version format. Let's make it default value in catch block."));
|
||||||
|
}
|
||||||
|
*(v[i]) = std::stoi(s);
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
_major = 0;
|
||||||
|
_minor = 0;
|
||||||
|
_patch = 0;
|
||||||
|
_build = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Version::setVersionFrom(generic_string filePath)
|
void Version::setVersionFrom(generic_string filePath)
|
||||||
{
|
{
|
||||||
if (not filePath.empty() && ::PathFileExists(filePath.c_str()))
|
if (not filePath.empty() && ::PathFileExists(filePath.c_str()))
|
||||||
|
@ -110,6 +140,39 @@ generic_string Version::toString()
|
||||||
return ver;
|
return ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Version::compareTo(const Version& v2c) const
|
||||||
|
{
|
||||||
|
if (_major > v2c._major)
|
||||||
|
return 1;
|
||||||
|
else if (_major < v2c._major)
|
||||||
|
return -1;
|
||||||
|
else // (_major == v2c._major)
|
||||||
|
{
|
||||||
|
if (_minor > v2c._minor)
|
||||||
|
return 1;
|
||||||
|
else if (_minor < v2c._minor)
|
||||||
|
return -1;
|
||||||
|
else // (_minor == v2c._minor)
|
||||||
|
{
|
||||||
|
if (_patch > v2c._patch)
|
||||||
|
return 1;
|
||||||
|
else if (_patch < v2c._patch)
|
||||||
|
return -1;
|
||||||
|
else // (_patch == v2c._patch)
|
||||||
|
{
|
||||||
|
if (_build > v2c._build)
|
||||||
|
return 1;
|
||||||
|
else if (_build < v2c._build)
|
||||||
|
return -1;
|
||||||
|
else // (_build == v2c._build)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
generic_string PluginUpdateInfo::describe()
|
generic_string PluginUpdateInfo::describe()
|
||||||
{
|
{
|
||||||
generic_string desc;
|
generic_string desc;
|
||||||
|
@ -460,6 +523,7 @@ bool PluginsAdminDlg::exitToUpdateRemovePlugins(bool isUpdate, const vector<Plug
|
||||||
|
|
||||||
TCHAR nppFullPath[MAX_PATH];
|
TCHAR nppFullPath[MAX_PATH];
|
||||||
::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
|
::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
|
||||||
|
updaterParams += TEXT("\"");
|
||||||
updaterParams += nppFullPath;
|
updaterParams += nppFullPath;
|
||||||
updaterParams += TEXT("\" ");
|
updaterParams += TEXT("\" ");
|
||||||
|
|
||||||
|
@ -597,6 +661,10 @@ bool loadFromJson(PluginViewList & pl, const json& j)
|
||||||
valStr = i.at("description").get<std::string>();
|
valStr = i.at("description").get<std::string>();
|
||||||
pi->_description = wmc->char2wchar(valStr.c_str(), CP_ACP);
|
pi->_description = wmc->char2wchar(valStr.c_str(), CP_ACP);
|
||||||
|
|
||||||
|
valStr = i.at("version").get<std::string>();
|
||||||
|
generic_string newValStr(valStr.begin(), valStr.end());
|
||||||
|
pi->_version = Version(newValStr);
|
||||||
|
|
||||||
valStr = i.at("repository").get<std::string>();
|
valStr = i.at("repository").get<std::string>();
|
||||||
pi->_repository = wmc->char2wchar(valStr.c_str(), CP_ACP);
|
pi->_repository = wmc->char2wchar(valStr.c_str(), CP_ACP);
|
||||||
|
|
||||||
|
@ -737,6 +805,8 @@ bool PluginsAdminDlg::loadFromPluginInfos()
|
||||||
if (!_pPluginsManager)
|
if (!_pPluginsManager)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Search from loaded plugins, if loaded plugins are in the available list,
|
||||||
|
// add them into installed plugins list, and hide them from the available list
|
||||||
for (const auto& i : _pPluginsManager->_loadedDlls)
|
for (const auto& i : _pPluginsManager->_loadedDlls)
|
||||||
{
|
{
|
||||||
if (i._fileName.length() >= MAX_PATH)
|
if (i._fileName.length() >= MAX_PATH)
|
||||||
|
@ -764,6 +834,14 @@ bool PluginsAdminDlg::loadFromPluginInfos()
|
||||||
|
|
||||||
// Hide it from the available list
|
// Hide it from the available list
|
||||||
_availableList.hideFromListIndex(listIndex);
|
_availableList.hideFromListIndex(listIndex);
|
||||||
|
|
||||||
|
// if the installed plugin version is smaller than the one on the available list,
|
||||||
|
// put it in the update list as well.
|
||||||
|
if (pui->_version < foundInfo->_version)
|
||||||
|
{
|
||||||
|
PluginUpdateInfo* pui2 = new PluginUpdateInfo(*foundInfo);
|
||||||
|
_updateList.pushBack(pui2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cwctype>
|
||||||
|
#include <algorithm>
|
||||||
#include "StaticDialog.h"
|
#include "StaticDialog.h"
|
||||||
#include "pluginsAdminRes.h"
|
#include "pluginsAdminRes.h"
|
||||||
#include "TabBar.h"
|
#include "TabBar.h"
|
||||||
|
@ -41,8 +43,34 @@ struct Version
|
||||||
unsigned long _minor = 0;
|
unsigned long _minor = 0;
|
||||||
unsigned long _patch = 0;
|
unsigned long _patch = 0;
|
||||||
unsigned long _build = 0;
|
unsigned long _build = 0;
|
||||||
|
|
||||||
|
Version() {};
|
||||||
|
Version(const generic_string& versionStr);
|
||||||
|
|
||||||
void setVersionFrom(generic_string filePath);
|
void setVersionFrom(generic_string filePath);
|
||||||
generic_string toString();
|
generic_string toString();
|
||||||
|
bool isNumber(const generic_string& s) const {
|
||||||
|
return !s.empty() &&
|
||||||
|
find_if(s.begin(), s.end(), [](char c) { return !isdigit(c); }) == s.end();
|
||||||
|
};
|
||||||
|
|
||||||
|
int compareTo(const Version& v2c) const;
|
||||||
|
|
||||||
|
bool operator < (const Version& v2c) const {
|
||||||
|
return compareTo(v2c) == -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool operator > (const Version& v2c) const {
|
||||||
|
return compareTo(v2c) == 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool operator == (const Version& v2c) const {
|
||||||
|
return compareTo(v2c) == 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool operator != (const Version& v2c) const {
|
||||||
|
return compareTo(v2c) != 0;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PluginUpdateInfo
|
struct PluginUpdateInfo
|
||||||
|
|
Loading…
Reference in New Issue