Skip to content

Commit fe15c3e

Browse files
committed
V2024.6.2
1 parent 134891a commit fe15c3e

File tree

5 files changed

+47
-71
lines changed

5 files changed

+47
-71
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
2121

2222
#libnick Definition
23-
project ("libnick" LANGUAGES C CXX VERSION 2024.6.1 DESCRIPTION "A cross-platform base for native Nickvision applications.")
23+
project ("libnick" LANGUAGES C CXX VERSION 2024.6.2 DESCRIPTION "A cross-platform base for native Nickvision applications.")
2424
include(CMakePackageConfigHelpers)
2525
include(GNUInstallDirs)
2626
include(CTest)

docs/update.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@ Path: `Nickvision::Update::Updater`
2424
- Accepts: The url of a GitHub repo to check for updates, githubRepoUrl.
2525
- Throws: `std::invalid_argument` if the GitHub url is not of valid format
2626
- ```cpp
27-
Nickvision::Version fetchCurrentStableVersion()
27+
Nickvision::Version fetchCurrentVersion(VersionType type)
2828
```
29-
- Returns: The latest stable Version found in the repo.
29+
- Accepts: The type of version to fetch, type.
30+
- Returns: The latest Version of type found in the repo.
3031
- Returns: An empty version on error.
3132
- Note: This method scans the tags of the repo and parses versions in the format `major.minor.build`.
32-
- ```cpp
33-
Nickvision::Version fetchCurrentPreviewVersion()
34-
```
35-
- Returns: The latest preview (dev) Version found in the repo.
36-
- Returns: An empty version on error.
37-
- Note: This method scans the tags of the repo and parses versions in the format `major.minor.build-dev`.
3833
- ```cpp
3934
bool windowsUpdate(VersionType versionType)
4035
```

include/update/updater.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,16 @@ namespace Nickvision::Update
3030
*/
3131
Updater(Updater&& u) noexcept;
3232
/**
33-
* @brief Gets the latest stable version from the GitHub repo.
34-
* @return The current stable version if available, else empty Version
35-
*/
36-
Version fetchCurrentStableVersion();
37-
/**
38-
* @brief Gets the latest preview version from the GitHub repo.
39-
* @return The current preview version if available, else empty Version
33+
* @brief Gets the latest version of the provided type from the GitHub repo.
34+
* @brief This method looks for tags in the format major.minor.build-dev for preview versions and major.minor.build for stable versions.
35+
* @param versionType The type of the version to get
36+
* @return The current version of the provided type if available, else empty Version
4037
*/
41-
Version fetchCurrentPreviewVersion();
38+
Version fetchCurrentVersion(VersionType versionType);
4239
#ifdef _WIN32
4340
/**
44-
* @brief Downloads and installs an application update for Windows. getCurrentStableVersion or getCurrentPreviewVersion should be called first before running this method. This method will force quit the current running application to install the update.
41+
* @brief Downloads and installs an application update for Windows.
42+
* @brief fetchCurrentVersion should be called first before running this method.
4543
* @param versionType The type of version update to install
4644
* @return True if successful, else false
4745
*/
@@ -61,12 +59,6 @@ namespace Nickvision::Update
6159
Updater& operator=(Updater&& u) noexcept;
6260

6361
private:
64-
/**
65-
* @brief Gets the latest version of the provided type from the GitHub repo
66-
* @param versionType The type of the version to get
67-
* @return The current version of the proivded type if available, else empty Version
68-
*/
69-
Version fetchCurrentVersion(VersionType versionType);
7062
mutable std::mutex m_mutex;
7163
std::string m_repoOwner;
7264
std::string m_repoName;

src/update/updater.cpp

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,37 @@ namespace Nickvision::Update
5555
m_latestPreviewReleaseId = std::move(u.m_latestPreviewReleaseId);
5656
}
5757

58-
Version Updater::fetchCurrentStableVersion()
59-
{
60-
return fetchCurrentVersion(VersionType::Stable);
61-
}
62-
63-
Version Updater::fetchCurrentPreviewVersion()
58+
Version Updater::fetchCurrentVersion(VersionType versionType)
6459
{
65-
return fetchCurrentVersion(VersionType::Preview);
60+
std::lock_guard<std::mutex> lock{ m_mutex };
61+
std::string releases{ WebHelpers::fetchJsonString("https://api.github.com/repos/" + m_repoOwner + "/" + m_repoName + "/releases") };
62+
if (!releases.empty())
63+
{
64+
Json::Value root;
65+
Json::Reader reader;
66+
if (reader.parse(releases, root, false))
67+
{
68+
for (const Json::Value& release : root)
69+
{
70+
std::string version{ release.get("tag_name", "NULL").asString() };
71+
if (version == "NULL")
72+
{
73+
return {};
74+
}
75+
if (versionType == VersionType::Stable && version.find('-') == std::string::npos)
76+
{
77+
m_latestStableReleaseId = release.get("id", -1).asInt();
78+
return version;
79+
}
80+
if (versionType == VersionType::Preview && version.find('-') != std::string::npos)
81+
{
82+
m_latestPreviewReleaseId = release.get("id", -1).asInt();
83+
return version;
84+
}
85+
}
86+
}
87+
}
88+
return {};
6689
}
6790

6891
#ifdef _WIN32
@@ -85,17 +108,16 @@ namespace Nickvision::Update
85108
std::string name{ asset.get("name", "").asString() };
86109
if (StringHelpers::toLower(name).find("setup.exe") != std::string::npos)
87110
{
88-
std::filesystem::path setup{ UserDirectories::getApplicationCache() / name };
89-
if (WebHelpers::downloadFile(asset.get("browser_download_url", "").asString(), setup))
111+
std::filesystem::path setupPath{ UserDirectories::getCache() / name };
112+
std::wstring quotedSetupPath{ L"\"" + setupPath.wstring() + L"\""};
113+
if (WebHelpers::downloadFile(asset.get("browser_download_url", "").asString(), setupPath))
90114
{
91-
std::wstring cmd{ L"\"" + setup.wstring() + L"\"" };
92-
if ((INT_PTR)ShellExecuteW(nullptr, L"open", cmd.c_str(), nullptr, nullptr, SW_SHOWDEFAULT) > 32)
115+
if ((INT_PTR)ShellExecuteW(nullptr, L"open", quotedSetupPath.c_str(), nullptr, nullptr, SW_SHOWDEFAULT) > 32)
93116
{
94-
std::exit(0);
95117
return true;
96118
}
97-
return false;
98119
}
120+
return false;
99121
}
100122
}
101123
}
@@ -131,37 +153,4 @@ namespace Nickvision::Update
131153
}
132154
return *this;
133155
}
134-
135-
Version Updater::fetchCurrentVersion(VersionType versionType)
136-
{
137-
std::lock_guard<std::mutex> lock{ m_mutex };
138-
std::string releases{ WebHelpers::fetchJsonString("https://api.github.com/repos/" + m_repoOwner + "/" + m_repoName + "/releases") };
139-
if (!releases.empty())
140-
{
141-
Json::Value root;
142-
Json::Reader reader;
143-
if (reader.parse(releases, root, false))
144-
{
145-
for (const Json::Value& release : root)
146-
{
147-
std::string version{ release.get("tag_name", "NULL").asString() };
148-
if (version == "NULL")
149-
{
150-
return {};
151-
}
152-
if (versionType == VersionType::Stable && version.find('-') == std::string::npos)
153-
{
154-
m_latestStableReleaseId = release.get("id", -1).asInt();
155-
return version;
156-
}
157-
if (versionType == VersionType::Preview && version.find('-') != std::string::npos)
158-
{
159-
m_latestPreviewReleaseId = release.get("id", -1).asInt();
160-
return version;
161-
}
162-
}
163-
}
164-
}
165-
return {};
166-
}
167156
}

tests/updatertests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace Nickvision::Update;
77
TEST(UpdaterTests, ParabolicStableUpdate)
88
{
99
Updater updater{ "https://github.com/NickvisionApps/Parabolic" };
10-
Version stable{ updater.fetchCurrentStableVersion() };
10+
Version stable{ updater.fetchCurrentVersion(VersionType::Stable) };
1111
ASSERT_TRUE(!stable.empty());
1212
ASSERT_TRUE(stable.getVersionType() == VersionType::Stable);
1313
ASSERT_TRUE(stable >= Version("2023.12.0"));

0 commit comments

Comments
 (0)