From 0350c97f0a03fdce0e18c326b9b38ba80ea73ca5 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 20 Feb 2016 19:29:00 +0100 Subject: [PATCH] Merge with develop --- code/CMakeLists.txt | 3 +- code/nel/include/nel/misc/bitmap.h | 12 +- code/nel/include/nel/misc/common.h | 9 + code/nel/include/nel/misc/debug.h | 2 +- code/nel/include/nel/misc/path.h | 1 - .../nel/pipeline}/database_config.h | 4 + .../nel/include/nel/pipeline/project_config.h | 80 +++++ .../nel/{misc => pipeline}/tool_logger.h | 22 +- .../3d/driver/direct3d/driver_direct3d.cpp | 22 +- .../src/3d/driver/opengl/driver_opengl.cpp | 10 +- .../opengl/driver_opengl_vertex_program.cpp | 2 +- .../3d/driver/opengl/driver_opengl_window.cpp | 20 +- code/nel/src/3d/font_generator.cpp | 104 ++++++- code/nel/src/3d/landscapeig_manager.cpp | 5 - code/nel/src/CMakeLists.txt | 4 + code/nel/src/gui/group_html.cpp | 4 +- code/nel/src/ligo/stdligo.h | 1 - code/nel/src/misc/async_file_manager.cpp | 22 +- code/nel/src/misc/big_file.cpp | 16 +- code/nel/src/misc/bitmap.cpp | 21 +- code/nel/src/misc/cmd_args.cpp | 6 +- code/nel/src/misc/common.cpp | 159 +++++----- code/nel/src/misc/config_file/config_file.cpp | 2 +- code/nel/src/misc/cpu_time_stat.cpp | 4 +- code/nel/src/misc/debug.cpp | 24 +- code/nel/src/misc/diff_tool.cpp | 2 +- code/nel/src/misc/displayer.cpp | 80 +---- code/nel/src/misc/dummy_window.cpp | 24 +- code/nel/src/misc/dynloadlib.cpp | 2 +- code/nel/src/misc/eid_translator.cpp | 2 +- code/nel/src/misc/file.cpp | 4 +- code/nel/src/misc/i18n.cpp | 2 +- code/nel/src/misc/inter_window_msg_queue.cpp | 4 +- code/nel/src/misc/log.cpp | 6 +- code/nel/src/misc/mem_displayer.cpp | 29 +- code/nel/src/misc/mutex.cpp | 2 +- code/nel/src/misc/path.cpp | 115 +++---- code/nel/src/misc/report.cpp | 17 +- code/nel/src/misc/sha1.cpp | 2 +- code/nel/src/misc/shared_memory.cpp | 4 +- code/nel/src/misc/sstring.cpp | 4 +- code/nel/src/misc/system_info.cpp | 28 +- code/nel/src/misc/system_utils.cpp | 20 +- code/nel/src/misc/win32_util.cpp | 8 +- code/nel/src/misc/win_displayer.cpp | 64 ++-- code/nel/src/misc/win_thread.cpp | 26 +- code/nel/src/misc/xml_pack.cpp | 6 +- code/nel/src/net/email.cpp | 4 +- code/nel/src/net/service.cpp | 5 +- code/nel/src/pipeline/CMakeLists.txt | 18 ++ .../pipeline}/database_config.cpp | 6 +- code/nel/src/pipeline/project_config.cpp | 238 +++++++++++++++ .../src/{misc => pipeline}/tool_logger.cpp | 7 +- code/nel/src/sound/audio_decoder.cpp | 11 +- .../driver/xaudio2/sound_driver_xaudio2.cpp | 6 +- code/nel/tools/3d/mesh_utils/CMakeLists.txt | 2 +- .../tools/3d/mesh_utils/assimp_material.cpp | 2 +- code/nel/tools/3d/mesh_utils/assimp_shape.cpp | 2 +- code/nel/tools/3d/mesh_utils/mesh_utils.cpp | 20 +- .../nel/tools/3d/mesh_utils/scene_context.cpp | 2 +- code/nel/tools/3d/mesh_utils/scene_context.h | 4 +- .../nel/tools/3d/tile_edit_qt/tiles_model.cpp | 15 +- .../tools/nel_unit_test/ut_ligo_primitive.h | 2 +- code/nel/tools/nel_unit_test/ut_misc_file.h | 13 +- code/ryzom/client/src/cdb_synchronised.cpp | 41 ++- code/ryzom/client/src/client.cpp | 10 +- code/ryzom/client/src/client_cfg.cpp | 3 +- code/ryzom/client/src/client_cfg.h | 1 + code/ryzom/client/src/commands.cpp | 2 +- code/ryzom/client/src/http_client_curl.cpp | 70 ++++- code/ryzom/client/src/init.cpp | 2 +- .../src/interface_v3/action_handler_help.cpp | 8 +- .../src/interface_v3/interface_manager.cpp | 2 +- .../client/src/interface_v3/music_player.cpp | 284 +++++++++--------- code/ryzom/client/src/login.cpp | 18 +- code/ryzom/client/src/login_patch.cpp | 203 +++++++++---- code/ryzom/client/src/login_patch.h | 1 + code/ryzom/client/src/login_xdelta.cpp | 8 +- code/ryzom/client/src/permanent_ban.cpp | 4 +- .../src/r2/dmc/client_edition_module.cpp | 6 +- code/ryzom/client/src/seven_zip/seven_zip.cpp | 2 +- code/ryzom/client/src/sheet_manager.cpp | 2 +- code/ryzom/client/src/sound_manager.cpp | 7 +- code/ryzom/common/src/game_share/bmp4image.h | 2 +- .../common/src/game_share/cst_loader.cpp | 137 ++++----- code/ryzom/common/src/game_share/cst_loader.h | 80 ++--- .../game_share/file_description_container.cpp | 20 -- .../common/src/game_share/persistent_data.cpp | 5 +- code/ryzom/common/src/game_share/utils.h | 15 +- .../mission_manager/missions_commands.cpp | 11 +- .../src/plugins/georges_editor/CMakeLists.txt | 7 +- .../plugins/gui_editor/widget_serializer.cpp | 3 + .../src/plugins/world_editor/CMakeLists.txt | 2 + .../world_editor/world_editor_actions.cpp | 4 + .../world_editor/world_editor_misc.cpp | 3 +- 95 files changed, 1415 insertions(+), 915 deletions(-) rename code/nel/{tools/3d/mesh_utils => include/nel/pipeline}/database_config.h (97%) create mode 100644 code/nel/include/nel/pipeline/project_config.h rename code/nel/include/nel/{misc => pipeline}/tool_logger.h (89%) create mode 100644 code/nel/src/pipeline/CMakeLists.txt rename code/nel/{tools/3d/mesh_utils => src/pipeline}/database_config.cpp (96%) create mode 100644 code/nel/src/pipeline/project_config.cpp rename code/nel/src/{misc => pipeline}/tool_logger.cpp (92%) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index b229d87a5..84654584a 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -258,7 +258,8 @@ IF(WITH_QT5) FIND_PACKAGE(Qt5Network) IF(WIN32) - FIND_PACKAGE(Qt5WinExtras) + # Please add option to switch off + # FIND_PACKAGE(Qt5WinExtras) ENDIF() IF(QT_STATIC) diff --git a/code/nel/include/nel/misc/bitmap.h b/code/nel/include/nel/misc/bitmap.h index 8d2bf156f..0466cd673 100644 --- a/code/nel/include/nel/misc/bitmap.h +++ b/code/nel/include/nel/misc/bitmap.h @@ -320,16 +320,8 @@ public: // don't forget to update operator=() and swap() if adding a data member - CBitmap() - { - _MipMapCount = 1; - _Width = 0; - _Height = 0; - PixelFormat = RGBA; - _LoadGrayscaleAsAlpha = true; - } - - virtual ~CBitmap() { } + CBitmap(); + virtual ~CBitmap(); // swap 2 bitmaps contents void swap(CBitmap &other); diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 3b5465eaa..dd1c80fb3 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); 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/tools/3d/mesh_utils/database_config.h b/code/nel/include/nel/pipeline/database_config.h similarity index 97% rename from code/nel/tools/3d/mesh_utils/database_config.h rename to code/nel/include/nel/pipeline/database_config.h index 25bcc2a00..ec9bb6ec6 100644 --- a/code/nel/tools/3d/mesh_utils/database_config.h +++ b/code/nel/include/nel/pipeline/database_config.h @@ -28,6 +28,8 @@ typedef NLMISC::CSString TPathString; typedef std::string TPathString; #endif +namespace NLPIPELINE { + /// Asset database configuration class CDatabaseConfig { @@ -55,4 +57,6 @@ private: }; +} /* namespace NLPIPELINE */ + /* end of file */ diff --git a/code/nel/include/nel/pipeline/project_config.h b/code/nel/include/nel/pipeline/project_config.h new file mode 100644 index 000000000..a63cbda20 --- /dev/null +++ b/code/nel/include/nel/pipeline/project_config.h @@ -0,0 +1,80 @@ +// NeL - MMORPG Framework +// Copyright (C) 2015 Winch Gate Property Limited +// Author: Jan Boon +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef NLPIPELINE_PROJECT_CONFIG_H +#define NLPIPELINE_PROJECT_CONFIG_H +#include +#include + +namespace NLMISC { + class CConfigFile; +} + +#ifdef NL_OS_WINDOWS +#include +typedef NLMISC::CSString TPathString; +#else +typedef std::string TPathString; +#endif + +namespace NLPIPELINE { + +/// Asset project configuration. Used to configure lookup directories for tools and buildsite specific setup. Do not use for pipeline build settings +class CProjectConfig +{ +public: + enum Flags + { + DatabaseTextureSearchPaths = 0x0001, + DatabaseMaterialSearchPaths = 0x0002, + RuntimeTextureSearchPaths = 0x0100, + RuntimeShapeSearchPaths = 0x0200, + }; + +public: + ~CProjectConfig(); + + /// Searches for the configuration for the specified asset path by recursively going through all parent directories looking for 'nel.cfg', matches it to a project cfg if partial is not set, initializes and applies the configuration. + static bool init(const std::string &asset, Flags flags, bool partial = false); + /// Undo init + static void release(); + +private: + static void cleanup(); + static void searchDirectories(const char *var); + + static CProjectConfig s_Instance; + + static uint32 s_AssetConfigModification; + static uint32 s_ProjectConfigModification; + + static TPathString s_AssetConfigPath; + static TPathString s_ProjectConfigPath; + + static std::string s_ProjectName; + static CProjectConfig::Flags s_InitFlags; + + static std::vector s_ConfigPaths; + static std::vector s_ConfigFiles; + +}; + +} /* namespace NLPIPELINE */ + +#endif /* #ifndef NLPIPELINE_PROJECT_CONFIG_H */ + +/* end of file */ diff --git a/code/nel/include/nel/misc/tool_logger.h b/code/nel/include/nel/pipeline/tool_logger.h similarity index 89% rename from code/nel/include/nel/misc/tool_logger.h rename to code/nel/include/nel/pipeline/tool_logger.h index ff78a6afa..55b3b2455 100644 --- a/code/nel/include/nel/misc/tool_logger.h +++ b/code/nel/include/nel/pipeline/tool_logger.h @@ -27,8 +27,8 @@ * . */ -#ifndef NLMISC_TOOL_LOGGER_H -#define NLMISC_TOOL_LOGGER_H +#ifndef NLPIPELINE_TOOL_LOGGER_H +#define NLPIPELINE_TOOL_LOGGER_H #include // STL includes @@ -47,16 +47,16 @@ #endif #ifdef NL_DEBUG_H -#define tlerror(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLMISC::ERROR, path, error, ## __VA_ARGS__) -#define tlwarning(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLMISC::WARNING, path, error, ## __VA_ARGS__) -#define tlmessage(toolLogger, path, error, ...) nlinfo(error, ## __VA_ARGS__), toolLogger.writeError(NLMISC::MESSAGE, path, error, ## __VA_ARGS__) +#define tlerror(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLPIPELINE::ERROR, path, error, ## __VA_ARGS__) +#define tlwarning(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLPIPELINE::WARNING, path, error, ## __VA_ARGS__) +#define tlmessage(toolLogger, path, error, ...) nlinfo(error, ## __VA_ARGS__), toolLogger.writeError(NLPIPELINE::MESSAGE, path, error, ## __VA_ARGS__) #else -#define tlerror(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::ERROR, path, error, ## __VA_ARGS__) -#define tlwarning(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::WARNING, path, error, ## __VA_ARGS__) -#define tlmessage(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::MESSAGE, path, error, ## __VA_ARGS__) +#define tlerror(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::ERROR, path, error, ## __VA_ARGS__) +#define tlwarning(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::WARNING, path, error, ## __VA_ARGS__) +#define tlmessage(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::MESSAGE, path, error, ## __VA_ARGS__) #endif -namespace NLMISC { +namespace NLPIPELINE { enum TError { @@ -203,8 +203,8 @@ public: } }; /* class CToolLogger */ -} /* namespace NLMISC */ +} /* namespace NLPIPELINE */ -#endif /* #ifndef NLMISC_TOOL_LOGGER_H */ +#endif /* #ifndef NLPIPELINE_TOOL_LOGGER_H */ /* end of file */ 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 d2abbfd38..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) @@ -1629,7 +1629,7 @@ bool CDriverGL::destroyWindow() if (_hDC) wglMakeCurrent(_hDC, NULL); - if (_DestroyWindow && _hRC) + if (_hRC) { wglDeleteContext(_hRC); _hRC = NULL; @@ -1644,7 +1644,7 @@ bool CDriverGL::destroyWindow() #elif defined(NL_OS_MAC) #elif defined(NL_OS_UNIX) - if (_DestroyWindow && _ctx) + if (_DestroyWindow && _ctx) // FIXME: _DestroyWindow may need to be removed here as well glXDestroyContext(_dpy, _ctx); _ctx = NULL; @@ -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/CMakeLists.txt b/code/nel/src/CMakeLists.txt index 06faa5251..60e5afccb 100644 --- a/code/nel/src/CMakeLists.txt +++ b/code/nel/src/CMakeLists.txt @@ -35,3 +35,7 @@ ENDIF(WITH_NEL_CEGUI) IF(WITH_PACS) ADD_SUBDIRECTORY(pacs) ENDIF(WITH_PACS) + +IF(WITH_NEL_TOOLS) + ADD_SUBDIRECTORY(pipeline) +ENDIF(WITH_NEL_TOOLS) 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/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 c1249319e..11a27e67e 100644 --- a/code/nel/src/misc/bitmap.cpp +++ b/code/nel/src/misc/bitmap.cpp @@ -84,6 +84,20 @@ void MakeWhite(CBitmap &bitmaps) } #endif // NEL_ALL_BITMAP_WHITE +CBitmap::CBitmap() +{ + _MipMapCount = 1; + _Width = 0; + _Height = 0; + PixelFormat = RGBA; + _LoadGrayscaleAsAlpha = true; +} + +CBitmap::~CBitmap() +{ + +} + /*-------------------------------------------------------------------*\ load \*-------------------------------------------------------------------*/ @@ -541,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..647bac008 100644 --- a/code/nel/src/misc/cmd_args.cpp +++ b/code/nel/src/misc/cmd_args.cpp @@ -199,11 +199,11 @@ 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); if (len && len < 4096) - argv.push_back(str); + argv.push_back(wideToUtf8(str)); #endif std::string::size_type pos1 = 0, pos2 = 0; diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index decd52dbf..c71688174 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,8 +782,26 @@ 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 @@ -869,76 +906,28 @@ bool launchProgram(const std::string &programName, const std::string &arguments, sint launchProgramAndWaitForResult(const std::string &programName, const std::string &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)); + if (!createProcess(programName, arguments, log, pi)) return -1; - si.cb = sizeof(si); + // Successfully created the process. Wait for it to finish. + WaitForSingleObject(pi.hProcess, INFINITE); - // 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) - { - SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL ); - } + // Get the exit code. + DWORD exitCode = 0; + BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode); - const char *sProgramName = programName.c_str(); + //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); - std::string args; + if (ok) return (sint)exitCode; - // 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; - } + if (log) + nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str()); - BOOL ok = CreateProcessA(sProgramName, (char*)args.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); - - if (ok) - { - // Successfully created the process. Wait for it to finish. - WaitForSingleObject(pi.hProcess, INFINITE); - - // Get the exit code. - DWORD exitCode = 0; - 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) - { - res = (sint)exitCode; - } - else - { - if (log) - nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str()); - } - } - 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()); - } - - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - } + return -1; #else // program name is the only required string std::string command = programName; @@ -947,13 +936,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) @@ -1099,6 +1088,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..7ea9ad544 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -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,19 +315,19 @@ 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]; - if(RegQueryValueEx(hkey, Entry.c_str(), NULL, &dwType, Buffer, &dwSize) != ERROR_SUCCESS) + if (RegQueryValueExW(hkey, utf8ToWide(Entry), NULL, &dwType, Buffer, &dwSize) != ERROR_SUCCESS) { nlwarning("Can't get the reg key '%s'", Entry.c_str()); } else { - ret = (char*)Buffer; + ret = wideToUtf8(Buffer); } RegCloseKey(hkey); } @@ -346,10 +346,12 @@ 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) + wchar_t nstr[] = { 0x00 }; + if (RegCreateKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, nstr, 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); + 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 +455,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/pipeline/CMakeLists.txt b/code/nel/src/pipeline/CMakeLists.txt new file mode 100644 index 000000000..47ab9a376 --- /dev/null +++ b/code/nel/src/pipeline/CMakeLists.txt @@ -0,0 +1,18 @@ +FILE(GLOB SRC *.cpp *.h) +FILE(GLOB HEADERS ../../include/nel/pipeline/*.h) + +SOURCE_GROUP("" FILES ${HEADERS} ${SRC}) + +NL_TARGET_LIB(nelpipeline ${HEADERS} ${SRC}) + +INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR}) + +TARGET_LINK_LIBRARIES(nelpipeline nelmisc) +NL_DEFAULT_PROPS(nelpipeline "NeL, Library: NeL Pipeline") +NL_ADD_RUNTIME_FLAGS(nelpipeline) + +NL_ADD_LIB_SUFFIX(nelpipeline) + +IF((WITH_INSTALL_LIBRARIES AND WITH_STATIC) OR NOT WITH_STATIC) + INSTALL(TARGETS nelpipeline LIBRARY DESTINATION ${NL_LIB_PREFIX} ARCHIVE DESTINATION ${NL_LIB_PREFIX} COMPONENT libraries) +ENDIF((WITH_INSTALL_LIBRARIES AND WITH_STATIC) OR NOT WITH_STATIC) diff --git a/code/nel/tools/3d/mesh_utils/database_config.cpp b/code/nel/src/pipeline/database_config.cpp similarity index 96% rename from code/nel/tools/3d/mesh_utils/database_config.cpp rename to code/nel/src/pipeline/database_config.cpp index 7e6ea5b37..b326a2888 100644 --- a/code/nel/tools/3d/mesh_utils/database_config.cpp +++ b/code/nel/src/pipeline/database_config.cpp @@ -16,7 +16,7 @@ // along with this program. If not, see . #include -#include "database_config.h" +#include "nel/pipeline/database_config.h" #include #include @@ -25,6 +25,8 @@ using namespace std; using namespace NLMISC; +namespace NLPIPELINE { + TPathString CDatabaseConfig::s_RootPath; NLMISC::CConfigFile *CDatabaseConfig::s_ConfigFile = NULL; CDatabaseConfig CDatabaseConfig::s_Instance; @@ -104,4 +106,6 @@ void CDatabaseConfig::release() cleanup(); } +} /* namespace NLPIPELINE */ + /* end of file */ diff --git a/code/nel/src/pipeline/project_config.cpp b/code/nel/src/pipeline/project_config.cpp new file mode 100644 index 000000000..995f92fd4 --- /dev/null +++ b/code/nel/src/pipeline/project_config.cpp @@ -0,0 +1,238 @@ +// NeL - MMORPG Framework +// Copyright (C) 2015 Winch Gate Property Limited +// Author: Jan Boon +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include +#include "nel/pipeline/project_config.h" + +#ifdef NL_OS_WINDOWS +# include +#else +# include +#endif + +#include + +#include +#include +#include + +using namespace std; +using namespace NLMISC; + +namespace NLPIPELINE { + +TPathString CProjectConfig::s_AssetConfigPath; +TPathString CProjectConfig::s_ProjectConfigPath; +std::vector CProjectConfig::s_ConfigFiles; +std::vector CProjectConfig::s_ConfigPaths; +CProjectConfig CProjectConfig::s_Instance; +uint32 CProjectConfig::s_AssetConfigModification; +uint32 CProjectConfig::s_ProjectConfigModification; +CProjectConfig::Flags CProjectConfig::s_InitFlags = (CProjectConfig::Flags)0; +std::string CProjectConfig::s_ProjectName; + +static std::set s_SearchPaths; + +void CProjectConfig::cleanup() +{ + for (std::vector::iterator it(s_ConfigFiles.begin()), end(s_ConfigFiles.end()); it != end; ++it) + delete *it; + s_ConfigFiles.clear(); +} + +CProjectConfig::~CProjectConfig() +{ + cleanup(); +} + +bool CProjectConfig::init(const std::string &asset, Flags flags, bool partial) +{ + TPathString rootPath = NLMISC::CPath::standardizePath(asset, false); + TPathString configPath = rootPath + "/nel.cfg"; + while (!CFile::fileExists(configPath)) + { + int sep = CFile::getLastSeparator(rootPath); + if (sep == string::npos) + return false; + + rootPath = rootPath.substr(0, sep); + if (rootPath.empty()) + return false; + + configPath = rootPath + "/nel.cfg"; + } + + rootPath += "/"; + uint32 configFileModification = CFile::getFileModificationDate(configPath); + bool assetConfigSame = configPath == s_AssetConfigPath && s_AssetConfigModification == configFileModification && s_InitFlags == flags; + + std::vector configRootPaths; + TPathString projectConfigPath; + uint32 projectConfigModification; + std::string projectName; + if (partial) + { + if (assetConfigSame && s_ProjectConfigPath.empty()) + return true; // Do not reload + } + else + { + if (assetConfigSame && !s_ProjectConfigPath.empty() && CFile::fileExists(s_ProjectConfigPath)) + { + projectConfigModification = CFile::getFileModificationDate(s_ProjectConfigPath); + + if (s_ProjectConfigModification == projectConfigModification) + return true; // Do not reload + } + + // Search for project and load up all root paths + std::vector files; + CPath::getPathContent(CPath::getApplicationDirectory("NeL", true) + "/projects", false, false, true, files); + for (std::vector::iterator it(files.begin()), end(files.end()); it != end; ++it) + { + const std::string& file = *it; + if (file.length() >= 4 && (file.compare(file.length() - 4, 4, ".cfg") == 0)) + { + CConfigFile project; + project.load(file); + CConfigFile::CVar &directories = project.getVar("Directories"); + bool isProject = false; + for (uint i = 0; i < directories.size(); ++i) + { + if (rootPath == CPath::standardizePath(directories.asString(i), true)) + { + isProject = true; + break; + } + } + if (isProject) + { + projectConfigModification = CFile::getFileModificationDate(file); + projectConfigPath = file; + + for (uint i = 0; i < directories.size(); ++i) + { + std::string dir = CPath::standardizePath(directories.asString(i), true); + std::string cfgPath = dir + "nel.cfg"; + if (CFile::fileExists(cfgPath)) + configRootPaths.push_back(dir); + } + + projectName = project.getVar("ProjectName").asString(); + + break; + } + } + } + } + + if (projectConfigPath.empty()) + { + projectName = "NeL Project"; + configRootPaths.push_back(rootPath); + projectConfigModification = 0; + } + + nldebug("Initializing project config '%s'", projectConfigPath.empty() ? configPath.c_str() : projectConfigPath.c_str()); + release(); + + s_InitFlags = flags; + s_AssetConfigPath = configPath; + s_AssetConfigModification = configFileModification; + s_ProjectConfigPath = projectConfigPath; + s_ProjectConfigModification = projectConfigModification; + s_ProjectName = projectName; + s_ConfigPaths = configRootPaths; + + std::map configFiles; + for (std::vector::iterator it(configRootPaths.begin()), end(configRootPaths.end()); it != end; ++it) + { + const std::string &dir = *it; + const std::string &cfgPath = *it + "nel.cfg"; + CConfigFile *cfgFile = new CConfigFile(); + cfgFile->load(cfgPath); + std::string identifier = cfgFile->getVar("Identifier").asString(); + if (configFiles.find(identifier) != configFiles.end()) // Identifier already exists + { + if (dir == rootPath) + { + // Replace config that was already added, asset root gets priority + std::vector::iterator old = std::find(s_ConfigFiles.begin(), s_ConfigFiles.end(), configFiles[identifier]); + uint idx = old - s_ConfigFiles.begin(); + s_ConfigFiles.erase(old); + s_ConfigPaths.erase(s_ConfigPaths.begin() + idx); + } + else + { + // Skip, first listed config gets priority + s_ConfigPaths.erase(s_ConfigPaths.begin() + s_ConfigFiles.size()); + continue; + } + } +#ifdef NL_OS_WINDOWS + SetEnvironmentVariableA(identifier.c_str(), dir.c_str()); +#else + setenv(identifier.c_str(), dir.c_str(), 1); +#endif + configFiles[identifier] = cfgFile; + s_ConfigFiles.push_back(cfgFile); + } + + nlassert(s_ConfigFiles.size() == s_ConfigPaths.size()); + + if (flags & DatabaseTextureSearchPaths) + { + searchDirectories("DatabaseTextureSearchPaths"); + } + + return true; +} + +void CProjectConfig::searchDirectories(const char *var) +{ + for (uint i = 0; i < s_ConfigFiles.size(); ++i) + { + CConfigFile *cfg = s_ConfigFiles[i]; + const TPathString &dir = s_ConfigPaths[i]; + CConfigFile::CVar *paths = cfg->getVarPtr(var); + if (paths) + { + for (uint i = 0; i < paths->size(); i++) + { + TPathString path = paths->asString(i); + if (!CPath::isAbsolutePath(path)) path = dir + path; + path = CPath::standardizePath(path); + if (s_SearchPaths.find(path) == s_SearchPaths.end()) + { + CPath::addSearchPath(path); + s_SearchPaths.insert(path); + } + } + } + } +} + +void CProjectConfig::release() +{ + s_SearchPaths.clear(); + CPath::clearMap(); + cleanup(); +} + +} /* namespace NLPIPELINE */ + +/* end of file */ diff --git a/code/nel/src/misc/tool_logger.cpp b/code/nel/src/pipeline/tool_logger.cpp similarity index 92% rename from code/nel/src/misc/tool_logger.cpp rename to code/nel/src/pipeline/tool_logger.cpp index e6a9fbf36..064e25f77 100644 --- a/code/nel/src/misc/tool_logger.cpp +++ b/code/nel/src/pipeline/tool_logger.cpp @@ -25,8 +25,7 @@ * . */ -#include "stdmisc.h" -#include "nel/misc/tool_logger.h" +#include "nel/pipeline/tool_logger.h" // STL includes @@ -35,11 +34,11 @@ // Project includes -namespace NLMISC { +namespace NLPIPELINE { // Tool logger is fully implemented in header so small tools do not need to link to this library unnecessarily. void dummy_tool_logger_cpp() { } -} /* namespace NLMISC */ +} /* namespace NLPIPELINE */ /* end of file */ 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/mesh_utils/CMakeLists.txt b/code/nel/tools/3d/mesh_utils/CMakeLists.txt index a5a9fa952..c8390587c 100644 --- a/code/nel/tools/3d/mesh_utils/CMakeLists.txt +++ b/code/nel/tools/3d/mesh_utils/CMakeLists.txt @@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES(${assimp_INCLUDE_DIRS}) NL_TARGET_LIB(mesh_utils ${SRCS} ${HDRS}) -TARGET_LINK_LIBRARIES(mesh_utils ${assimp_LIBRARIES} nelmisc nel3d) +TARGET_LINK_LIBRARIES(mesh_utils ${assimp_LIBRARIES} nelmisc nelpipeline nel3d) NL_DEFAULT_PROPS(mesh_utils "NeL, Tools, 3D: Mesh Utils") NL_ADD_RUNTIME_FLAGS(mesh_utils) diff --git a/code/nel/tools/3d/mesh_utils/assimp_material.cpp b/code/nel/tools/3d/mesh_utils/assimp_material.cpp index 5dbe8643c..4830d1b33 100644 --- a/code/nel/tools/3d/mesh_utils/assimp_material.cpp +++ b/code/nel/tools/3d/mesh_utils/assimp_material.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include diff --git a/code/nel/tools/3d/mesh_utils/assimp_shape.cpp b/code/nel/tools/3d/mesh_utils/assimp_shape.cpp index 7b404d1e2..7ab0729ae 100644 --- a/code/nel/tools/3d/mesh_utils/assimp_shape.cpp +++ b/code/nel/tools/3d/mesh_utils/assimp_shape.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include diff --git a/code/nel/tools/3d/mesh_utils/mesh_utils.cpp b/code/nel/tools/3d/mesh_utils/mesh_utils.cpp index b8d70660e..8765e3960 100644 --- a/code/nel/tools/3d/mesh_utils/mesh_utils.cpp +++ b/code/nel/tools/3d/mesh_utils/mesh_utils.cpp @@ -19,7 +19,8 @@ #include "mesh_utils.h" #include -#include +#include +#include #include #include #include @@ -28,7 +29,6 @@ #include #include -#include "database_config.h" #include "scene_meta.h" #include @@ -231,7 +231,7 @@ void exportShapes(CMeshUtilsContext &context) if (nodeContext.Shape) { std::string shapePath = NLMISC::CPath::standardizePath(context.Settings.DestinationDirectoryPath, true) + it->first + ".shape"; - context.ToolLogger.writeDepend(NLMISC::BUILD, shapePath.c_str(), "*"); + context.ToolLogger.writeDepend(NLPIPELINE::BUILD, shapePath.c_str(), "*"); NLMISC::COFile f; if (f.open(shapePath, false, false, true)) { @@ -262,7 +262,7 @@ void exportShapes(CMeshUtilsContext &context) std::string knownPath = NLMISC::CPath::lookup(fileName, false, false, false); if (!knownPath.empty()) { - context.ToolLogger.writeDepend(NLMISC::RUNTIME, shapePath.c_str(), knownPath.c_str()); + context.ToolLogger.writeDepend(NLPIPELINE::RUNTIME, shapePath.c_str(), knownPath.c_str()); } else { @@ -289,17 +289,17 @@ int exportScene(const CMeshUtilsSettings &settings) context.ToolLogger.initDepend(settings.ToolDependLog); if (!settings.ToolErrorLog.empty()) context.ToolLogger.initError(settings.ToolErrorLog); - context.ToolLogger.writeDepend(NLMISC::BUILD, "*", NLMISC::CPath::standardizePath(context.Settings.SourceFilePath, false).c_str()); // Base input file + context.ToolLogger.writeDepend(NLPIPELINE::BUILD, "*", NLMISC::CPath::standardizePath(context.Settings.SourceFilePath, false).c_str()); // Base input file // Apply database configuration - if (!CDatabaseConfig::init(settings.SourceFilePath)) + if (!NLPIPELINE::CProjectConfig::init(settings.SourceFilePath, + NLPIPELINE::CProjectConfig::DatabaseTextureSearchPaths, + true)) { tlerror(context.ToolLogger, context.Settings.SourceFilePath.c_str(), "Unable to find database.cfg in input path or any of its parents."); - return EXIT_FAILURE; + // return EXIT_FAILURE; We can continue but the output will not be guaranteed... } - CDatabaseConfig::initTextureSearchDirectories(); - Assimp::Importer importer; const aiScene *scene = importer.ReadFile(settings.SourceFilePath, 0 | aiProcess_Triangulate @@ -321,7 +321,7 @@ int exportScene(const CMeshUtilsSettings &settings) context.InternalScene = scene; if (context.SceneMeta.load(context.Settings.SourceFilePath)) - context.ToolLogger.writeDepend(NLMISC::BUILD, "*", context.SceneMeta.metaFilePath().c_str()); // Meta input file + context.ToolLogger.writeDepend(NLPIPELINE::BUILD, "*", context.SceneMeta.metaFilePath().c_str()); // Meta input file validateInternalNodeNames(context, context.InternalScene->mRootNode); diff --git a/code/nel/tools/3d/mesh_utils/scene_context.cpp b/code/nel/tools/3d/mesh_utils/scene_context.cpp index 6812a312a..243f13482 100644 --- a/code/nel/tools/3d/mesh_utils/scene_context.cpp +++ b/code/nel/tools/3d/mesh_utils/scene_context.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include using namespace std; using namespace NLMISC; diff --git a/code/nel/tools/3d/mesh_utils/scene_context.h b/code/nel/tools/3d/mesh_utils/scene_context.h index 714e3ff54..10fa55e46 100644 --- a/code/nel/tools/3d/mesh_utils/scene_context.h +++ b/code/nel/tools/3d/mesh_utils/scene_context.h @@ -23,7 +23,7 @@ #include "scene_meta.h" #include -#include +#include #include #include @@ -67,7 +67,7 @@ struct CMeshUtilsContext const CMeshUtilsSettings &Settings; - NLMISC::CToolLogger ToolLogger; + NLPIPELINE::CToolLogger ToolLogger; const NL_SCENE_INTERNAL_TYPE *InternalScene; CSceneMeta SceneMeta; 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/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; iwrite(id,f); - fclose(f); + FILE * f = nlfopen(fileName, "w"); + if (f) + { + ICDBNode::CTextId id; + _Database->write(id,f); + fclose(f); + + res = true; + } } - else + + if (!res) { nlwarning(" can't write %s : the database has not been initialized",fileName.c_str()); } diff --git a/code/ryzom/client/src/client.cpp b/code/ryzom/client/src/client.cpp index 83f8881f5..3e6f73b80 100644 --- a/code/ryzom/client/src/client.cpp +++ b/code/ryzom/client/src/client.cpp @@ -175,7 +175,7 @@ int main(int argc, char **argv) Args.setVersion(getDisplayVersion()); Args.setDescription("Ryzom client"); - Args.addArg("c", "config", "id", "Use this configuration to determine what directory to use by default"); + Args.addArg("p", "profile", "id", "Use this profile to determine what directory to use by default"); Args.addAdditionalArg("login", "Login to use", true, false); Args.addAdditionalArg("password", "Password to use", true, false); Args.addAdditionalArg("shard_id", "Shard ID to use", true, false); @@ -210,13 +210,13 @@ int main(int argc, char **argv) LoginShardId = std::numeric_limits::max(); // if client_default.cfg is not in current directory, use application default directory - if (Args.haveArg("c") || !CFile::isExists("client_default.cfg")) + if (Args.haveArg("p") || !CFile::isExists("client_default.cfg")) { std::string currentPath = CPath::getApplicationDirectory("Ryzom"); - // append config ID to directory - if (Args.haveArg("c")) - currentPath = NLMISC::CPath::standardizePath(currentPath) + Args.getArg("c").front(); + // append profile ID to directory + if (Args.haveArg("p")) + currentPath = NLMISC::CPath::standardizePath(currentPath) + Args.getArg("p").front(); if (!CFile::isExists(currentPath)) CFile::createDirectory(currentPath); diff --git a/code/ryzom/client/src/client_cfg.cpp b/code/ryzom/client/src/client_cfg.cpp index ac5314ac4..99f425f8a 100644 --- a/code/ryzom/client/src/client_cfg.cpp +++ b/code/ryzom/client/src/client_cfg.cpp @@ -877,6 +877,7 @@ void CClientConfig::setValues() // defined in client_default.cfg READ_STRING_FV(ConditionsTermsURL) + READ_STRING_FV(NamingPolicyURL) READ_STRING_FV(LoginSupportURL) #ifndef RZ_NO_CLIENT @@ -1921,7 +1922,7 @@ void CClientConfig::init(const string &configFileName) if(!CFile::fileExists(configFileName)) { // create the basic .cfg - FILE *fp = fopen(configFileName.c_str(), "w"); + FILE *fp = nlfopen(configFileName, "w"); if (fp == NULL) nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str()); diff --git a/code/ryzom/client/src/client_cfg.h b/code/ryzom/client/src/client_cfg.h index 75c7698da..5fe0cfa1c 100644 --- a/code/ryzom/client/src/client_cfg.h +++ b/code/ryzom/client/src/client_cfg.h @@ -160,6 +160,7 @@ struct CClientConfig string CreateAccountURL; string EditAccountURL; string ConditionsTermsURL; + string NamingPolicyURL; string BetaAccountURL; string ForgetPwdURL; string FreeTrialURL; diff --git a/code/ryzom/client/src/commands.cpp b/code/ryzom/client/src/commands.cpp index f958869f5..3308ee7ad 100644 --- a/code/ryzom/client/src/commands.cpp +++ b/code/ryzom/client/src/commands.cpp @@ -695,7 +695,7 @@ NLMISC_COMMAND(bugReport, "Call the bug report tool with dump", " if (ClientCfg.Local) sys += "ShardName OFFLINE "; - FILE *fp = fopen (std::string(getLogDirectory() + "bug_report.txt").c_str(), "wb"); + FILE *fp = nlfopen (getLogDirectory() + "bug_report.txt", "wb"); if (fp != NULL) { string res = addSlashR(getDebugInformation()); diff --git a/code/ryzom/client/src/http_client_curl.cpp b/code/ryzom/client/src/http_client_curl.cpp index 008bef19a..c8452c02e 100644 --- a/code/ryzom/client/src/http_client_curl.cpp +++ b/code/ryzom/client/src/http_client_curl.cpp @@ -15,9 +15,12 @@ // along with this program. If not, see . #include "stdpch.h" -#include #include "http_client_curl.h" +#include + +#include + using namespace NLMISC; using namespace NLNET; using namespace std; @@ -58,16 +61,73 @@ bool CCurlHttpClient::authenticate(const std::string &user, const std::string &p const char *CAFilename = "ssl_ca_cert.pem"; // this is the certificate "Thawte Server CA" +static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) +{ + string path = CPath::lookup(CAFilename); + nldebug("Cert path '%s'", path.c_str()); + + CIFile file; + + if (!file.open(CAFilename)) + { + nlwarning("Unable to open %s", CAFilename.c_str()); + return CURLE_SSL_CACERT; + } + + CURLcode res = CURLE_OK; + + std::vector buffer(file.getFileSize()); + file.serialBuffer(&buffer[0], file.getFileSize()); + + // get a BIO + BIO *bio = BIO_new_mem_buf(&buffer[0], file.getFileSize()); + + if (bio) + { + // use it to read the PEM formatted certificate from memory into an X509 + // structure that SSL can use + X509 *cert = NULL; + PEM_read_bio_X509(bio, &cert, 0, NULL); + + if (cert) + { + // get a pointer to the X509 certificate store (which may be empty!) + X509_STORE *store = SSL_CTX_get_cert_store((SSL_CTX *)sslctx); + + // add our certificate to this store + if (X509_STORE_add_cert(store, cert) == 0) + { + nlwarning("Error adding certificate"); + res = CURLE_SSL_CACERT; + } + + // decrease reference counts + X509_free(cert); + } + else + { + nlwarning("PEM_read_bio_X509 failed..."); + res = CURLE_SSL_CACERT; + } + + // decrease reference counts + BIO_free(bio); + } + + // all set to go + return CURLE_OK ; +} + // *************************************************************************** bool CCurlHttpClient::verifyServer(bool verify) { curl_easy_setopt(_Curl, CURLOPT_SSL_VERIFYHOST, verify ? 2 : 0); curl_easy_setopt(_Curl, CURLOPT_SSL_VERIFYPEER, verify ? 1 : 0); curl_easy_setopt(_Curl, CURLOPT_SSLCERTTYPE, "PEM"); - //curl_easy_setopt(_Curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); // would allow to provide the CA in memory instead of using CURLOPT_CAINFO, but needs to include and link OpenSSL - string path = CPath::lookup(CAFilename); - nldebug("cert path '%s'", path.c_str()); - curl_easy_setopt(_Curl, CURLOPT_CAINFO, path.c_str()); + // would allow to provide the CA in memory instead of using CURLOPT_CAINFO, but needs to include and link OpenSSL + curl_easy_setopt(_Curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); + // don't use that anymore, because CA can't be loaded from BNP and doesn't support UTF-8 under Windows + // curl_easy_setopt(_Curl, CURLOPT_CAINFO, path.c_str()); curl_easy_setopt(_Curl, CURLOPT_CAPATH, NULL); return true; } diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index a203614e4..864451718 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -271,7 +271,7 @@ static INT_PTR CALLBACK ExitClientErrorDialogProc(HWND hwndDlg, UINT uMsg, WPARA GetWindowRect (GetDesktopWindow (), &rectDesktop); SetWindowPos (hwndDlg, HWND_TOPMOST, (rectDesktop.right-rectDesktop.left-rect.right+rect.left)/2, (rectDesktop.bottom-rectDesktop.top-rect.bottom+rect.top)/2, 0, 0, SWP_NOSIZE); HICON exitClientDlgIcon = LoadIcon(HInstance, MAKEINTRESOURCE(IDI_MAIN_ICON)); - ::SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) exitClientDlgIcon); + ::SendMessageA(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) exitClientDlgIcon); } break; case WM_COMMAND: diff --git a/code/ryzom/client/src/interface_v3/action_handler_help.cpp b/code/ryzom/client/src/interface_v3/action_handler_help.cpp index ed2b34ce3..072d53591 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_help.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_help.cpp @@ -3937,13 +3937,15 @@ public: s += getSystemInformation(); string progname; - char name[1024] = ""; + std::string moduleName; #ifdef NL_OS_WINDOWS - GetModuleFileName (NULL, name, 1023); + wchar_t name[1024]; + GetModuleFileNameW(NULL, name, 1023); + moduleName = wideToUtf8(name); #else // TODO for Linux #endif - progname = CFile::getFilename(name); + progname = CFile::getFilename(moduleName); progname += " "; progname += "Statistic Report"; diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index b8721ffdd..4d2248249 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -2704,7 +2704,7 @@ void CInterfaceManager::log(const ucstring &str, const std::string &cat) { // Open file with the name of the player const string fileName= "save/log_" + PlayerSelectedFileName + ".txt"; - FILE *f = fopen(fileName.c_str(), "at"); + FILE *f = nlfopen(fileName, "at"); if (f != NULL) { const string finalString = string(NLMISC::IDisplayer::dateToHumanString()) + " (" + NLMISC::toUpper(cat) + ") * " + str.toUtf8(); diff --git a/code/ryzom/client/src/interface_v3/music_player.cpp b/code/ryzom/client/src/interface_v3/music_player.cpp index 39aeea825..ece6f0d43 100644 --- a/code/ryzom/client/src/interface_v3/music_player.cpp +++ b/code/ryzom/client/src/interface_v3/music_player.cpp @@ -196,162 +196,176 @@ public: InitMouseWithCursor (true); Driver->showCursor (true); - if (false) //supportUnicode()) + bool oggSupported = false; + bool mp3Supported = false; + + for(uint i = 0; i < extensions.size(); ++i) { + if (extensions[i] == "ogg") + { + oggSupported = true; + } + else if (extensions[i] == "mp3") + { + mp3Supported = true; + } } - else + + std::vector filters; + + // supported formats + filters.push_back("All Supported Files"); // TODO: translate + + std::string filter; + if (mp3Supported) filter += "*.mp3;*.mp2;*.mp1;"; + if (oggSupported) filter += "*.ogg;"; + filter += "*.m3u;*.m3u8"; + + filters.push_back(filter); + + // mp3 format + if (mp3Supported) { - bool oggSupported = false; - bool mp3Supported = false; + filters.push_back("MPEG Audio Files (*.mp3;*.mp2;*.mp1)"); + filters.push_back("*.mp3;*.mp2;*.mp1"); + } - for(uint i = 0; i < extensions.size(); ++i) + // ogg format + if (oggSupported) + { + filters.push_back("Vorbis Files (*.ogg)"); + filters.push_back("*.ogg"); + } + + // playlist + filters.push_back("Playlist Files (*.m3u;*.m3u8)"); + filters.push_back("*.m3u;*.m3u8"); + + // all files + filters.push_back("All Files (*.*)"); + filters.push_back("*.*"); + + filters.push_back(""); + + static wchar_t szFilter[1024] = { '\0' }; + + uint offset = 0; + + for(uint i = 0; i < filters.size(); ++i) + { + wcscpy(szFilter + offset, utf8ToWide(filters[i])); + + // move offset to string length + 1 for \0 + offset += filters[i].length() + 1; + } + + // Filename buffer + wchar_t buffer[1024]; + buffer[0]=0; + + OPENFILENAMEW ofn; + memset (&ofn, 0, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = Driver ? Driver->getDisplay():NULL; + ofn.hInstance = HInstance; + ofn.lpstrFilter = szFilter; + ofn.nFilterIndex = 0; + ofn.lpstrFile = buffer; + ofn.nMaxFile = sizeof(buffer); + ofn.lpstrTitle = (wchar_t*)NLMISC::CI18N::get("uiPlaySongs").c_str(); + ofn.Flags = OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING|OFN_EXPLORER; + + if (Driver) + Driver->beginDialogMode(); + + if (GetOpenFileNameW (&ofn)) + { + bool useUtf8 = false; + + // Skip the directory name + const wchar_t *bufferPtr = buffer; + + // Multi filename ? + string path; + if (ofn.nFileOffset>wcslen(buffer)) { - if (extensions[i] == "ogg") - { - oggSupported = true; - } - else if (extensions[i] == "mp3") - { - mp3Supported = true; - } + // Backup the path and point to the next filename + path = wideToUtf8(buffer); + path += "\\"; + bufferPtr += wcslen(bufferPtr)+1; } - std::vector filters; - - // supported formats - filters.push_back("All Supported Files"); - - std::string filter; - if (mp3Supported) filter += "*.mp3;*.mp2;*.mp1;"; - if (oggSupported) filter += "*.ogg;"; - filter += "*.m3u"; - - filters.push_back(filter); - - // mp3 format - if (mp3Supported) + // Get selected files and playlists + std::vector filenames; + std::vector playlists; + while (*bufferPtr) { - filters.push_back("MPEG Audio Files (*.mp3;*.mp2;*.mp1)"); - filters.push_back("*.mp3;*.mp2;*.mp1"); - } - - // ogg format - if (oggSupported) - { - filters.push_back("Vorbis Files (*.ogg)"); - filters.push_back("*.ogg"); - } - - // playlist - filters.push_back("Playlist Files (*.m3u)"); - filters.push_back("*.m3u"); - - // all files - filters.push_back("All Files (*.*)"); - filters.push_back("*.*"); - - filters.push_back(""); - - static char szFilter[1024] = { '\0' }; - - uint offset = 0; - - for(uint i = 0; i < filters.size(); ++i) - { - strcpy(szFilter + offset, filters[i].c_str()); - - // move offset to string length + 1 for \0 - offset += filters[i].length() + 1; - } - - // Filename buffer - char buffer[65535]; - buffer[0]=0; - - OPENFILENAME ofn; - memset (&ofn, 0, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = Driver ? Driver->getDisplay():NULL; - ofn.hInstance = HInstance; - ofn.lpstrFilter = szFilter; - ofn.nFilterIndex = 0; - ofn.lpstrFile = buffer; - ofn.nMaxFile = sizeof(buffer); - ofn.lpstrTitle = "Play songs"; - ofn.Flags = OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING|OFN_EXPLORER; - - if (Driver) - Driver->beginDialogMode(); - - if (GetOpenFileName (&ofn)) - { - // Skip the directory name - const char *bufferPtr = buffer; - - // Multi filename ? - string path; - if (ofn.nFileOffset>strlen(buffer)) + // Concat the directory name with the filename + std::string ext = toLower(CFile::getExtension(wideToUtf8(bufferPtr))); + if (ext == "m3u" || ext == "m3u8") { - // Backup the path and point to the next filename - path = buffer; - path += "\\"; - bufferPtr+=strlen(bufferPtr)+1; + playlists.push_back (path + wideToUtf8(bufferPtr)); + } + else + { + filenames.push_back (path + wideToUtf8(bufferPtr)); } - // Get selected files and playlists - std::vector filenames; - std::vector playlists; - while (*bufferPtr) - { - // Concat the directory name with the filename - if (toLower(CFile::getExtension(bufferPtr)) == "m3u") - playlists.push_back (path+bufferPtr); - else - filenames.push_back (path+bufferPtr); - bufferPtr+=strlen(bufferPtr)+1; - } + bufferPtr += wcslen(bufferPtr) + 1; + } - // Sort songs by filename - sort (filenames.begin(), filenames.end()); + // Sort songs by filename + sort (filenames.begin(), filenames.end()); - // Add playlist - uint i; - for (i=0; i= 3 && memcmp(line, utf8Header, 3) == 0) + useUtf8 = true; + + if (!useUtf8) lineStr = ucstring(line).toUtf8(); + + if (lineStr[0] != '#') + filenames.push_back (CPath::makePathAbsolute(lineStr, basePlaylist)); } + fclose (file); } - - // Build the songs array - std::vector songs; - for (i=0; igetMixer()->getSongTitle(filenames[i], song.Title); - songs.push_back (song); - } - - MusicPlayer.playSongs(songs); } - if (Driver) - Driver->endDialogMode(); + // Build the songs array + std::vector songs; + for (i=0; igetMixer()->getSongTitle(filenames[i], song.Title); + songs.push_back (song); + } + + MusicPlayer.playSongs(songs); } + if (Driver) + Driver->endDialogMode(); + // Restore mouse InitMouseWithCursor (wasHardware); Driver->showCursor (wasHardware); diff --git a/code/ryzom/client/src/login.cpp b/code/ryzom/client/src/login.cpp index b4dc7ff42..80e184efe 100644 --- a/code/ryzom/client/src/login.cpp +++ b/code/ryzom/client/src/login.cpp @@ -1787,7 +1787,7 @@ class CAHReboot : public IActionHandler } catch (const std::exception &e) { - im->messageBoxWithHelp(ucstring(e.what()), "ui:login", "login_quit"); + im->messageBoxWithHelp(ucstring::makeFromUtf8(e.what()), "ui:login", "login_quit"); } } }; @@ -1857,17 +1857,7 @@ class CAHOpenURL : public IActionHandler // TODO: for Linux and Mac OS #endif - /* - if (sParams == "cfg_CreateAccountURL") - { - url = ClientCfg.CreateAccountURL; - - if (!installTag.empty()) - { - url += string("/?from=")+installTag; - } - } - else */if (sParams == "cfg_EditAccountURL") + if (sParams == "cfg_EditAccountURL") { url = ClientCfg.EditAccountURL; } @@ -1896,6 +1886,10 @@ class CAHOpenURL : public IActionHandler { url = ClientCfg.ConditionsTermsURL; } + else if (sParams == "cfg_NamingPolicyURL") + { + url = ClientCfg.NamingPolicyURL; + } else { nlwarning("no URL found"); diff --git a/code/ryzom/client/src/login_patch.cpp b/code/ryzom/client/src/login_patch.cpp index 0c4abc207..3d73635f9 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -119,14 +119,20 @@ CPatchManager::CPatchManager() : State("t_state"), DataScanState("t_data_scan_st #ifdef NL_OS_WINDOWS UpdateBatchFilename = "updt_nl.bat"; + UpgradeBatchFilename = "upgd_nl.bat"; #else UpdateBatchFilename = "updt_nl.sh"; + UpgradeBatchFilename = "upgd_nl.sh"; #endif - // use application directory by default - std::string rootPath = Args.getProgramPath(); + std::string rootPath; - if (!CFile::fileExists(rootPath + "client_default.cfg")) + if (ClientCfg.getDefaultConfigLocation(rootPath)) + { + // use same directory as client_default.cfg + rootPath = CFile::getPath(rootPath); + } + else { // use current directory rootPath = CPath::getCurrentPath(); @@ -698,7 +704,7 @@ bool CPatchManager::getThreadState (ucstring &stateOut, vector &stateL // verbose log if (isVerboseLog() && !stateLogOut.empty()) for (uint32 i = 0; i < stateLogOut.size(); ++i) - nlinfo("%s", stateLogOut[i].toString().c_str()); + nlinfo("%s", stateLogOut[i].toUtf8().c_str()); return changed; } @@ -733,6 +739,18 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool const CBNPCategorySet &rDescCats = descFile.getCategories(); OptionalCat.clear(); + string SrcPath = ClientPatchPath; + string DstPath = ClientRootPath; + +#ifdef NL_OS_WINDOWS + // only fix backslashes for .bat + string batchSrcPath = CPath::standardizeDosPath(SrcPath); + string batchDstPath = CPath::standardizeDosPath(DstPath); +#else + string batchSrcPath = SrcPath; + string batchDstPath = DstPath; +#endif + for (uint32 i = 0; i < rDescCats.categoryCount(); ++i) { // For all optional categories check if there is a 'file to patch' in it @@ -741,14 +759,14 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool if (!rCat.getUnpackTo().empty()) for (uint32 j = 0; j < rCat.fileCount(); ++j) { - string rFilename = ClientPatchPath + rCat.getFile(j); + string rFilename = SrcPath + rCat.getFile(j); nlwarning("\tFileName = %s", rFilename.c_str()); // Extract to patch vector vFilenames; bool result = false; try { - result = bnpUnpack(rFilename, ClientPatchPath, vFilenames); + result = bnpUnpack(rFilename, SrcPath, vFilenames); } catch(...) { @@ -766,45 +784,59 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool { for (uint32 fff = 0; fff < vFilenames.size (); fff++) { - string SrcPath = ClientPatchPath; - string DstPath = CPath::standardizePath(rCat.getUnpackTo()); // to be sure there is a / at the end - NLMISC::CFile::createDirectoryTree(DstPath); - // this file must be moved -#ifdef NL_OS_WINDOWS - SrcPath = CPath::standardizeDosPath(SrcPath); - DstPath = CPath::standardizeDosPath(DstPath); -#endif + string fullDstPath = CPath::standardizePath(rCat.getUnpackTo()); // to be sure there is a / at the end + NLMISC::CFile::createDirectoryTree(fullDstPath); - std::string SrcName = SrcPath + vFilenames[fff]; - std::string DstName = DstPath + vFilenames[fff]; + std::string FileName = vFilenames[fff]; bool succeeded = false; if (!useBatchFile) { // don't check result, because it's possible the olk file doesn't exist - CFile::deleteFile(DstName); + CFile::deleteFile(fullDstPath + FileName); // try to move it, if fails move it later in a script - if (CFile::moveFile(DstName, SrcName)) + if (CFile::moveFile(fullDstPath + FileName, SrcPath + FileName)) succeeded = true; } // if we didn't succeed to delete or move the file, create a batch file anyway if (!succeeded) { + string batchRelativeDstPath; + + if (fullDstPath.compare(0, DstPath.length(), DstPath) == 0) + { + batchRelativeDstPath = fullDstPath.substr(DstPath.length()) + FileName; + } + else + { + batchRelativeDstPath = fullDstPath + FileName; + } +#ifdef NL_OS_WINDOWS + // only fix backslashes for .bat + batchRelativeDstPath = CPath::standardizeDosPath(batchRelativeDstPath); +#endif + // write windows .bat format else write sh format #ifdef NL_OS_WINDOWS + string realDstPath = toString("\"%%DSTPATH%%\\%s\"", batchRelativeDstPath.c_str()); + string realSrcPath = toString("\"%%SRCPATH%%\\%s\"", FileName.c_str()); + content += toString(":loop%u\n", nblab); - content += toString("attrib -r -a -s -h \"%s\"\n", DstName.c_str()); - content += toString("del \"%s\"\n", DstName.c_str()); - content += toString("if exist \"%s\" goto loop%u\n", DstName.c_str(), nblab); - content += toString("move \"%s\" \"%s\"\n", SrcName.c_str(), DstPath.c_str()); + content += toString("attrib -r -a -s -h %s\n", realDstPath.c_str()); + content += toString("del %s\n", realDstPath.c_str()); + content += toString("if exist %s goto loop%u\n", realDstPath.c_str(), nblab); + content += toString("move %s %s\n", realSrcPath.c_str(), realDstPath.c_str()); #else - content += toString("rm -rf \"%s\"\n", DstName.c_str()); - content += toString("mv %s \"%s\"\n", SrcName.c_str(), DstPath.c_str()); + content += toString("rm -rf %s\n", realDstPath.c_str()); + // TODO: add test of returned $? + content += toString("mv %s %s\n", realSrcPath.c_str(), realDstPath.c_str()); #endif + + content += "\n"; } nblab++; @@ -851,10 +883,10 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool content += patchContent; - content += toString("rd /Q /S \"" + patchDirectory + "\"\n"); - content += toString("if exist \"" + patchDirectory + "\" goto looppatch\n"); + content += toString("rd /Q /S \"%s\"\n", patchDirectory.c_str()); + content += toString("if exist \"%s\" goto looppatch\n", patchDirectory.c_str()); #else - content += toString("rm -rf \"" + patchDirectory + "\"\n"); + content += toString("rm -rf \"%s\"\n", patchDirectory.c_str()); #endif } else @@ -869,7 +901,7 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool std::string batchFilename = ClientRootPath + UpdateBatchFilename; - FILE *fp = fopen (batchFilename.c_str(), "wt"); + FILE *fp = nlfopen (batchFilename, "wt"); if (fp == NULL) { @@ -877,30 +909,70 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool throw Exception (err); } + string contentPrefix; + //use bat if windows if not use sh #ifdef NL_OS_WINDOWS - fprintf(fp, "@echo off\n"); + contentPrefix += "@echo off\n"; + contentPrefix += "set RYZOM_CLIENT=%1\n"; + contentPrefix += "set SRCPATH=%2\n"; + contentPrefix += "set DSTPATH=%3\n"; + contentPrefix += "set LOGIN=%4\n"; + contentPrefix += "set PASSWORD=%5\n"; + contentPrefix += "set SHARDID=%6\n"; + contentPrefix += toString("set UPGRADE_FILE=%%DSTPATH%%\\%s\n", UpgradeBatchFilename.c_str()); #else - fprintf(fp, "#!/bin/sh\n"); + contentPrefix += "#!/bin/sh\n"; + contentPrefix += "RYZOM_CLIENT=$1\n"; + contentPrefix += "SRCPATH=$2\n"; + contentPrefix += "DSTPATH=$3\n"; + contentPrefix += "LOGIN=$4\n"; + contentPrefix += "PASSWORD=$5\n"; + contentPrefix += "SHARDID=$6\n"; + contentPrefix += toString("UPGRADE_FILE=$DSTPATH\\%s\n", UpgradeBatchFilename.c_str()); #endif + contentPrefix += "\n"; + // append content of script - fprintf(fp, content.c_str()); + fputs(contentPrefix.c_str(), fp); + fputs(content.c_str(), fp); + + std::string additionalParams; + + if (Args.haveLongArg("profile")) + { + additionalParams = "--profile " + Args.getLongArg("profile").front(); + } if (wantRyzomRestart) { + string contentSuffix; + #ifdef NL_OS_WINDOWS - fprintf(fp, "start \"\" \"%s\" %%1 %%2 %%3\n", CPath::standardizeDosPath(RyzomFilename).c_str()); + // launch upgrade script if present (it'll execute additional steps like moving or deleting files) + contentSuffix += "if exist \"%UPGRADE_FILE%\" call \"%UPGRADE_FILE%\"\n"; + + // client shouldn't be in memory anymore else it couldn't be overwritten + contentSuffix += toString("start \"\" /D \"%%DSTPATH%%\" \"%%RYZOM_CLIENT%%\" %s %%LOGIN%% %%PASSWORD%% %%SHARDID%%\n", additionalParams.c_str()); #else - // wait until client is not in memory - fprintf(fp, "until ! pgrep %s > /dev/null; do sleep 1; done\n", CFile::getFilename(RyzomFilename).c_str()); + // wait until client not in memory anymore + contentSuffix += toString("until ! pgrep %s > /dev/null; do sleep 1; done\n", CFile::getFilename(RyzomFilename).c_str()); + + // launch upgrade script if present (it'll execute additional steps like moving or deleting files) + contentSuffix += "if [ -e \"$UPGRADE_FILE\" ]; then chmod +x \"$UPGRADE_FILE\" && \"$UPGRADE_FILE\"; fi\n"; // be sure file is executable - fprintf(fp, "chmod +x \"%s\"\n", RyzomFilename.c_str()); + contentSuffix += "chmod +x \"$RYZOM_CLIENT\"\n"); + + // change to previous client directory + contentSuffix += "cd \"$DSTPATH\"\n"); // launch new client - fprintf(fp, "\"%s\" $1 $2 $3\n", RyzomFilename.c_str()); + contentSuffix += toString("\"$RYZOM_CLIENT\" %s $LOGIN $PASSWORD $SHARDID\n", additionalParams.c_str()); #endif + + fputs(contentSuffix.c_str(), fp); } bool writeError = ferror(fp) != 0; @@ -940,12 +1012,20 @@ void CPatchManager::executeBatchFile() batchFilename += UpdateBatchFilename; -#ifdef NL_OS_UNIX - // make script executable under UNIX - chmod(batchFilename.c_str(), S_IRWXU); + // make script executable + CFile::setRWAccess(batchFilename); + + std::string arguments; + + // 3 first parameters are Ryzom client full path, patch directory full path and client root directory full path +#ifdef NL_OS_WINDOWS + arguments += "\"" + CPath::standardizeDosPath(RyzomFilename) + "\" \"" + CPath::standardizeDosPath(ClientPatchPath) + "\" \"" + CPath::standardizeDosPath(ClientRootPath) + "\""; +#else + arguments += "\"" + RyzomFilename + "\" \"" + ClientPatchPath + "\" " + ClientRootPath + "\""; #endif - std::string arguments = LoginLogin + " " + LoginPassword; + // append login and password + arguments += " " + LoginLogin + " " + LoginPassword; if (!r2Mode) { @@ -1025,7 +1105,7 @@ void CPatchManager::setRWAccess (const string &filename, bool bThrowException) { s = CI18N::get("uiAttribErr") + " " + CFile::getFilename(filename) + " (" + toString(errno) + "," + strerror(errno) + ")"; setState(true, s); - throw Exception (s.toString()); + throw Exception (s.toUtf8()); } } @@ -1039,7 +1119,7 @@ string CPatchManager::deleteFile (const string &filename, bool bThrowException, { s = CI18N::get("uiDelNoFile"); setState(true, s); - return s.toString(); + return s.toUtf8(); } if (!NLMISC::CFile::deleteFile(filename)) @@ -1048,8 +1128,8 @@ string CPatchManager::deleteFile (const string &filename, bool bThrowException, if(bWarning) setState(true, s); if(bThrowException) - throw Exception (s.toString()); - return s.toString(); + throw Exception (s.toUtf8()); + return s.toUtf8(); } return ""; } @@ -1064,7 +1144,7 @@ void CPatchManager::renameFile (const string &src, const string &dst) { s = CI18N::get("uiRenameErr") + " " + src + " -> " + dst + " (" + toString(errno) + "," + strerror(errno) + ")"; setState(true, s); - throw Exception (s.toString()); + throw Exception (s.toUtf8()); } } @@ -1302,7 +1382,7 @@ void CPatchManager::downloadFileWithCurl (const string &source, const string &de setRWAccess(dest, false); NLMISC::CFile::deleteFile(dest.c_str()); } - FILE *fp = fopen (dest.c_str(), "wb"); + FILE *fp = nlfopen (dest, "wb"); if (fp == NULL) { curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL); @@ -1441,8 +1521,8 @@ void CPatchManager::decompressFile (const string &filename) string dest = filename.substr(0, filename.size ()-4); setRWAccess(dest, false); - //if(isVerboseLog()) nlinfo("Calling fopen('%s','wb')", dest.c_str()); - FILE *fp = fopen (dest.c_str(), "wb"); + //if(isVerboseLog()) nlinfo("Calling nlfopen('%s','wb')", dest.c_str()); + FILE *fp = nlfopen (dest, "wb"); if (fp == NULL) { string err = toString("Can't open file '%s' : code=%d %s, (error code 32)", dest.c_str(), errno, strerror(errno)); @@ -1512,21 +1592,18 @@ void CPatchManager::applyDate (const string &sFilename, uint32 nDate) // change the file time if(nDate != 0) { -// _utimbuf utb; -// utb.actime = utb.modtime = nDate; setRWAccess(sFilename, false); - ucstring s = CI18N::get("uiChangeDate") + " " + NLMISC::CFile::getFilename(sFilename) + " " + toString(NLMISC::CFile::getFileModificationDate (sFilename)) + - " -> " + toString(nDate); + ucstring s = CI18N::get("uiChangeDate") + " " + NLMISC::CFile::getFilename(sFilename) + " " + timestampToHumanReadable(NLMISC::CFile::getFileModificationDate (sFilename)) + + " -> " + timestampToHumanReadable(nDate); setState(true,s); if (!NLMISC::CFile::setFileModificationDate(sFilename, nDate)) -// if (_utime (sFilename.c_str (), &utb) == -1) { int err = NLMISC::getLastError(); - s = CI18N::get("uiChgDateErr") + " " + sFilename + " (" + toString(err) + ", " + formatErrorMessage(err) + ")"; + s = CI18N::get("uiChgDateErr") + " " + CFile::getFilename(sFilename) + " (" + toString(err) + ", " + formatErrorMessage(err) + ")"; setState(true,s); } - s = CI18N::get("uiNowDate") + " " + sFilename + " " + toString(NLMISC::CFile::getFileModificationDate (sFilename)); + s = CI18N::get("uiNowDate") + " " + CFile::getFilename(sFilename) + " " + timestampToHumanReadable(NLMISC::CFile::getFileModificationDate (sFilename)); setState(true,s); } } @@ -1744,7 +1821,7 @@ bool CPatchManager::bnpUnpack(const string &srcBigfile, const string &dstPath, v if (!bnpFile.readHeader()) { - ucstring s = CI18N::get("uiUnpackErrHead") + " " + SourceName; + ucstring s = CI18N::get("uiUnpackErrHead") + " " + CFile::getFilename(SourceName); setState(true,s); return false; } @@ -1783,14 +1860,14 @@ int CPatchManager::validateProgress(void *foo, double t, double d, double /* ult if (units.empty()) { - units.push_back("B"); // there is no translation for byte unit... + units.push_back(CI18N::get("uiByte").toUtf8()); units.push_back(CI18N::get("uiKb").toUtf8()); units.push_back(CI18N::get("uiMb").toUtf8()); } CPatchManager *pPM = CPatchManager::getInstance(); double pour1 = t!=0.0?d*100.0/t:0.0; - ucstring sTranslate = CI18N::get("uiLoginGetFile") + ucstring::makeFromUtf8(toString(" %s : %s / %s (%5.02f %%)", NLMISC::CFile::getFilename(pPM->CurrentFile).c_str(), + ucstring sTranslate = CI18N::get("uiLoginGetFile") + ucstring::makeFromUtf8(toString(" %s : %s / %s (%.02f %%)", NLMISC::CFile::getFilename(pPM->CurrentFile).c_str(), NLMISC::bytesToHumanReadableUnits((uint64)d, units).c_str(), NLMISC::bytesToHumanReadableUnits((uint64)t, units).c_str(), pour1)); pPM->setState(false, sTranslate); if (foo) @@ -1805,7 +1882,7 @@ void CPatchManager::MyPatchingCB::progress(float f) { CPatchManager *pPM = CPatchManager::getInstance(); double p = 100.0*f; - ucstring sTranslate = CI18N::get("uiApplyingDelta") + toString(" %s (%5.02f %%)", CFile::getFilename(patchFilename).c_str(), p); + ucstring sTranslate = CI18N::get("uiApplyingDelta") + ucstring::makeFromUtf8(toString(" %s (%.02f %%)", CFile::getFilename(patchFilename).c_str(), p)); pPM->setState(false, sTranslate); } @@ -1981,7 +2058,7 @@ void CPatchManager::clearDataScanLog() // *************************************************************************** void CPatchManager::getCorruptedFileInfo(const SFileToPatch &ftp, ucstring &sTranslate) { - sTranslate = CI18N::get("uiCorruptedFile") + " " + ftp.FileName + " (" + + sTranslate = CI18N::get("uiCorruptedFile") + " " + ucstring::makeFromUtf8(ftp.FileName) + " (" + toString("%.1f ", (float)ftp.FinalFileSize/1000000.f) + CI18N::get("uiMb") + ")"; } @@ -2068,7 +2145,7 @@ void CCheckThread::run () for (i = 0; i < rDescFiles.fileCount(); ++i) { CPatchManager::SFileToPatch ftp; - sTranslate = CI18N::get("uiCheckingFile") + " " + rDescFiles.getFile(i).getFileName(); + sTranslate = CI18N::get("uiCheckingFile") + " " + ucstring::makeFromUtf8(rDescFiles.getFile(i).getFileName()); pPM->setState(true, sTranslate); // get list of patch to apply to this file. don't to a full checksum test if possible nlwarning(rDescFiles.getFile(i).getFileName().c_str()); @@ -2192,7 +2269,7 @@ void CCheckThread::run () if (bnpFile.readHeader()) { // read the file inside the bnp and calculate the sha1 - FILE *bnp = fopen (sBNPFilename.c_str(), "rb"); + FILE *bnp = nlfopen (sBNPFilename, "rb"); if (bnp != NULL) { for (uint32 k = 0; k < bnpFile.SFiles.size(); ++k) @@ -3068,7 +3145,7 @@ bool CPatchManager::extract(const std::string& patchPath, uint nblab = 0; pPM->deleteFile(updateBatchFilename, false, false); - FILE *fp = fopen (updateBatchFilename.c_str(), "wt"); + FILE *fp = nlfopen (updateBatchFilename, "wt"); if (fp == 0) { diff --git a/code/ryzom/client/src/login_patch.h b/code/ryzom/client/src/login_patch.h index c7f0f4509..9407290e9 100644 --- a/code/ryzom/client/src/login_patch.h +++ b/code/ryzom/client/src/login_patch.h @@ -433,6 +433,7 @@ private: /// Now deprecated : the launcher is the client ryzom std::string RyzomFilename; std::string UpdateBatchFilename; + std::string UpgradeBatchFilename; // Where the client get all delta and desc file std::string ClientPatchPath; // Temporary path diff --git a/code/ryzom/client/src/login_xdelta.cpp b/code/ryzom/client/src/login_xdelta.cpp index f8e733b68..5cb1ddc7d 100644 --- a/code/ryzom/client/src/login_xdelta.cpp +++ b/code/ryzom/client/src/login_xdelta.cpp @@ -95,7 +95,7 @@ bool CXDPFileReader::init(const std::string &sFilename, sint32 nLowerBound, sint { // First open the file with a normal function #ifdef NL_OS_WINDOWS - int fd = _open(sFilename.c_str(), _O_BINARY | _O_RDONLY); + int fd = _wopen(utf8ToWide(sFilename), _O_BINARY | _O_RDONLY); #else int fd = open(sFilename.c_str(), O_RDONLY); #endif @@ -143,7 +143,7 @@ bool CXDPFileReader::init(const std::string &sFilename, sint32 nLowerBound, sint } else { - _File = fopen(sFilename.c_str(), "rb"); + _File = nlfopen(sFilename, "rb"); if (_File == NULL) return false; fseek(_File, nLowerBound, SEEK_SET); @@ -560,7 +560,7 @@ CXDeltaPatch::TApplyResult CXDeltaPatch::apply(const std::string &sFileToPatch, errorMsg = toString("output file %s already exists", sFileOutput.c_str()); return ApplyResult_Error; } - FILE *outFILE = fopen(sFileOutput.c_str(), "wb"); + FILE *outFILE = nlfopen(sFileOutput, "wb"); if (outFILE == NULL) { errorMsg = toString("cant create %s", sFileOutput.c_str()); @@ -572,7 +572,7 @@ CXDeltaPatch::TApplyResult CXDeltaPatch::apply(const std::string &sFileToPatch, bool ftpPresent = false; if (pFromSource) { - ftpFILE = fopen(sFileToPatch.c_str(), "rb"); + ftpFILE = nlfopen(sFileToPatch, "rb"); if (ftpFILE == NULL) { errorMsg = toString("expecting file %s", sFileToPatch.c_str()); diff --git a/code/ryzom/client/src/permanent_ban.cpp b/code/ryzom/client/src/permanent_ban.cpp index fe56446d2..cbd39d93f 100644 --- a/code/ryzom/client/src/permanent_ban.cpp +++ b/code/ryzom/client/src/permanent_ban.cpp @@ -84,7 +84,7 @@ static void setPermanentBanFileMarker(const std::string &path, bool on) // simply touch a file COFile f(path); #ifdef NL_OS_WINDOWS - SetFileAttributes(path.c_str(), FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM); + SetFileAttributesW(utf8ToWide(path), FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM); #endif } catch(const EStream &e) @@ -141,7 +141,7 @@ static void markBNPFile(std::string &path) uint32 nFileSize=CFile::getFileSize(path); if (!nFileSize) return; - FILE *f = fopen(path.c_str(), "rb+"); + FILE *f = nlfopen(path, "rb+"); if (!f) return; // Result if (nlfseek64 (f, nFileSize-4, SEEK_SET) != 0) diff --git a/code/ryzom/client/src/r2/dmc/client_edition_module.cpp b/code/ryzom/client/src/r2/dmc/client_edition_module.cpp index 073be77cc..d47093c5d 100644 --- a/code/ryzom/client/src/r2/dmc/client_edition_module.cpp +++ b/code/ryzom/client/src/r2/dmc/client_edition_module.cpp @@ -1384,7 +1384,7 @@ bool CClientEditionModule::loadUserComponent(const std::string& filename, bool m uint32 timeStamp = 0; if (! compressed) { - FILE* file = fopen(filename.c_str(),"rb"); + FILE* file = nlfopen(filename, "rb"); if (!file) { nlwarning("Try to open an invalid file %s (access error)", filename.c_str()); @@ -1491,7 +1491,7 @@ bool CClientEditionModule::loadUserComponent(const std::string& filename, bool m else { // Get Uncompressed File length (4 last byte of a gz) - FILE* file = fopen(filename.c_str(),"rb"); + FILE* file = nlfopen(filename, "rb"); if (!file) { nlwarning("Try to open an invalid file %s (access error)", filename.c_str()); @@ -1653,7 +1653,7 @@ void CClientEditionModule::saveUserComponentFile(const std::string& filename, bo if (!mustCompress) { { - FILE* output = fopen(uncompressedName.c_str(), "wb"); + FILE* output = nlfopen(uncompressedName, "wb"); if (output) { fwrite(component->UncompressedData, sizeof(char) , component->UncompressedDataLength, output); diff --git a/code/ryzom/client/src/seven_zip/seven_zip.cpp b/code/ryzom/client/src/seven_zip/seven_zip.cpp index 28ae2d0f7..765500deb 100644 --- a/code/ryzom/client/src/seven_zip/seven_zip.cpp +++ b/code/ryzom/client/src/seven_zip/seven_zip.cpp @@ -154,7 +154,7 @@ bool unpack7Zip(const std::string &sevenZipFile, const std::string &destFileName SzArEx_GetFileNameUtf16(&db, 0, &filename[0]); // write the extracted file - FILE *outputHandle = fopen(destFileName.c_str(), "wb+"); + FILE *outputHandle = nlfopen(destFileName, "wb+"); if (outputHandle == 0) { diff --git a/code/ryzom/client/src/sheet_manager.cpp b/code/ryzom/client/src/sheet_manager.cpp index cdb9b4ff1..3c902ed74 100644 --- a/code/ryzom/client/src/sheet_manager.cpp +++ b/code/ryzom/client/src/sheet_manager.cpp @@ -1020,7 +1020,7 @@ void CSheetManager::dumpVisualSlots() // *************************************************************************** void CSheetManager::dumpVisualSlotsIndex() { - FILE * vsIndexFile = fopen(std::string(getLogDirectory() + "vs_index.txt").c_str(),"w"); + FILE * vsIndexFile = nlfopen(getLogDirectory() + "vs_index.txt", "w"); if( vsIndexFile ) { for (uint i=0; i < SLOTTYPE::NB_SLOT; ++i) diff --git a/code/ryzom/client/src/sound_manager.cpp b/code/ryzom/client/src/sound_manager.cpp index 4a981366d..5c1f49b1c 100644 --- a/code/ryzom/client/src/sound_manager.cpp +++ b/code/ryzom/client/src/sound_manager.cpp @@ -1028,17 +1028,18 @@ void CSoundManager::loadProperties(const string &soundName, USource *source) // Search for the file. string filePath = CPath::lookup(soundName+".sdf"); - ifstream file(filePath.c_str(), ios::in); + + CIFile file; // Try to open the file. - if(file.is_open()) + if (file.open(filePath)) { char tmpBuff[260]; char delimiterBox[] = "\t "; // While the end of the file is not reached. while(!file.eof()) { - // Get a line (teh line should not be more than _MAX_LINE_SIZE). + // Get a line (the line should not be more than _MAX_LINE_SIZE). file.getline(tmpBuff, 260); char *token = strtok(tmpBuff, delimiterBox); while(token != NULL) diff --git a/code/ryzom/common/src/game_share/bmp4image.h b/code/ryzom/common/src/game_share/bmp4image.h index 542fc4200..4ecbd79f5 100644 --- a/code/ryzom/common/src/game_share/bmp4image.h +++ b/code/ryzom/common/src/game_share/bmp4image.h @@ -65,7 +65,7 @@ public: /*bool write(char *filename) { - FILE *outf=fopen(filename,"wb"); + FILE *outf=nlfopen(filename, "wb"); if (outf==NULL) return false; diff --git a/code/ryzom/common/src/game_share/cst_loader.cpp b/code/ryzom/common/src/game_share/cst_loader.cpp index b957d7f34..87e587ba1 100644 --- a/code/ryzom/common/src/game_share/cst_loader.cpp +++ b/code/ryzom/common/src/game_share/cst_loader.cpp @@ -26,11 +26,11 @@ using namespace NLMISC; /****************************************************************\ buildTableFormat() \****************************************************************/ -void CSTLoader::buildTableFormat( string fileName, list >& tableFormat ) +void CSTLoader::buildTableFormat(const string &fileName, list >& tableFormat ) { - _File = new ifstream(fileName.c_str(), ios::in); + _File = nlfopen(fileName, "rb"); - if( !_File->is_open() ) + if (!_File) { nlerror("can't open file : %s\n", fileName.c_str()); } @@ -40,7 +40,7 @@ void CSTLoader::buildTableFormat( string fileName, list > //================ char readBuffer[4096]; char * token; - _File->getline(readBuffer, 4096); + if (fgets(readBuffer, 4096, _File) == NULL) return; // extract first token //==================== @@ -102,13 +102,17 @@ void CSTLoader::readData( list >& data ) char * token; bool firstToken = true; - while( !_File->eof() ) + while( !feof(_File) ) { // list of current object values list lineData; // read a line - _File->getline(readBuffer, 4096); + if (fgets(readBuffer, 4096, _File) == NULL) + { + // EOF + break; + } // check all tokens of the current line do @@ -146,74 +150,44 @@ void CSTLoader::readData( list >& data ) /****************************************************************\ generateDerivedClasses() \****************************************************************/ -void CSTLoader::generateDerivedClasses(ofstream &file, std::list< std::pair > &format, std::list< std::list< std::string> > &data ) +void CSTLoader::generateDerivedClasses(const std::list< std::pair > &format, const std::list< std::list< std::string> > &data ) { + std::string content; - - std::list< std::list< std::string> >::iterator it_dl = data.begin(); + std::list< std::list< std::string> >::const_iterator it_dl = data.begin(); while ( it_dl != data.end() ) { - std::list< std::pair >::iterator it_def = format.begin(); - std::list::iterator it_val = (*it_dl).begin(); + std::list< std::pair >::const_iterator it_def = format.begin(); + std::list::const_iterator it_val = (*it_dl).begin(); // sint32 size = data.size(); // sint32 size2 = (*it_dl).size(); -// std::string name = convertName( *it_val ); +// std::string name = convertName( *it_val ); -// std::string test = *it_val; +// std::string test = *it_val; if ( (*it_dl).size() ) { - file << "From Item : Define " << convertName( *it_val ) << endl; + content += "From Item : Define " + convertName( *it_val ) + "\n"; it_val++; it_def++; - file << "{" << endl; - file << "\tComponent:" << endl; + content += "{\n"; + content += "\tComponent:\n"; } - std::list< std::pair >::iterator it_obj = format.begin(); + std::list< std::pair >::const_iterator it_obj = format.begin(); it_obj++; while ( it_obj != format.end() ) { - file << "\t\t"; - switch ( (*it_obj).second ) - { - case UINT8: - file << "uint8"; - break; - case SINT8: - file << "sint8"; - break; - case UINT16: - file << "uint16"; - break; - case SINT16: - file << "sint16"; - break; - case UINT32: - file << "uint32"; - break; - case SINT32: - file << "sint32"; - break; - case FLOAT: - file << "Float"; - break; - case STRING: - file << "String"; - break; - case BOOL: - file << "Bool"; - break; - } - file << "<'" << (*it_obj).first << "', Static>;" << endl; + content += "\t\t" + convertFromType((*it_obj).second); + content += "<'" + (*it_obj).first + "', Static>;\n"; it_obj++; } - file << "\tEnd" << endl << endl; + content += "\tEnd\n"; - file << "\t StaticInit()" << endl; + content += "\t StaticInit()\n"; while ( it_def != format.end() && it_val != (*it_dl).end() ) { @@ -222,50 +196,52 @@ void CSTLoader::generateDerivedClasses(ofstream &file, std::list< std::pair& fileFormat) +void CSTLoader::init(const string &fileName, const map& fileFormat) { _FileFormat = fileFormat; _FileName = fileName; - _File = new ifstream(fileName.c_str(), ios::in); + _File = nlfopen(fileName, "rb"); - if( !_File->is_open() ) + if (!_File) { nlerror("can't open file : %s\n", fileName.c_str()); } @@ -291,7 +267,8 @@ void CSTLoader::init(string fileName, const map& fileFormat) // read first line char readBuffer[4096]; char * token; - _File->getline(readBuffer, 4096); + + if (fgets(readBuffer, 4096, _File) == NULL) return; // extract first token token = strtok(readBuffer, _Seps.c_str()); @@ -316,7 +293,7 @@ void CSTLoader::init(string fileName, const map& fileFormat) \****************************************************************/ bool CSTLoader::readLine() { - if( _File->eof() ) + if (feof(_File)) { return false; } @@ -333,7 +310,7 @@ bool CSTLoader::readLine() _Tokens.clear(); // read a line - _File->getline(readBuffer, 4096); + if (fgets(readBuffer, 4096, _File) == NULL) return false; // if the line is empty we consider we are at end of file if( strlen(readBuffer) == 0) @@ -429,3 +406,21 @@ bool CSTLoader::readLine() return true; } +std::string CSTLoader::convertFromType(TDataType type) +{ + switch (type) + { + case UINT8: return "uint8"; + case SINT8: return "sint8"; + case UINT16: return "uint16"; + case SINT16: return "sint16"; + case UINT32: return "uint32"; + case SINT32: return "sint32"; + case FLOAT: return "Float"; + case STRING: return "String"; + case BOOL: return "Bool"; + default: break; + } + + return ""; +} diff --git a/code/ryzom/common/src/game_share/cst_loader.h b/code/ryzom/common/src/game_share/cst_loader.h index b80cad107..51fa6e9aa 100644 --- a/code/ryzom/common/src/game_share/cst_loader.h +++ b/code/ryzom/common/src/game_share/cst_loader.h @@ -25,7 +25,6 @@ #include #include #include -#include /** @@ -55,10 +54,10 @@ public: private: /// cst file - std::ifstream * _File; + FILE *_File; /// name of the cst file (used for debug information) - std::string _FileName; + std::string _FileName; /// separators std::string _Seps; @@ -101,7 +100,7 @@ public: * \param fileName the name of the file * \param fileFormat the name of the columns and their data type */ - void buildTableFormat( std::string fileName, std::list >& tableFormat ); + void buildTableFormat( const std::string &fileName, std::list >& tableFormat ); /** @@ -117,7 +116,7 @@ public: * \param fileName the name of the file * \param fileFormat the name of the columns and their data type */ - void init( std::string fileName, const std::map& fileFormat); + void init( const std::string &fileName, const std::map& fileFormat); /** @@ -213,77 +212,50 @@ public: /// close file void close() { - _File->close(); - delete _File; + fclose(_File); + _File = NULL; } - void Load(std::string fileName,std::ofstream &script_file) + void Load(const std::string &fileName) { // Generates the base class std::list< std::pair > format; buildTableFormat( fileName, format ); - generateBaseClass( script_file, format); + generateBaseClass( format); // Generates a derived class for each type of object std::list< std::list > data; readData( data ); - generateDerivedClasses( script_file, format, data ); + generateDerivedClasses( format, data ); } - void generateBaseClass(std::ofstream &file, std::list< std::pair > &/* format */) + void generateBaseClass(const std::list< std::pair > &/* format */) { - file << "From Agent : Define Item" << std::endl; - file << "{" << std::endl; -/* file << "\tComponent:" << std::endl; + std::string content; + content += "From Agent : Define Item\n"; + content += "{\n"; +/* content += "\tComponent:\n"; std::list< std::pair >::iterator it_obj = format.begin(); it_obj++; while ( it_obj != format.end() ) { - file << "\t\t"; - switch ( (*it_obj).second ) - { - case UINT8: - file << "uint8"; - break; - case SINT8: - file << "sint8"; - break; - case UINT16: - file << "uint16"; - break; - case SINT16: - file << "sint16"; - break; - case UINT32: - file << "uint32"; - break; - case SINT32: - file << "sint32"; - break; - case FLOAT: - file << "Float"; - break; - case STRING: - file << "String"; - break; - case BOOL: - file << "Bool"; - break; - } - file << "<'" << (*it_obj).first << "', Static>;" << std::endl; + content += "\t\t" + convertFromType((*it_obj).second); + content += "<'" + (*it_obj).first + "', Static>;\n"; it_obj++; } - file << "\tEnd" << std::endl;*/ - file << "}" << std::endl; - file << std::endl; + content += "\tEnd\n"; */ + content += "}\n"; + content += "\n"; + + fwrite(content.c_str(), 1, content.length(), _File); } - void generateDerivedClasses(std::ofstream &, std::list< std::pair > &, std::list< std::list< std::string> > &); + void generateDerivedClasses(const std::list< std::pair > &, const std::list< std::list< std::string> > &); - TDataType convertType(std::string type_str) + TDataType convertType(const std::string &type_str) { if ( type_str == "UINT8") return UINT8; @@ -306,11 +278,13 @@ public: return (TDataType)0; } - std::string convertName(std::string &name) + std::string convertFromType(TDataType type); + + std::string convertName(const std::string &name) const { int i = 0; char buffer[1024]; - std::string::iterator it_c = name.begin(); + std::string::const_iterator it_c = name.begin(); while ( it_c != name.end() ) { char c = *it_c; diff --git a/code/ryzom/common/src/game_share/file_description_container.cpp b/code/ryzom/common/src/game_share/file_description_container.cpp index ae4a2e07f..e974bd7d2 100644 --- a/code/ryzom/common/src/game_share/file_description_container.cpp +++ b/code/ryzom/common/src/game_share/file_description_container.cpp @@ -26,13 +26,6 @@ #include "utils.h" #include "file_description_container.h" -#ifdef NL_OS_WINDOWS -#include -#include -//#include -#include -#endif - //------------------------------------------------------------------------------------------------- // namespaces @@ -110,23 +103,10 @@ void CFileDescriptionContainer::addFile(const string& fileName, uint32 timeStamp void CFileDescriptionContainer::addFile(const string& fileName) { -//#ifdef NL_OS_WINDOWS -// -// struct _stat buffer; -// uint32 result= _stat(fileName.c_str(),&buffer); -// if (result==0) -// { -// addFile(fileName, uint32(buffer.st_mtime), buffer.st_size); -// } -// -//#else - if (CFile::fileExists(fileName)) { addFile(fileName,CFile::getFileModificationDate(fileName),CFile::getFileSize(fileName)); } - -//#endif } void CFileDescriptionContainer::addFileSpec(const string& fileSpec,bool recurse) diff --git a/code/ryzom/common/src/game_share/persistent_data.cpp b/code/ryzom/common/src/game_share/persistent_data.cpp index 85c873ba4..ad52a7b4d 100644 --- a/code/ryzom/common/src/game_share/persistent_data.cpp +++ b/code/ryzom/common/src/game_share/persistent_data.cpp @@ -520,7 +520,7 @@ uint32 CPersistentDataRecord::getNumValues() const } } - // restore the original values of teh state variables + // restore the original values of the state variables _ArgOffset=oldArgOffset; _TokenOffset=oldTokenOffset; _ReadingStructStack=oldRSS; @@ -1117,10 +1117,11 @@ bool CPersistentDataRecord::readFromFile(const std::string &fileName) { H_AUTO(pdrReadFromFile) + // TODO: see why code is different under Linux and Windows #ifdef NL_OS_WINDOWS // open the file - FILE* inf= fopen(fileName.c_str(), "rb"); + FILE* inf= nlfopen(fileName, "rb"); DROP_IF( inf==NULL, "Failed to open input file " << fileName, return false); // get the file size diff --git a/code/ryzom/common/src/game_share/utils.h b/code/ryzom/common/src/game_share/utils.h index a93c68a4d..96099a466 100644 --- a/code/ryzom/common/src/game_share/utils.h +++ b/code/ryzom/common/src/game_share/utils.h @@ -671,14 +671,6 @@ struct TTypeLimits }; static uint32 floor(uint32 value) { return value; } }; -/* -#ifdef NL_OS_WINDOWS -template <> -struct TTypeLimits : public TTypeLimits -{ -}; -#endif -*/ template <> struct TTypeLimits { @@ -728,12 +720,7 @@ struct TTypeLimits }; static sint32 floor(sint32 value) { return value; } }; -/*#ifdef NL_OS_WINDOWS -template <> -struct TTypeLimits : public TTypeLimits -{ -}; -#endif*/ + template <> struct TTypeLimits { diff --git a/code/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp b/code/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp index a23ccab88..f7cd1b6af 100644 --- a/code/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp +++ b/code/ryzom/server/src/entities_game_service/mission_manager/missions_commands.cpp @@ -40,6 +40,8 @@ #include "creature_manager/creature_manager.h" #include "world_instances.h" +#include "server_share/used_continent.h" +#include "game_share/shard_names.h" using namespace NLMISC; using namespace NLNET; @@ -1007,36 +1009,39 @@ NLMISC_COMMAND(getTarget, "get target of player", "") //---------------------------------------------------------------------------- NLMISC_COMMAND(getMoney, "get money of player", "") { - GET_ACTIVE_CHARACTER string value = toString("%"NL_I64"u", c->getMoney()); log.displayNL(value.c_str()); + + return true; } //---------------------------------------------------------------------------- NLMISC_COMMAND(getPvpPoints, "get pvp points of player", "") { - GET_ACTIVE_CHARACTER string value = toString("%u", c->getPvpPoint()); log.displayNL(value.c_str()); + + return true; } //---------------------------------------------------------------------------- NLMISC_COMMAND(getCivCultOrg, "get civ cult and organization of player", "") { - GET_ACTIVE_CHARACTER std::pair allegiance = c->getAllegiance(); log.displayNL("%s|%s|%u", PVP_CLAN::toString(allegiance.first).c_str(), PVP_CLAN::toString(allegiance.second).c_str(), c->getOrganization()); + + return true; } diff --git a/code/studio/src/plugins/georges_editor/CMakeLists.txt b/code/studio/src/plugins/georges_editor/CMakeLists.txt index 68b37421d..216034fea 100644 --- a/code/studio/src/plugins/georges_editor/CMakeLists.txt +++ b/code/studio/src/plugins/georges_editor/CMakeLists.txt @@ -1,13 +1,14 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDES} - ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser) + ${LIBXML2_INCLUDE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser) FILE(GLOB SRC *.cpp *.h) SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h georges_editor_form.h @@ -49,7 +50,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(studio_plugin_georges_editor MODULE ${SRC} ${OVQT_PLUG_GEORGES_EDITOR_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_GEORGES_EDITOR_UI_HDRS} ${OVQT_PLUGIN_GEORGES_EDITOR_RC_SRCS}) -TARGET_LINK_LIBRARIES(studio_plugin_georges_editor studio_plugin_core nelmisc nelgeorges qt_property_browser ${QT_LIBRARIES}) +TARGET_LINK_LIBRARIES(studio_plugin_georges_editor studio_plugin_core nelmisc nelgeorges qt_property_browser ${QT_LIBRARIES} ${LIBXML2_LIBRARIES}) NL_DEFAULT_PROPS(studio_plugin_georges_editor "Tools: Studio Plugin: Georges Editor") NL_ADD_RUNTIME_FLAGS(studio_plugin_georges_editor) diff --git a/code/studio/src/plugins/gui_editor/widget_serializer.cpp b/code/studio/src/plugins/gui_editor/widget_serializer.cpp index 8006a6b50..a8594afed 100644 --- a/code/studio/src/plugins/gui_editor/widget_serializer.cpp +++ b/code/studio/src/plugins/gui_editor/widget_serializer.cpp @@ -19,6 +19,9 @@ #include "nel/gui/interface_group.h" #include "nel/gui/widget_manager.h" +#include +#include + namespace GUIEditor { bool WidgetSerializer::serialize( const std::string &masterGroup ) diff --git a/code/studio/src/plugins/world_editor/CMakeLists.txt b/code/studio/src/plugins/world_editor/CMakeLists.txt index 1a7ff652d..b494f3f21 100644 --- a/code/studio/src/plugins/world_editor/CMakeLists.txt +++ b/code/studio/src/plugins/world_editor/CMakeLists.txt @@ -1,6 +1,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDES} + ${LIBXML2_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser ) @@ -59,6 +60,7 @@ TARGET_LINK_LIBRARIES( studio_plugin_world_editor qt_property_browser ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY} + ${LIBXML2_LIBRARIES} ) NL_DEFAULT_PROPS(studio_plugin_world_editor "Tools: Studio Plugin: World Editor") diff --git a/code/studio/src/plugins/world_editor/world_editor_actions.cpp b/code/studio/src/plugins/world_editor/world_editor_actions.cpp index 5255e976f..a25cb5e18 100644 --- a/code/studio/src/plugins/world_editor/world_editor_actions.cpp +++ b/code/studio/src/plugins/world_editor/world_editor_actions.cpp @@ -41,6 +41,10 @@ #include #include +// libxml +#include +#include + namespace WorldEditor { diff --git a/code/studio/src/plugins/world_editor/world_editor_misc.cpp b/code/studio/src/plugins/world_editor/world_editor_misc.cpp index a2736b1c5..2dd86df15 100644 --- a/code/studio/src/plugins/world_editor/world_editor_misc.cpp +++ b/code/studio/src/plugins/world_editor/world_editor_misc.cpp @@ -26,8 +26,7 @@ #include #include - -// Qt includes +#include namespace WorldEditor {