Permalink
Browse files

mod data is not retreived until the download start while polling events

  • Loading branch information...
Turupawn committed Jul 29, 2018
1 parent 4bb405a commit 84e3b9d56b2a07ee714587b134c5e8c99829a0e4
View
@@ -41,27 +41,5 @@ src/modio.lib
src/modio.exp
src/modio.a
examples/*/.modio/
examples/*/mods_dir/*
examples/*/modio.dll
examples/*/modio.lib
examples/*/modio.a
examples/*/*.dll
examples/*/01_Authentication
examples/*/02_BrowseMods
examples/*/03_ErrorResponse
examples/*/04_DownloadImages
examples/*/05_EditImage
examples/*/06_DownloadModfile
examples/*/07_AddModfile
examples/*/08_EditModfile
examples/*/09_AddMod
examples/*/10_EditMod
examples/*/11_DeleteMod
examples/*/12_GetTags
examples/*/13_AddTags
examples/*/14_DeleteTags
!examples/c/mods_dir/readme.txt
!examples/c++/mods_dir/readme.txt
@@ -6,6 +6,5 @@
#include "../../Globals.h"
#include "../ModioC.h"
#include "../schemas/ModioInstalledMod.h"
#include "callbacks/DownloadsCallbacks.h"
#endif

This file was deleted.

Oops, something went wrong.
@@ -28,7 +28,7 @@ void pauseModDownloads();
void resumeModDownloads();
void download(u32 call_number, std::vector<std::string> headers, std::string url, std::string path, FILE *file, std::function<void(u32 call_number, u32 response_code)> callback);
void downloadMod(QueuedModDownload *queued_mod_download);
void queueModDownload(ModioMod *modio_mod);
void queueModDownload(u32 mod_id);
void uploadModfile(QueuedModfileUpload *queued_modfile_upload);
void queueModfileUpload(u32 mod_id, ModioModfileCreator *modio_modfile_creator);
@@ -3,15 +3,7 @@
extern "C" {
void modioInstallMod(u32 mod_id)
{
std::string url = modio::MODIO_URL + modio::MODIO_VERSION_PATH + "games/" + modio::toString(modio::GAME_ID) + "/mods/" + modio::toString(mod_id) + "?api_key=" + modio::API_KEY;
u32 call_number = modio::curlwrapper::getCallNumber();
get_install_mod_callbacks[call_number] = new GetInstallModParams;
get_install_mod_callbacks[call_number]->mod_id = mod_id;
get_install_mod_callbacks[call_number]->destination_path = modio::getModIODirectory() + "mods/" + modio::toString(mod_id);
modio::curlwrapper::get(call_number, url, modio::getHeaders(), &onGetInstallMod);
modio::curlwrapper::queueModDownload(mod_id);
}
bool modioUninstallMod(u32 mod_id)

This file was deleted.

Oops, something went wrong.
@@ -357,55 +357,122 @@ void download(u32 call_number, std::vector<std::string> headers, std::string url
}
}
void downloadMod(QueuedModDownload *queued_mod_download)
{
writeLogLine("Download started. Mod id: " + toString(queued_mod_download->mod_id) + " Url: " + queued_mod_download->url, MODIO_DEBUGLEVEL_LOG);
std::map<u32, QueuedModDownload *> queued_mod_download_callbacks;
FILE *file;
curl_off_t progress = (curl_off_t)getFileSize(queued_mod_download->path);
if (progress != 0)
void onGetInstallMod(u32 call_number, u32 response_code, json response_json)
{
if (response_code == 200)
{
file = fopen(queued_mod_download->path.c_str(), "ab");
writeLogLine("Resuming download from " + toString((u32)progress), MODIO_DEBUGLEVEL_LOG);
ModioMod modio_mod;
modioInitMod(&modio_mod, response_json);
//TODO: Return a download listener error if mod has no modfile
if (modio_mod.modfile.download.binary_url == NULL)
{
modio::writeLogLine("The mod " + modio::toString(modio_mod.id) + " has no modfile to be downloaded", MODIO_DEBUGLEVEL_ERROR);
if (modio::download_callback)
{
modio::download_callback(404, modio_mod.id);
}
return;
}
else
{
QueuedModDownload *queued_mod_download = queued_mod_download_callbacks[call_number];
queued_mod_download->url = modio_mod.modfile.download.binary_url;
writeLogLine("Download started. Mod id: " + toString(queued_mod_download->mod_id) + " Url: " + queued_mod_download->url, MODIO_DEBUGLEVEL_LOG);
FILE *file;
curl_off_t progress = (curl_off_t)getFileSize(queued_mod_download->path);
if (progress != 0)
{
file = fopen(queued_mod_download->path.c_str(), "ab");
writeLogLine("Resuming download from " + toString((u32)progress), MODIO_DEBUGLEVEL_LOG);
}
else
{
file = fopen(queued_mod_download->path.c_str(), "wb");
}
CURL *curl;
curl = curl_easy_init();
queued_mod_download->state = MODIO_MOD_STARTING_DOWNLOAD;
current_mod_download_file = file;
current_mod_download_curl_handle = curl;
current_queued_mod_download = queued_mod_download;
if (curl)
{
queued_mod_download->url = modio::replaceSubstrings(queued_mod_download->url, " ", "%20");
curl_easy_setopt(curl, CURLOPT_URL, queued_mod_download->url.c_str());
if (progress != 0)
{
curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, progress);
writeLogLine("Download progress detected. Resuming from " + modio::toString((u32)progress) + " bytes", MODIO_DEBUGLEVEL_LOG);
}
setHeaders(modio::getHeaders(), curl);
setVerifies(curl);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, onGetFileData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, onModDownloadProgress);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, queued_mod_download);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_multi_add_handle(curl_multi_handle, curl);
}
}
}
else
{
file = fopen(queued_mod_download->path.c_str(), "wb");
modio::writeLogLine("Could not download mod. Could not gather mod information.", MODIO_DEBUGLEVEL_ERROR);
}
}
CURL *curl;
curl = curl_easy_init();
void downloadMod(QueuedModDownload *queued_mod_download)
{
u32 call_number = modio::curlwrapper::getCallNumber();
queued_mod_download_callbacks[call_number] = queued_mod_download;
queued_mod_download->state = MODIO_MOD_STARTING_DOWNLOAD;
current_mod_download_file = file;
current_mod_download_curl_handle = curl;
current_queued_mod_download = queued_mod_download;
std::string url = modio::MODIO_URL + modio::MODIO_VERSION_PATH + "games/" + modio::toString(modio::GAME_ID) + "/mods/" + modio::toString(queued_mod_download->mod_id) + "?api_key=" + modio::API_KEY;
if (curl)
{
queued_mod_download->url = modio::replaceSubstrings(queued_mod_download->url, " ", "%20");
curl_easy_setopt(curl, CURLOPT_URL, queued_mod_download->url.c_str());
modio::curlwrapper::get(call_number, url, modio::getHeaders(), &onGetInstallMod);
}
if (progress != 0)
void queueModDownload(u32 mod_id)
{
for (auto &queued_mod_download : mod_download_queue)
{
if (queued_mod_download->mod_id == mod_id)
{
curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, progress);
writeLogLine("Download progress detected. Resuming from " + modio::toString((u32)progress) + " bytes", MODIO_DEBUGLEVEL_LOG);
writeLogLine("Could not queue the mod: " + toString(mod_id) + ". It's already queued.", MODIO_DEBUGLEVEL_WARNING);
return;
}
}
setHeaders(modio::getHeaders(), curl);
setVerifies(curl);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
QueuedModDownload *queued_mod_download = new QueuedModDownload();
queued_mod_download->state = MODIO_MOD_QUEUED;
queued_mod_download->mod_id = mod_id;
queued_mod_download->current_progress = 0;
queued_mod_download->total_size = 0;
queued_mod_download->url = "";
queued_mod_download->path = modio::getModIODirectory() + "tmp/" + modio::toString(mod_id) + "_modfile.zip";
mod_download_queue.push_back(queued_mod_download);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, onGetFileData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
updateModDownloadQueueFile();
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, onModDownloadProgress);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, queued_mod_download);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
writeLogLine("Download queued. Mod id: " + toString(mod_id), MODIO_DEBUGLEVEL_LOG);
curl_multi_add_handle(curl_multi_handle, curl);
if (mod_download_queue.size() == 1)
{
downloadMod(queued_mod_download);
}
}
@@ -474,45 +541,6 @@ void uploadModfile(QueuedModfileUpload *queued_modfile_upload)
}
}
void queueModDownload(ModioMod *modio_mod)
{
for (auto &queued_mod_download : mod_download_queue)
{
if (queued_mod_download->mod_id == modio_mod->id)
{
writeLogLine("Could not queue the mod: " + toString(modio_mod->id) + ". It's already queued.", MODIO_DEBUGLEVEL_WARNING);
return;
}
}
if(modio_mod->modfile.download.binary_url == NULL)
{
writeLogLine("Could not queue the mod: " + toString(modio_mod->id) + ". It doesn't has a modfile.", MODIO_DEBUGLEVEL_ERROR);
return;
}
std::string url = modio_mod->modfile.download.binary_url;
QueuedModDownload *queued_mod_download = new QueuedModDownload();
queued_mod_download->state = MODIO_MOD_QUEUED;
queued_mod_download->mod_id = modio_mod->id;
queued_mod_download->current_progress = 0;
queued_mod_download->total_size = 0;
queued_mod_download->url = url;
queued_mod_download->mod.initialize(*modio_mod);
queued_mod_download->path = modio::getModIODirectory() + "tmp/" + modio::toString(modio_mod->id) + "_modfile.zip";
mod_download_queue.push_back(queued_mod_download);
updateModDownloadQueueFile();
writeLogLine("Download queued. Mod id: " + toString(modio_mod->id) + " Url: " + url, MODIO_DEBUGLEVEL_LOG);
if (mod_download_queue.size() == 1)
{
downloadMod(queued_mod_download);
}
}
void queueModfileUpload(u32 mod_id, ModioModfileCreator *modio_modfile_creator)
{
for (auto &queued_modfile_upload : modfile_upload_queue)

0 comments on commit 84e3b9d

Please sign in to comment.