From e7125d21cb172047ce30a826175006003b7c1ca4 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Tue, 22 Jan 2013 19:37:04 +0200 Subject: [PATCH 1/3] Fix torrent creator when saving to a non-latin path in Windows. --- src/torrentcreator/torrentcreatordlg.cpp | 2 +- src/torrentcreator/torrentcreatorthread.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/torrentcreator/torrentcreatordlg.cpp b/src/torrentcreator/torrentcreatordlg.cpp index f5d642bb5..02cd856cb 100644 --- a/src/torrentcreator/torrentcreatordlg.cpp +++ b/src/torrentcreator/torrentcreatordlg.cpp @@ -141,7 +141,7 @@ void TorrentCreatorDlg::on_createButton_clicked() { connect(creatorThread, SIGNAL(creationSuccess(QString, QString)), this, SLOT(handleCreationSuccess(QString, QString))); connect(creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString))); connect(creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int))); - creatorThread->create(input, destination, trackers, url_seeds, comment, check_private->isChecked(), getPieceSize()); + creatorThread->create(input, QDir::toNativeSeparators(destination), trackers, url_seeds, comment, check_private->isChecked(), getPieceSize()); } void TorrentCreatorDlg::handleCreationFailure(QString msg) { diff --git a/src/torrentcreator/torrentcreatorthread.cpp b/src/torrentcreator/torrentcreatorthread.cpp index caf488f64..68803d97d 100644 --- a/src/torrentcreator/torrentcreatorthread.cpp +++ b/src/torrentcreator/torrentcreatorthread.cpp @@ -129,7 +129,14 @@ void TorrentCreatorThread::run() { if (abort) return; // create the torrent and print it to out qDebug("Saving to %s", qPrintable(save_path)); +#ifdef _MSC_VER + wchar_t *wsave_path = new wchar_t[save_path.length()]; + save_path.toWCharArray(wsave_path); + std::ofstream outfile(wsave_path, std::ios_base::out|std::ios_base::binary); + delete[] wsave_path; +#else std::ofstream outfile(save_path.toLocal8Bit().constData(), std::ios_base::out|std::ios_base::binary); +#endif if (outfile.fail()) throw std::exception(); bencode(std::ostream_iterator(outfile), t.generate()); From ed26846a5439e9288965e48e22f0417b97042ef4 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Wed, 23 Jan 2013 17:30:44 +0200 Subject: [PATCH 2/3] Null terminate the wide string in torrent creator. --- src/torrentcreator/torrentcreatorthread.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/torrentcreator/torrentcreatorthread.cpp b/src/torrentcreator/torrentcreatorthread.cpp index 68803d97d..e8e91c03c 100644 --- a/src/torrentcreator/torrentcreatorthread.cpp +++ b/src/torrentcreator/torrentcreatorthread.cpp @@ -130,8 +130,9 @@ void TorrentCreatorThread::run() { // create the torrent and print it to out qDebug("Saving to %s", qPrintable(save_path)); #ifdef _MSC_VER - wchar_t *wsave_path = new wchar_t[save_path.length()]; - save_path.toWCharArray(wsave_path); + wchar_t *wsave_path = new wchar_t[save_path.length()+1]; + int len = save_path.toWCharArray(wsave_path); + wsave_path[len+1] = '\0'; std::ofstream outfile(wsave_path, std::ios_base::out|std::ios_base::binary); delete[] wsave_path; #else From 2309c25aa452bc419f476d36f0cad645e252bb6a Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 26 Jan 2013 20:35:50 +0200 Subject: [PATCH 3/3] Fix null termination of wsave_path. --- src/torrentcreator/torrentcreatorthread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/torrentcreator/torrentcreatorthread.cpp b/src/torrentcreator/torrentcreatorthread.cpp index e8e91c03c..6bbaa8472 100644 --- a/src/torrentcreator/torrentcreatorthread.cpp +++ b/src/torrentcreator/torrentcreatorthread.cpp @@ -132,7 +132,7 @@ void TorrentCreatorThread::run() { #ifdef _MSC_VER wchar_t *wsave_path = new wchar_t[save_path.length()+1]; int len = save_path.toWCharArray(wsave_path); - wsave_path[len+1] = '\0'; + wsave_path[len] = '\0'; std::ofstream outfile(wsave_path, std::ios_base::out|std::ios_base::binary); delete[] wsave_path; #else