Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes required to migrate from uTorrent. #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 ImportHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void ImportHelper::ImportImpl(fs::path const& targetDataDir, ITorrentStateIterat

try
{
Logger(Logger::Info) << prefix << "Import started";
Logger(Logger::Info) << prefix << "Import started, SavePath: " << box.SavePath;
m_targetStore->Import(targetDataDir, box, m_fileStreamProvider);
++result.SuccessCount;
Logger(Logger::Info) << prefix << "Import succeeded";
Expand Down
6 changes: 5 additions & 1 deletion Store/TransmissionStateStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ std::string const Dnd = "dnd";
std::string const DoneDate = "done-date";
std::string const Downloaded = "downloaded";
std::string const Name = "name";
std::string const Files = "files";
std::string const Paused = "paused";
std::string const Priority = "priority";
std::string const Progress = "progress";
Expand Down Expand Up @@ -379,6 +380,9 @@ void TransmissionStateStore::Import(fs::path const& dataDir, Box const& box, IFi
resume[RField::DoneDate] = static_cast<std::int64_t>(box.CompletedAt);
resume[RField::Downloaded] = box.DownloadedSize;
//resume["downloading-time-seconds"] = 0;
try {
resume[RField::Files] = box.Torrent.GetFiles(box.SavePath.filename().string());
} catch (...) {}
//resume["idle-limit"] = ojson::object();
//resume["max-peers"] = 5;
resume[RField::Name] = box.SavePath.filename().string();
Expand All @@ -398,7 +402,7 @@ void TransmissionStateStore::Import(fs::path const& dataDir, Box const& box, IFi
torrent.SetTrackers(box.Trackers);

std::string const baseName = Util::GetEnvironmentVariable("BT_MIGRATE_TRANSMISSION_2_9X", {}).empty() ?
torrent.GetInfoHash() : resume[RField::Name].as_string() + '.' + torrent.GetInfoHash().substr(0, 16);
torrent.GetInfoHash() : box.Caption + '.' + torrent.GetInfoHash().substr(0, 16);

fs::path const torrentFilePath = Detail::GetTorrentFilePath(dataDir, baseName, m_stateType);
fs::create_directories(torrentFilePath.parent_path());
Expand Down
11 changes: 8 additions & 3 deletions Store/uTorrentStateStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ std::string const Path = "path";
std::string const Prio = "prio";
std::string const Started = "started";
std::string const Targets = "targets";
std::string const Caption = "caption";
std::string const Trackers = "trackers";
std::string const Uploaded = "uploaded";
std::string const UpSpeed = "upspeed";
Expand Down Expand Up @@ -181,6 +182,7 @@ bool uTorrentTorrentStateIterator::GetNext(Box& nextBox)
box.UploadedSize = resume[RField::Uploaded].as<std::uint64_t>();
box.CorruptedSize = resume[RField::Corrupt].as<std::uint64_t>();
box.SavePath = Util::GetPath(resume[RField::Path].as<std::string>());
box.Caption = resume[RField::Caption].as<std::string>();
box.BlockSize = box.Torrent.GetPieceSize();
box.RatioLimit = FromStoreRatioLimit(resume[RField::OverrideSeedSettings], resume[RField::WantedRatio]);
box.DownloadSpeedLimit = FromStoreSpeedLimit(resume[RField::DownSpeed]);
Expand All @@ -195,7 +197,7 @@ bool uTorrentTorrentStateIterator::GetNext(Box& nextBox)
fs::path const changedPath = GetChangedFilePath(targets, i);

Box::FileInfo file;
file.DoNotDownload = filePriority == Detail::DoNotDownloadPriority;
file.DoNotDownload = (filePriority == Detail::DoNotDownloadPriority || filePriority < 0);
file.Priority = file.DoNotDownload ? Box::NormalPriority : BoxHelper::Priority::FromStore(filePriority,
Detail::MinPriority, Detail::MaxPriority);
file.Path = changedPath;
Expand Down Expand Up @@ -231,6 +233,7 @@ bool uTorrentTorrentStateIterator::GetNext(fs::path& torrentFilePath, ojson& res

for (; m_torrentIt != m_torrentEnd; ++m_torrentIt)
{
try{
torrentFilePath = m_dataDir / std::string(m_torrentIt->key());
if (torrentFilePath.extension().string() != Detail::TorrentFileExtension)
{
Expand All @@ -239,10 +242,12 @@ bool uTorrentTorrentStateIterator::GetNext(fs::path& torrentFilePath, ojson& res

if (!fs::is_regular_file(torrentFilePath))
{
Logger(Logger::Warning) << "File " << torrentFilePath << " is not a regular file, skipping";
//Logger(Logger::Warning) << "File " << torrentFilePath << " is not a regular file, skipping";
continue;
}

} catch (boost::filesystem::filesystem_error) {
continue;
}
resume = m_torrentIt->value();

++m_torrentIt;
Expand Down
2 changes: 2 additions & 0 deletions Torrent/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct Box
bool DoNotDownload;
int Priority;
boost::filesystem::path Path;
std::string Caption;

FileInfo();
};
Expand All @@ -75,4 +76,5 @@ struct Box
std::vector<FileInfo> Files;
std::vector<bool> ValidBlocks;
std::vector<std::vector<std::string>> Trackers;
std::string Caption;
};
20 changes: 20 additions & 0 deletions Torrent/TorrentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ std::string TorrentInfo::GetName() const
return info["name"].as<std::string>();
}

ojson TorrentInfo::GetFiles(const std::string &base) const
{
ojson result = ojson::array();

ojson const& info = m_torrent["info"];
if (!info.contains("files")) {
throw 20;
}
ojson const& files = info["files"];
for (std::size_t i = 0; i < files.size(); i++) {
std::string file_path = base;
for (ojson const& pathPart : files[i]["path"].array_range())
{
file_path += "/" + pathPart.as<std::string>();
}
result.add(file_path);
}
return result;
}

fs::path TorrentInfo::GetFilePath(std::size_t fileIndex) const
{
fs::path result;
Expand Down
2 changes: 2 additions & 0 deletions Torrent/TorrentInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class TorrentInfo
std::string GetName() const;
boost::filesystem::path GetFilePath(std::size_t fileIndex) const;

ojson GetFiles(const std::string&) const;

void SetTrackers(std::vector<std::vector<std::string>> const& trackers);

static TorrentInfo Decode(std::istream& stream, IStructuredDataCodec const& codec);
Expand Down