forked from premiere/premiere-libtorrent
more dynamic link build fixes
This commit is contained in:
parent
9b0f7bbe72
commit
21d1f6f649
|
@ -267,6 +267,38 @@ bool is_absolute_path(std::string const& f)
|
|||
#endif
|
||||
}
|
||||
|
||||
std::string leaf_path(std::string f)
|
||||
{
|
||||
if (f.empty()) return "";
|
||||
char const* first = f.c_str();
|
||||
char const* sep = strrchr(first, '/');
|
||||
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
|
||||
char const* altsep = strrchr(first, '\\');
|
||||
if (sep == 0 || altsep > sep) sep = altsep;
|
||||
#endif
|
||||
if (sep == 0) return f;
|
||||
|
||||
if (sep - first == int(f.size()) - 1)
|
||||
{
|
||||
// if the last character is a / (or \)
|
||||
// ignore it
|
||||
int len = 0;
|
||||
while (sep > first)
|
||||
{
|
||||
--sep;
|
||||
if (*sep == '/'
|
||||
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
|
||||
|| *sep == '\\'
|
||||
#endif
|
||||
)
|
||||
return std::string(sep + 1, len);
|
||||
++len;
|
||||
}
|
||||
return std::string(first, len);
|
||||
}
|
||||
return std::string(sep + 1);
|
||||
}
|
||||
|
||||
std::string path_append(std::string const& lhs, std::string const& rhs)
|
||||
{
|
||||
if (lhs.empty() || lhs == ".") return rhs;
|
||||
|
@ -606,11 +638,7 @@ std::string path_to_url(std::string f)
|
|||
"0123456789";
|
||||
|
||||
// make sure the path is an absolute path
|
||||
#ifdef TORRENT_WINDOWS
|
||||
if (f[1] != ':')
|
||||
#else
|
||||
if (f[0] != '/')
|
||||
#endif
|
||||
if (!is_absolute_path(f))
|
||||
{
|
||||
char cwd[TORRENT_MAX_PATH];
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
|
@ -660,7 +688,7 @@ void add_torrent(libtorrent::session& ses
|
|||
lazy_entry resume_data;
|
||||
|
||||
std::string filename = path_append(save_path, path_append(".resume"
|
||||
, libtorrent::filename(torrent) + ".resume"));
|
||||
, leaf_path(torrent) + ".resume"));
|
||||
|
||||
error_code ec;
|
||||
load_file(filename.c_str(), p.resume_data, ec);
|
||||
|
@ -1033,7 +1061,7 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
|
|||
std::vector<char> out;
|
||||
bencode(std::back_inserter(out), *p->resume_data);
|
||||
torrent_status st = h.status(torrent_handle::query_save_path);
|
||||
save_file(path_append(st.save_path, path_append(".resume", libtorrent::filename(
|
||||
save_file(path_append(st.save_path, path_append(".resume", leaf_path(
|
||||
hash_to_filename[st.info_hash]) + ".resume")), out);
|
||||
if (h.is_valid()
|
||||
&& non_files.find(h) == non_files.end()
|
||||
|
@ -2252,7 +2280,7 @@ int main(int argc, char* argv[])
|
|||
std::vector<char> out;
|
||||
bencode(std::back_inserter(out), *rd->resume_data);
|
||||
save_file(path_append(st.save_path, path_append(".resume"
|
||||
, libtorrent::filename(hash_to_filename[st.info_hash]) + ".resume")), out);
|
||||
, leaf_path(hash_to_filename[st.info_hash]) + ".resume")), out);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,6 +102,38 @@ boost::detail::atomic_count num_suggest(0);
|
|||
// the number of requests made from suggested pieces
|
||||
boost::detail::atomic_count num_suggested_requests(0);
|
||||
|
||||
std::string leaf_path(std::string f)
|
||||
{
|
||||
if (f.empty()) return "";
|
||||
char const* first = f.c_str();
|
||||
char const* sep = strrchr(first, '/');
|
||||
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
|
||||
char const* altsep = strrchr(first, '\\');
|
||||
if (sep == 0 || altsep > sep) sep = altsep;
|
||||
#endif
|
||||
if (sep == 0) return f;
|
||||
|
||||
if (sep - first == int(f.size()) - 1)
|
||||
{
|
||||
// if the last character is a / (or \)
|
||||
// ignore it
|
||||
int len = 0;
|
||||
while (sep > first)
|
||||
{
|
||||
--sep;
|
||||
if (*sep == '/'
|
||||
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
|
||||
|| *sep == '\\'
|
||||
#endif
|
||||
)
|
||||
return std::string(sep + 1, len);
|
||||
++len;
|
||||
}
|
||||
return std::string(first, len);
|
||||
}
|
||||
return std::string(sep + 1);
|
||||
}
|
||||
|
||||
struct peer_conn
|
||||
{
|
||||
peer_conn(io_service& ios, int num_pieces, int blocks_pp, tcp::endpoint const& ep
|
||||
|
@ -879,7 +911,7 @@ int main(int argc, char* argv[])
|
|||
if (strcmp(command, "gen-torrent") == 0)
|
||||
{
|
||||
std::vector<char> tmp;
|
||||
std::string name = filename(torrent_file);
|
||||
std::string name = leaf_path(torrent_file);
|
||||
name = name.substr(0, name.find_last_of('.'));
|
||||
printf("generating torrent: %s\n", name.c_str());
|
||||
generate_torrent(tmp, size ? size : 1024, num_files ? num_files : 1
|
||||
|
|
|
@ -105,11 +105,45 @@ int load_file(std::string const& filename, std::vector<char>& v, libtorrent::err
|
|||
return 0;
|
||||
}
|
||||
|
||||
std::string branch_path(std::string const& f)
|
||||
{
|
||||
if (f.empty()) return f;
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
if (f == "\\\\") return "";
|
||||
#endif
|
||||
if (f == "/") return "";
|
||||
|
||||
int len = f.size();
|
||||
// if the last character is / or \ ignore it
|
||||
if (f[len-1] == '/' || f[len-1] == '\\') --len;
|
||||
while (len > 0)
|
||||
{
|
||||
--len;
|
||||
if (f[len] == '/' || f[len] == '\\')
|
||||
break;
|
||||
}
|
||||
|
||||
if (f[len] == '/' || f[len] == '\\') ++len;
|
||||
return std::string(f.c_str(), len);
|
||||
}
|
||||
|
||||
// do not include files and folders whose
|
||||
// name starts with a .
|
||||
bool file_filter(std::string const& f)
|
||||
{
|
||||
if (filename(f)[0] == '.') return false;
|
||||
if (f.empty()) return false;
|
||||
|
||||
char const* first = f.c_str();
|
||||
char const* sep = strrchr(first, '/');
|
||||
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
|
||||
char const* altsep = strrchr(first, '\\');
|
||||
if (sep == 0 || altsep > sep) sep = altsep;
|
||||
#endif
|
||||
// return false if the first character of the filename is a .
|
||||
if (sep == 0 && f[0] == '.') return false;
|
||||
if (sep[1] == '.') return false;
|
||||
|
||||
fprintf(stderr, "%s\n", f.c_str());
|
||||
return true;
|
||||
}
|
||||
|
@ -242,7 +276,21 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
file_storage fs;
|
||||
std::string full_path = libtorrent::complete(argv[1]);
|
||||
std::string full_path = argv[1];
|
||||
#ifdef TORRENT_WINDOWS
|
||||
if (full_path[1] != ':')
|
||||
#else
|
||||
if (full_path[0] != '/')
|
||||
#endif
|
||||
{
|
||||
char cwd[TORRENT_MAX_PATH];
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
#ifdef TORRENT_WINDOWS
|
||||
full_path = cwd + ("\\" + full_path);
|
||||
#else
|
||||
full_path = cwd + ("/" + full_path);
|
||||
#endif
|
||||
}
|
||||
|
||||
add_files(fs, full_path, file_filter, flags);
|
||||
if (fs.num_files() == 0)
|
||||
|
@ -262,7 +310,7 @@ int main(int argc, char* argv[])
|
|||
t.add_url_seed(*i);
|
||||
|
||||
error_code ec;
|
||||
set_piece_hashes(t, parent_path(full_path)
|
||||
set_piece_hashes(t, branch_path(full_path)
|
||||
, boost::bind(&print_progress, _1, t.num_pieces()), ec);
|
||||
if (ec)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/assert.hpp"
|
||||
#include <cstdlib> // malloc/free/realloc
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <algorithm> // for std::swap
|
||||
|
||||
namespace libtorrent {
|
||||
|
||||
|
|
Loading…
Reference in New Issue