#include "utils.h"
|
|
|
|
std::vector<char> load_file(const std::string filename)
|
|
{
|
|
std::ifstream ifs(filename, std::ios_base::binary);
|
|
ifs.unsetf(std::ios_base::skipws);
|
|
return { std::istream_iterator<char>(ifs), std::istream_iterator<char>() };
|
|
}
|
|
|
|
bool save_file(const std::string filename, const std::vector<char> &bytes)
|
|
{
|
|
std::fstream f(filename, std::ios_base::trunc | std::ios_base::out | std::ios_base::binary);
|
|
f.write(bytes.data(), int(bytes.size()));
|
|
return !f.fail();
|
|
}
|
|
|
|
QString resume_file(const lt::info_hash_t hashes)
|
|
{
|
|
return QString::fromStdString(to_hex(hashes.get_best())) + ".resume";
|
|
}
|
|
|
|
std::string to_hex(const lt::sha1_hash &s)
|
|
{
|
|
std::stringstream ret;
|
|
ret << s;
|
|
return ret.str();
|
|
}
|
|
|
|
std::string file_ext(std::string path)
|
|
{
|
|
return path.substr(path.find_last_of("."));
|
|
}
|
|
|
|
bool should_keep_file(std::string path)
|
|
{
|
|
static const std::unordered_set<std::string> exts({".mp4", ".avi", ".mkv", ".srt"});
|
|
return exts.count(file_ext(path)) > 0;
|
|
}
|