diff -Nru linuxdcpp/client/File.h linuxdcpp-ru/client/File.h --- linuxdcpp/client/File.h 2006-10-07 20:31:39.000000000 +0400 +++ linuxdcpp-ru/client/File.h 2006-11-12 19:22:47.000000000 +0300 @@ -132,16 +132,16 @@ DWORD l = ::SetFilePointer(h, 0, &x, FILE_CURRENT); return (int64_t)l | ((int64_t)x)<<32; - } + } virtual void setPos(int64_t pos) throw() { LONG x = (LONG) (pos>>32); ::SetFilePointer(h, (DWORD)(pos & 0xffffffff), &x, FILE_BEGIN); - } + } virtual void setEndPos(int64_t pos) throw() { LONG x = (LONG) (pos>>32); ::SetFilePointer(h, (DWORD)(pos & 0xffffffff), &x, FILE_END); - } + } virtual void movePos(int64_t pos) throw() { LONG x = (LONG) (pos>>32); @@ -178,18 +178,18 @@ return 0; } - static void deleteFile(const string& aFileName) throw() { ::DeleteFile(Text::toT(aFileName).c_str()); } - static void renameFile(const string& source, const string& target) throw(FileException) { - if(!::MoveFile(Text::toT(source).c_str(), Text::toT(target).c_str())) { + static void deleteFile(const string& aFileName) throw() { ::DeleteFile(Text::utf8ToFileName(aFileName).c_str()); } + static void renameFile(const string& source, const string& target) throw(FileException) { + if(!::MoveFile(Text::utf8ToFileName(source).c_str(), Text::utf8ToFileName(target).c_str())) { // Can't move, try copy/delete... - if(!CopyFile(Text::toT(source).c_str(), Text::toT(target).c_str(), FALSE)) { + if(!CopyFile(Text::utf8ToFileName(source).c_str(), Text::utf8ToFileName(target).c_str(), FALSE)) { throw FileException(Util::translateError(GetLastError())); } deleteFile(source); } } static void copyFile(const string& src, const string& target) throw(FileException) { - if(!::CopyFile(Text::toT(src).c_str(), Text::toT(target).c_str(), FALSE)) { + if(!::CopyFile(Text::utf8ToFileName(src).c_str(), Text::utf8ToFileName(target).c_str(), FALSE)) { throw FileException(Util::translateError(GetLastError())); } } @@ -198,7 +198,7 @@ WIN32_FIND_DATA fd; HANDLE hFind; - hFind = FindFirstFile(Text::toT(aFileName).c_str(), &fd); + hFind = FindFirstFile(Text::utf8ToFileName(aFileName).c_str(), &fd); if (hFind == INVALID_HANDLE_VALUE) { return -1; @@ -211,7 +211,7 @@ static void ensureDirectory(const string& aFile) { // Skip the first dir... tstring file; - Text::toT(aFile, file); + Text::utf8ToFileName(aFile, file); wstring::size_type start = file.find_first_of(L"\\/"); if(start == string::npos) return; @@ -249,9 +249,9 @@ m |= O_TRUNC; } - h = open(aFileName.c_str(), m, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + h = open(Text::utf8ToFileName(aFileName).c_str(), m, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if(h == -1) throw FileException("Could not open " + filename); - } + } u_int32_t getLastModified() { struct stat s; @@ -323,6 +323,6 @@ pos = (int64_t) lseek(h,0,SEEK_CUR); eof = (int64_t) lseek(h,0,SEEK_END); - if (eof < pos) + if (eof < pos) ret = extendFile(pos); else ret = ftruncate(h,(off_t)pos); @@ -335,7 +335,7 @@ int64_t pos = getPos(); setPos(newSize); setEOF(); - setPos(pos); + setPos(pos); } virtual size_t flush() throw(Exception) { @@ -353,16 +353,16 @@ work across different mount points, even if the same filesystem is mounted on both.) */ static void renameFile(const string& source, const string& target) throw() { - int ret = ::rename(source.c_str(), target.c_str()); + int ret = ::rename(Text::utf8ToFileName(source).c_str(), Text::utf8ToFileName(target).c_str()); if ( ( ret != 0 ) && ( errno == EXDEV ) ) { - copyFile(source.c_str(), target.c_str()); - deleteFile(source.c_str()); + copyFile(Text::utf8ToFileName(source).c_str(), Text::utf8ToFileName(target).c_str()); + deleteFile(Text::utf8ToFileName(source).c_str()); } else if (ret != 0) throw FileException(source.c_str() + Util::translateError(errno)); } // This doesn't assume all bytes are written in one write call, it is a bit safer - static void copyFile(const string& source, const string& target) throw(FileException) { + static void copyFile(const string& source, const string& target) throw(FileException) { const size_t BUF_SIZE = 64 * 1024; AutoArray buffer(BUF_SIZE); size_t count = BUF_SIZE; @@ -382,14 +382,14 @@ static int64_t getSize(const string& aFileName) { struct stat s; - if(stat(aFileName.c_str(), &s) == -1) + if(stat(Text::utf8ToFileName(aFileName).c_str(), &s) == -1) return -1; return s.st_size; } static void ensureDirectory(const string& aFile) { - string acp = Text::utf8ToAcp(aFile); + string acp = Text::utf8ToFileName(aFile); string::size_type start = 0; while( (start = aFile.find_first_of(L'/', start)) != string::npos) { mkdir(aFile.substr(0, start+1).c_str(), S_IRWXU | S_IRWXG | S_IRWXO); diff -Nru linuxdcpp/client/QueueManager.cpp linuxdcpp-ru/client/QueueManager.cpp --- linuxdcpp/client/QueueManager.cpp 2006-08-17 00:11:46.000000000 +0400 +++ linuxdcpp-ru/client/QueueManager.cpp 2006-11-12 19:13:36.000000000 +0300 @@ -365,11 +365,11 @@ while (struct dirent* ent = readdir(dir)) { if (fnmatch("*.xml.bz2", ent->d_name, 0) == 0 || fnmatch("*.DcLst", ent->d_name, 0) == 0) { - File::deleteFile(path + ent->d_name); + File::deleteFile(path + Text::fileNameToUtf8 (ent->d_name)); } } closedir(dir); - } + } #endif } } diff -Nru linuxdcpp/client/SFVReader.cpp linuxdcpp-ru/client/SFVReader.cpp --- linuxdcpp/client/SFVReader.cpp 2006-06-15 22:30:50.000000000 +0400 +++ linuxdcpp-ru/client/SFVReader.cpp 2006-11-12 19:13:36.000000000 +0300 @@ -79,22 +79,22 @@ string fname = Util::getFileName(fileName); DIR* dir = opendir(path.c_str()); - if (!dir) + if (!dir) return; while (struct dirent* ent = readdir(dir)) { if (fnmatch("*.sfv", ent->d_name, 0) == 0) { try { - if(tryFile(path + Text::fromT(ent->d_name), fname)) { + if(tryFile(path + Text::fileNameToUtf8(ent->d_name), fname)) { closedir(dir); return; } } catch(const FileException&) { // Ignore... - } + } } } - closedir(dir); + closedir(dir); #endif } diff -Nru linuxdcpp/client/ShareManager.cpp linuxdcpp-ru/client/ShareManager.cpp --- linuxdcpp/client/ShareManager.cpp 2006-09-12 00:44:37.000000000 +0400 +++ linuxdcpp-ru/client/ShareManager.cpp 2006-11-12 19:13:36.000000000 +0300 @@ -85,11 +85,11 @@ if (dir) { while (struct dirent* ent = readdir(dir)) { if (fnmatch("files*.xml.bz2", ent->d_name, 0) == 0) { - File::deleteFile(Util::getConfigPath() + ent->d_name); + File::deleteFile(Util::getConfigPath() + Text::fileNameToUtf8 (ent->d_name)); } } closedir(dir); - } + } #endif for(Directory::MapIter j = directories.begin(); j != directories.end(); ++j) { @@ -579,25 +579,25 @@ dir = NULL; data.ent = NULL; } - + ~FileFindIter() { if (dir) closedir(dir); } FileFindIter(const string& name) { - dir = opendir(name.c_str()); + dir = opendir(Text::utf8ToFileName (name).c_str()); if (!dir) return; - data.base = name; + data.base = Text::utf8ToFileName (name); data.ent = readdir(dir); if (!data.ent) { closedir(dir); dir = NULL; } } - + FileFindIter& operator++() { - if (!dir) + if (!dir) return *this; data.ent = readdir(dir); if (!data.ent) { @@ -616,7 +616,7 @@ DirData() : ent(NULL) {} string getFileName() { if (!ent) return Util::emptyString; - return string(ent->d_name); + return Text::fileNameToUtf8 (ent->d_name); } bool isDirectory() { struct stat inode; diff -Nru linuxdcpp/client/Text.cpp linuxdcpp-ru/client/Text.cpp --- linuxdcpp/client/Text.cpp 2006-09-12 00:44:37.000000000 +0400 +++ linuxdcpp-ru/client/Text.cpp 2006-11-12 19:13:36.000000000 +0300 @@ -267,13 +267,10 @@ string Text::acpToUtf8(const string& str) throw() { std::string utf8String; - gchar *utf8CString = g_filename_to_utf8(str.c_str(), -1, NULL, NULL, NULL); + gchar *utf8CString = NULL; + utf8CString = g_convert(str.c_str(), -1, "UTF-8", WGETS("default-charset").c_str(), NULL, NULL, NULL); if (utf8CString == NULL) - { - utf8CString = g_convert_with_fallback(str.c_str(), -1, "UTF-8", "ISO-8859-15", "", NULL, NULL, NULL); - if (utf8CString == NULL) - return utf8String; - } + return utf8String; utf8String = string(utf8CString); g_free(utf8CString); return utf8String; @@ -283,5 +283,5 @@ { std::string acpString; - gchar *acpCString = g_filename_from_utf8(str.c_str(), -1, NULL, NULL, NULL); + gchar *acpCString = g_convert(str.c_str(), -1, WGETS("default-charset").c_str(), "UTF-8", NULL, NULL, NULL); if (acpCString == NULL) return acpString; @@ -290,16 +284,44 @@ return acpString; } + +string Text::utf8ToFileName (const string& str) throw () +{ + std::string acpString; + gchar *acpCString; + acpCString = g_filename_from_utf8(str.c_str(), -1, NULL, NULL, NULL); + + if (acpCString == NULL) + return acpString; + + acpString = string(acpCString); + g_free(acpCString); + return acpString; +} + + +string Text::fileNameToUtf8 (const string& str) throw () +{ + std::string utf8String; + gchar *utf8CString = g_filename_to_utf8(str.c_str(), -1, NULL, NULL, NULL); + + if (utf8CString == NULL) + return utf8String; + + utf8String = string(utf8CString); + g_free(utf8CString); + return utf8String; +} + + string Text::toLower(const string& str) throw() { - std::string lowerString = acpToUtf8(str); + std::string lowerString; gchar *lowerCString; - if (!lowerString.empty()) - { - lowerCString = g_utf8_strdown(lowerString.c_str(), -1); - lowerString = string(lowerCString); - g_free(lowerCString); - } + + lowerCString = g_utf8_strdown(str.c_str(), -1); + lowerString = string(lowerCString); + g_free(lowerCString); return lowerString; } diff -Nru linuxdcpp/client/Text.h linuxdcpp-ru/client/Text.h --- linuxdcpp/client/Text.h 2006-09-12 00:44:37.000000000 +0400 +++ linuxdcpp-ru/client/Text.h 2006-11-12 19:13:36.000000000 +0300 @@ -52,5 +52,8 @@ static string utf8ToAcp(const string& str) throw(); + static string utf8ToFileName (const string& str) throw (); + static string fileNameToUtf8 (const string& str) throw (); + static wstring& utf8ToWide(const string& str, wstring& tmp) throw(); static wstring utf8ToWide(const string& str) throw() { wstring tmp;