Skip to content

Commit

Permalink
Updater - Allow specifying github url in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Dec 7, 2023
1 parent 96853c6 commit f79a9de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 3 additions & 1 deletion include/update/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ namespace Nickvision::Aura::Update
public:
/**
* @brief Constructs an Updater.
* @param githubRepoUrl The url of the GitHub repo to fetch updates for. Must be a valid github url. If the url is invalid, Updater will attempt to get a repo url from Aura
* @exception std::invalid_argument Thrown if no valid url can be determined
*/
Updater();
Updater(std::string githubRepoUrl = "");
/**
* @brief Gets the latest stable version from the GitHub repo.
* @return The current stable version if available, else empty Version
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/webhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ namespace Nickvision::Aura
{
bool WebHelpers::isValidWebsite(const std::string& url)
{
if (url.empty())
{
return false;
}
curl_global_init(CURL_GLOBAL_DEFAULT);
CURL* curl{ curl_easy_init() };
if (!curl)
Expand All @@ -27,6 +31,10 @@ namespace Nickvision::Aura

bool WebHelpers::downloadFile(const std::string& url, const std::filesystem::path& path, const CurlProgressFunction& progress, bool overwrite)
{
if (url.empty())
{
return false;
}
if (std::filesystem::exists(path) && !overwrite)
{
return false;
Expand Down Expand Up @@ -69,6 +77,10 @@ namespace Nickvision::Aura

std::string WebHelpers::fetchJsonString(const std::string& url)
{
if (url.empty())
{
return "";
}
curl_global_init(CURL_GLOBAL_DEFAULT);
CURL* curl{ curl_easy_init() };
if (!curl)
Expand Down
23 changes: 17 additions & 6 deletions src/update/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@

namespace Nickvision::Aura::Update
{
Updater::Updater()
Updater::Updater(std::string githubRepoUrl)
: m_latestStableReleaseId{ -1 },
m_latestPreviewReleaseId{ -1 }
{
if (!WebHelpers::isValidWebsite(Aura::getActive().getAppInfo().getSourceRepo()))
if (!WebHelpers::isValidWebsite(githubRepoUrl))
{
throw std::invalid_argument("The source repo of the active Aura::AppInfo is invalid.");
githubRepoUrl = Aura::getActive().getAppInfo().getSourceRepo();
if (!WebHelpers::isValidWebsite(githubRepoUrl))
{
throw std::invalid_argument("The source repo of the active Aura::AppInfo is invalid.");
}
}
try
{
std::vector<std::string> fields = StringHelpers::split(githubRepoUrl, "/");
m_repoOwner = fields[3];
m_repoName = fields[4];
}
catch (...)
{
throw std::invalid_argument("The url is not a valid github repo.");
}
std::vector<std::string> fields = StringHelpers::split(Aura::getActive().getAppInfo().getSourceRepo(), "/");
m_repoOwner = fields[3];
m_repoName = fields[4];
}

Version Updater::fetchCurrentStableVersion()
Expand Down

0 comments on commit f79a9de

Please sign in to comment.