54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include "sgu_stdafx.h"
|
|
#include "sgu_mode_download.h"
|
|
|
|
#include "sgu_download_ant.h"
|
|
|
|
#include "sgu_utils.h"
|
|
#include "sgu_download_cos.h"
|
|
|
|
bool downloadFile(const char* szDownloadUrl, const char* szLocalFile)
|
|
{
|
|
if (szDownloadUrl == nullptr || szLocalFile == nullptr)
|
|
{
|
|
printf("Error: download url or local file is null.\n");
|
|
return false;
|
|
}
|
|
|
|
std::string urlStr = szDownloadUrl;
|
|
|
|
if (_stricmp(urlStr.substr(0, 6).c_str(), "cos://") == 0)
|
|
{
|
|
downloadFileFromCOS(urlStr.substr(6).c_str(), szLocalFile);
|
|
}
|
|
else
|
|
{
|
|
CDownloadAnt ant;
|
|
ant.init(convertAnsiStringToWide(szDownloadUrl).c_str(), convertAnsiStringToWide(szLocalFile).c_str());
|
|
|
|
// Wait for download to finish
|
|
ant.begin(true);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool uploadFile(const char* szLocalFile, const char* szUploadUrl)
|
|
{
|
|
if (szLocalFile == nullptr || szUploadUrl == nullptr)
|
|
{
|
|
printf("Error: upload url or local file is null.\n");
|
|
return false;
|
|
}
|
|
|
|
std::string urlStr = szUploadUrl;
|
|
|
|
if (_stricmp(urlStr.substr(0, 6).c_str(), "cos://") == 0)
|
|
{
|
|
uploadFileToCos(szLocalFile, urlStr.substr(6).c_str());
|
|
}
|
|
else
|
|
{
|
|
printf("Error: unsupported upload url scheme: %s\n", szUploadUrl);
|
|
return false;
|
|
}
|
|
return true;
|
|
} |