BUGFIX: Stop enforcing UTF-8 and use system locale instead

This commit is contained in:
Christophe Dumez 2009-07-12 08:13:00 +00:00
parent ca83fdecff
commit 0153b03160
22 changed files with 123 additions and 122 deletions

View file

@ -260,7 +260,7 @@ unsigned int bittorrent::getUnfinishedPausedTorrentsNb() const {
// Delete a torrent from the session, given its hash
// permanent = true means that the torrent will be removed from the hard-drive too
void bittorrent::deleteTorrent(QString hash, bool permanent) {
qDebug("Deleting torrent with hash: %s", hash.toUtf8().data());
qDebug("Deleting torrent with hash: %s", hash.toLocal8Bit().data());
QTorrentHandle h = getTorrentHandle(hash);
if(!h.is_valid()) {
qDebug("/!\\ Error: Invalid handle");
@ -344,7 +344,7 @@ void bittorrent::loadWebSeeds(QString hash) {
QStringList seeds_to_delete;
QStringList existing_seeds = h.url_seeds();
foreach(const QString &existing_seed, existing_seeds) {
if(!url_seeds.contains(existing_seed.toUtf8())) {
if(!url_seeds.contains(existing_seed.toLocal8Bit())) {
seeds_to_delete << existing_seed;
}
}
@ -372,7 +372,7 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
// create it if it is not
if(! torrentBackup.exists()) {
if(! torrentBackup.mkpath(torrentBackup.path())) {
std::cerr << "Couldn't create the directory: '" << torrentBackup.path().toUtf8().data() << "'\n";
std::cerr << "Couldn't create the directory: '" << torrentBackup.path().toLocal8Bit().data() << "'\n";
exit(1);
}
}
@ -382,11 +382,11 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
return h;
}
Q_ASSERT(!file.startsWith("http://", Qt::CaseInsensitive) && !file.startsWith("https://", Qt::CaseInsensitive) && !file.startsWith("ftp://", Qt::CaseInsensitive));
qDebug("Adding %s to download list", file.toUtf8().data());
qDebug("Adding %s to download list", file.toLocal8Bit().data());
boost::intrusive_ptr<torrent_info> t;
try {
// Getting torrent file informations
t = new torrent_info(file.toUtf8().data());
t = new torrent_info(file.toLocal8Bit().data());
} catch(std::exception&) {
if(!from_url.isNull()) {
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
@ -410,7 +410,7 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
QFileInfo fi(file);
QString old_hash = fi.baseName();
if(old_hash != hash){
qDebug("* ERROR: Strange, hash changed from %s to %s", old_hash.toUtf8().data(), hash.toUtf8().data());
qDebug("* ERROR: Strange, hash changed from %s to %s", old_hash.toLocal8Bit().data(), hash.toLocal8Bit().data());
}
}
// Check if torrent is already in download list
@ -436,8 +436,8 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
add_torrent_params p;
//Getting fast resume data if existing
std::vector<char> buf;
qDebug("Trying to load fastresume data: %s", (torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toUtf8().data());
if (load_file((torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toUtf8().data(), buf) == 0) {
qDebug("Trying to load fastresume data: %s", (torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().data());
if (load_file((torrentBackup.path()+QDir::separator()+hash+QString(".fastresume")).toLocal8Bit().data(), buf) == 0) {
fastResume = true;
p.resume_data = &buf;
qDebug("Successfuly loaded");
@ -447,13 +447,13 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".savepath"));
if(!savepath_file.exists()) {
savepath_file.open(QIODevice::WriteOnly | QIODevice::Text);
savepath_file.write(savePath.toUtf8());
savepath_file.write(savePath.toLocal8Bit());
savepath_file.close();
}
if(defaultTempPath.isEmpty()) {
p.save_path = savePath.toUtf8().data();
p.save_path = savePath.toLocal8Bit().data();
} else {
p.save_path = defaultTempPath.toUtf8().data();
p.save_path = defaultTempPath.toLocal8Bit().data();
}
p.ti = t;
// Preallocate all?
@ -648,7 +648,7 @@ void bittorrent::enableLSD(bool b) {
}
void bittorrent::loadSessionState() {
boost::filesystem::ifstream ses_state_file((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toUtf8().data()
boost::filesystem::ifstream ses_state_file((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
, std::ios_base::binary);
ses_state_file.unsetf(std::ios_base::skipws);
s->load_state(bdecode(
@ -659,7 +659,7 @@ void bittorrent::loadSessionState() {
void bittorrent::saveSessionState() {
qDebug("Saving session state to disk...");
entry session_state = s->state();
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toUtf8().data()
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
, std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), session_state);
@ -672,7 +672,7 @@ bool bittorrent::enableDHT(bool b) {
entry dht_state;
QString dht_state_path = misc::qBittorrentPath()+QString::fromUtf8("dht_state");
if(QFile::exists(dht_state_path)) {
boost::filesystem::ifstream dht_state_file(dht_state_path.toUtf8().data(), std::ios_base::binary);
boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().data(), std::ios_base::binary);
dht_state_file.unsetf(std::ios_base::skipws);
try{
dht_state = bdecode(std::istream_iterator<char>(dht_state_file), std::istream_iterator<char>());
@ -701,13 +701,13 @@ bool bittorrent::enableDHT(bool b) {
}
void bittorrent::saveTorrentSpeedLimits(QString hash) {
qDebug("Saving speedLimits file for %s", hash.toUtf8().data());
qDebug("Saving speedLimits file for %s", hash.toLocal8Bit().data());
QTorrentHandle h = getTorrentHandle(hash);
int download_limit = h.download_limit();
int upload_limit = h.upload_limit();
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
if(!speeds_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug("* Error: Couldn't open speed limits file for torrent: %s", hash.toUtf8().data());
qDebug("* Error: Couldn't open speed limits file for torrent: %s", hash.toLocal8Bit().data());
return;
}
speeds_file.write(misc::toQByteArray(download_limit)+QByteArray(" ")+misc::toQByteArray(upload_limit));
@ -715,7 +715,7 @@ void bittorrent::saveTorrentSpeedLimits(QString hash) {
}
void bittorrent::loadTorrentSpeedLimits(QString hash) {
// qDebug("Loading speedLimits file for %s", hash.toUtf8().data());
// qDebug("Loading speedLimits file for %s", hash.toLocal8Bit().data());
QTorrentHandle h = getTorrentHandle(hash);
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
if(!speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -748,7 +748,7 @@ void bittorrent::loadFilesPriorities(QTorrentHandle &h) {
}
// Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug("* Error: Couldn't open priorities file: %s", hash.toUtf8().data());
qDebug("* Error: Couldn't open priorities file: %s", hash.toLocal8Bit().data());
return;
}
QByteArray pieces_priorities = pieces_file.readAll();
@ -833,7 +833,7 @@ void bittorrent::saveFastResumeData() {
// Remove old fastresume file if it exists
QFile::remove(torrentBackup.path()+QDir::separator()+ h.hash() + ".fastresume");
QString file = h.hash()+".fastresume";
boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary);
boost::filesystem::ofstream out(fs::path(torrentBackup.path().toLocal8Bit().data()) / file.toLocal8Bit().data(), std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), *rd->resume_data);
// Remove torrent from session
@ -888,7 +888,7 @@ bool bittorrent::isFilePreviewPossible(QString hash) const{
// and add them to download list
void bittorrent::scanDirectory(QString scan_dir) {
FSMutex->lock();
qDebug("Scanning directory: %s", scan_dir.toUtf8().data());
qDebug("Scanning directory: %s", scan_dir.toLocal8Bit().data());
QDir dir(scan_dir);
QStringList filters;
filters << "*.torrent";
@ -897,10 +897,10 @@ void bittorrent::scanDirectory(QString scan_dir) {
QString fullPath = dir.path()+QDir::separator()+file;
QFile torrent(fullPath);
if(torrent.size() != 0) {
qDebug("Adding for scan_dir: %s", fullPath.toUtf8().data());
qDebug("Adding for scan_dir: %s", fullPath.toLocal8Bit().data());
addTorrent(fullPath, true);
} else {
qDebug("Ignoring empty file: %s", fullPath.toUtf8().data());
qDebug("Ignoring empty file: %s", fullPath.toLocal8Bit().data());
}
}
FSMutex->unlock();
@ -1055,7 +1055,7 @@ bool bittorrent::loadTrackerFile(QString hash) {
}
void bittorrent::saveTrackerFile(QString hash) {
qDebug("Saving tracker file for %s", hash.toUtf8().data());
qDebug("Saving tracker file for %s", hash.toLocal8Bit().data());
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QFile tracker_file(torrentBackup.path()+QDir::separator()+ hash + ".trackers");
if(tracker_file.exists()) {
@ -1161,7 +1161,7 @@ void bittorrent::readAlerts() {
}
}
h.save_resume_data();
qDebug("Received finished alert for %s", h.name().toUtf8().data());
qDebug("Received finished alert for %s", h.name().toLocal8Bit().data());
}
}
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) {
@ -1171,10 +1171,10 @@ void bittorrent::readAlerts() {
// Delete old fastresume file if necessary
if(QFile::exists(file))
QFile::remove(file);
qDebug("Saving fastresume data in %s", file.toUtf8().data());
qDebug("Saving fastresume data in %s", file.toLocal8Bit().data());
if (p->resume_data)
{
boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary);
boost::filesystem::ofstream out(fs::path(torrentBackup.path().toLocal8Bit().data()) / file.toLocal8Bit().data(), std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), *p->resume_data);
}
@ -1211,7 +1211,7 @@ void bittorrent::readAlerts() {
else if (tracker_reply_alert* p = dynamic_cast<tracker_reply_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()){
qDebug("Received a tracker reply from %s", (const char*)h.current_tracker().toUtf8());
qDebug("Received a tracker reply from %s", (const char*)h.current_tracker().toLocal8Bit());
QString hash = h.hash();
QHash<QString, QString> errors = trackersErrors.value(hash, QHash<QString, QString>());
// p->url requires at least libtorrent v0.13.1
@ -1239,7 +1239,7 @@ void bittorrent::readAlerts() {
else if (fastresume_rejected_alert* p = dynamic_cast<fastresume_rejected_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()){
qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toUtf8().data(), p->message().c_str());
qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toLocal8Bit().data(), p->message().c_str());
addConsoleMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), QString::fromUtf8("red"));
//emit fastResumeDataRejected(h.name());
}
@ -1252,7 +1252,7 @@ void bittorrent::readAlerts() {
QTorrentHandle h(p->handle);
if(h.is_valid()){
QString hash = h.hash();
qDebug("%s have just finished checking", hash.toUtf8().data());
qDebug("%s have just finished checking", hash.toLocal8Bit().data());
emit torrentFinishedChecking(h);
}
}
@ -1291,7 +1291,7 @@ QString bittorrent::getSavePath(QString hash) {
QDir saveDir(savePath);
if(!saveDir.exists()) {
if(!saveDir.mkpath(saveDir.path())) {
std::cerr << "Couldn't create the save directory: " << saveDir.path().toUtf8().data() << "\n";
std::cerr << "Couldn't create the save directory: " << saveDir.path().toLocal8Bit().data() << "\n";
// XXX: handle this better
return QDir::homePath();
}
@ -1357,7 +1357,7 @@ void bittorrent::saveDHTEntry() {
if(DHTEnabled) {
try{
entry dht_state = s->dht_state();
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("dht_state")).toUtf8().data(), std::ios_base::binary);
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), dht_state);
qDebug("DHT entry saved");