diff --git a/include/gtorrent/Platform.hpp b/include/gtorrent/Platform.hpp index 4e3852b..42e4090 100644 --- a/include/gtorrent/Platform.hpp +++ b/include/gtorrent/Platform.hpp @@ -37,7 +37,7 @@ namespace gt * Creates a directory * returns the values of the POSIX syscall. */ - int makeDir(std::string, unsigned); + int makeDir(std::string, mode_t); /** * Checks if a directory exists. */ diff --git a/include/gtorrent/Torrent.hpp b/include/gtorrent/Torrent.hpp index 0d1f0da..31abc19 100644 --- a/include/gtorrent/Torrent.hpp +++ b/include/gtorrent/Torrent.hpp @@ -14,7 +14,7 @@ std::string getFileSizeString(boost::int64_t file_size); namespace libtorrent { - struct add_torrent_params; + class add_torrent_params; } namespace gt @@ -56,7 +56,7 @@ namespace gt } // Returns formatted active time as string - inline std::string getTextActiveTime() + inline std::string getActiveTimeString() { return getTimeString(getActiveTime()); } @@ -68,9 +68,16 @@ namespace gt } // Returns formatted eta as string - inline std::string getTextEta() + inline std::string getEtaString() { - return getTimeString(getEta()); + if (getHandle().status().progress_ppm == 1000000) + { + return "∞"; + } + else + { + return getTimeString(getEta()); + } } // Returns a vector of bools for each piece, true if we have it, false otherwise @@ -82,6 +89,7 @@ namespace gt return ((float) getHandle().status().progress_ppm / 1000000.0f) * 100.0f; } + // Returns the current upload rate of the torrent inline unsigned int getUploadRate() { @@ -175,34 +183,34 @@ namespace gt void torrentForceRecheck(); // Returns a friendly string for the torrent state - std::string getTextState(); + std::string getStateString(); // Returns a friendly string for the current upload rate - inline std::string getTextUploadRate() + inline std::string getUploadRateString() { return getRateString(getUploadRate()); } // Returns a friendly string for the current download rate - inline std::string getTextDownloadRate() + inline std::string getDownloadRateString() { return getRateString(getDownloadRate()); } // Returns a friendly string for the current upload total - inline std::string getTextTotalUploaded() + inline std::string getTotalUploadedString() { return getFileSizeString(getTotalUploaded()); } // Returns a friendly string for the current download total - inline std::string getTextTotalDownloaded() + inline std::string getTotalDownloadedString() { return getFileSizeString(getTotalDownloaded()); } // Returns a friendly string for the total size of files in torrent - inline std::string getTextSize() + inline std::string getSizeString() { return getFileSizeString(getSize()); } @@ -210,20 +218,21 @@ namespace gt // Returns a the total size of files remaining to download in torrent inline boost::int64_t getRemaining() { - return getSize() - getTotalDownloaded(); + //return getSize() - getTotalDownloaded(); + return getHandle().status().total_wanted - getHandle().status().total_wanted_done; } // Returns a friendly string for the total size of files remaining to download in torrent - inline std::string getTextRemaining() + inline std::string getRemainingString() { return getFileSizeString(getRemaining()); } // Returns a friendly string for the current ratio - std::string getTextTotalRatio(); + std::string getTotalRatioString(); // Returns a friendly string for the current time remaining - inline std::string getTextTimeRemaining() + inline std::string getTimeRemainingString() { return getTimeString(getTimeRemaining()); } @@ -256,12 +265,203 @@ namespace gt { return getHandle().status().name; } + inline std::string getTorrentFileNameString() + { + //return std::string(getHandle().status().torrent_file); + std::stringstream tfn; + tfn << "torrent-filename.torrent"; + return tfn.str(); + } + + inline std::string getCurrentTrackerString() + { + return getHandle().status().current_tracker; + } + + inline std::string getWantedDoneString() + { + //size_type total_wanted_done; + return getFileSizeString(getHandle().status().total_wanted_done); + } + inline std::string getTotalWantedString() + { + //size_type total_wanted; + return getFileSizeString(getHandle().status().total_wanted); + } + inline std::string getAllTimeUploadString() + { + ////size_type all_time_upload; + return getFileSizeString(getHandle().status().all_time_upload); + } + inline std::string getAllTimeDownloadString() + { + //size_type all_time_download; + return getFileSizeString(getHandle().status().all_time_download); + } + inline std::string getStorageModeString() + { + std::stringstream sm; + sm << getHandle().status().storage_mode; + return sm.str(); + } + inline std::string getProgressString() + { + std::stringstream p; + p << getHandle().status().progress; + return p.str(); + } + inline std::string getProgressPpmString() + { + std::stringstream pp; + pp << getHandle().status().progress_ppm; + return pp.str(); + } + inline std::string getNumSeedsString() + { + std::stringstream ns; + ns << getHandle().status().num_seeds; + return ns.str(); + } + inline std::string getNumPeersString() + { + std::stringstream np; + np << getHandle().status().num_peers; + return np.str(); + } + inline std::string getNumCompleteString() + { + std::stringstream nc; + nc << getHandle().status().num_complete; + return nc.str(); + } + inline std::string getNumIncompleteString() + { + std::stringstream ni; + ni << getHandle().status().num_incomplete; + return ni.str(); + } + inline std::string getListSeedsString() + { + std::stringstream ls; + ls << getHandle().status().list_seeds; + return ls.str(); + } + inline std::string getListPeersString() + { + std::stringstream lp; + lp << getHandle().status().list_peers; + return lp.str(); + } + inline std::string getConnectCandidatesString() + { + std::stringstream cc; + cc << getHandle().status().connect_candidates; + return cc.str(); + } + inline std::string getDistributedCopiesString() + { + std::stringstream dc; + dc << getHandle().status().distributed_copies; + return dc.str(); + } + + inline std::string getNumUploadsString() + { + std::stringstream nu; + nu << getHandle().status().num_uploads; + return nu.str(); + } + inline std::string getNumConnectionsString() + { + std::stringstream nc; + nc << getHandle().status().num_connections; + return nc.str(); + } + inline std::string getSeedingTimeString() + { + return getTimeString(getHandle().status().seeding_time); + } + inline std::string getSeedRankString() + { + std::stringstream sr; + sr << getHandle().status().seed_rank; + return sr.str(); + } + inline std::string getLastScrapeString() + { + return getTimeString(getHandle().status().last_scrape); + } + inline std::string getSparseRegionsString() + { + std::stringstream sr; + sr << getHandle().status().sparse_regions; + return sr.str(); + } + inline std::string getPriorityString() + { + std::stringstream p; + p << getHandle().status().priority; + return p.str(); + } + inline std::string getIpFilterAppliesString() + { + std::stringstream ifa; + ifa << getHandle().status().ip_filter_applies; + return ifa.str(); + } + inline std::string getPausedString() + { + std::stringstream pa; + pa << getHandle().status().paused; + return pa.str(); + } + inline std::string getAutoManagedString() + { + std::stringstream am; + am << getHandle().status().auto_managed; + return am.str(); + } + inline std::string getSequentialDownloadString() + { + std::stringstream sd; + sd << getHandle().status().sequential_download; + return sd.str(); + } + inline std::string getIsSeedingString() + { + std::stringstream ise; + ise << getHandle().status().is_seeding; + return ise.str(); + } + inline std::string getIsFinishedString() + { + std::stringstream ifi; + ifi << getHandle().status().is_finished; + return ifi.str(); + } inline bool hasMetadata() { return getHandle().status().has_metadata; } - + inline std::string getHasMetadataString() + { + std::stringstream hm; + hm << getHandle().status().has_metadata; + return hm.str(); + } + inline std::string getHasIncomingString() + { + std::stringstream hi; + hi << getHandle().status().has_incoming; + return hi.str(); + } + inline std::string getInfoHashString() + { + std::stringstream ih; + ih << getHandle().status().info_hash; + return ih.str(); + } inline std::string getSavePath() { return getHandle().status().save_path; diff --git a/spec.md b/spec.md index 1a306c5..a1fa806 100644 --- a/spec.md +++ b/spec.md @@ -24,19 +24,19 @@ Gets the path passed in to the constructor. Returns the number of seconds the torrent has been active. -- `string getTextActiveTime()` +- `string getActiveTimeString()` Returns the active time formatted as a string. -- `boost::int64_t getEta()` +- `boost::int64_t getEta()` Returns the ETA in seconds for the torrent. -- `string getTextEta()` +- `string getEtaString()` Returns the ETA formatted as string -- `vector getPieces()` +- `vector getPieces()` Returns a vector of bools representing the pieces - true if we have it and false otherwise. @@ -100,27 +100,27 @@ Returns the URL of the last working tracker Force a recheck of the torrent -- `string getTextState()` +- `string getStateString()` Returns a the torrent state as a string. -- `string getTextUploadRate()` +- `string getUploadRateString()` Returns the current upload rate as a string. -- `string getTextDownloadRate()` +- `string getDownloadRateString()` Returns the current download rate as a string. -- `string getTextTotalUploaded()` +- `string getTotalUploadedString()` Returns the current upload total as a string. -- `string getTextTotalDownloaded()` +- `string getTotalDownloadedString()` Returns the current download total as a string. -- `string getTextSize()` +- `string getSizeString()` Returns the total size of files in the torrent as a string. @@ -128,15 +128,15 @@ Returns the total size of files in the torrent as a string. Returns the total size of files remaining to download in the torrent. -- `string getTextRemaining()` +- `string getRemainingString()` Returns the total size of files remaining to download in the torrent as a string. -- `string getTextTotalRatio()` +- `string getTotalRatioString()` Returns the current ratio as a string. -- `string getTextTimeRemaining()` +- `string getTimeRemainingString()` Returns a friendly string for the current time remaining @@ -161,4 +161,3 @@ Resumes the torrent. - `void pause()` Pauses the torrent. - diff --git a/src/Core.cpp b/src/Core.cpp index 24552ef..6344a2d 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -64,14 +64,13 @@ shared_ptr gt::Core::addTorrent(string path, vector *resumeda libtorrent::error_code ec; auto params = t->getTorrentParams(); - params.flags |= 128; // torrent duplication is error params.resume_data = resumedata != nullptr ? *resumedata : vector(); //TODO: Look if fast resume data exists for this torrent libtorrent::torrent_handle h = m_session.add_torrent(params, ec); - if(!h.status().has_metadata) - for(auto tor : getTorrents()) - if(t->getTorrentParams().url == tor->getTorrentParams().url) - return shared_ptr(); + //Actually, libtorrent silentely deals with duplicates, we just have to make this function not to return another Torrent to the UI + for(auto tor : getTorrents()) + if(t->getHandle().status().has_metadata && tor->getHandle().info_hash() == t->getTorrentParams().ti->info_hash()) + return shared_ptr(); if (ec.value() != 0) { diff --git a/src/Platform_linux.cpp b/src/Platform_linux.cpp index 4c40c53..e05a154 100644 --- a/src/Platform_linux.cpp +++ b/src/Platform_linux.cpp @@ -17,7 +17,7 @@ bool gt::Platform::checkDirExist(string dir) if(state == 0) gt::Log::Debug(string(dir + " exists,").c_str()); if(state != 0) - gt::Log::Debug(string(dir + " doesn't exists,").c_str()); + gt::Log::Debug(string(dir + " deoesn't exists,").c_str()); return state == 0; //stat() returns 0 if the dir exist } diff --git a/src/Platform_win.cpp b/src/Platform_win.cpp index 6ca81eb..cf0d8f9 100644 --- a/src/Platform_win.cpp +++ b/src/Platform_win.cpp @@ -33,7 +33,7 @@ string gt::Platform::getDefaultSavePath() return getHomeDir() + "Downloads"; } -string gt::Platform::getDefaultConfigPath() +string getDefaultConfigPath() { return string(getenv("APPDATA")) + "\\gtorrent"; } @@ -43,7 +43,7 @@ char gt::Platform::getFileSeparator() return '\\'; } -string gt::Platform::getHomeDir() +string getHomeDir() { return string(getenv("HOMEDRIVE")) + string(getenv("HOMEPATH")) + '\\'; } @@ -73,11 +73,11 @@ void gt::Platform::associate(bool magnet, bool torrent) // TODO Figure out how to do registry keys and stuff. if(torrent) { - + } if(magnet) { - + } } diff --git a/src/Torrent.cpp b/src/Torrent.cpp index ccae9b8..c7edcb1 100644 --- a/src/Torrent.cpp +++ b/src/Torrent.cpp @@ -76,7 +76,7 @@ string getFileSizeString(boost::int64_t file_size) } else if (file_size > 0) { - fss << file_size << "B "; + fss << file_size << " B"; } return fss.str(); } @@ -137,7 +137,7 @@ bool gt::Torrent::pollEvent(gt::Event &event) return false; } -string gt::Torrent::getTextState() +string gt::Torrent::getStateString() { ostringstream o; int precision = 1; @@ -180,7 +180,7 @@ float gt::Torrent::getTotalRatio() return 0.0f; } -string gt::Torrent::getTextTotalRatio() +string gt::Torrent::getTotalRatioString() { ostringstream ttr; ttr << fixed << setprecision(3) << getTotalRatio();