Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion thcrap/src/jansson_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ json_t *json5_loadb(const void *buffer, size_t size, char **error)
json5pp::impl::imemstream istream(buffer, size);
json5 = json5pp::parse5(istream, false);
}
catch (json5pp::syntax_error e) {
catch (const json5pp::syntax_error& e) {
if (error) {
*error = strdup(e.what());
}
Expand Down
2 changes: 1 addition & 1 deletion thcrap/src/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool RepoWrite(const repo_t *repo)
try {
std::filesystem::create_directories(repo_dir);
}
catch (std::filesystem::filesystem_error e) {
catch (const std::filesystem::filesystem_error& e) {
log_printf("Failed to create repo folder %s.\nError %d: %s\n", (const char*)repo_dir.u8string().c_str(), e.code().value(), e.what());
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions thcrap/src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ static DWORD WINAPI SearchThread(void *param_)
if (ent->path().extension() == L".exe")
SearchCheckExe(*state, *ent);
}
catch (std::system_error &) {}
catch (const std::system_error&) {}
}
} catch (std::system_error &) {}
} catch (const std::system_error&) {}

return 0;
}
Expand Down
8 changes: 6 additions & 2 deletions thcrap_update/src/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ std::list<DownloadUrl> Downloader::serversListToDownloadUrlList(const std::list<
}

void Downloader::addFile(const std::list<std::string>& serversUrl, std::string filePath,
File::success_t successCallback, File::failure_t failureCallback, File::progress_t progressCallback)
File::SuccessCallback successCallback,
File::FailureCallback failureCallback,
File::ProgressCallback progressCallback)
{
std::scoped_lock lock(this->mutex);

Expand All @@ -41,7 +43,9 @@ void Downloader::addFile(const std::list<std::string>& serversUrl, std::string f
}

void Downloader::addFile(char** serversUrl, std::string filePath,
File::success_t successCallback, File::failure_t failureCallback, File::progress_t progressCallback)
File::SuccessCallback successCallback,
File::FailureCallback failureCallback,
File::ProgressCallback progressCallback)
{
std::list<std::string> serversList;

Expand Down
12 changes: 6 additions & 6 deletions thcrap_update/src/downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class Downloader
Downloader();
~Downloader();
void addFile(const std::list<std::string>& servers, std::string filename,
File::success_t successCallback = File::defaultSuccessFunction,
File::failure_t failureCallback = File::defaultFailureFunction,
File::progress_t progressCallback = File::defaultProgressFunction);
File::SuccessCallback successCallback = File::defaultSuccessFunction,
File::FailureCallback failureCallback = File::defaultFailureFunction,
File::ProgressCallback progressCallback = File::defaultProgressFunction);
void addFile(char** servers, std::string filename,
File::success_t successCallback = File::defaultSuccessFunction,
File::failure_t failureCallback = File::defaultFailureFunction,
File::progress_t progressCallback = File::defaultProgressFunction);
File::SuccessCallback successCallback = File::defaultSuccessFunction,
File::FailureCallback failureCallback = File::defaultFailureFunction,
File::ProgressCallback progressCallback = File::defaultProgressFunction);
size_t current() const;
size_t total() const;
void wait();
Expand Down
16 changes: 8 additions & 8 deletions thcrap_update/src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
using namespace std::string_literals;

File::File(std::list<DownloadUrl>&& urls,
success_t successCallback,
failure_t failureCallback,
progress_t progressCallback)
SuccessCallback successCallback,
FailureCallback failureCallback,
ProgressCallback progressCallback)
: status(Status::Todo), urls(urls),
userSuccessCallback(successCallback), userFailureCallback(failureCallback), userProgressCallback(progressCallback)
{
if (urls.empty()) {
throw new std::invalid_argument("Input URL list must not be empty");
throw std::invalid_argument("Input URL list must not be empty");
}
}

Expand Down Expand Up @@ -62,7 +62,7 @@ void File::download(IHttpHandle& http, const DownloadUrl& url)
}
);
if (!status) {
if (status.get() == HttpStatus::ServerError || status.get() == HttpStatus::SystemError) {
if (status.get() == HttpStatus::Status::ServerError || status.get() == HttpStatus::Status::SystemError) {
// If the server is dead, we don't want to continue using it.
// If the library returned an error, future downloads to the
// same server are also likely to fail.
Expand Down Expand Up @@ -105,10 +105,10 @@ extern "C" int download_single_file(const char* url, const char* fn) {
return 0;
}
else {
return res.second.get();
return static_cast<int>(res.second.get());
}
}
catch (std::bad_alloc e) {
return HttpStatus::SystemError;
catch (const std::bad_alloc& e) {
return static_cast<int>(HttpStatus::Status::SystemError);
}
}
18 changes: 9 additions & 9 deletions thcrap_update/src/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
class File
{
public:
typedef std::function<void (const DownloadUrl& url, std::vector<uint8_t>& data)> success_t;
typedef std::function<void (const DownloadUrl& url, HttpStatus status)> failure_t;
typedef std::function<bool (const DownloadUrl& url, size_t file_progress, size_t file_size)> progress_t;
using SuccessCallback = std::function<void (const DownloadUrl& url, std::vector<uint8_t>& data)>;
using FailureCallback = std::function<void (const DownloadUrl& url, HttpStatus status)>;
using ProgressCallback = std::function<bool (const DownloadUrl& url, size_t file_progress, size_t file_size)>;
static void defaultSuccessFunction(const DownloadUrl&, std::vector<uint8_t>&) {}
static void defaultFailureFunction(const DownloadUrl&, HttpStatus) {}
static bool defaultProgressFunction(const DownloadUrl&, size_t, size_t) { return true; }
Expand All @@ -35,9 +35,9 @@ class File
std::list<DownloadUrl> urls;

// User-provided callbacks
success_t userSuccessCallback;
failure_t userFailureCallback;
progress_t userProgressCallback;
SuccessCallback userSuccessCallback;
FailureCallback userFailureCallback;
ProgressCallback userProgressCallback;

size_t writeCallback(std::vector<uint8_t>& buffer, const uint8_t *data, size_t size);
bool progressCallback(const DownloadUrl& url, size_t dlnow, size_t dltotal);
Expand All @@ -46,9 +46,9 @@ class File

public:
File(std::list<DownloadUrl>&& urls,
success_t successCallback = defaultSuccessFunction,
failure_t failureCallback = defaultFailureFunction,
progress_t progressCallback = defaultProgressFunction);
SuccessCallback successCallback = defaultSuccessFunction,
FailureCallback failureCallback = defaultFailureFunction,
ProgressCallback progressCallback = defaultProgressFunction);
File(const File&) = delete;
File(File&&) = delete;
File& operator=(const File&) = delete;
Expand Down
12 changes: 6 additions & 6 deletions thcrap_update/src/http_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ HttpStatus::~HttpStatus()

HttpStatus HttpStatus::makeOk()
{
return HttpStatus(Ok, 0, "success");
return HttpStatus(Status::Ok, 0, "success");
}

HttpStatus HttpStatus::makeCancelled()
{
return HttpStatus(Cancelled, 0, "cancelled");
return HttpStatus(Status::Cancelled, 0, "cancelled");
}

HttpStatus HttpStatus::makeNetworkError(unsigned int httpCode)
{
HttpStatus::Status status;
if (300 <= httpCode && httpCode < 499) {
status = ClientError;
status = Status::ClientError;
}
else {
status = ServerError;
status = Status::ServerError;
}

std::map<unsigned int, const char*> messages = {
Expand Down Expand Up @@ -67,7 +67,7 @@ HttpStatus HttpStatus::makeNetworkError(unsigned int httpCode)

HttpStatus HttpStatus::makeSystemError(unsigned int systemCode, std::string text)
{
return HttpStatus(SystemError, systemCode, text);
return HttpStatus(Status::SystemError, systemCode, text);
}

HttpStatus::Status HttpStatus::get() const
Expand All @@ -77,7 +77,7 @@ HttpStatus::Status HttpStatus::get() const

HttpStatus::operator bool() const
{
return this->status == Ok;
return this->status == Status::Ok;
}

bool HttpStatus::operator==(Status status) const
Expand Down
2 changes: 1 addition & 1 deletion thcrap_update/src/http_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class HttpStatus
{
public:
enum Status {
enum class Status {
// 200 - success
Ok,
// Download cancelled by the progress callback, or another client
Expand Down
2 changes: 1 addition & 1 deletion thcrap_update/src/loader_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ BOOL loader_update_with_UI(const char *exe_fn, char *args)

state.update_at_exit = globalconfig_get_boolean("update_at_exit", false);
state.background_updates = globalconfig_get_boolean("background_updates", false);
state.time_between_updates = (int)globalconfig_get_integer("time_between_updates", 5);
state.time_between_updates = static_cast<int>(globalconfig_get_integer("time_between_updates", 5));
state.update_others = globalconfig_get_boolean("update_others", true);

SetLastError(0);
Expand Down
2 changes: 1 addition & 1 deletion thcrap_update/src/self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ LRESULT CALLBACK smartdlg_proc(
if (state && state->hProgress) {
std::lock_guard<std::mutex> lock(state->progress_mutex);
if (state->total_size > 0) {
int pos = (int)((state->current_progress * 100) / state->total_size);
int pos = static_cast<int>((state->current_progress * 100) / state->total_size);
SendMessage(state->hProgress, PBM_SETPOS, pos, 0);
}
}
Expand Down
8 changes: 4 additions & 4 deletions thcrap_update/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const std::string& Server::getUrl() const
return this->baseUrl;
}

std::pair<std::vector<uint8_t>, HttpStatus> Server::downloadFile(const std::string& name, File::progress_t progress)
std::pair<std::vector<uint8_t>, HttpStatus> Server::downloadFile(const std::string& name, File::ProgressCallback progress)
{
std::list<DownloadUrl> urls{
DownloadUrl(*this, name)
Expand All @@ -75,7 +75,7 @@ std::pair<std::vector<uint8_t>, HttpStatus> Server::downloadFile(const std::stri
return std::make_pair(std::move(ret), status);
}

std::pair<ScopedJson, HttpStatus> Server::downloadJsonFile(const std::string& name, File::progress_t progress)
std::pair<ScopedJson, HttpStatus> Server::downloadJsonFile(const std::string& name, File::ProgressCallback progress)
{
auto [data, status] = this->downloadFile(name, progress);
if (!status) {
Expand Down Expand Up @@ -189,13 +189,13 @@ std::pair<Server&, std::string> ServerCache::urlToServer(const std::string& url)
}
}

std::pair<std::vector<uint8_t>, HttpStatus> ServerCache::downloadFile(const std::string& url, File::progress_t progress)
std::pair<std::vector<uint8_t>, HttpStatus> ServerCache::downloadFile(const std::string& url, File::ProgressCallback progress)
{
auto [server, path] = this->urlToServer(url);
return server.downloadFile(path, progress);
}

std::pair<ScopedJson, HttpStatus> ServerCache::downloadJsonFile(const std::string& url, File::progress_t progress)
std::pair<ScopedJson, HttpStatus> ServerCache::downloadJsonFile(const std::string& url, File::ProgressCallback progress)
{
auto [server, path] = this->urlToServer(url);
return server.downloadJsonFile(path, progress);
Expand Down
10 changes: 5 additions & 5 deletions thcrap_update/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BorrowedHttpHandle
class Server
{
public:
typedef std::function<std::unique_ptr<IHttpHandle>(void)> HttpHandleFactory;
using HttpHandleFactory = std::function<std::unique_ptr<IHttpHandle>(void)>;

private:
HttpHandleFactory handleFactory;
Expand All @@ -54,10 +54,10 @@ class Server
// Download a single file from this server.
std::pair<std::vector<uint8_t>, HttpStatus> downloadFile(
const std::string& name,
File::progress_t progress = File::defaultProgressFunction
File::ProgressCallback progress = File::defaultProgressFunction
);
// Download a single json file from this server.
std::pair<ScopedJson, HttpStatus> downloadJsonFile(const std::string& name, File::progress_t progress = File::defaultProgressFunction);
std::pair<ScopedJson, HttpStatus> downloadJsonFile(const std::string& name, File::ProgressCallback progress = File::defaultProgressFunction);

// Borrow a HttpHandle from the server.
// You own it until the BorrowedHttpHandle is destroyed.
Expand Down Expand Up @@ -102,8 +102,8 @@ class ServerCache
// Find the server for url and call downloadFile on it
std::pair<std::vector<uint8_t>, HttpStatus> downloadFile(
const std::string& url,
File::progress_t progress = File::defaultProgressFunction
File::ProgressCallback progress = File::defaultProgressFunction
);
// Find the server for url and call downloadJsonFile on it
std::pair<ScopedJson, HttpStatus> downloadJsonFile(const std::string& url, File::progress_t progress = File::defaultProgressFunction);
std::pair<ScopedJson, HttpStatus> downloadJsonFile(const std::string& url, File::ProgressCallback progress = File::defaultProgressFunction);
};
14 changes: 7 additions & 7 deletions thcrap_update/src/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "strings_array.h"
#include "3rdparty/crc32.h"

Update::Update(Update::filter_t filterCallback,
Update::Update(Update::FilterCallback filterCallback,
progress_callback_t progressCallback, void *progressData)
: filterCallback(filterCallback), progressCallback(progressCallback), progressData(progressData)
{
Expand All @@ -17,15 +17,15 @@ Update::Update(Update::filter_t filterCallback,
get_status_t Update::httpStatusToGetStatus(HttpStatus status)
{
switch (status.get()) {
case HttpStatus::Ok:
case HttpStatus::Status::Ok:
return GET_OK;
case HttpStatus::Cancelled:
case HttpStatus::Status::Cancelled:
return GET_CANCELLED;
case HttpStatus::ClientError:
case HttpStatus::Status::ClientError:
return GET_CLIENT_ERROR;
case HttpStatus::ServerError:
case HttpStatus::Status::ServerError:
return GET_SERVER_ERROR;
case HttpStatus::SystemError:
case HttpStatus::Status::SystemError:
return GET_SYSTEM_ERROR;
default:
throw std::invalid_argument("Invalid status");
Expand Down Expand Up @@ -236,7 +236,7 @@ void Update::startPatchUpdate(const patch_t *patch)
this->onFilesJsComplete(patch, data);
},
[patch_id = std::string(patch->id)](const DownloadUrl& url, HttpStatus httpStatus) {
if (httpStatus.get() == HttpStatus::Cancelled) {
if (httpStatus.get() == HttpStatus::Status::Cancelled) {
// Another file finished before
return ;
}
Expand Down
6 changes: 3 additions & 3 deletions thcrap_update/src/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void thcrap_update_exit(void);
class Update
{
private:
typedef std::function<bool(const std::string&)> filter_t;
using FilterCallback = std::function<bool(const std::string&)>;

// Downloader used for the files.js downloads
Downloader filesJsDownloader;
Expand All @@ -106,7 +106,7 @@ class Update
// files.js is downloaded.
Downloader mainDownloader;

filter_t filterCallback;
FilterCallback filterCallback;
progress_callback_t progressCallback;
void *progressData;

Expand All @@ -121,7 +121,7 @@ class Update
std::string fnToUrl(const std::string& url, uint32_t crc32);

public:
Update(filter_t filterCallback, progress_callback_t progressCallback, void *progressData);
Update(FilterCallback filterCallback, progress_callback_t progressCallback, void *progressData);
void run(const std::list<const patch_t*>& patchs);
};
/// ---------------------------------------
Expand Down