diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index a798d51ad..c42deac84 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -251,7 +251,13 @@ int ftFileCreator::locked_initializeFileAttrs() * attempt to open file */ +#ifdef WINDOWS_SYS + std::wstring wfile_name; + librs::util::ConvertUtf8ToUtf16(file_name, wfile_name); + fd = _wfopen(wfile_name.c_str(), L"r+b"); +#else fd = fopen64(file_name.c_str(), "r+b"); +#endif if (!fd) { @@ -262,7 +268,11 @@ int ftFileCreator::locked_initializeFileAttrs() std::cerr << std::endl; /* try opening for write */ +#ifdef WINDOWS_SYS + fd = _wfopen(wfile_name.c_str(), L"w+b"); +#else fd = fopen64(file_name.c_str(), "w+b"); +#endif if (!fd) { std::cerr << "ftFileCreator::initializeFileAttrs()"; diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index 3b82105f8..7581f0e90 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -426,54 +426,70 @@ bool RsDirUtil::checkDirectory(const std::string& dir) bool RsDirUtil::checkCreateDirectory(const std::string& dir) { #ifdef RSDIR_DEBUG - std::cerr << "RsDirUtil::checkCreateDirectory() dir: " << dir << std::endl; + std::cerr << "RsDirUtil::checkCreateDirectory() dir: " << dir << std::endl; #endif - DIR *direc = opendir(dir.c_str()); - if (!direc) - { - // directory don't exist. create. + +#ifdef WINDOWS_SYS + std::wstring wdir; + librs::util::ConvertUtf8ToUtf16(dir, wdir); + _WDIR *direc = _wopendir(wdir.c_str()); + if (!direc) +#else + DIR *direc = opendir(dir.c_str()); + if (!direc) +#endif + { + // directory don't exist. create. /******************************** WINDOWS/UNIX SPECIFIC PART ******************/ #ifndef WINDOWS_SYS // UNIX - if (-1 == mkdir(dir.c_str(), 0777)) + if (-1 == mkdir(dir.c_str(), 0777)) #else // WIN - if (-1 == mkdir(dir.c_str())) + if (-1 == _wmkdir(wdir.c_str())) #endif /******************************** WINDOWS/UNIX SPECIFIC PART ******************/ - { + { #ifdef RSDIR_DEBUG - std::cerr << "check_create_directory() Fatal Error et oui--"; - std::cerr < -//#include -//#include -//#include +#ifdef WINDOWS_SYS + _wclosedir(direc); +#else + closedir(direc) ; +#endif + + return 1; +} bool RsDirUtil::cleanupDirectory(const std::string& cleandir, const std::list &keepFiles) { /* check for the dir existance */ +#ifdef WINDOWS_SYS + std::wstring wcleandir; + librs::util::ConvertUtf8ToUtf16(cleandir, wcleandir); + _WDIR *dir = _wopendir(wcleandir.c_str()); +#else DIR *dir = opendir(cleandir.c_str()); +#endif + std::list::const_iterator it; if (!dir) @@ -481,31 +497,60 @@ bool RsDirUtil::cleanupDirectory(const std::string& cleandir, const std::list d_name; + std::wstring wfullname = wcleandir + L"/" + wfname; +#else const std::string &fname = dent -> d_name; std::string fullname = cleandir + "/" + fname; +#endif - if (-1 != stat(fullname.c_str(), &buf)) +#ifdef WINDOWS_SYS + if (-1 != _wstat(wfullname.c_str(), &buf)) +#else + if (-1 != stat(fullname.c_str(), &buf)) +#endif { /* only worry about files */ if (S_ISREG(buf.st_mode)) { +#ifdef WINDOWS_SYS + std::string fname; + librs::util::ConvertUtf16ToUtf8(wfname, fname); +#endif /* check if we should keep it */ if (keepFiles.end() == (it = std::find(keepFiles.begin(), keepFiles.end(), fname))) { /* can remove */ +#ifdef WINDOWS_SYS + _wremove(wfullname.c_str()); +#else remove(fullname.c_str()); +#endif } } } } + /* close directory */ +#ifdef WINDOWS_SYS + _wclosedir(dir); +#else closedir(dir); +#endif return true; } diff --git a/retroshare-gui/src/gui/ShareDialog.cpp b/retroshare-gui/src/gui/ShareDialog.cpp index 7398cebd9..2e0c3323d 100644 --- a/retroshare-gui/src/gui/ShareDialog.cpp +++ b/retroshare-gui/src/gui/ShareDialog.cpp @@ -67,7 +67,7 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent, Qt::WFlags flags void ShareDialog::browseDirectory() { /* select a dir*/ - QString qdir = QFileDialog::getExistingDirectory(this, tr("Select A Folder To Share"), "", QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + QString qdir = QFileDialog::getExistingDirectory(this, tr("Select A Folder To Share"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); /* add it to the server */ if (qdir.isEmpty()) { diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index e5bdf35f7..356eb3a72 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -1339,7 +1339,7 @@ void TransfersDialog::openFolderTransfer() } /* open folder with a suitable application */ - qinfo.setFile(path.c_str()); + qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists() && qinfo.isDir()) { if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) { std::cerr << "openFolderTransfer(): can't open folder " << path << std::endl; @@ -1379,16 +1379,16 @@ void TransfersDialog::previewTransfer() /* open or preview them with a suitable application */ QFileInfo qinfo; if (complete) { - qinfo.setFile(QString::fromStdString(path)); + qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) { std::cerr << "previewTransfer(): can't preview file " << path << std::endl; } } } else { - QString linkName = QString::fromStdString(path) + - QString::fromStdString(info.fname.substr(info.fname.find_last_of('.'))); - if (QFile::link(QString::fromStdString(path), linkName)) { + QString linkName = QString::fromUtf8(path.c_str()) + + QString::fromUtf8(info.fname.substr(info.fname.find_last_of('.')).c_str()); + if (QFile::link(QString::fromUtf8(path.c_str()), linkName)) { qinfo.setFile(linkName); if (qinfo.exists()) { if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) { @@ -1427,7 +1427,7 @@ void TransfersDialog::openTransfer() /* open file with a suitable application */ QFileInfo qinfo; - qinfo.setFile(path.c_str()); + qinfo.setFile(QString::fromUtf8(path.c_str())); if (qinfo.exists()) { if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) { std::cerr << "openTransfer(): can't open file " << path << std::endl; @@ -1436,7 +1436,7 @@ void TransfersDialog::openTransfer() } else { /* rise a message box for incompleted download file */ QMessageBox::information(this, tr("Open Transfer"), - tr("File %1 is not completed. If it is a media file, try to preview it.").arg(info.fname.c_str())); + tr("File %1 is not completed. If it is a media file, try to preview it.").arg(QString::fromUtf8(info.fname.c_str()))); } } diff --git a/retroshare-gui/src/gui/settings/DirectoriesPage.cpp b/retroshare-gui/src/gui/settings/DirectoriesPage.cpp index f9dfe0eb7..83bc5fdb8 100755 --- a/retroshare-gui/src/gui/settings/DirectoriesPage.cpp +++ b/retroshare-gui/src/gui/settings/DirectoriesPage.cpp @@ -220,10 +220,9 @@ void DirectoriesPage::removeShareDirectory() void DirectoriesPage::setIncomingDirectory() { - QString qdir = QFileDialog::getExistingDirectory(this, tr("Set Incoming Directory"), "", - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + QString qdir = QFileDialog::getExistingDirectory(this, tr("Set Incoming Directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - std::string dir = qdir.toStdString(); + std::string dir = qdir.toUtf8().constData(); if (dir != "") { rsFiles->setDownloadDirectory(dir); @@ -249,10 +248,9 @@ void DirectoriesPage::setIncomingDirectory() void DirectoriesPage::setPartialsDirectory() { - QString qdir = QFileDialog::getExistingDirectory(this, tr("Set Partials Directory"), "", - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + QString qdir = QFileDialog::getExistingDirectory(this, tr("Set Partials Directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - std::string dir = qdir.toStdString(); + std::string dir = qdir.toUtf8().constData(); if (dir != "") { rsFiles->setPartialsDirectory(dir);