This commit is contained in:
Sude 2015-08-15 07:56:53 +03:00
commit b6d07f5343
4 changed files with 15 additions and 5 deletions

View File

@ -68,6 +68,7 @@ class Config
std::string sDLCSubdir; std::string sDLCSubdir;
std::string sGameSubdir; std::string sGameSubdir;
std::string sFileIdString; std::string sFileIdString;
std::string sOutputFilename;
std::string sLanguagePriority; std::string sLanguagePriority;
std::string sPlatformPriority; std::string sPlatformPriority;
std::string sIgnoreDLCCountRegex; std::string sIgnoreDLCCountRegex;

View File

@ -68,7 +68,7 @@ class Downloader
void checkOrphans(); void checkOrphans();
void checkStatus(); void checkStatus();
void updateCache(); void updateCache();
void downloadFileWithId(const std::string& fileid_string); void downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath);
void showWishlist(); void showWishlist();
CURL* curlhandle; CURL* curlhandle;
Timer timer; Timer timer;

View File

@ -151,6 +151,7 @@ int main(int argc, char *argv[])
("update-cache", bpo::value<bool>(&config.bUpdateCache)->zero_tokens()->default_value(false), "Update game details cache") ("update-cache", bpo::value<bool>(&config.bUpdateCache)->zero_tokens()->default_value(false), "Update game details cache")
("no-platform-detection", bpo::value<bool>(&bNoPlatformDetection)->zero_tokens()->default_value(false), "Don't try to detect supported platforms from game shelf.\nSkips the initial fast platform detection and detects the supported platforms from game details which is slower but more accurate.\nUseful in case platform identifier is missing for some games in the game shelf.\nUsing --platform with --list doesn't work with this option.") ("no-platform-detection", bpo::value<bool>(&bNoPlatformDetection)->zero_tokens()->default_value(false), "Don't try to detect supported platforms from game shelf.\nSkips the initial fast platform detection and detects the supported platforms from game details which is slower but more accurate.\nUseful in case platform identifier is missing for some games in the game shelf.\nUsing --platform with --list doesn't work with this option.")
("download-file", bpo::value<std::string>(&config.sFileIdString)->default_value(""), "Download a single file using fileid\nFormat: \"gamename/fileid\"\nor: \"gogdownloader://gamename/fileid\"\nThis option ignores all subdir options. The file is downloaded to directory specified with --directory option.") ("download-file", bpo::value<std::string>(&config.sFileIdString)->default_value(""), "Download a single file using fileid\nFormat: \"gamename/fileid\"\nor: \"gogdownloader://gamename/fileid\"\nThis option ignores all subdir options. The file is downloaded to directory specified with --directory option.")
("output-file,o", bpo::value<std::string>(&config.sOutputFilename)->default_value(""), "Set filename of file downloaded with --download-file.")
("wishlist", bpo::value<bool>(&config.bShowWishlist)->zero_tokens()->default_value(false), "Show wishlist") ("wishlist", bpo::value<bool>(&config.bShowWishlist)->zero_tokens()->default_value(false), "Show wishlist")
("login-api", bpo::value<bool>(&config.bLoginAPI)->zero_tokens()->default_value(false), "Login (API only)") ("login-api", bpo::value<bool>(&config.bLoginAPI)->zero_tokens()->default_value(false), "Login (API only)")
("login-website", bpo::value<bool>(&config.bLoginHTTP)->zero_tokens()->default_value(false), "Login (website only)") ("login-website", bpo::value<bool>(&config.bLoginHTTP)->zero_tokens()->default_value(false), "Login (website only)")
@ -525,12 +526,12 @@ int main(int argc, char *argv[])
size_t back = config.sFileIdString.find(',', front); size_t back = config.sFileIdString.find(',', front);
if (back == (size_t) -1) if (back == (size_t) -1)
back = config.sFileIdString.length(); back = config.sFileIdString.length();
downloader.downloadFileWithId(config.sFileIdString.substr(front, back-front)); downloader.downloadFileWithId(config.sFileIdString.substr(front, back-front), config.sOutputFilename);
front = back + 1; front = back + 1;
} while(front < config.sFileIdString.length()); } while(front < config.sFileIdString.length());
} }
else else
downloader.downloadFileWithId(config.sFileIdString); downloader.downloadFileWithId(config.sFileIdString, config.sOutputFilename);
} }
else if (config.bRepair) // Repair file else if (config.bRepair) // Repair file
downloader.repair(); downloader.repair();

View File

@ -1174,6 +1174,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
// Get directory from filepath // Get directory from filepath
boost::filesystem::path pathname = filepath; boost::filesystem::path pathname = filepath;
pathname = boost::filesystem::absolute(pathname, boost::filesystem::current_path());
std::string directory = pathname.parent_path().string(); std::string directory = pathname.parent_path().string();
std::string filenameXML = pathname.filename().string() + ".xml"; std::string filenameXML = pathname.filename().string() + ".xml";
std::string xml_directory; std::string xml_directory;
@ -3174,13 +3175,17 @@ void Downloader::saveSerials(const std::string& serials, const std::string& file
return; return;
} }
void Downloader::downloadFileWithId(const std::string& fileid_string) void Downloader::downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath)
{ {
size_t pos = fileid_string.find("/"); size_t pos = fileid_string.find("/");
if (pos == std::string::npos) if (pos == std::string::npos)
{ {
std::cout << "Invalid file id " << fileid_string << ": could not find separator \"/\"" << std::endl; std::cout << "Invalid file id " << fileid_string << ": could not find separator \"/\"" << std::endl;
} }
else if (!output_filepath.empty() && boost::filesystem::is_directory(output_filepath))
{
std::cout << "Failed to create the file " << output_filepath << ": Is a directory" << std::endl;
}
else else
{ {
std::string gamename, fileid, url; std::string gamename, fileid, url;
@ -3198,7 +3203,10 @@ void Downloader::downloadFileWithId(const std::string& fileid_string)
{ {
std::string filename, filepath; std::string filename, filepath;
filename.assign(url.begin()+url.find_last_of("/")+1, url.begin()+url.find_first_of("?")); filename.assign(url.begin()+url.find_last_of("/")+1, url.begin()+url.find_first_of("?"));
filepath = Util::makeFilepath(config.sDirectory, filename, gamename); if (output_filepath.empty())
filepath = Util::makeFilepath(config.sDirectory, filename, gamename);
else
filepath = output_filepath;
std::cout << "Downloading: " << filepath << std::endl; std::cout << "Downloading: " << filepath << std::endl;
this->downloadFile(url, filepath, std::string(), gamename); this->downloadFile(url, filepath, std::string(), gamename);
std::cout << std::endl; std::cout << std::endl;