diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 858af1d5c..c14632a0a 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -114,6 +114,7 @@ ENDIF(WIN32) FIND_PACKAGE(ZLIB REQUIRED) FIND_PACKAGE(LibXml2 REQUIRED) FIND_PACKAGE(PNG REQUIRED) +FIND_PACKAGE(OpenSSL REQUIRED) FIND_PACKAGE(GIF) FIND_PACKAGE(Jpeg) @@ -253,11 +254,6 @@ IF(WITH_QT5) FIND_PACKAGE(Qt5LinguistTools) FIND_PACKAGE(Qt5Network) - IF(WIN32) - # Please add option to switch off - # FIND_PACKAGE(Qt5WinExtras) - ENDIF() - IF(QT_STATIC) ADD_DEFINITIONS(-DQT_STATICPLUGIN) @@ -343,8 +339,6 @@ IF(WITH_QT5) # Network SET(QT_LIBRARIES ${QT_LIBRARIES} Qt5::Network Qt5::Xml) - - FIND_PACKAGE(OpenSSL REQUIRED) SET(QT_LIBRARIES ${QT_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES}) IF(WIN32) @@ -418,12 +412,8 @@ IF(WITH_NEL) IF(CURL_STATIC) SET(CURL_DEFINITIONS -DCURL_STATICLIB) - FIND_PACKAGE(OpenSSL QUIET) - - IF(OPENSSL_FOUND) - SET(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR}) - SET(CURL_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES}) - ENDIF(OPENSSL_FOUND) + SET(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR}) + SET(CURL_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES}) IF(UNIX) # CURL depends on libidn diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 3b5465eaa..4ddc88076 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -282,6 +282,13 @@ inline sint nlstricmp(const std::string &lhs, const std::string &rhs) { return s inline sint nlstricmp(const std::string &lhs, const char *rhs) { return stricmp(lhs.c_str(),rhs); } inline sint nlstricmp(const char *lhs, const std::string &rhs) { return stricmp(lhs,rhs.c_str()); } +// macros helper to convert UTF-8 std::string and wchar_t* +#define wideToUtf8(str) (ucstring((ucchar*)str).toUtf8()) +#define utf8ToWide(str) ((wchar_t*)ucstring::makeFromUtf8(str).c_str()) + +// wrapper for fopen to be able to open files with an UTF-8 filename +FILE* nlfopen(const std::string &filename, const std::string &mode); + /** Signed 64 bit fseek. Same interface as fseek */ int nlfseek64( FILE *stream, sint64 offset, int origin ); @@ -346,6 +353,8 @@ uint32 humanReadableToBytes (const std::string &str); /// Convert a time into a string that is easily readable by an human, for example 3600 -> "1h" std::string secondsToHumanReadable (uint32 time); +/// Convert a UNIX timestamp to a formatted date in ISO format +std::string timestampToHumanReadable(uint32 timestamp); /// Get a bytes or time in string format and convert it in seconds or bytes uint32 fromHumanReadable (const std::string &str); @@ -357,6 +366,9 @@ std::string formatThousands(const std::string& s); /// The program will be launched in the current directory bool launchProgram (const std::string &programName, const std::string &arguments, bool log = true); +/// Same but with an array of strings for arguments +bool launchProgramArray (const std::string &programName, const std::vector &arguments, bool log = true); + /// This function executes a program and wait for result (used for example for crash report). /// The program will be launched in the current directory sint launchProgramAndWaitForResult (const std::string &programName, const std::string &arguments, bool log = true); @@ -369,6 +381,10 @@ std::string getCommandOutput(const std::string &command); /// Authorized characters in names are A-Z, a-z, 0-9 and _ std::string expandEnvironmentVariables(const std::string &s); +/// Functions to convert a string with arguments to array or array to string (will espace strings with spaces) +bool explodeArguments(const std::string &str, std::vector &args); +std::string joinArguments(const std::vector &args); + /// This function kills a program using his pid (on unix, it uses the kill() POSIX function) bool killProgram(uint32 pid); diff --git a/code/nel/include/nel/misc/debug.h b/code/nel/include/nel/misc/debug.h index 8d2483e4e..54e22880d 100644 --- a/code/nel/include/nel/misc/debug.h +++ b/code/nel/include/nel/misc/debug.h @@ -229,7 +229,7 @@ void setCrashAlreadyReported(bool state); *\code void function(char *filename) { - FILE *fp = fopen (filename, "r"); + FILE *fp = nlfopen (filename, "r"); if (fp==NULL) { nlerror("file not found"); diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index 1fa049fa5..a16b03f15 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -722,7 +722,6 @@ struct CFile /** Try to set the file access to read/write if not already set. * return true if the file doesn't exist or if the file already have RW access. - * Work actually only on Windows and returns always true on other platforms. * \return true if RW access is granted */ static bool setRWAccess(const std::string &filename); diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp index 23ed1bedc..2b90ea1ed 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -1243,23 +1243,23 @@ bool CDriverD3D::init (uintptr_t windowIcon, emptyProc exitFunc) createCursors(); + _WindowClass = "NLD3D" + toString(windowIcon); + // Register a window class - WNDCLASSW wc; + WNDCLASSA wc; memset(&wc,0,sizeof(wc)); wc.style = 0; // CS_HREDRAW | CS_VREDRAW ;//| CS_DBLCLKS; wc.lpfnWndProc = (WNDPROC)WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; - wc.hInstance = GetModuleHandleW(NULL); + wc.hInstance = GetModuleHandleA(NULL); wc.hIcon = (HICON)windowIcon; wc.hCursor = _DefaultCursor; wc.hbrBackground = WHITE_BRUSH; - _WindowClass = "NLD3D" + toString(windowIcon); - ucstring us = _WindowClass; - wc.lpszClassName = (LPCWSTR)us.c_str(); + wc.lpszClassName = _WindowClass.c_str(); wc.lpszMenuName = NULL; - if (!RegisterClassW(&wc)) + if (!RegisterClassA(&wc)) { DWORD error = GetLastError(); if (error != ERROR_CLASS_ALREADY_EXISTS) @@ -1806,7 +1806,7 @@ emptyProc CDriverD3D::getWindowProc() IDriver::TMessageBoxId CDriverD3D::systemMessageBox (const char* message, const char* title, TMessageBoxType type, TMessageBoxIcon icon) { - switch (::MessageBox (_HWnd, message, title, ((type==retryCancelType)?MB_RETRYCANCEL: + switch (::MessageBoxW (_HWnd, utf8ToWide(message), utf8ToWide(title), ((type==retryCancelType)?MB_RETRYCANCEL: (type==yesNoCancelType)?MB_YESNOCANCEL: (type==okCancelType)?MB_OKCANCEL: (type==abortRetryIgnoreType)?MB_ABORTRETRYIGNORE: @@ -2327,13 +2327,13 @@ void CDriverD3D::setWindowIcon(const std::vector &bitmaps) if (winIconBig) { - SendMessage(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); - SendMessage(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig); + SendMessageA(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); + SendMessageA(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig); } else { - SendMessage(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); - SendMessage(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall); + SendMessageA(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); + SendMessageA(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall); } } diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 2b7f76515..e247275ab 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -2527,7 +2527,7 @@ void CDriverGL::retrieveATIDriverVersion() // get from the registry HKEY parentKey; // open key about current video card - LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &parentKey); + LONG result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &parentKey); if (result == ERROR_SUCCESS) { // find last config @@ -2541,7 +2541,7 @@ void CDriverGL::retrieveATIDriverVersion() for(;;) { nameBufferSize = sizeof(subKeyName) / sizeof(subKeyName[0]); - result = RegEnumKeyEx(parentKey, keyIndex, subKeyName, &nameBufferSize, NULL, NULL, NULL, &lastWriteTime); + result = RegEnumKeyExA(parentKey, keyIndex, subKeyName, &nameBufferSize, NULL, NULL, NULL, &lastWriteTime); if (result == ERROR_NO_MORE_ITEMS) break; if (result == ERROR_SUCCESS) { @@ -2577,14 +2577,14 @@ void CDriverGL::retrieveATIDriverVersion() if (configFound) { HKEY subKey; - result = RegOpenKeyEx(parentKey, latestSubKeyName, 0, KEY_READ, &subKey); + result = RegOpenKeyExA(parentKey, latestSubKeyName, 0, KEY_READ, &subKey); if (result == ERROR_SUCCESS) { // see if it is a radeon card DWORD valueType; char driverDesc[256]; DWORD driverDescBufSize = sizeof(driverDesc) / sizeof(driverDesc[0]); - result = RegQueryValueEx(subKey, "DriverDesc", NULL, &valueType, (unsigned char *) driverDesc, &driverDescBufSize); + result = RegQueryValueExA(subKey, "DriverDesc", NULL, &valueType, (unsigned char *) driverDesc, &driverDescBufSize); if (result == ERROR_SUCCESS && valueType == REG_SZ) { toLower(driverDesc); @@ -2592,7 +2592,7 @@ void CDriverGL::retrieveATIDriverVersion() { char driverVersion[256]; DWORD driverVersionBufSize = sizeof(driverVersion) / sizeof(driverVersion[0]); - result = RegQueryValueEx(subKey, "DriverVersion", NULL, &valueType, (unsigned char *) driverVersion, &driverVersionBufSize); + result = RegQueryValueExA(subKey, "DriverVersion", NULL, &valueType, (unsigned char *) driverVersion, &driverVersionBufSize); if (result == ERROR_SUCCESS && valueType == REG_SZ) { int subVersionNumber[4]; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_vertex_program.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_vertex_program.cpp index 1c06ece9a..93d281fec 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_vertex_program.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_vertex_program.cpp @@ -1672,7 +1672,7 @@ bool CDriverGL::compileEXTVertexShader(CVertexProgram *program) } /* - FILE *f = fopen(getLogDirectory() + "test.txt", "wb"); + FILE *f = nlfopen(getLogDirectory() + "test.txt", "wb"); if (f) { std::string vpText; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index 3595a31ba..db6400042 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -326,7 +326,7 @@ bool CDriverGL::init (uintptr_t windowIcon, emptyProc exitFunc) } // Backup monitor color parameters - HDC dc = CreateDC ("DISPLAY", NULL, NULL, NULL); + HDC dc = CreateDCA ("DISPLAY", NULL, NULL, NULL); if (dc) { _NeedToRestoreGammaRamp = GetDeviceGammaRamp (dc, _GammaRampBackuped) != FALSE; @@ -468,7 +468,7 @@ bool CDriverGL::unInit() // Restore monitor color parameters if (_NeedToRestoreGammaRamp) { - HDC dc = CreateDC ("DISPLAY", NULL, NULL, NULL); + HDC dc = CreateDCA ("DISPLAY", NULL, NULL, NULL); if (dc) { if (!SetDeviceGammaRamp (dc, _GammaRampBackuped)) @@ -558,13 +558,13 @@ void CDriverGL::setWindowIcon(const std::vector &bitmaps) if (winIconBig) { - SendMessage(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); - SendMessage(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig); + SendMessageA(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); + SendMessageA(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig); } else { - SendMessage(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); - SendMessage(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall); + SendMessageA(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); + SendMessageA(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall); } #elif defined(NL_OS_MAC) @@ -2622,7 +2622,7 @@ IDriver::TMessageBoxId CDriverGL::systemMessageBox (const char* message, const c { H_AUTO_OGL(CDriverGL_systemMessageBox) #ifdef NL_OS_WINDOWS - switch (::MessageBox (NULL, message, title, ((type==retryCancelType)?MB_RETRYCANCEL: + switch (::MessageBoxW (NULL, utf8ToWide(message), utf8ToWide(title), ((type==retryCancelType)?MB_RETRYCANCEL: (type==yesNoCancelType)?MB_YESNOCANCEL: (type==okCancelType)?MB_OKCANCEL: (type==abortRetryIgnoreType)?MB_ABORTRETRYIGNORE: @@ -2847,7 +2847,7 @@ bool CDriverGL::setMonitorColorProperties (const CMonitorColorProperties &proper #ifdef NL_OS_WINDOWS // Get a DC - HDC dc = CreateDC ("DISPLAY", NULL, NULL, NULL); + HDC dc = CreateDCA ("DISPLAY", NULL, NULL, NULL); if (dc) { // The ramp diff --git a/code/nel/src/3d/font_generator.cpp b/code/nel/src/3d/font_generator.cpp index 21453ba82..cdbaf8834 100644 --- a/code/nel/src/3d/font_generator.cpp +++ b/code/nel/src/3d/font_generator.cpp @@ -22,6 +22,7 @@ #include "nel/misc/debug.h" #include "nel/misc/common.h" #include "nel/misc/path.h" +#include "nel/misc/file.h" #include "nel/3d/font_generator.h" @@ -81,6 +82,93 @@ CFontGenerator *newCFontGenerator(const std::string &fontFileName) return new CFontGenerator(fontFileName); } +// Freetype will call this function to get a buffer in data +static unsigned long nlFreetypeStreamIo(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count) +{ + // if count is 0, we don't need to do anything + if (count > 0) + { + // get a pointer on our CIFile + CIFile *file = (CIFile*)stream->descriptor.pointer; + + // try to seek to offset + if (file->seek(offset, IStream::begin)) + { + try + { + // try to fill buffer with data from file + file->serialBuffer(buffer, count); + } + catch(const EFile &e) + { + nlwarning("Unable to read %u bytes from position %u of %s", (uint)count, (uint)offset, file->getStreamName().c_str()); + count = 0; + } + } + else + { + nlwarning("Unable to seek to position %u of %s", (uint)offset, file->getStreamName().c_str()); + count = 0; + } + } + + return count; +} + +// Freetype will call this function when it won't need to access to file anymore +static void nlFreetypeStreamClose(FT_Stream stream) +{ + if (!stream) return; + + // get a pointer on our CIFile + CIFile *file = (CIFile*)stream->descriptor.pointer; + + if (file) + { + // close and delete file + file->close(); + delete file; + + stream->descriptor.pointer = NULL; + } + + // free Freetype stream structure + free(stream); +} + +// helper to open a font and use our functions to handle BNP files and UTF-8 filenames +static bool createFreetypeStream(const std::string &filename, FT_Open_Args &args) +{ + CIFile *file = new CIFile(); + + if (!file->open(filename)) + { + nlwarning("Unable to open %s", filename.c_str()); + return false; + } + + args.flags = FT_OPEN_STREAM; + args.stream = (FT_Stream)malloc(sizeof(*args.stream)); + + if (args.stream == NULL) + { + nlwarning("Unable to allocate FT_Stream for %s", filename.c_str()); + + delete file; + return false; + } + + args.stream->base = NULL; // only used for memory streams + args.stream->size = file->getFileSize(); + args.stream->pos = 0; + args.stream->descriptor.pointer = file; + args.stream->pathname.pointer = NULL; // filename is already managed by CIFile + args.stream->read = nlFreetypeStreamIo; + args.stream->close = nlFreetypeStreamClose; + + return true; +} + /* * Constructor */ @@ -102,7 +190,14 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri } ++_LibraryInit; - error = FT_New_Face (_Library, fontFileName.c_str (), 0, &_Face); + FT_Open_Args args; + + if (!createFreetypeStream(fontFileName, args)) + { + nlerror ("createFreetypeStream failed with file '%s'", fontFileName.c_str()); + } + + error = FT_Open_Face(_Library, &args, 0, &_Face); if (error) { nlerror ("FT_New_Face() failed with file '%s': %s", fontFileName.c_str(), getFT2Error(error)); @@ -117,7 +212,12 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri if (!fontEx.empty()) { - error = FT_Attach_File (_Face, fontEx.c_str ()); + if (!createFreetypeStream(fontEx, args)) + { + nlerror ("createFreetypeStream failed with file '%s'", fontFileName.c_str()); + } + + error = FT_Attach_Stream(_Face, &args); if (error) { nlwarning ("FT_Attach_File() failed with file '%s': %s", fontEx.c_str(), getFT2Error(error)); diff --git a/code/nel/src/3d/landscapeig_manager.cpp b/code/nel/src/3d/landscapeig_manager.cpp index d69ba3166..f4388f9fa 100644 --- a/code/nel/src/3d/landscapeig_manager.cpp +++ b/code/nel/src/3d/landscapeig_manager.cpp @@ -26,9 +26,6 @@ #include "nel/misc/file.h" #include "nel/misc/hierarchical_timer.h" -// std. -#include - using namespace NLMISC; using namespace std; @@ -85,8 +82,6 @@ void CLandscapeIGManager::initIG(UScene *scene, const std::string &igDesc, UDriv string igFile = CPath::lookup(igDesc); - //ifstream file(igFile.c_str(), ios::in); - CIFile file; // Shape to add should be empty ! diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index a0f65827e..f72198ec7 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -304,7 +304,7 @@ namespace NLGUI return; } - FILE *fp = fopen (tmpdest.c_str(), "wb"); + FILE *fp = nlfopen (tmpdest, "wb"); if (fp == NULL) { curl_easy_cleanup(curl); @@ -411,7 +411,7 @@ namespace NLGUI return false; } - FILE *fp = fopen (tmpdest.c_str(), "wb"); + FILE *fp = nlfopen (tmpdest, "wb"); if (fp == NULL) { curl_easy_cleanup(curl); diff --git a/code/nel/src/ligo/stdligo.h b/code/nel/src/ligo/stdligo.h index c8f4e2a9a..85e7a2120 100644 --- a/code/nel/src/ligo/stdligo.h +++ b/code/nel/src/ligo/stdligo.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/code/nel/src/misc/CMakeLists.txt b/code/nel/src/misc/CMakeLists.txt index c5fb2080e..fb6752982 100644 --- a/code/nel/src/misc/CMakeLists.txt +++ b/code/nel/src/misc/CMakeLists.txt @@ -152,6 +152,7 @@ FILE(GLOB NLMISC_BITMAP FILE(GLOB NLMISC_CRYPT md5.cpp ../../include/nel/misc/md5.h sha1.cpp ../../include/nel/misc/sha1.h + ../../include/nel/misc/wang_hash.h ) SOURCE_GROUP("" FILES ${SRC} ${HEADERS}) diff --git a/code/nel/src/misc/async_file_manager.cpp b/code/nel/src/misc/async_file_manager.cpp index 366237722..e8f6414e4 100644 --- a/code/nel/src/misc/async_file_manager.cpp +++ b/code/nel/src/misc/async_file_manager.cpp @@ -207,16 +207,11 @@ CAsyncFileManager::CFileLoad::CFileLoad (const std::string& sFileName, uint8 **p // *************************************************************************** void CAsyncFileManager::CFileLoad::run (void) { - FILE *f = fopen (_FileName.c_str(), "rb"); + FILE *f = nlfopen (_FileName, "rb"); if (f != NULL) { - uint8 *ptr; - long filesize=CFile::getFileSize (f); - //fseek (f, 0, SEEK_END); - //long filesize = ftell (f); - //nlSleep(5); - //fseek (f, 0, SEEK_SET); - ptr = new uint8[filesize]; + uint32 filesize=CFile::getFileSize (f); + uint8 *ptr = new uint8[filesize]; if (fread (ptr, filesize, 1, f) != 1) nlwarning("AFM: Couldn't read '%s'", _FileName.c_str()); fclose (f); @@ -253,16 +248,11 @@ void CAsyncFileManager::CMultipleFileLoad::run (void) { for (uint32 i = 0; i < _FileNames.size(); ++i) { - FILE *f = fopen (_FileNames[i].c_str(), "rb"); + FILE *f = nlfopen (_FileNames[i], "rb"); if (f != NULL) { - uint8 *ptr; - long filesize=CFile::getFileSize (f); - //fseek (f, 0, SEEK_END); - //long filesize = ftell (f); - //nlSleep(5); - //fseek (f, 0, SEEK_SET); - ptr = new uint8[filesize]; + uint32 filesize=CFile::getFileSize (f); + uint8 *ptr = new uint8[filesize]; if (fread (ptr, filesize, 1, f) != 1) nlwarning("AFM: Couldn't read '%s'", _FileNames[i].c_str()); fclose (f); diff --git a/code/nel/src/misc/big_file.cpp b/code/nel/src/misc/big_file.cpp index 1de1c2b73..a458b602d 100644 --- a/code/nel/src/misc/big_file.cpp +++ b/code/nel/src/misc/big_file.cpp @@ -136,7 +136,7 @@ bool CBigFile::add (const std::string &sBigFileName, uint32 nOptions) CHandleFile &handle= _ThreadFileArray.get(bnp.ThreadFileId); // Open the big file. - handle.File = fopen (sBigFileName.c_str(), "rb"); + handle.File = nlfopen (sBigFileName, "rb"); if (handle.File == NULL) return false; @@ -197,7 +197,7 @@ bool CBigFile::BNP::readHeader() // Only external use if (InternalUse || BigFileName.empty()) return false; - FILE *f = fopen (BigFileName.c_str(), "rb"); + FILE *f = nlfopen (BigFileName, "rb"); if (f == NULL) return false; bool res = readHeader(f); @@ -348,7 +348,7 @@ bool CBigFile::BNP::appendHeader() // Only external use if (InternalUse || BigFileName.empty()) return false; - FILE *f = fopen (BigFileName.c_str(), "ab"); + FILE *f = nlfopen (BigFileName, "ab"); if (f == NULL) return false; uint32 nNbFile = (uint32)SFiles.size(); @@ -438,10 +438,10 @@ bool CBigFile::BNP::appendFile(const std::string &filename) SFiles.push_back(ftmp); OffsetFromBeginning += ftmp.Size; - FILE *f1 = fopen(BigFileName.c_str(), "ab"); + FILE *f1 = nlfopen(BigFileName, "ab"); if (f1 == NULL) return false; - FILE *f2 = fopen(filename.c_str(), "rb"); + FILE *f2 = nlfopen(filename, "rb"); if (f2 == NULL) { fclose(f1); @@ -473,7 +473,7 @@ bool CBigFile::BNP::unpack(const std::string &sDestDir, TUnpackProgressCallback // Only external use if (InternalUse || BigFileName.empty()) return false; - FILE *bnp = fopen (BigFileName.c_str(), "rb"); + FILE *bnp = nlfopen (BigFileName, "rb"); if (bnp == NULL) return false; @@ -506,7 +506,7 @@ bool CBigFile::BNP::unpack(const std::string &sDestDir, TUnpackProgressCallback return false; } - out = fopen (filename.c_str(), "wb"); + out = nlfopen (filename, "wb"); if (out != NULL) { nlfseek64 (bnp, rBNPFile.Pos, SEEK_SET); @@ -681,7 +681,7 @@ FILE* CBigFile::getFile (const std::string &sFileName, uint32 &rFileSize, */ if(handle.File== NULL) { - handle.File = fopen (bnp->BigFileName.c_str(), "rb"); + handle.File = nlfopen (bnp->BigFileName, "rb"); if (handle.File == NULL) { nlwarning ("bnp: can't fopen big file '%s' error %d '%s'", bnp->BigFileName.c_str(), errno, strerror(errno)); diff --git a/code/nel/src/misc/bitmap.cpp b/code/nel/src/misc/bitmap.cpp index 798a52019..11a27e67e 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -555,17 +555,10 @@ uint8 CBitmap::readDDS(NLMISC::IStream &f, uint mipMapSkip) (very) bad rendered with this fix so we have to deactivate it the for moment */ -//#ifdef NL_OS_WINDOWS -// if(PixelFormat==DXTC1) //AlphaBitDepth -// { -// PixelFormat = DXTC1Alpha; -// } -//#else if(PixelFormat==DXTC1 && _DDSSurfaceDesc[21]>0) //AlphaBitDepth { PixelFormat = DXTC1Alpha; } -//#endif if(PixelFormat!= DXTC1 && PixelFormat!= DXTC1Alpha && PixelFormat!= DXTC3 && PixelFormat!= DXTC5) { diff --git a/code/nel/src/misc/cmd_args.cpp b/code/nel/src/misc/cmd_args.cpp index 85239e8ff..65aae5769 100644 --- a/code/nel/src/misc/cmd_args.cpp +++ b/code/nel/src/misc/cmd_args.cpp @@ -199,45 +199,16 @@ bool CCmdArgs::parse(const std::string &args) std::vector argv; #ifdef NL_OS_WINDOWS - char str[4096]; - uint len = GetModuleFileNameA(NULL, str, 4096); + wchar_t str[4096]; + uint len = GetModuleFileNameW(NULL, str, 4096); + // first argument should be full path to executable if (len && len < 4096) - argv.push_back(str); + argv.push_back(wideToUtf8(str)); #endif - std::string::size_type pos1 = 0, pos2 = 0; - - do - { - // Look for the first non space character - pos1 = args.find_first_not_of (" ", pos2); - if(pos1 == std::string::npos) break; - - // Look for the first space or " - pos2 = args.find_first_of (" \"", pos1); - if(pos2 != std::string::npos) - { - // " ? - if(args[pos2] == '"') - { - // Look for the final \" - pos2 = args.find_first_of ("\"", pos2+1); - if(pos2 != std::string::npos) - { - // Look for the first space - pos2 = args.find_first_of (" ", pos2+1); - } - } - } - - // Compute the size of the string to extract - std::string::difference_type length = (pos2 != std::string::npos) ? pos2-pos1 : std::string::npos; - - std::string tmp = args.substr (pos1, length); - argv.push_back (tmp); - } - while(pos2 != std::string::npos); + // convert string with arguments to array + explodeArguments(args, argv); return parse(argv); } diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index decd52dbf..5954ac9c9 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -506,6 +506,21 @@ string secondsToHumanReadable (uint32 time) return toString ("%u%s", res, divTable[div]); } +std::string timestampToHumanReadable(uint32 timestamp) +{ + char buffer[30]; + time_t dtime = timestamp; + tm *tms = localtime(&dtime); + + if (tms) + { + strftime(buffer, 30, "%Y-%m-%d %H:%M:%S", tms); + return std::string(buffer); + } + + return ""; +} + uint32 fromHumanReadable (const std::string &str) { if (str.size() == 0) @@ -710,50 +725,54 @@ bool abortProgram(uint32 pid) #endif } -bool launchProgram(const std::string &programName, const std::string &arguments, bool log) -{ #ifdef NL_OS_WINDOWS - STARTUPINFOA si; - PROCESS_INFORMATION pi; +static bool createProcess(const std::string &programName, const std::string &arguments, bool log, PROCESS_INFORMATION &pi) +{ + STARTUPINFOW si; memset(&si, 0, sizeof(si)); memset(&pi, 0, sizeof(pi)); si.cb = sizeof(si); // Enable nlassert/nlstop to display the error reason & callstack - const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS"); - TCHAR envBuf [2]; - if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) != 0) + const char *SE_TRANSLATOR_IN_MAIN_MODULE = "NEL_SE_TRANS"; + + char envBuf[2]; + if (GetEnvironmentVariableA(SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2) != 0) { - SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL ); + SetEnvironmentVariableA(SE_TRANSLATOR_IN_MAIN_MODULE, NULL); } - const char *sProgramName = programName.c_str(); - + wchar_t *sProgramName = NULL; + std::string args; // a .bat file must have first parameter to NULL and use 2nd parameter to pass filename if (CFile::getExtension(programName) == "bat") { - sProgramName = NULL; args = "\"" + programName + "\" " + arguments; } else { + ucstring ucProgramName; + ucProgramName.fromUtf8(programName); + + sProgramName = new wchar_t[MAX_PATH]; + wcscpy(sProgramName, (wchar_t*)ucProgramName.c_str()); + args = arguments; } - BOOL res = CreateProcessA(sProgramName, (char*)args.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); + BOOL res = CreateProcessW(sProgramName, utf8ToWide(args), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); - if (res) + if (sProgramName) { - //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); - return true; + delete [] sProgramName; + sProgramName = NULL; } - else + + if (!res) { if (log) { @@ -763,13 +782,31 @@ bool launchProgram(const std::string &programName, const std::string &arguments, CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); + + return false; } + return true; +} + +#endif + +bool launchProgram(const std::string &programName, const std::string &arguments, bool log) +{ +#ifdef NL_OS_WINDOWS + PROCESS_INFORMATION pi; + + if (!createProcess(programName, arguments, log, pi)) return false; + + //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + return true; #else #ifdef NL_OS_MAC // special OS X case with bundles - if (toLower(programName).find(".app") != std::string::npos) + if (toLower(CFile::getExtension(programName)) == ".app") { // we need to open bundles with "open" command std::string command = NLMISC::toString("open \"%s\"", programName.c_str()); @@ -794,6 +831,7 @@ bool launchProgram(const std::string &programName, const std::string &arguments, #endif static bool firstLaunchProgram = true; + if (firstLaunchProgram) { // The aim of this is to avoid defunct process. @@ -814,15 +852,7 @@ bool launchProgram(const std::string &programName, const std::string &arguments, // convert one arg into several args vector args; - string::size_type pos1 = 0, pos2 = 0; - do - { - pos1 = arguments.find_first_not_of (" ", pos2); - if (pos1 == string::npos) break; - pos2 = arguments.find_first_of (" ", pos1); - args.push_back (arguments.substr (pos1, pos2-pos1)); - } - while (pos2 != string::npos); + explodeArguments(arguments, args); // Store the size of each arg vector argv(args.size()+2); @@ -867,78 +897,136 @@ bool launchProgram(const std::string &programName, const std::string &arguments, return false; } -sint launchProgramAndWaitForResult(const std::string &programName, const std::string &arguments, bool log) +bool launchProgramArray (const std::string &programName, const std::vector &arguments, bool log) { - sint res = 0; - #ifdef NL_OS_WINDOWS - STARTUPINFOA si; PROCESS_INFORMATION pi; - memset(&si, 0, sizeof(si)); - memset(&pi, 0, sizeof(pi)); + std::string argumentsJoined = joinArguments(arguments); - si.cb = sizeof(si); + if (!createProcess(programName, argumentsJoined, log, pi)) return false; - // Enable nlassert/nlstop to display the error reason & callstack - const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS"); - TCHAR envBuf [2]; - if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) != 0) + //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + return true; +#else + +#ifdef NL_OS_MAC + // special OS X case with bundles + if (toLower(CFile::getExtension(programName)) == "app") { - SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL ); - } + // we need to open bundles with "open" command + std::string command = NLMISC::toString("open \"%s\"", programName.c_str()); - const char *sProgramName = programName.c_str(); + std::string argumentsJoined = joinArguments(arguments); - std::string args; + // append arguments if any + if (!argumentsJoined.empty()) + { + command += NLMISC::toString(" --args %s", argumentsJoined.c_str()); + } - // a .bat file must have first parameter to NULL and use 2nd parameter to pass filename - if (CFile::getExtension(programName) == "bat") - { - sProgramName = NULL; - args = "\"" + programName + "\" " + arguments; - } - else - { - args = arguments; + int res = system(command.c_str()); + + if (!res) return true; + + if (log) + { + nlwarning ("LAUNCH: Failed launched '%s' with arg '%s' return code %d", programName.c_str(), argumentsJoined.c_str(), res); + } + + return false; } +#endif - BOOL ok = CreateProcessA(sProgramName, (char*)args.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); + static bool firstLaunchProgram = true; - if (ok) + if (firstLaunchProgram) { - // Successfully created the process. Wait for it to finish. - WaitForSingleObject(pi.hProcess, INFINITE); + // The aim of this is to avoid defunct process. + // + // From "man signal": + //------ + // According to POSIX (3.3.1.3) it is unspecified what happens when SIGCHLD is set to SIG_IGN. Here + // the BSD and SYSV behaviours differ, causing BSD software that sets the action for SIGCHLD to + // SIG_IGN to fail on Linux. + //------ + // + // But it works fine on my GNU/Linux so I do this because it's easier :) and I don't know exactly + // what to do to be portable. + signal(SIGCHLD, SIG_IGN); - // Get the exit code. - DWORD exitCode = 0; - ok = GetExitCodeProcess(pi.hProcess, &exitCode); + firstLaunchProgram = false; + } - //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); + // Store the size of each arg + vector argv(arguments.size()+2); + uint i = 0; + argv[i] = (char *)programName.c_str(); + for (; i < arguments.size(); i++) + { + argv[i+1] = (char *) arguments[i].c_str(); + } + argv[i+1] = NULL; + + int status = vfork (); + ///////////////////////////////////////////////////////// + /// WARNING : NO MORE INSTRUCTION AFTER VFORK ! + /// READ VFORK manual + ///////////////////////////////////////////////////////// + if (status == -1) + { + char *err = strerror (errno); + if (log) + nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), joinArguments(arguments).c_str(), errno, err); + } + else if (status == 0) + { + // Exec (the only allowed instruction after vfork) + status = execvp(programName.c_str(), &argv.front()); - if (ok) - { - res = (sint)exitCode; - } - else + if (status == -1) { - if (log) - nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + perror("Failed launched"); + _exit(EXIT_FAILURE); } } else { - if (log) - { - sint lastError = getLastError(); - nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), lastError, formatErrorMessage(lastError).c_str()); - } + //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); + return true; } +#endif + + return false; +} + +sint launchProgramAndWaitForResult(const std::string &programName, const std::string &arguments, bool log) +{ +#ifdef NL_OS_WINDOWS + PROCESS_INFORMATION pi; + + if (!createProcess(programName, arguments, log, pi)) return -1; + + // Successfully created the process. Wait for it to finish. + WaitForSingleObject(pi.hProcess, INFINITE); + + // Get the exit code. + DWORD exitCode = 0; + BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode); + + //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + if (ok) return (sint)exitCode; + + if (log) + nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + + return -1; #else // program name is the only required string std::string command = programName; @@ -947,13 +1035,13 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st if (!arguments.empty()) command += " " + arguments; // execute the command - res = system(command.c_str()); + sint res = system(command.c_str()); if (res && log) nlwarning ("LAUNCH: Failed launched '%s' with arg '%s' return code %d", programName.c_str(), arguments.c_str(), res); -#endif return res; +#endif } std::string getCommandOutput(const std::string &command) @@ -1050,6 +1138,75 @@ std::string expandEnvironmentVariables(const std::string &s) return ret; } +bool explodeArguments(const std::string &str, std::vector &args) +{ + if (str.empty()) return false; + + std::string::size_type pos1 = 0, pos2 = 0; + + do + { + // Look for the first non space character + pos1 = str.find_first_not_of (" ", pos2); + if (pos1 == std::string::npos) break; + + // Look for the first space or " + pos2 = str.find_first_of (" \"", pos1); + if (pos2 != std::string::npos) + { + // " ? + if (str[pos2] == '"') + { + // Look for the final \" + pos2 = str.find_first_of ("\"", pos2+1); + if (pos2 != std::string::npos) + { + // Look for the first space + pos2 = str.find_first_of (" ", pos2+1); + } + } + } + + // Compute the size of the string to extract + std::string::difference_type length = (pos2 != std::string::npos) ? pos2-pos1 : std::string::npos; + + std::string tmp = str.substr (pos1, length); + + // remove escape " from argument + if (tmp.length() > 1 && tmp[0] == '"' && tmp[tmp.length()-1] == '"') tmp = tmp.substr(1, tmp.length()-2); + + args.push_back (tmp); + } + while(pos2 != std::string::npos); + + return true; +} + +std::string joinArguments(const std::vector &args) +{ + std::string res; + + for(uint i = 0, len = (uint)args.size(); i < len; ++i) + { + const std::string &arg = args[i]; + + // prepend space + if (!res.empty()) res += " "; + + // escape only if spaces or empty argument + if (arg.empty() || arg.find(' ') != std::string::npos) + { + res += "\"" + arg + "\""; + } + else + { + res += arg; + } + } + + return res; +} + /* * Display the bits (with 0 and 1) composing a byte (from right to left) */ @@ -1099,6 +1256,14 @@ void displayDwordBits( uint32 b, uint nbits, sint beginpos, bool displayBegin, N } } +FILE* nlfopen(const std::string &filename, const std::string &mode) +{ +#ifdef NL_OS_WINDOWS + return _wfopen(utf8ToWide(filename), utf8ToWide(mode)); +#else + return fopen(filename.c_str(), mode.c_str()); +#endif +} int nlfseek64( FILE *stream, sint64 offset, int origin ) { diff --git a/code/nel/src/misc/config_file/config_file.cpp b/code/nel/src/misc/config_file/config_file.cpp index c969f614d..093992487 100644 --- a/code/nel/src/misc/config_file/config_file.cpp +++ b/code/nel/src/misc/config_file/config_file.cpp @@ -600,7 +600,7 @@ void CConfigFile::save () const // Avoid any problem, Force Locale to default setlocale(LC_ALL, "C"); - FILE *fp = fopen (getFilename().c_str (), "w"); + FILE *fp = nlfopen (getFilename(), "w"); if (fp == NULL) { nlwarning ("CF: Couldn't create %s file", getFilename().c_str ()); diff --git a/code/nel/src/misc/cpu_time_stat.cpp b/code/nel/src/misc/cpu_time_stat.cpp index 6441a8b45..455104b25 100644 --- a/code/nel/src/misc/cpu_time_stat.cpp +++ b/code/nel/src/misc/cpu_time_stat.cpp @@ -42,7 +42,7 @@ bool CCPUTimeStat::getCPUTicks(uint64& user, uint64& nice, uint64& system, uint6 #ifdef NL_OS_UNIX const char* statfile = "/proc/stat"; - FILE* f = fopen(statfile, "r"); + FILE* f = nlfopen(statfile, "r"); if (f == NULL) return false; @@ -66,7 +66,7 @@ bool CCPUTimeStat::getPIDTicks(uint64& utime, uint64& stime, uint64& cutime, uin #ifdef NL_OS_UNIX std::string statfile = NLMISC::toString("/proc/%u/stat", pid); - FILE* f = fopen(statfile.c_str(), "r"); + FILE* f = nlfopen(statfile, "r"); if (f == NULL) return false; diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index 44cd6f706..1f0bb4fd1 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -310,14 +310,14 @@ static DWORD __stdcall GetModuleBase(HANDLE hProcess, DWORD dwReturnAddress) &memoryBasicInfo, sizeof(memoryBasicInfo))) { DWORD cch = 0; - char szFile[MAX_PATH] = { 0 }; + wchar_t szFile[MAX_PATH] = { 0 }; - cch = GetModuleFileNameA((HINSTANCE)memoryBasicInfo.AllocationBase, + cch = GetModuleFileNameW((HINSTANCE)memoryBasicInfo.AllocationBase, szFile, MAX_PATH); - if (cch && (lstrcmpA(szFile, "DBFN")== 0)) - { - if (!SymLoadModule(hProcess, + if (cch && (lstrcmpA(szFile, "DBFN")== 0)) + { + if (!SymLoadModule(hProcess, NULL, "MN", NULL, (DWORD) memoryBasicInfo.AllocationBase, 0)) { @@ -527,9 +527,9 @@ public: string progname; if(!shortExc.empty() || !longExc.empty()) { - char name[1024]; - GetModuleFileNameA (NULL, name, 1023); - progname = CFile::getFilename(name); + wchar_t name[1024]; + GetModuleFileNameW (NULL, name, 1023); + progname = CFile::getFilename(wideToUtf8(name)); progname += " "; } @@ -1171,12 +1171,12 @@ void createDebug (const char *logPath, bool logInFile, bool eraseLastLog) // Use an environment variable to share the value among the EXE and its child DLLs // (otherwise there would be one distinct bool by module, and the last // _set_se_translator would overwrite the previous ones) - const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS"); - TCHAR envBuf [2]; - if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) == 0) + const char *SE_TRANSLATOR_IN_MAIN_MODULE = "NEL_SE_TRANS"; + char envBuf [2]; + if ( GetEnvironmentVariableA( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) == 0) { _set_se_translator(exceptionTranslator); - SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, _T("1") ); + SetEnvironmentVariableA( SE_TRANSLATOR_IN_MAIN_MODULE, "1" ); } } # endif // NL_OS_WINDOWS diff --git a/code/nel/src/misc/diff_tool.cpp b/code/nel/src/misc/diff_tool.cpp index 15a91cdb8..f57746b1a 100644 --- a/code/nel/src/misc/diff_tool.cpp +++ b/code/nel/src/misc/diff_tool.cpp @@ -93,7 +93,7 @@ bool loadStringFile(const std::string filename, vector &stringInfos return true; } */ -/* FILE *fp = fopen(filename.c_str(), "rb"); +/* FILE *fp = nlfopen(filename, "rb"); if (fp == NULL) { diff --git a/code/nel/src/misc/displayer.cpp b/code/nel/src/misc/displayer.cpp index 60fa244b6..798a4f80a 100644 --- a/code/nel/src/misc/displayer.cpp +++ b/code/nel/src/misc/displayer.cpp @@ -216,7 +216,7 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess static bool consoleModeTest = false; if (!consoleModeTest) { - HANDLE handle = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); + HANDLE handle = CreateFileA ("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); consoleMode = handle != INVALID_HANDLE_VALUE; if (consoleMode) CloseHandle (handle); @@ -286,20 +286,14 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess // WARNING: READ THIS !!!!!!!!!!!!!!!! /////////////////////////// // If at the release time, it freezes here, it's a microsoft bug: // http://support.microsoft.com/support/kb/articles/q173/2/60.asp - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(str2).c_str()); + OutputDebugStringW(utf8ToWide(str2)); } else { - /*OutputDebugString(ss2.str().c_str()); - OutputDebugString("\n\t\t\t"); - OutputDebugString("message end: "); - OutputDebugString(&message[strlen(message) - 1024]); - OutputDebugString("\n");*/ - sint count = 0; uint n = (uint)strlen(message); std::string s(&str2.c_str()[0], (str2.size() - n)); - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str()); + OutputDebugStringW(utf8ToWide(s)); for(;;) { @@ -307,15 +301,15 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess if((n - count) < maxOutString ) { s = std::string(&message[count], (n - count)); - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str()); - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8("\n").c_str()); + OutputDebugStringW(utf8ToWide(s)); + OutputDebugStringW(L"\n"); break; } else { s = std::string(&message[count] , count + maxOutString); - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str()); - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8("\n\t\t\t").c_str()); + OutputDebugStringW(utf8ToWide(s)); + OutputDebugStringW(L"\n\t\t\t"); count += maxOutString; } } @@ -329,13 +323,13 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess if (pos+1000 < args.CallstackAndLog.size ()) { splited = args.CallstackAndLog.substr (pos, 1000); - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(splited).c_str()); + OutputDebugStringW(utf8ToWide(splited)); pos += 1000; } else { splited = args.CallstackAndLog.substr (pos); - OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(splited).c_str()); + OutputDebugStringW(utf8ToWide(splited)); break; } } @@ -491,7 +485,7 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes if (_FilePointer == (FILE*)1) { - _FilePointer = fopen (_FileName.c_str(), "at"); + _FilePointer = nlfopen (_FileName, "at"); if (_FilePointer == NULL) printf ("Can't open log file '%s': %s\n", _FileName.c_str(), strerror (errno)); } @@ -702,58 +696,4 @@ void CMsgBoxDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *m } } - - -/***************************************************************/ -/******************* THE FOLLOWING CODE IS COMMENTED OUT *******/ -/*************************************************************** -void CStdDisplayer::display (const std::string& str) -{ -// printf("%s", str.c_str ()); - cout << str; - -#ifdef NL_OS_WINDOWS - // display the string in the debugger is the application is started with the debugger - if (IsDebuggerPresent ()) - OutputDebugString(str.c_str ()); -#endif -} - - -void CFileDisplayer::display (const std::string& str) -{ - if (_FileName.size () == 0) return; - - ofstream ofs (_FileName.c_str (), ios::out | ios::app); - if (ofs.is_open ()) - { - ofs << str; - ofs.close(); - } - - -// FILE *fp = fopen (_FileName.c_str (), "a"); -// if (fp == NULL) return; - -// fprintf (fp, "%s", str.c_str ()); - -// fclose (fp); -} - - - -void CMsgBoxDisplayer::display (const std::string& str) -{ -#ifdef NL_OS_WINDOWS - - CSystemUtils::copyTextToClipboard(str); - - string strf = str; - strf += "\n\n(this message was copied in the clipboard)"; - MessageBox (NULL, strf.c_str (), "", MB_OK | MB_ICONEXCLAMATION); -#endif -} -**************************************************************************/ - - } // NLMISC diff --git a/code/nel/src/misc/dummy_window.cpp b/code/nel/src/misc/dummy_window.cpp index a0d807ac5..60fe51795 100644 --- a/code/nel/src/misc/dummy_window.cpp +++ b/code/nel/src/misc/dummy_window.cpp @@ -45,32 +45,32 @@ bool CDummyWindow::init(HINSTANCE hInstance, WNDPROC winProc) { release(); static const char *INVISIBLE_WINDOW_CLASS = "nl_invisible_wnd_class"; - WNDCLASSEX wc; - wc.cbSize = sizeof(WNDCLASSEX); - if (!GetClassInfoEx(hInstance, INVISIBLE_WINDOW_CLASS, &wc)) + WNDCLASSEXA wc; + wc.cbSize = sizeof(WNDCLASSEXA); + if (!GetClassInfoExA(hInstance, INVISIBLE_WINDOW_CLASS, &wc)) { - wc.cbSize = sizeof(WNDCLASSEX); + wc.cbSize = sizeof(WNDCLASSEXA); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = nlDefaultWinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; - wc.hIcon = 0; - wc.hCursor = 0; - wc.hbrBackground = 0; - wc.lpszMenuName = 0; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; wc.lpszClassName = INVISIBLE_WINDOW_CLASS; - wc.hIconSm = 0; - RegisterClassEx(&wc); + wc.hIconSm = NULL; + RegisterClassExA(&wc); } - _HWnd = CreateWindow(INVISIBLE_WINDOW_CLASS, "", WS_POPUP, + _HWnd = CreateWindowA(INVISIBLE_WINDOW_CLASS, "", WS_POPUP, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL, 0, hInstance, 0); if (_HWnd) { - if (winProc) SetWindowLongPtr(_HWnd, GWLP_WNDPROC, (LONG_PTR) winProc); + if (winProc) SetWindowLongPtrA(_HWnd, GWLP_WNDPROC, (LONG_PTR) winProc); return true; } return false; diff --git a/code/nel/src/misc/dynloadlib.cpp b/code/nel/src/misc/dynloadlib.cpp index 0b456f166..fadf2e249 100644 --- a/code/nel/src/misc/dynloadlib.cpp +++ b/code/nel/src/misc/dynloadlib.cpp @@ -32,7 +32,7 @@ NL_LIB_HANDLE nlLoadLibrary(const std::string &libName) { NL_LIB_HANDLE res = 0; #ifdef NL_OS_WINDOWS - res = LoadLibrary(libName.c_str()); + res = LoadLibraryW(utf8ToWide(libName)); #elif defined(NL_OS_UNIX) res = dlopen(libName.c_str(), RTLD_NOW); #else diff --git a/code/nel/src/misc/eid_translator.cpp b/code/nel/src/misc/eid_translator.cpp index acf4046e5..591b9db7a 100644 --- a/code/nel/src/misc/eid_translator.cpp +++ b/code/nel/src/misc/eid_translator.cpp @@ -445,7 +445,7 @@ void cbInvalidEntityNamesFilename(const std::string &invalidEntityNamesFilename) return; } - FILE *fp = fopen (fn.c_str(), "r"); + FILE *fp = nlfopen (fn, "r"); if (fp == NULL) { nlwarning ("EIT: Can't load filename '%s' for invalid entity names filename", fn.c_str()); diff --git a/code/nel/src/misc/file.cpp b/code/nel/src/misc/file.cpp index 00a1823ef..01c417635 100644 --- a/code/nel/src/misc/file.cpp +++ b/code/nel/src/misc/file.cpp @@ -243,7 +243,7 @@ bool CIFile::open(const std::string &path, bool text) _IsInXMLPackFile = false; _BigFileOffset = 0; _AlwaysOpened = false; - _F = fopen (path.c_str(), mode); + _F = nlfopen (path, mode); if (_F != NULL) { /* @@ -598,7 +598,7 @@ bool COFile::open(const std::string &path, bool append, bool text, bool useTempF return false; } - _F=fopen(fileToOpen.c_str(), mode); + _F = nlfopen(fileToOpen, mode); return _F!=NULL; } diff --git a/code/nel/src/misc/i18n.cpp b/code/nel/src/misc/i18n.cpp index 99e9c68a0..427c102da 100644 --- a/code/nel/src/misc/i18n.cpp +++ b/code/nel/src/misc/i18n.cpp @@ -567,7 +567,7 @@ void CI18N::readTextFile(const string &filename, if (!readContext.IfStack.empty()) { - nlwarning("Preprocess: Missing %u closing #endif after parsing %s", readContext.IfStack.size(), filename.c_str() ); + nlwarning("Preprocess: Missing %u closing #endif after parsing %s", (uint)readContext.IfStack.size(), filename.c_str() ); } } diff --git a/code/nel/src/misc/inter_window_msg_queue.cpp b/code/nel/src/misc/inter_window_msg_queue.cpp index 77e72e654..cca8f1a37 100644 --- a/code/nel/src/misc/inter_window_msg_queue.cpp +++ b/code/nel/src/misc/inter_window_msg_queue.cpp @@ -96,7 +96,7 @@ namespace NLMISC nlassert(_Id == 0); // init done twice release(); // create a system wide mutex - _SharedMemMutex = CreateMutex(NULL, FALSE, toString("NL_MUTEX_%d", (int) id).c_str()); + _SharedMemMutex = CreateMutexA(NULL, FALSE, toString("NL_MUTEX_%d", (int) id).c_str()); if (!_SharedMemMutex) return false; _Id = id; return true; @@ -197,7 +197,7 @@ namespace NLMISC cds.lpData = (PVOID) msgOut.buffer(); for(;;) { - LRESULT result = ::SendMessage(targetWindow, WM_COPYDATA, (WPARAM) _Parent->_LocalWindow.getWnd(), (LPARAM) &cds); + LRESULT result = ::SendMessageA(targetWindow, WM_COPYDATA, (WPARAM) _Parent->_LocalWindow.getWnd(), (LPARAM) &cds); if (result) break; // retry ... Sleep(30); diff --git a/code/nel/src/misc/log.cpp b/code/nel/src/misc/log.cpp index 9e5f0a1bc..08f6b3107 100644 --- a/code/nel/src/misc/log.cpp +++ b/code/nel/src/misc/log.cpp @@ -59,9 +59,9 @@ void CLog::setDefaultProcessName () #ifdef NL_OS_WINDOWS if ((*_ProcessName).empty()) { - char name[1024]; - GetModuleFileName (NULL, name, 1023); - (*_ProcessName) = CFile::getFilename(name); + wchar_t name[1024]; + GetModuleFileNameW(NULL, name, 1023); + (*_ProcessName) = CFile::getFilename(wideToUtf8(name)); } #else if ((*_ProcessName).empty()) diff --git a/code/nel/src/misc/mem_displayer.cpp b/code/nel/src/misc/mem_displayer.cpp index 40cc1bb6e..b8f4f2ea3 100644 --- a/code/nel/src/misc/mem_displayer.cpp +++ b/code/nel/src/misc/mem_displayer.cpp @@ -165,16 +165,15 @@ static DWORD __stdcall GetModuleBase(HANDLE hProcess, DWORD dwReturnAddress) DWORD cch = 0; char szFile[MAX_PATH] = { 0 }; - cch = GetModuleFileNameA((HINSTANCE)memoryBasicInfo.AllocationBase, - szFile, MAX_PATH); + cch = GetModuleFileNameA((HINSTANCE)memoryBasicInfo.AllocationBase, szFile, MAX_PATH); - if (cch && (lstrcmp(szFile, "DBFN")== 0)) - { - char mn[] = { 'M', 'N', 0x00 }; + if (cch && (lstrcmpA(szFile, "DBFN")== 0)) + { + char mn[] = { 'M', 'N', 0x00 }; #ifdef NL_OS_WIN64 - if (!SymLoadModule64( + if (!SymLoadModule64( #else - if (!SymLoadModule( + if (!SymLoadModule( #endif hProcess, NULL, mn, @@ -227,28 +226,28 @@ static void displayCallStack (CLog *log) if (symbolPath.empty()) { - CHAR tmpPath[stringSize]; + wchar_t tmpPath[stringSize]; symbolPath = "."; - if (GetEnvironmentVariable ("_NT_SYMBOL_PATH", tmpPath, stringSize)) + if (GetEnvironmentVariableW (L"_NT_SYMBOL_PATH", tmpPath, stringSize)) { symbolPath += ";"; - symbolPath += tmpPath; + symbolPath += wideToUtf8(tmpPath); } - if (GetEnvironmentVariable ("_NT_ALTERNATE_SYMBOL_PATH", tmpPath, stringSize)) + if (GetEnvironmentVariableW (L"_NT_ALTERNATE_SYMBOL_PATH", tmpPath, stringSize)) { symbolPath += ";"; - symbolPath += tmpPath; + symbolPath += wideToUtf8(tmpPath); } - if (GetEnvironmentVariable ("SYSTEMROOT", tmpPath, stringSize)) + if (GetEnvironmentVariableW (L"SYSTEMROOT", tmpPath, stringSize)) { symbolPath += ";"; - symbolPath += tmpPath; + symbolPath += wideToUtf8(tmpPath); symbolPath += ";"; - symbolPath += tmpPath; + symbolPath += wideToUtf8(tmpPath); symbolPath += "\\system32"; } } diff --git a/code/nel/src/misc/mutex.cpp b/code/nel/src/misc/mutex.cpp index 098bce795..ef0cb4216 100644 --- a/code/nel/src/misc/mutex.cpp +++ b/code/nel/src/misc/mutex.cpp @@ -159,7 +159,7 @@ bool CSharedMutex::createByName( const char *objectName ) #ifdef NL_DEBUG nlassert( _Mutex == NULL ); #endif - _Mutex = (void *) CreateMutex( NULL, FALSE, objectName ); + _Mutex = (void *) CreateMutexA( NULL, FALSE, objectName ); //nldebug( "Creating mutex %s: handle %p", objectName, _Mutex ); return ( _Mutex != NULL ); } diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index ee47fd494..b5375e005 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -681,11 +681,11 @@ std::string CPath::getCurrentPath () std::string CFileContainer::getCurrentPath () { - char buffer [1024]; - #ifdef NL_OS_WINDOWS - return standardizePath(_getcwd(buffer, 1024), false); + wchar_t buffer[1024]; + return standardizePath(wideToUtf8(_wgetcwd(buffer, 1024)), false); #else + char buffer [1024]; return standardizePath(getcwd(buffer, 1024), false); #endif } @@ -700,7 +700,7 @@ bool CFileContainer::setCurrentPath (const std::string &path) int res; //nldebug("Change current path to '%s' (current path is '%s')", path.c_str(), getCurrentPath().c_str()); #ifdef NL_OS_WINDOWS - res = _chdir(path.c_str()); + res = _wchdir(utf8ToWide(path)); #else res = chdir(path.c_str()); #endif @@ -756,11 +756,11 @@ std::string CFileContainer::getFullPath (const std::string &path, bool addFinalS #ifdef NL_OS_WINDOWS -# define dirent WIN32_FIND_DATA +# define dirent WIN32_FIND_DATAW # define DIR void static string sDir; -static WIN32_FIND_DATA findData; +static WIN32_FIND_DATAW findData; static HANDLE hFind; DIR *opendir (const char *path) @@ -792,13 +792,12 @@ dirent *readdir (DIR *dir) // first visit in this directory : FindFirstFile() if (hFind == NULL) { - string fullPath = CPath::standardizePath(sDir) + "*"; - hFind = FindFirstFileA (fullPath.c_str(), &findData); + hFind = FindFirstFileW (utf8ToWide(CPath::standardizePath(sDir) + "*"), &findData); } // directory already visited : FindNextFile() else { - if (!FindNextFileA (hFind, &findData)) + if (!FindNextFileW (hFind, &findData)) return NULL; } @@ -845,7 +844,7 @@ string getname (dirent *de) { nlassert (de != NULL); #ifdef NL_OS_WINDOWS - return de->cFileName; + return wideToUtf8(de->cFileName); #else return de->d_name; #endif // NL_OS_WINDOWS @@ -1269,7 +1268,7 @@ void CFileContainer::addSearchBigFile (const string &sBigFilename, bool recurse, // Open and read the big file header nlassert(!_MemoryCompressed); - FILE *Handle = fopen (sBigFilename.c_str(), "rb"); + FILE *Handle = nlfopen (sBigFilename, "rb"); if (Handle == NULL) { nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't open file, skip it", sBigFilename.c_str(), recurse, alternative); @@ -1421,7 +1420,7 @@ void CFileContainer::addSearchXmlpackFile (const string &sXmlpackFilename, bool } // Open and read the xmlpack file header - FILE *Handle = fopen (sXmlpackFilename.c_str(), "rb"); + FILE *Handle = nlfopen (sXmlpackFilename, "rb"); if (Handle == NULL) { nlwarning ("PATH: CPath::addSearchXmlpackFile(%s, %d, %d): can't open file, skip it", sXmlpackFilename.c_str(), recurse, alternative); @@ -1766,14 +1765,14 @@ std::string CFileContainer::getWindowsDirectory() nlwarning("not a ms windows platform"); return ""; #else - char winDir[MAX_PATH]; - UINT numChar = ::GetWindowsDirectory(winDir, MAX_PATH); + wchar_t winDir[MAX_PATH]; + UINT numChar = GetWindowsDirectoryW(winDir, MAX_PATH); if (numChar > MAX_PATH || numChar == 0) { nlwarning("Couldn't retrieve windows directory"); return ""; } - return CPath::standardizePath(winDir); + return CPath::standardizePath(wideToUtf8(winDir)); #endif } @@ -1789,18 +1788,18 @@ std::string CFileContainer::getApplicationDirectory(const std::string &appName, if (appPath.empty()) { #ifdef NL_OS_WINDOWS - char buffer[MAX_PATH]; + wchar_t buffer[MAX_PATH]; #ifdef CSIDL_LOCAL_APPDATA if (local) { - SHGetSpecialFolderPathA(NULL, buffer, CSIDL_LOCAL_APPDATA, TRUE); + SHGetSpecialFolderPathW(NULL, buffer, CSIDL_LOCAL_APPDATA, TRUE); } else #endif { - SHGetSpecialFolderPathA(NULL, buffer, CSIDL_APPDATA, TRUE); + SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, TRUE); } - appPath = CPath::standardizePath(buffer); + appPath = CPath::standardizePath(wideToUtf8(buffer)); #elif defined(NL_OS_MAC) appPath = CPath::standardizePath(getenv("HOME")); appPath += "/Library/Application Support/"; @@ -1918,7 +1917,7 @@ string CFile::getPath (const string &filename) bool CFile::isDirectory (const string &filename) { #ifdef NL_OS_WINDOWS - DWORD res = GetFileAttributes(filename.c_str()); + DWORD res = GetFileAttributesW(utf8ToWide(filename)); if (res == INVALID_FILE_ATTRIBUTES) { // nlwarning ("PATH: '%s' is not a valid file or directory name", filename.c_str ()); @@ -1941,7 +1940,7 @@ bool CFile::isDirectory (const string &filename) bool CFile::isExists (const string &filename) { #ifdef NL_OS_WINDOWS - return (GetFileAttributes(filename.c_str()) != INVALID_FILE_ATTRIBUTES); + return GetFileAttributesW(utf8ToWide(filename)) != INVALID_FILE_ATTRIBUTES; #else // NL_OS_WINDOWS struct stat buf; return stat (filename.c_str (), &buf) == 0; @@ -1950,7 +1949,7 @@ bool CFile::isExists (const string &filename) bool CFile::createEmptyFile (const std::string& filename) { - FILE *file = fopen (filename.c_str(), "wb"); + FILE *file = nlfopen (filename, "wb"); if (file) { @@ -1964,7 +1963,14 @@ bool CFile::createEmptyFile (const std::string& filename) bool CFile::fileExists (const string& filename) { //H_AUTO(FileExists); - return ! ! fstream( filename.c_str(), ios::in ); +#ifdef NL_OS_WINDOWS + DWORD attr = GetFileAttributesW(utf8ToWide(filename)); + // attributes are valid and file is not a directory + if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY)) return false; + return true; +#else + return access(filename.c_str(), R_OK) != -1; +#endif } @@ -2013,7 +2019,7 @@ uint32 CFile::getFileSize (const std::string &filename) { #if defined (NL_OS_WINDOWS) struct _stat buf; - int result = _stat (filename.c_str (), &buf); + int result = _wstat (utf8ToWide(filename), &buf); #elif defined (NL_OS_UNIX) struct stat buf; int result = stat (filename.c_str (), &buf); @@ -2064,7 +2070,7 @@ uint32 CFile::getFileModificationDate(const std::string &filename) // Use the WIN32 API to read the file times in UTC // create a file handle (this does not open the file) - HANDLE h = CreateFile(fn.c_str(), 0, 0, NULL, OPEN_EXISTING, 0, 0); + HANDLE h = CreateFileW(utf8ToWide(fn), 0, 0, NULL, OPEN_EXISTING, 0, 0); if (h == INVALID_HANDLE_VALUE) { nlwarning("Can't get modification date on file '%s' : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str()); @@ -2134,7 +2140,7 @@ bool CFile::setFileModificationDate(const std::string &filename, uint32 modTime) // Use the WIN32 API to set the file times in UTC // create a file handle (this does not open the file) - HANDLE h = CreateFile(fn.c_str(), GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); + HANDLE h = CreateFileW(utf8ToWide(fn), GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); if (h == INVALID_HANDLE_VALUE) { nlwarning("Can't set modification date on file '%s' (error accessing file) : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str()); @@ -2219,10 +2225,10 @@ uint32 CFile::getFileCreationDate(const std::string &filename) #if defined (NL_OS_WINDOWS) struct _stat buf; - int result = _stat (fn.c_str (), &buf); + int result = _wstat(utf8ToWide(fn), &buf); #elif defined (NL_OS_UNIX) struct stat buf; - int result = stat (fn.c_str (), &buf); + int result = stat(fn.c_str (), &buf); #endif if (result != 0) return 0; @@ -2299,9 +2305,6 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c std::string sdest = CPath::standardizePath(dest,false); std::string ssrc = CPath::standardizePath(src,false); -// return copyFile ? CopyFile(dossrc.c_str(), dosdest.c_str(), failIfExists) != FALSE -// : MoveFile(dossrc.c_str(), dosdest.c_str()) != FALSE; - if (progress) progress->progress(0.f); if(copyFile) { @@ -2311,13 +2314,13 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c { totalSize = CFile::getFileSize(ssrc); } - FILE *fp1 = fopen(ssrc.c_str(), "rb"); + FILE *fp1 = nlfopen(ssrc, "rb"); if (fp1 == NULL) { nlwarning ("PATH: CopyMoveFile error: can't fopen in read mode '%s'", ssrc.c_str()); return false; } - FILE *fp2 = fopen(sdest.c_str(), "wb"); + FILE *fp2 = nlfopen(sdest, "wb"); if (fp2 == NULL) { nlwarning ("PATH: CopyMoveFile error: can't fopen in read write mode '%s'", sdest.c_str()); @@ -2356,7 +2359,7 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c else { #ifdef NL_OS_WINDOWS - if (MoveFile(ssrc.c_str(), sdest.c_str()) == 0) + if (MoveFileW(utf8ToWide(ssrc), utf8ToWide(sdest)) == 0) { sint lastError = NLMISC::getLastError(); nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)", @@ -2390,15 +2393,15 @@ bool CFile::copyFile(const std::string &dest, const std::string &src, bool failI bool CFile::quickFileCompare(const std::string &fileName0, const std::string &fileName1) { // make sure the files both exist - if (!fileExists(fileName0.c_str()) || !fileExists(fileName1.c_str())) + if (!fileExists(fileName0) || !fileExists(fileName1)) return false; // compare time stamps - if (getFileModificationDate(fileName0.c_str()) != getFileModificationDate(fileName1.c_str())) + if (getFileModificationDate(fileName0) != getFileModificationDate(fileName1)) return false; // compare file sizes - if (getFileSize(fileName0.c_str()) != getFileSize(fileName1.c_str())) + if (getFileSize(fileName0) != getFileSize(fileName1)) return false; // everything matched so return true @@ -2408,14 +2411,14 @@ bool CFile::quickFileCompare(const std::string &fileName0, const std::string &fi bool CFile::thoroughFileCompare(const std::string &fileName0, const std::string &fileName1,uint32 maxBufSize) { // make sure the files both exist - if (!fileExists(fileName0.c_str()) || !fileExists(fileName1.c_str())) + if (!fileExists(fileName0) || !fileExists(fileName1)) return false; // setup the size variable from file length of first file - uint32 fileSize=getFileSize(fileName0.c_str()); + uint32 fileSize=getFileSize(fileName0); // compare file sizes - if (fileSize != getFileSize(fileName1.c_str())) + if (fileSize != getFileSize(fileName1)) return false; // allocate a couple of data buffers for our 2 files @@ -2459,7 +2462,7 @@ bool CFile::moveFile(const std::string &dest, const std::string &src) bool CFile::createDirectory(const std::string &filename) { #ifdef NL_OS_WINDOWS - return _mkdir(filename.c_str())==0; + return _wmkdir(utf8ToWide(filename))==0; #else // Set full permissions.... return mkdir(filename.c_str(), 0xFFFF)==0; @@ -2680,11 +2683,16 @@ bool CPath::isAbsolutePath(const std::string &path) bool CFile::setRWAccess(const std::string &filename) { #ifdef NL_OS_WINDOWS + ucstring ucFile; + ucFile.fromUtf8(filename); + + wchar_t *wideFile = (wchar_t*)ucFile.c_str(); + // if the file exists and there's no write access - if (_access (filename.c_str(), 00) == 0 && _access (filename.c_str(), 06) == -1) + if (_waccess (wideFile, 00) == 0 && _waccess (wideFile, 06) == -1) { // try to set the read/write access - if (_chmod (filename.c_str(), _S_IREAD | _S_IWRITE) == -1) + if (_wchmod (wideFile, _S_IREAD | _S_IWRITE) == -1) { if (INelContext::getInstance().getAlreadyCreateSharedAmongThreads()) { @@ -2719,15 +2727,14 @@ bool CFile::setRWAccess(const std::string &filename) return true; } - -#ifdef NL_OS_WINDOWS -#define unlink _unlink -#endif - bool CFile::deleteFile(const std::string &filename) { setRWAccess(filename); - int res = unlink (filename.c_str()); +#ifdef NL_OS_WINDOWS + sint res = _wunlink(utf8ToWide(filename)); +#else + sint res = unlink(filename.c_str()); +#endif if (res == -1) { if (INelContext::getInstance().getAlreadyCreateSharedAmongThreads()) @@ -2739,14 +2746,14 @@ bool CFile::deleteFile(const std::string &filename) return true; } -#ifdef NL_OS_WINDOWS -#define rmdir _rmdir -#endif - bool CFile::deleteDirectory(const std::string &filename) { setRWAccess(filename); - int res = rmdir (filename.c_str()); +#ifdef NL_OS_WINDOWS + sint res = _wrmdir(utf8ToWide(filename)); +#else + sint res = rmdir(filename.c_str()); +#endif if (res == -1) { nlwarning ("PATH: Can't delete directory '%s': (errno %d) %s", filename.c_str(), errno, strerror(errno)); diff --git a/code/nel/src/misc/report.cpp b/code/nel/src/misc/report.cpp index 261ef4d5d..f997be6e0 100644 --- a/code/nel/src/misc/report.cpp +++ b/code/nel/src/misc/report.cpp @@ -82,9 +82,10 @@ TReportResult report(const std::string &title, const std::string &subject, const { std::string reportFile = getLogDirectory() + NLMISC::toString("nel_report_%u.log", (uint)time(NULL)); reportPath = CFile::findNewFile(reportFile); - std::ofstream f; - f.open(reportPath.c_str()); - if (!f.good()) + + FILE *f = nlfopen(reportPath, "wb"); // write as binary so \n are preserved + + if (!f) { #if NL_DEBUG_REPORT if (INelContext::isContextInitialised()) @@ -94,8 +95,14 @@ TReportResult report(const std::string &title, const std::string &subject, const } else { - f << body; - f.close(); + size_t written = fwrite(body.c_str(), 1, body.length(), f); + + if (written != body.length()) + { + nlwarning("Unable to write %u bytes to %s, only %u written", (uint)body.length(), reportPath.c_str(), (uint)written); + } + + fclose(f); } } diff --git a/code/nel/src/misc/sha1.cpp b/code/nel/src/misc/sha1.cpp index 19e8a440a..8afa0c039 100644 --- a/code/nel/src/misc/sha1.cpp +++ b/code/nel/src/misc/sha1.cpp @@ -147,7 +147,7 @@ CHashKey getSHA1(const string &filename, bool forcePath) return CHashKey(); } - //FILE *fp = fopen (filename.c_str(), "rb"); + //FILE *fp = nlfopen (filename, "rb"); //if (fp == NULL) return CHashKey(); err = SHA1Reset(&sha); diff --git a/code/nel/src/misc/shared_memory.cpp b/code/nel/src/misc/shared_memory.cpp index 3afe795f1..99333a9c8 100644 --- a/code/nel/src/misc/shared_memory.cpp +++ b/code/nel/src/misc/shared_memory.cpp @@ -51,7 +51,7 @@ void *CSharedMemory::createSharedMemory( TSharedMemId sharedMemId, uint32 size #ifdef NL_OS_WINDOWS // Create a file mapping backed by the virtual memory swap file (not a data file) - HANDLE hMapFile = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, sharedMemId ); + HANDLE hMapFile = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, sharedMemId ); if ( (hMapFile == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS) ) { nlwarning( "SHDMEM: Cannot create file mapping for smid %s: error %u%s, mapFile %p", sharedMemId, GetLastError(), (GetLastError()==ERROR_ALREADY_EXISTS) ? " (already exists) ": "", hMapFile ); @@ -97,7 +97,7 @@ void *CSharedMemory::accessSharedMemory( TSharedMemId sharedMemId ) #ifdef NL_OS_WINDOWS // Open the existing file mapping by name - HANDLE hMapFile = OpenFileMapping( FILE_MAP_ALL_ACCESS, false, sharedMemId ); + HANDLE hMapFile = OpenFileMappingA( FILE_MAP_ALL_ACCESS, false, sharedMemId ); if ( hMapFile == NULL ) return NULL; //nldebug( "SHDMEM: Opening smid %s --> mapFile %p", sharedMemId, hMapFile ); diff --git a/code/nel/src/misc/sstring.cpp b/code/nel/src/misc/sstring.cpp index 5f5702d01..a42981421 100644 --- a/code/nel/src/misc/sstring.cpp +++ b/code/nel/src/misc/sstring.cpp @@ -1743,7 +1743,7 @@ namespace NLMISC bool CSString::readFromFile(const CSString& fileName) { FILE* file; - file=fopen(fileName.c_str(),"rb"); + file = nlfopen(fileName, "rb"); if (file==NULL) { clear(); @@ -1766,7 +1766,7 @@ namespace NLMISC bool CSString::writeToFile(const CSString& fileName) const { FILE* file; - file=fopen(fileName.c_str(),"wb"); + file = nlfopen(fileName, "wb"); if (file==NULL) { nlwarning("Failed to open file for writing: %s",fileName.c_str()); diff --git a/code/nel/src/misc/system_info.cpp b/code/nel/src/misc/system_info.cpp index aa826bccd..f5a80238a 100644 --- a/code/nel/src/misc/system_info.cpp +++ b/code/nel/src/misc/system_info.cpp @@ -638,7 +638,7 @@ string CSystemInfo::getOS() else // Test for specific product on Windows NT 4.0 SP5 and earlier { HKEY hKey; - TCHAR szProductType[BUFSIZE]; + char szProductType[BUFSIZE]; DWORD dwBufLen=BUFSIZE; LONG lRet; @@ -652,18 +652,18 @@ string CSystemInfo::getOS() RegCloseKey( hKey ); - if ( lstrcmpi( _T("WINNT"), szProductType) == 0 ) + if ( lstrcmpiA( "WINNT", szProductType) == 0 ) OSString += " Workstation"; - if ( lstrcmpi( _T("LANMANNT"), szProductType) == 0 ) + if ( lstrcmpiA( "LANMANNT", szProductType) == 0 ) OSString += " Server"; - if ( lstrcmpi( _T("SERVERNT"), szProductType) == 0 ) + if ( lstrcmpiA( "SERVERNT", szProductType) == 0 ) OSString += " Advanced Server"; } } std::string servicePack; - if( osvi.dwMajorVersion == 4 && lstrcmpi( osvi.szCSDVersion, _T("Service Pack 6") ) == 0 ) + if (osvi.dwMajorVersion == 4 && lstrcmpiA(osvi.szCSDVersion, "Service Pack 6") == 0 ) { HKEY hKey; LONG lRet; @@ -768,7 +768,7 @@ string CSystemInfo::getProc () { // get processor name valueSize = 1024; - result = ::RegQueryValueEx (hKey, _T("ProcessorNameString"), NULL, NULL, (LPBYTE)value, &valueSize); + result = ::RegQueryValueExA (hKey, "ProcessorNameString", NULL, NULL, (LPBYTE)value, &valueSize); if (result == ERROR_SUCCESS) ProcString = value; else @@ -778,7 +778,7 @@ string CSystemInfo::getProc () // get processor identifier valueSize = 1024; - result = ::RegQueryValueEx (hKey, _T("Identifier"), NULL, NULL, (LPBYTE)value, &valueSize); + result = ::RegQueryValueExA (hKey, "Identifier", NULL, NULL, (LPBYTE)value, &valueSize); if (result == ERROR_SUCCESS) ProcString += value; else @@ -788,7 +788,7 @@ string CSystemInfo::getProc () // get processor vendor valueSize = 1024; - result = ::RegQueryValueEx (hKey, _T("VendorIdentifier"), NULL, NULL, (LPBYTE)value, &valueSize); + result = ::RegQueryValueExA (hKey, "VendorIdentifier", NULL, NULL, (LPBYTE)value, &valueSize); if (result == ERROR_SUCCESS) ProcString += value; else @@ -797,7 +797,7 @@ string CSystemInfo::getProc () ProcString += " / "; // get processor frequency - result = ::RegQueryValueEx (hKey, _T("~MHz"), NULL, NULL, (LPBYTE)value, &valueSize); + result = ::RegQueryValueExA (hKey, "~MHz", NULL, NULL, (LPBYTE)value, &valueSize); if (result == ERROR_SUCCESS) { uint32 freq = *(int *)value; @@ -1062,7 +1062,7 @@ uint64 CSystemInfo::availableHDSpace (const string &filename) return (uint64)(stfs.f_bavail * stst.st_blksize); #else ULARGE_INTEGER freeSpace = {0}; - BOOL bRes = ::GetDiskFreeSpaceExA(path.c_str(), &freeSpace, NULL, NULL); + BOOL bRes = ::GetDiskFreeSpaceExW(utf8ToWide(path), &freeSpace, NULL, NULL); if (!bRes) return 0; return (uint64)freeSpace.QuadPart; @@ -1387,12 +1387,12 @@ bool CSystemInfo::getVideoInfo (std::string &deviceName, uint64 &driverVersion) } // Version dll link - HMODULE hmVersion = LoadLibrary (_T("version")); + HMODULE hmVersion = LoadLibraryA ("version.dll"); if (hmVersion) { - BOOL (WINAPI* _GetFileVersionInfo)(LPTSTR, DWORD, DWORD, LPVOID) = NULL; - DWORD (WINAPI* _GetFileVersionInfoSize)(LPTSTR, LPDWORD) = NULL; - BOOL (WINAPI* _VerQueryValue)(const LPVOID, LPTSTR, LPVOID*, PUINT) = NULL; + BOOL (WINAPI* _GetFileVersionInfo)(LPSTR, DWORD, DWORD, LPVOID) = NULL; + DWORD (WINAPI* _GetFileVersionInfoSize)(LPSTR, LPDWORD) = NULL; + BOOL (WINAPI* _VerQueryValue)(const LPVOID, LPSTR, LPVOID*, PUINT) = NULL; *(FARPROC*)&_GetFileVersionInfo = GetProcAddress(hmVersion, "GetFileVersionInfoA"); *(FARPROC*)&_GetFileVersionInfoSize = GetProcAddress(hmVersion, "GetFileVersionInfoSizeA"); *(FARPROC*)&_VerQueryValue = GetProcAddress(hmVersion, "VerQueryValueA"); diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index 3997f75ab..de23db001 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -231,11 +231,11 @@ bool CSystemUtils::supportUnicode() { init = true; #ifdef NL_OS_WINDOWS - OSVERSIONINFO osvi; + OSVERSIONINFOA osvi; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // get Windows version - if (GetVersionEx(&osvi)) + if (GetVersionExA(&osvi)) { if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { @@ -273,14 +273,14 @@ bool CSystemUtils::isScreensaverEnabled() // SystemParametersInfoA(SPI_GETSCREENSAVEACTIVE, 0, &bRetValue, 0); // res = (bRetValue == TRUE); HKEY hKeyScreenSaver = NULL; - LSTATUS lReturn = RegOpenKeyExA(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, &hKeyScreenSaver); + LSTATUS lReturn = RegOpenKeyExA(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_QUERY_VALUE, &hKeyScreenSaver); if (lReturn == ERROR_SUCCESS) { DWORD dwType = 0L; DWORD dwSize = KeyMaxLength; unsigned char Buffer[KeyMaxLength] = {0}; - lReturn = RegQueryValueExA(hKeyScreenSaver, TEXT("SCRNSAVE.EXE"), NULL, &dwType, NULL, &dwSize); + lReturn = RegQueryValueExA(hKeyScreenSaver, "SCRNSAVE.EXE", NULL, &dwType, NULL, &dwSize); // if SCRNSAVE.EXE is present, check also if it's empty if (lReturn == ERROR_SUCCESS) res = (Buffer[0] != '\0'); @@ -315,20 +315,21 @@ string CSystemUtils::getRegKey(const string &Entry) #ifdef NL_OS_WINDOWS HKEY hkey; - if(RegOpenKeyEx(HKEY_CURRENT_USER, RootKey.c_str(), 0, KEY_READ, &hkey) == ERROR_SUCCESS) + if (RegOpenKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, KEY_READ, &hkey) == ERROR_SUCCESS) { DWORD dwType = 0L; DWORD dwSize = KeyMaxLength; - unsigned char Buffer[KeyMaxLength]; + wchar_t Buffer[KeyMaxLength]; - if(RegQueryValueEx(hkey, Entry.c_str(), NULL, &dwType, Buffer, &dwSize) != ERROR_SUCCESS) + if (RegQueryValueExW(hkey, utf8ToWide(Entry), NULL, &dwType, (LPBYTE)Buffer, &dwSize) != ERROR_SUCCESS) { nlwarning("Can't get the reg key '%s'", Entry.c_str()); } else { - ret = (char*)Buffer; + ret = wideToUtf8(Buffer); } + RegCloseKey(hkey); } else @@ -346,10 +347,14 @@ bool CSystemUtils::setRegKey(const string &ValueName, const string &Value) HKEY hkey; DWORD dwDisp; - char nstr[] = { 0x00 }; - if (RegCreateKeyExA(HKEY_CURRENT_USER, RootKey.c_str(), 0, nstr, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) + if (RegCreateKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) { - if (RegSetValueExA(hkey, ValueName.c_str(), 0L, REG_SZ, (const BYTE *)Value.c_str(), (DWORD)(Value.size())+1) == ERROR_SUCCESS) + ucstring utf16Value = ucstring::makeFromUtf8(Value); + + // we must use the real Unicode string size in bytes + DWORD size = (utf16Value.length() + 1) * 2; + + if (RegSetValueExW(hkey, utf8ToWide(ValueName), 0L, REG_SZ, (const BYTE *)utf16Value.c_str(), size) == ERROR_SUCCESS) res = true; RegCloseKey(hkey); } @@ -453,7 +458,7 @@ static void EnumerateUsingDXGI(IDXGIFactory *pDXGIFactory) { SAdapter adapter; adapter.id = index; - adapter.name = ucstring((ucchar*)desc.Description).toUtf8(); + adapter.name = wideToUtf8(desc.Description); adapter.memory = desc.DedicatedVideoMemory / 1024; adapter.found = true; diff --git a/code/nel/src/misc/win32_util.cpp b/code/nel/src/misc/win32_util.cpp index 6085e98e5..7631ac7b2 100644 --- a/code/nel/src/misc/win32_util.cpp +++ b/code/nel/src/misc/win32_util.cpp @@ -32,12 +32,12 @@ namespace NLMISC void CWin32Util::localizeWindow(HWND wnd) { if (!wnd) return; - int textLength = GetWindowTextLength(wnd); + sint textLength = GetWindowTextLengthW(wnd); if (textLength > 0) { - std::vector str(textLength + 1); - GetWindowText(wnd, &str[0], textLength + 1); - std::string winText(str.begin(), str.end() - 1); + wchar_t str[1024]; + GetWindowTextW(wnd, str, 1024); + std::string winText = wideToUtf8(str); if (CI18N::hasTranslation(winText)) { SetWindowTextW(wnd, (const WCHAR *) CI18N::get(winText).c_str()); diff --git a/code/nel/src/misc/win_displayer.cpp b/code/nel/src/misc/win_displayer.cpp index 5da7db65b..c9e81bbb3 100644 --- a/code/nel/src/misc/win_displayer.cpp +++ b/code/nel/src/misc/win_displayer.cpp @@ -40,7 +40,7 @@ using namespace std; namespace NLMISC { -static CHARFORMAT2 CharFormat; +static CHARFORMAT2A CharFormat; CWinDisplayer::CWinDisplayer(const char *displayerName) : CWindowDisplayer(displayerName), Exit(false) { @@ -149,10 +149,9 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtr (hWnd, GWLP_USERDATA); // get the text as unicode string GetWindowTextW(cwd->_HInputEdit, wText, 20000); - ucstring ucs((ucchar*)wText); // and convert it to UTF-8 encoding. - TextSend = ucs.toUtf8(); - SendMessage (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)""); + TextSend = wideToUtf8(wText); + SendMessageA (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)""); const char *pos2 = TextSend.c_str(); string str; while (*pos2 != '\0') @@ -193,14 +192,13 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) // get the text as unicode string GetWindowTextW(cwd->_HInputEdit, wText, 20000); - ucstring ucs((ucchar*)wText); // and convert it to UTF-8 encoding - string str = ucs.toUtf8(); + string str = wideToUtf8(wText); nlassert (cwd->Log != NULL); ICommand::expand (str, *cwd->Log); - SendMessage (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)str.c_str()); + SendMessageW (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)wText); - SendMessage (cwd->_HInputEdit, EM_SETSEL, str.size(), str.size()); + SendMessageA (cwd->_HInputEdit, EM_SETSEL, wcslen(wText), wcslen(wText)); return 1; } @@ -209,7 +207,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (pmf->wParam == VK_UP) { - CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrW (hWnd, GWLP_USERDATA); + CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrA (hWnd, GWLP_USERDATA); if (cwd->_PosInHistory > 0) cwd->_PosInHistory--; @@ -221,7 +219,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ucs.fromUtf8(cwd->_History[cwd->_PosInHistory]); // set the text as unicode string SetWindowTextW(cwd->_HInputEdit, (LPCWSTR)ucs.c_str()); - SendMessage (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size()); + SendMessageA (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size()); } } else if (pmf->wParam == VK_DOWN) @@ -238,7 +236,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ucs.fromUtf8(cwd->_History[cwd->_PosInHistory]); // set the text as unicode string SetWindowTextW(cwd->_HInputEdit, (LPCWSTR)ucs.c_str()); - SendMessage (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size()); + SendMessageA (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size()); } } } @@ -262,13 +260,13 @@ void CWinDisplayer::updateLabels () // create a button for command and label for variables if (access.value()[i].Value[0] == '@') { - access.value()[i].Hwnd = CreateWindowW (L"BUTTON", L"", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL); + access.value()[i].Hwnd = CreateWindowA ("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtrA(_HWnd, GWLP_HINSTANCE), NULL); } else { - access.value()[i].Hwnd = CreateWindowW (L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL); + access.value()[i].Hwnd = CreateWindowA ("STATIC", "", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtrA(_HWnd, GWLP_HINSTANCE), NULL); } - SendMessage ((HWND)access.value()[i].Hwnd, WM_SETFONT, (WPARAM)_HFont, TRUE); + SendMessageA ((HWND)access.value()[i].Hwnd, WM_SETFONT, (WPARAM)_HFont, TRUE); needResize = true; } @@ -290,7 +288,7 @@ void CWinDisplayer::updateLabels () } } - SendMessage ((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM) n.c_str()); + SendMessageW ((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM) utf8ToWide(n)); access.value()[i].NeedUpdate = false; } } @@ -427,14 +425,14 @@ void CWinDisplayer::open (string titleBar, bool iconified, sint x, sint y, sint dwStyle |= WS_HSCROLL; _HEdit = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, RICHEDIT_CLASSW, L"", dwStyle, 0, _ToolBarHeight, w, h-_ToolBarHeight-_InputEditHeight, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL); - SendMessage (_HEdit, WM_SETFONT, (WPARAM)_HFont, TRUE); + SendMessageA (_HEdit, WM_SETFONT, (WPARAM)_HFont, TRUE); // set the edit text limit to lot of :) - SendMessage (_HEdit, EM_LIMITTEXT, -1, 0); + SendMessageA (_HEdit, EM_LIMITTEXT, -1, 0); CharFormat.cbSize = sizeof(CharFormat); CharFormat.dwMask = CFM_COLOR; - SendMessage(_HEdit,EM_GETCHARFORMAT,(WPARAM)0,(LPARAM)&CharFormat); + SendMessageA(_HEdit,EM_GETCHARFORMAT,(WPARAM)0,(LPARAM)&CharFormat); CharFormat.dwEffects &= ~CFE_AUTOCOLOR; // create the input edit control @@ -445,7 +443,7 @@ void CWinDisplayer::open (string titleBar, bool iconified, sint x, sint y, sint LRESULT dwEvent = SendMessageW(_HInputEdit, EM_GETEVENTMASK, (WPARAM)0, (LPARAM)0); dwEvent |= ENM_MOUSEEVENTS | ENM_KEYEVENTS | ENM_CHANGE; - SendMessage(_HInputEdit, EM_SETEVENTMASK, (WPARAM)0, (LPARAM)dwEvent); + SendMessageA(_HInputEdit, EM_SETEVENTMASK, (WPARAM)0, (LPARAM)dwEvent); // resize the window RECT rc; @@ -477,8 +475,8 @@ void CWinDisplayer::clear () bool focus = (GetFocus() == _HEdit); if (focus) { - SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL); - SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL); + SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL); + SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL); } // get number of line @@ -534,13 +532,13 @@ void CWinDisplayer::display_main () bool focus = (GetFocus() == _HEdit); if (focus) { - SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL); - SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL); + SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL); + SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL); } // store old selection DWORD startSel, endSel; - SendMessage (_HEdit, EM_GETSEL, (WPARAM)&startSel, (LPARAM)&endSel); + SendMessageA (_HEdit, EM_GETSEL, (WPARAM)&startSel, (LPARAM)&endSel); // find how many lines we have to remove in the current output to add new lines @@ -554,7 +552,7 @@ void CWinDisplayer::display_main () if (nblineremove == _HistorySize) { - SendMessage (_HEdit, WM_SETTEXT, 0, (LPARAM) ""); + SendMessageA (_HEdit, WM_SETTEXT, 0, (LPARAM) ""); startSel = endSel = -1; } else @@ -594,31 +592,31 @@ void CWinDisplayer::display_main () str += ucstring::makeFromUtf8((*it).second); } - SendMessage (_HEdit, EM_SETSEL, -1, -1); + SendMessageA(_HEdit, EM_SETSEL, -1, -1); if ((col>>24) == 0) { // there s a specific color CharFormat.crTextColor = RGB ((col>>16)&0xFF, (col>>8)&0xFF, col&0xFF); - SendMessage((HWND) _HEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM) &CharFormat); + SendMessageA(_HEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM) &CharFormat); } // add the string to the edit control - SendMessageW (_HEdit, EM_REPLACESEL, FALSE, (LPARAM) str.c_str()); + SendMessageW(_HEdit, EM_REPLACESEL, FALSE, (LPARAM) str.c_str()); } // restore old selection - SendMessage (_HEdit, EM_SETSEL, startSel, endSel); + SendMessageA(_HEdit, EM_SETSEL, startSel, endSel); - SendMessage(_HEdit,EM_SETMODIFY,(WPARAM)TRUE,(LPARAM)0); + SendMessageA(_HEdit,EM_SETMODIFY,(WPARAM)TRUE,(LPARAM)0); if (bottom) - SendMessage(_HEdit,WM_VSCROLL,(WPARAM)SB_BOTTOM,(LPARAM)0L); + SendMessageA(_HEdit,WM_VSCROLL,(WPARAM)SB_BOTTOM,(LPARAM)0L); if (focus) { - SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOVSCROLL); - SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOHSCROLL); + SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOVSCROLL); + SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOHSCROLL); } } diff --git a/code/nel/src/misc/win_thread.cpp b/code/nel/src/misc/win_thread.cpp index 4178b7a58..f8063b6b7 100644 --- a/code/nel/src/misc/win_thread.cpp +++ b/code/nel/src/misc/win_thread.cpp @@ -277,10 +277,10 @@ uint64 CWinThread::getCPUMask() std::string CWinThread::getUserName() { - char userName[512]; + wchar_t userName[512]; DWORD size = 512; - GetUserName (userName, &size); - return (const char*)userName; + GetUserNameW (userName, &size); + return wideToUtf8(userName); } // **** Process @@ -333,10 +333,10 @@ class CPSAPILib { public: typedef BOOL (WINAPI *EnumProcessesFunPtr)(DWORD *lpidProcess, DWORD cb, DWORD *cbNeeded); - typedef DWORD (WINAPI *GetModuleFileNameExAFunPtr)(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize); + typedef DWORD (WINAPI *GetModuleFileNameExWFunPtr)(HANDLE hProcess, HMODULE hModule, LPWSTR lpFilename, DWORD nSize); typedef BOOL (WINAPI *EnumProcessModulesFunPtr)(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded); EnumProcessesFunPtr EnumProcesses; - GetModuleFileNameExAFunPtr GetModuleFileNameExA; + GetModuleFileNameExWFunPtr GetModuleFileNameExW; EnumProcessModulesFunPtr EnumProcessModules; public: CPSAPILib(); @@ -353,7 +353,7 @@ CPSAPILib::CPSAPILib() _LoadFailed = false; _PSAPILibHandle = NULL; EnumProcesses = NULL; - GetModuleFileNameExA = NULL; + GetModuleFileNameExW = NULL; EnumProcessModules = NULL; } @@ -373,7 +373,7 @@ bool CPSAPILib::init() if (_LoadFailed) return false; if (!_PSAPILibHandle) { - _PSAPILibHandle = LoadLibrary("psapi.dll"); + _PSAPILibHandle = LoadLibraryA("psapi.dll"); if (!_PSAPILibHandle) { nlwarning("couldn't load psapi.dll, possibly not supported by os"); @@ -381,10 +381,10 @@ bool CPSAPILib::init() return false; } EnumProcesses = (EnumProcessesFunPtr) GetProcAddress(_PSAPILibHandle, "EnumProcesses"); - GetModuleFileNameExA = (GetModuleFileNameExAFunPtr) GetProcAddress(_PSAPILibHandle, "GetModuleFileNameExA"); + GetModuleFileNameExW = (GetModuleFileNameExWFunPtr) GetProcAddress(_PSAPILibHandle, "GetModuleFileNameExW"); EnumProcessModules = (EnumProcessModulesFunPtr) GetProcAddress(_PSAPILibHandle, "EnumProcessModules"); if (!EnumProcesses || - !GetModuleFileNameExA || + !GetModuleFileNameExW || !EnumProcessModules ) { @@ -453,12 +453,12 @@ bool CWinProcess::enumProcessModules(uint32 processId, std::vector } moduleNames.clear(); std::vector resultModuleNames; - char moduleName[MAX_PATH + 1]; + wchar_t moduleName[MAX_PATH + 1]; for (uint m = 0; m < prcModules.size(); ++m) { - if (PSAPILib.GetModuleFileNameExA(hProcess, prcModules[m], moduleName, MAX_PATH)) + if (PSAPILib.GetModuleFileNameExW(hProcess, prcModules[m], moduleName, MAX_PATH)) { - moduleNames.push_back(moduleName); + moduleNames.push_back(wideToUtf8(moduleName)); } } CloseHandle(hProcess); @@ -563,7 +563,7 @@ public: PROCESS_INFORMATION processInfo; STARTUPINFO startupInfo = {0}; startupInfo.cb = sizeof(STARTUPINFO); - if (CreateProcess(programName.c_str(), const_cast(arguments.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo)) + if (CreateProcessW(programName.c_str(), const_cast(arguments.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo)) { WatchTask = new CProcessWatchTask(processInfo.hProcess); WatchThread = IThread::create(WatchTask); diff --git a/code/nel/src/misc/xml_pack.cpp b/code/nel/src/misc/xml_pack.cpp index 4494be062..ec12eb6bc 100644 --- a/code/nel/src/misc/xml_pack.cpp +++ b/code/nel/src/misc/xml_pack.cpp @@ -93,7 +93,7 @@ namespace NLMISC TXMLPackInfo &packInfo = _XMLPacks[packId]; // open the xml pack for later access -// packInfo.FileHandler = fopen(xmlPackFileName.c_str(), "rb"); +// packInfo.FileHandler = nlfopen(xmlPackFileName, "rb"); // open the xml pack for parsing CIFile packFile; @@ -182,7 +182,7 @@ namespace NLMISC fileInfo.FileName = CStringMapper::map(subFileName); fileInfo.FileOffset = (uint32)(beginOfFile - buffer.begin()); fileInfo.FileSize = (uint32)(endOfFile - beginOfFile); -// fileInfo.FileHandler = fopen(xmlPackFileName.c_str(), "rb"); +// fileInfo.FileHandler = nlfopen(xmlPackFileName, "rb"); packInfo._XMLFiles.insert(make_pair(fileInfo.FileName, fileInfo)); // advance to next line @@ -264,7 +264,7 @@ namespace NLMISC rFileOffset = fileInfo.FileOffset; rCacheFileOnOpen = false; rAlwaysOpened = false; - FILE *fp = fopen(parts[0].c_str(), "rb"); + FILE *fp = nlfopen(parts[0], "rb"); return fp; } diff --git a/code/nel/src/net/email.cpp b/code/nel/src/net/email.cpp index ae6f92477..9ac22c886 100644 --- a/code/nel/src/net/email.cpp +++ b/code/nel/src/net/email.cpp @@ -271,7 +271,7 @@ bool sendEmail (const string &smtpServer, const string &from, const string &to, char dst_buf[dst_buf_size + 1]; size_t size; - FILE *src_stream = fopen (attachedFile.c_str(), "rb"); + FILE *src_stream = nlfopen (attachedFile, "rb"); if (src_stream == NULL) { nlwarning ("EMAIL: Can't attach file '%s' to the email because the file can't be open", attachedFile.c_str()); @@ -299,7 +299,7 @@ bool sendEmail (const string &smtpServer, const string &from, const string &to, } // debug, display what we send into a file - // { FILE *fp = fopen (CFile::findNewFile(getLogDirectory() + "mail.txt").c_str(), "wb"); + // { FILE *fp = nlfopen (CFile::findNewFile(getLogDirectory() + "mail.txt"), "wb"); // fwrite (formatedBody.c_str(), 1, formatedBody.size(), fp); // fclose (fp); } diff --git a/code/nel/src/net/service.cpp b/code/nel/src/net/service.cpp index 8f5a142cc..e2db26bd5 100644 --- a/code/nel/src/net/service.cpp +++ b/code/nel/src/net/service.cpp @@ -575,7 +575,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName, if (haveLongArg("writepid")) { // use legacy C primitives - FILE *fp = fopen("pid.state", "wt"); + FILE *fp = nlfopen("pid.state", "wt"); if (fp) { fprintf(fp, "%u", getpid()); @@ -600,7 +600,6 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName, ListeningPort = servicePort; - // setReportEmailFunction ((void*)sendEmail); // setDefaultEmailParams ("gw.nevrax.com", "", "cado@nevrax.com"); @@ -623,7 +622,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName, else { // create the basic .cfg that link the default one - FILE *fp = fopen (cfn.c_str(), "w"); + FILE *fp = nlfopen (cfn, "w"); if (fp == NULL) { nlerror ("SERVICE: Can't create config file '%s'", cfn.c_str()); diff --git a/code/nel/src/sound/audio_decoder.cpp b/code/nel/src/sound/audio_decoder.cpp index d8283c227..f4884a427 100644 --- a/code/nel/src/sound/audio_decoder.cpp +++ b/code/nel/src/sound/audio_decoder.cpp @@ -110,15 +110,18 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st CIFile ifile; ifile.setCacheFileOnOpen(false); ifile.allowBNPCacheFileOnOpen(false); - ifile.open(lookup); - return CAudioDecoderVorbis::getInfo(&ifile, artist, title); + if (ifile.open(lookup)) + return CAudioDecoderVorbis::getInfo(&ifile, artist, title); + + nlwarning("Unable to open: '%s'", filepath.c_str()); } else { nlwarning("Music file type unknown: '%s'", type_lower.c_str()); - artist.clear(); title.clear(); - return false; } + + artist.clear(); title.clear(); + return false; } /// Get audio/container extensions that are currently supported by the nel sound library. diff --git a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp index 3cc7a7dd2..d15f2f6aa 100644 --- a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp +++ b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp @@ -266,8 +266,7 @@ void CSoundDriverXAudio2::getDevices(std::vector &devices) for (uint i = 0; i < deviceCount; ++i) { _XAudio2->GetDeviceDetails(i, &deviceDetails); - std::basic_string deviceNameW = deviceDetails.DisplayName; - std::string deviceName = std::string(deviceNameW.begin(), deviceNameW.end()); + std::string deviceName = wideToUtf8(deviceDetails.DisplayName); nldebug("XA2: - %s", deviceName.c_str()); devices.push_back(deviceName); } @@ -289,8 +288,7 @@ uint CSoundDriverXAudio2::getDeviceIndex(const std::string &device, XAUDIO2_DEVI for (uint i = 0; i < deviceCount; ++i) { _XAudio2->GetDeviceDetails(i, deviceDetails); - std::basic_string deviceNameW = deviceDetails->DisplayName; - std::string deviceName = std::string(deviceNameW.begin(), deviceNameW.end()); + std::string deviceName = wideToUtf8(deviceDetails->DisplayName); if (deviceName == device) return i; } diff --git a/code/nel/tools/3d/tile_edit_qt/tiles_model.cpp b/code/nel/tools/3d/tile_edit_qt/tiles_model.cpp index d05495eb7..cabd810d7 100644 --- a/code/nel/tools/3d/tile_edit_qt/tiles_model.cpp +++ b/code/nel/tools/3d/tile_edit_qt/tiles_model.cpp @@ -53,32 +53,31 @@ tiles_model::tiles_model(QObject *parent) QVariant tiles_model::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); + if (!index.isValid()) + return QVariant(); - if (role == Qt::DecorationRole || role == Qt::UserRole) + if (role == Qt::DecorationRole || role == Qt::UserRole) { CTile_Widget wiwi; wiwi.initWidget(tiles.value(index.row()).getPixmap(), tiles.value(index.row()).getPixmapSide(), tiles.value(index.row()).getTileLabel()); #ifdef USE_QT5 QPixmap pixpix = wiwi.grab(wiwi.contentsRect()); #else - QPixmap::grabWidget(wiwi, wiwi.contentsRect()); + QPixmap pixpix = QPixmap::grabWidget(&wiwi, wiwi.contentsRect()); #endif return pixpix; } - else if (role == Qt::UserRole + 1) + else if (role == Qt::UserRole + 1) { - return tiles.value(index.row()).getIndex(); + return tiles.value(index.row()).getIndex(); } - return QVariant(); + return QVariant(); } void tiles_model::sort ( int column, Qt::SortOrder order) { qSort(tiles.begin(), tiles.end(), caseInsensitiveLessThan); - } diff --git a/code/nel/tools/CMakeLists.txt b/code/nel/tools/CMakeLists.txt index cb3e2b577..8734bf103 100644 --- a/code/nel/tools/CMakeLists.txt +++ b/code/nel/tools/CMakeLists.txt @@ -3,7 +3,7 @@ ADD_SUBDIRECTORY(misc) IF(WITH_NEL_TOOLS) ADD_SUBDIRECTORY(memory) -ENDIF(WITH_NEL_TOOLS) +ENDIF() # Max plugins are under the 3d directory as well. # Allow to compile only max plugins without other tools. @@ -15,21 +15,21 @@ ENDIF() IF(WITH_NEL_TOOLS) IF(WITH_PACS) ADD_SUBDIRECTORY(pacs) - ENDIF(WITH_PACS) + ENDIF() IF(WITH_LOGIC) ADD_SUBDIRECTORY(logic) - ENDIF(WITH_LOGIC) + ENDIF() IF(WITH_GEORGES) ADD_SUBDIRECTORY(georges) - ENDIF(WITH_GEORGES) + ENDIF() IF(WITH_SOUND) ADD_SUBDIRECTORY(sound) - ENDIF(WITH_SOUND) - - IF(WITH_NEL_TESTS) - ADD_SUBDIRECTORY(nel_unit_test) - ENDIF(WITH_NEL_TESTS) -ENDIF(WITH_NEL_TOOLS) + ENDIF() +ENDIF() + +IF(WITH_NEL_TESTS) + ADD_SUBDIRECTORY(nel_unit_test) +ENDIF() diff --git a/code/nel/tools/nel_unit_test/ut_ligo_primitive.h b/code/nel/tools/nel_unit_test/ut_ligo_primitive.h index 8df4db877..d4ba5df5a 100644 --- a/code/nel/tools/nel_unit_test/ut_ligo_primitive.h +++ b/code/nel/tools/nel_unit_test/ut_ligo_primitive.h @@ -72,7 +72,7 @@ private: + " \n" + ""; - FILE *fp = fopen(CLASS_FILE_NAME, "wt"); + FILE *fp = NLMISC::nlfopen(CLASS_FILE_NAME, "wt"); nlassert(fp != NULL); size_t s = fwrite(classfile.data(), 1, classfile.size(), fp); nlassert(s == classfile.size()); diff --git a/code/nel/tools/nel_unit_test/ut_misc_file.h b/code/nel/tools/nel_unit_test/ut_misc_file.h index 34de2d569..486320269 100644 --- a/code/nel/tools/nel_unit_test/ut_misc_file.h +++ b/code/nel/tools/nel_unit_test/ut_misc_file.h @@ -19,6 +19,7 @@ #include #include +#include // Test suite for NLMISC::CFile behavior struct CUTMiscFile : public Test::Suite @@ -49,7 +50,7 @@ private: void copyFileSize(uint fileSize) { // create a source file (using standard c code) - FILE *fp = fopen(_SrcFile.c_str(), "wb"); + FILE *fp = NLMISC::nlfopen(_SrcFile, "wb"); nlverify(fp != NULL); for (uint i=0; i + local givenName = ""; + if tonumber( dbNameRace ) == 1 then + -- Fyros + fullnameResult, nameResult = self:getFyrosName() + elseif tonumber( dbNameRace ) == 2 then + -- Matis + fullnameResult, nameResult = self:getMatisName() + elseif tonumber( dbNameRace ) == 3 then + -- Tryker + fullnameResult, nameResult = self:getTrykerName() + elseif tonumber( dbNameRace ) == 4 then + -- Zorai + fullnameResult, nameResult = self:getZoraiName() + elseif tonumber( dbNameRace ) == 5 then + -- Maraudeurs + tempResult_1 = ""; + tempResult_2 = ""; + if tonumber(dbNameSubRace) == 1 then + -- Fyros + fullnameResult, tempResult_1 = self:getFyrosName() + elseif tonumber( dbNameSubRace ) == 2 then + -- Matis F + fullnameResult, tempResult_1 = self:getMatisName(2) + elseif tonumber( dbNameSubRace ) == 3 then + -- Matis M + fullnameResult, tempResult_1 = self:getMatisName(1) + elseif tonumber( dbNameSubRace ) == 4 then + -- Tryker + fullnameResult, tempResult_1 = self:getTrykerName() + elseif tonumber( dbNameSubRace ) == 5 then + -- Zorai + fullnameResult, tempResult_1 = self:getZoraiName() + end + + if tonumber(dbNameSubRace2) == 1 then + -- Fyros + fullnameResult, tempResult_2 = self:getFyrosName() + elseif tonumber( dbNameSubRace2 ) == 2 then + -- Matis F + fullnameResult, tempResult_2 = self:getMatisName(2) + elseif tonumber( dbNameSubRace2 ) == 3 then + -- Matis M + fullnameResult, tempResult_2 = self:getMatisName(1) + elseif tonumber( dbNameSubRace2 ) == 4 then + -- Tryker + fullnameResult, tempResult_2 = self:getTrykerName() + elseif tonumber( dbNameSubRace2 ) == 5 then + -- Zorai + fullnameResult, tempResult_2 = self:getZoraiName() + end + + fullnameResult = tempResult_1 .. " " .. tempResult_2 + nameResult = tempResult_2 + end + + uiNameFull.hardtext = fullnameResult; + + nameResult = string.gsub(nameResult, "'", ""); + nameResult = string.gsub(nameResult, " ", ""); + nameResult = string.gsub(nameResult, "-", ""); + nameResult = string.lower( nameResult ); + nameResult = nameResult:gsub("^%l", string.upper); + uiGenText.input_string = nameResult; +end +-- Name sex slider update. +function outgame:procUpdateNameSexLabel() + local nameSexType = { "uiCP_Sex_Male", "uiCP_Sex_Female" } + local uiNameSexText = getUI("ui:outgame:appear_name:name_sex_slider:name_sex"); + local uiNameSex = getDbProp("UI:TEMP:NAME_SEX"); + + tempstr = tostring(i18n.get(nameSexType[tonumber(uiNameSex)])); + tempstr = string.lower( tempstr ); + tempstr = (tempstr:gsub("^%l", string.upper)); + + uiNameSexText.hardtext= tempstr; +end +-- Name race slider update. +function outgame:procUpdateNameRaceLabel() + local nameRaceType = { "Fyros", "Matis", "Tryker", "Zoraï", "uiCP_Maraudeur" } + + local uiNameRaceText = getUI("ui:outgame:appear_name:name_race_slider:name_race"); + local dbNameRace = getDbProp("UI:TEMP:NAME_RACE"); + + local uiNameSexSlider = getUI("ui:outgame:appear_name:name_sex_slider"); + + local uiNameSubRaceSlider = getUI("ui:outgame:appear_name:name_sub_race_slider"); + local uiNameSubRace2Slider = getUI("ui:outgame:appear_name:name_sub_race2_slider"); + + local uiNameGenerate = getUI("ui:outgame:appear_name:generate"); + -- Show/Hide sex slider + + uiNameGenerate.y = "-50" + if tonumber(dbNameRace) == 2 then + uiNameSexSlider.active = true; + uiNameGenerate.y = "-65" + else + uiNameSexSlider.active = false; + end + + -- Show/Hide sub race slider + if tonumber(dbNameRace) == 5 then + uiNameSubRaceSlider.active = true; + uiNameSubRace2Slider.active = true; + uiNameGenerate.y = "-105" + else + uiNameSubRaceSlider.active = false; + uiNameSubRace2Slider.active = false; + end + + + uiNameRaceText.hardtext= tostring(nameRaceType[tonumber(dbNameRace)]); +end + + +local matisF = "Matis " .. (string.lower(tostring(i18n.get("uiCP_Sex_Female")) )):gsub("^%l", string.upper); +local matisM = "Matis " .. (string.lower(tostring(i18n.get("uiCP_Sex_Male")) )):gsub("^%l", string.upper); + +function outgame:procUpdateNameSubRaceLabel() + local nameSubRaceType = { "Fyros", matisF, matisM, "Tryker", "Zoraï" } + local uiNameSubRaceText = getUI("ui:outgame:appear_name:name_sub_race_slider:name_race"); + local dbNameSubRace = getDbProp("UI:TEMP:NAME_SUB_RACE"); + + + uiNameSubRaceText.hardtext= tostring(nameSubRaceType[tonumber(dbNameSubRace)]); +end +function outgame:procUpdateNameSubRace2Label() + local nameSubRace2Type = { "Fyros", matisF, matisM, "Tryker", "Zoraï" } + local uiNameSubRace2Text = getUI("ui:outgame:appear_name:name_sub_race2_slider:name_race"); + local dbNameSubRace2 = getDbProp("UI:TEMP:NAME_SUB_RACE2"); + + + uiNameSubRace2Text.hardtext= tostring(nameSubRace2Type[tonumber(dbNameSubRace2)]); +end + ------------------------------------------------------------------------------------------------------------ -- called to construct icons function outgame:activePackElement(id, icon) @@ -50,15 +291,15 @@ function outgame:buildActionPack() -- Build Default Combat self:activePackElement(1, 'f1.tga'); -- Dagger self:activePackElement(2, 'f2.tga'); -- Accurate Attack - + -- Build Default Magic self:activePackElement(6, 'm2.tga'); -- Gloves self:activePackElement(7, 'm1.tga'); -- Acid - + -- Build Default Forage self:activePackElement(11, 'g1.tga'); -- Forage Tool self:activePackElement(12, 'g2.tga'); -- Basic Extract - + -- Build Default Craft self:activePackElement(16, 'c2.tga'); -- Craft Tool self:activePackElement(17, 'c1.tga'); -- 50 raw mat @@ -83,8 +324,8 @@ function outgame:buildActionPack() self:setPackJobText('M', 1); self:setPackJobText('G', 1); self:setPackJobText('C', 1); - - -- Set correct text for specalized version + + -- Set correct text for specalized version if (getDbProp('UI:TEMP:JOB_FIGHT') == 2) then self:setPackJobText('F', 2); elseif (getDbProp('UI:TEMP:JOB_MAGIC') == 2) then @@ -94,7 +335,7 @@ function outgame:buildActionPack() elseif (getDbProp('UI:TEMP:JOB_CRAFT') == 2) then self:setPackJobText('C', 2); end - + end @@ -135,8 +376,8 @@ end --function outgame:setPatchProgress(progress) -- --debugInfo("*** 3 ***") -- local progressPercentText = string.format("%d%%", 100 * progress) --- local progressPostfix = math.fmod(os.time(), 3) --- --debugInfo("Patch in progress : " .. tostring(progress)) +-- local progressPostfix = math.fmod(os.time(), 3) +-- --debugInfo("Patch in progress : " .. tostring(progress)) -- local progressDate = nltime.getLocalTime() / 500 -- local colValue = math.floor(230 + 24 * math.sin(progressDate)) -- local color = string.format("%d %d %d %d", colValue, colValue, colValue, 255) @@ -152,7 +393,7 @@ end -- --function outgame:setPatchError() -- --debugInfo("*** 5 ***") --- --debugInfo("Patch error") +-- --debugInfo("Patch error") -- self:setProgressText(i18n.get("uiBGD_PatchError"), "255 0 0 255", 0) --end -- @@ -168,9 +409,9 @@ end function outgame:launchGame() if not isPlayerSlotNewbieLand(getPlayerSelectedSlot()) then if not isFullyPatched() then - messageBoxWithHelp(i18n.get("uiBGD_MainlandCharFullPatchNeeded"), "ui:outgame") + messageBoxWithHelp(i18n.get("uiBGD_MainlandCharFullPatchNeeded"), "ui:outgame") return end - end + end runAH(getUICaller(), "proc", "proc_charsel_play") end diff --git a/code/ryzom/client/data/gamedev/interfaces_v3/out_v2_appear.xml b/code/ryzom/client/data/gamedev/interfaces_v3/out_v2_appear.xml index baac0bca6..a2646ad62 100644 --- a/code/ryzom/client/data/gamedev/interfaces_v3/out_v2_appear.xml +++ b/code/ryzom/client/data/gamedev/interfaces_v3/out_v2_appear.xml @@ -2,6 +2,10 @@ + + + + @@ -43,6 +47,18 @@ + + + + + + + + + + + +