Implement method to verify and write torrent files and file manifests to disk.
Also add some helper methods to file manifest and torrent file get add useful info encapsulated
in the name. Lastly fixed an apart bug in load_directory helper related to files from
boost::directory_iterator being in an arbitrary rather than lexicographical order.
Change-Id: I8a2c2f3224caec65cf97a418785778234a0d4d73
diff --git a/src/torrent-file.hpp b/src/torrent-file.hpp
index 98e222c..0536c17 100644
--- a/src/torrent-file.hpp
+++ b/src/torrent-file.hpp
@@ -107,6 +107,18 @@
getCatalog() const;
/**
+ * @brief Get the segment number for this torrent file
+ */
+ size_t
+ getSegmentNumber() const;
+
+ /**
+ * @brief Get the directory name for this torrent file
+ */
+ std::string
+ getTorrentFilePath() const;
+
+ /**
* @brief Decode from wire format
*/
void
@@ -272,6 +284,19 @@
return m_commonPrefix;
}
+inline std::string
+TorrentFile::getTorrentFilePath() const
+{
+ return (0 == getSegmentNumber() ? getFullName().get(-3) : getFullName().get(-4)).toUri();
+}
+
+inline size_t
+TorrentFile::getSegmentNumber() const
+{
+ const auto& lastComponent = getName().get(getName().size() - 1);
+ return lastComponent.isSequenceNumber() ? lastComponent.toSequenceNumber() : 0;
+}
+
} // namespace ntorrent