Merge with develop

--HG--
branch : compatibility-develop
This commit is contained in:
kervala 2016-02-20 19:29:00 +01:00
commit 3161ec2a77
95 changed files with 1415 additions and 915 deletions

View file

@ -258,7 +258,8 @@ IF(WITH_QT5)
FIND_PACKAGE(Qt5Network) FIND_PACKAGE(Qt5Network)
IF(WIN32) IF(WIN32)
FIND_PACKAGE(Qt5WinExtras) # Please add option to switch off
# FIND_PACKAGE(Qt5WinExtras)
ENDIF() ENDIF()
IF(QT_STATIC) IF(QT_STATIC)

View file

@ -320,16 +320,8 @@ public:
// don't forget to update operator=() and swap() if adding a data member // don't forget to update operator=() and swap() if adding a data member
CBitmap() CBitmap();
{ virtual ~CBitmap();
_MipMapCount = 1;
_Width = 0;
_Height = 0;
PixelFormat = RGBA;
_LoadGrayscaleAsAlpha = true;
}
virtual ~CBitmap() { }
// swap 2 bitmaps contents // swap 2 bitmaps contents
void swap(CBitmap &other); void swap(CBitmap &other);

View file

@ -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 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()); } 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 /** Signed 64 bit fseek. Same interface as fseek
*/ */
int nlfseek64( FILE *stream, sint64 offset, int origin ); 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" /// Convert a time into a string that is easily readable by an human, for example 3600 -> "1h"
std::string secondsToHumanReadable (uint32 time); 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 /// Get a bytes or time in string format and convert it in seconds or bytes
uint32 fromHumanReadable (const std::string &str); uint32 fromHumanReadable (const std::string &str);

View file

@ -229,7 +229,7 @@ void setCrashAlreadyReported(bool state);
*\code *\code
void function(char *filename) void function(char *filename)
{ {
FILE *fp = fopen (filename, "r"); FILE *fp = nlfopen (filename, "r");
if (fp==NULL) if (fp==NULL)
{ {
nlerror("file not found"); nlerror("file not found");

View file

@ -722,7 +722,6 @@ struct CFile
/** Try to set the file access to read/write if not already set. /** 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. * 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 * \return true if RW access is granted
*/ */
static bool setRWAccess(const std::string &filename); static bool setRWAccess(const std::string &filename);

View file

@ -28,6 +28,8 @@ typedef NLMISC::CSString TPathString;
typedef std::string TPathString; typedef std::string TPathString;
#endif #endif
namespace NLPIPELINE {
/// Asset database configuration /// Asset database configuration
class CDatabaseConfig class CDatabaseConfig
{ {
@ -55,4 +57,6 @@ private:
}; };
} /* namespace NLPIPELINE */
/* end of file */ /* end of file */

View file

@ -0,0 +1,80 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2015 Winch Gate Property Limited
// Author: Jan Boon <jan.boon@kaetemi.be>
//
// 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 <http://www.gnu.org/licenses/>.
#ifndef NLPIPELINE_PROJECT_CONFIG_H
#define NLPIPELINE_PROJECT_CONFIG_H
#include <nel/misc/types_nl.h>
#include <vector>
namespace NLMISC {
class CConfigFile;
}
#ifdef NL_OS_WINDOWS
#include <nel/misc/sstring.h>
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<TPathString> s_ConfigPaths;
static std::vector<NLMISC::CConfigFile *> s_ConfigFiles;
};
} /* namespace NLPIPELINE */
#endif /* #ifndef NLPIPELINE_PROJECT_CONFIG_H */
/* end of file */

View file

@ -27,8 +27,8 @@
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#ifndef NLMISC_TOOL_LOGGER_H #ifndef NLPIPELINE_TOOL_LOGGER_H
#define NLMISC_TOOL_LOGGER_H #define NLPIPELINE_TOOL_LOGGER_H
#include <nel/misc/types_nl.h> #include <nel/misc/types_nl.h>
// STL includes // STL includes
@ -47,16 +47,16 @@
#endif #endif
#ifdef NL_DEBUG_H #ifdef NL_DEBUG_H
#define tlerror(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLMISC::ERROR, 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(NLMISC::WARNING, 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(NLMISC::MESSAGE, path, error, ## __VA_ARGS__) #define tlmessage(toolLogger, path, error, ...) nlinfo(error, ## __VA_ARGS__), toolLogger.writeError(NLPIPELINE::MESSAGE, path, error, ## __VA_ARGS__)
#else #else
#define tlerror(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::ERROR, path, error, ## __VA_ARGS__) #define tlerror(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::ERROR, path, error, ## __VA_ARGS__)
#define tlwarning(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::WARNING, path, error, ## __VA_ARGS__) #define tlwarning(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::WARNING, path, error, ## __VA_ARGS__)
#define tlmessage(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::MESSAGE, path, error, ## __VA_ARGS__) #define tlmessage(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::MESSAGE, path, error, ## __VA_ARGS__)
#endif #endif
namespace NLMISC { namespace NLPIPELINE {
enum TError enum TError
{ {
@ -203,8 +203,8 @@ public:
} }
}; /* class CToolLogger */ }; /* class CToolLogger */
} /* namespace NLMISC */ } /* namespace NLPIPELINE */
#endif /* #ifndef NLMISC_TOOL_LOGGER_H */ #endif /* #ifndef NLPIPELINE_TOOL_LOGGER_H */
/* end of file */ /* end of file */

View file

@ -1243,23 +1243,23 @@ bool CDriverD3D::init (uintptr_t windowIcon, emptyProc exitFunc)
createCursors(); createCursors();
_WindowClass = "NLD3D" + toString(windowIcon);
// Register a window class // Register a window class
WNDCLASSW wc; WNDCLASSA wc;
memset(&wc,0,sizeof(wc)); memset(&wc,0,sizeof(wc));
wc.style = 0; // CS_HREDRAW | CS_VREDRAW ;//| CS_DBLCLKS; wc.style = 0; // CS_HREDRAW | CS_VREDRAW ;//| CS_DBLCLKS;
wc.lpfnWndProc = (WNDPROC)WndProc; wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
wc.cbWndExtra = 0; wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandleW(NULL); wc.hInstance = GetModuleHandleA(NULL);
wc.hIcon = (HICON)windowIcon; wc.hIcon = (HICON)windowIcon;
wc.hCursor = _DefaultCursor; wc.hCursor = _DefaultCursor;
wc.hbrBackground = WHITE_BRUSH; wc.hbrBackground = WHITE_BRUSH;
_WindowClass = "NLD3D" + toString(windowIcon); wc.lpszClassName = _WindowClass.c_str();
ucstring us = _WindowClass;
wc.lpszClassName = (LPCWSTR)us.c_str();
wc.lpszMenuName = NULL; wc.lpszMenuName = NULL;
if (!RegisterClassW(&wc)) if (!RegisterClassA(&wc))
{ {
DWORD error = GetLastError(); DWORD error = GetLastError();
if (error != ERROR_CLASS_ALREADY_EXISTS) 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) 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==yesNoCancelType)?MB_YESNOCANCEL:
(type==okCancelType)?MB_OKCANCEL: (type==okCancelType)?MB_OKCANCEL:
(type==abortRetryIgnoreType)?MB_ABORTRETRYIGNORE: (type==abortRetryIgnoreType)?MB_ABORTRETRYIGNORE:
@ -2327,13 +2327,13 @@ void CDriverD3D::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
if (winIconBig) if (winIconBig)
{ {
SendMessage(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); SendMessageA(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
SendMessage(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig); SendMessageA(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig);
} }
else else
{ {
SendMessage(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); SendMessageA(_HWnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
SendMessage(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall); SendMessageA(_HWnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall);
} }
} }

View file

@ -2527,7 +2527,7 @@ void CDriverGL::retrieveATIDriverVersion()
// get from the registry // get from the registry
HKEY parentKey; HKEY parentKey;
// open key about current video card // 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) if (result == ERROR_SUCCESS)
{ {
// find last config // find last config
@ -2541,7 +2541,7 @@ void CDriverGL::retrieveATIDriverVersion()
for(;;) for(;;)
{ {
nameBufferSize = sizeof(subKeyName) / sizeof(subKeyName[0]); 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_NO_MORE_ITEMS) break;
if (result == ERROR_SUCCESS) if (result == ERROR_SUCCESS)
{ {
@ -2577,14 +2577,14 @@ void CDriverGL::retrieveATIDriverVersion()
if (configFound) if (configFound)
{ {
HKEY subKey; HKEY subKey;
result = RegOpenKeyEx(parentKey, latestSubKeyName, 0, KEY_READ, &subKey); result = RegOpenKeyExA(parentKey, latestSubKeyName, 0, KEY_READ, &subKey);
if (result == ERROR_SUCCESS) if (result == ERROR_SUCCESS)
{ {
// see if it is a radeon card // see if it is a radeon card
DWORD valueType; DWORD valueType;
char driverDesc[256]; char driverDesc[256];
DWORD driverDescBufSize = sizeof(driverDesc) / sizeof(driverDesc[0]); 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) if (result == ERROR_SUCCESS && valueType == REG_SZ)
{ {
toLower(driverDesc); toLower(driverDesc);
@ -2592,7 +2592,7 @@ void CDriverGL::retrieveATIDriverVersion()
{ {
char driverVersion[256]; char driverVersion[256];
DWORD driverVersionBufSize = sizeof(driverVersion) / sizeof(driverVersion[0]); 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) if (result == ERROR_SUCCESS && valueType == REG_SZ)
{ {
int subVersionNumber[4]; int subVersionNumber[4];

View file

@ -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) if (f)
{ {
std::string vpText; std::string vpText;

View file

@ -326,7 +326,7 @@ bool CDriverGL::init (uintptr_t windowIcon, emptyProc exitFunc)
} }
// Backup monitor color parameters // Backup monitor color parameters
HDC dc = CreateDC ("DISPLAY", NULL, NULL, NULL); HDC dc = CreateDCA ("DISPLAY", NULL, NULL, NULL);
if (dc) if (dc)
{ {
_NeedToRestoreGammaRamp = GetDeviceGammaRamp (dc, _GammaRampBackuped) != FALSE; _NeedToRestoreGammaRamp = GetDeviceGammaRamp (dc, _GammaRampBackuped) != FALSE;
@ -468,7 +468,7 @@ bool CDriverGL::unInit()
// Restore monitor color parameters // Restore monitor color parameters
if (_NeedToRestoreGammaRamp) if (_NeedToRestoreGammaRamp)
{ {
HDC dc = CreateDC ("DISPLAY", NULL, NULL, NULL); HDC dc = CreateDCA ("DISPLAY", NULL, NULL, NULL);
if (dc) if (dc)
{ {
if (!SetDeviceGammaRamp (dc, _GammaRampBackuped)) if (!SetDeviceGammaRamp (dc, _GammaRampBackuped))
@ -558,13 +558,13 @@ void CDriverGL::setWindowIcon(const std::vector<NLMISC::CBitmap> &bitmaps)
if (winIconBig) if (winIconBig)
{ {
SendMessage(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); SendMessageA(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
SendMessage(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig); SendMessageA(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconBig);
} }
else else
{ {
SendMessage(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall); SendMessageA(_win, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)winIconSmall);
SendMessage(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall); SendMessageA(_win, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)winIconSmall);
} }
#elif defined(NL_OS_MAC) #elif defined(NL_OS_MAC)
@ -1629,7 +1629,7 @@ bool CDriverGL::destroyWindow()
if (_hDC) if (_hDC)
wglMakeCurrent(_hDC, NULL); wglMakeCurrent(_hDC, NULL);
if (_DestroyWindow && _hRC) if (_hRC)
{ {
wglDeleteContext(_hRC); wglDeleteContext(_hRC);
_hRC = NULL; _hRC = NULL;
@ -1644,7 +1644,7 @@ bool CDriverGL::destroyWindow()
#elif defined(NL_OS_MAC) #elif defined(NL_OS_MAC)
#elif defined(NL_OS_UNIX) #elif defined(NL_OS_UNIX)
if (_DestroyWindow && _ctx) if (_DestroyWindow && _ctx) // FIXME: _DestroyWindow may need to be removed here as well
glXDestroyContext(_dpy, _ctx); glXDestroyContext(_dpy, _ctx);
_ctx = NULL; _ctx = NULL;
@ -2622,7 +2622,7 @@ IDriver::TMessageBoxId CDriverGL::systemMessageBox (const char* message, const c
{ {
H_AUTO_OGL(CDriverGL_systemMessageBox) H_AUTO_OGL(CDriverGL_systemMessageBox)
#ifdef NL_OS_WINDOWS #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==yesNoCancelType)?MB_YESNOCANCEL:
(type==okCancelType)?MB_OKCANCEL: (type==okCancelType)?MB_OKCANCEL:
(type==abortRetryIgnoreType)?MB_ABORTRETRYIGNORE: (type==abortRetryIgnoreType)?MB_ABORTRETRYIGNORE:
@ -2847,7 +2847,7 @@ bool CDriverGL::setMonitorColorProperties (const CMonitorColorProperties &proper
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
// Get a DC // Get a DC
HDC dc = CreateDC ("DISPLAY", NULL, NULL, NULL); HDC dc = CreateDCA ("DISPLAY", NULL, NULL, NULL);
if (dc) if (dc)
{ {
// The ramp // The ramp

View file

@ -22,6 +22,7 @@
#include "nel/misc/debug.h" #include "nel/misc/debug.h"
#include "nel/misc/common.h" #include "nel/misc/common.h"
#include "nel/misc/path.h" #include "nel/misc/path.h"
#include "nel/misc/file.h"
#include "nel/3d/font_generator.h" #include "nel/3d/font_generator.h"
@ -81,6 +82,93 @@ CFontGenerator *newCFontGenerator(const std::string &fontFileName)
return new CFontGenerator(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 * Constructor
*/ */
@ -102,7 +190,14 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri
} }
++_LibraryInit; ++_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) if (error)
{ {
nlerror ("FT_New_Face() failed with file '%s': %s", fontFileName.c_str(), getFT2Error(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()) 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) if (error)
{ {
nlwarning ("FT_Attach_File() failed with file '%s': %s", fontEx.c_str(), getFT2Error(error)); nlwarning ("FT_Attach_File() failed with file '%s': %s", fontEx.c_str(), getFT2Error(error));

View file

@ -26,9 +26,6 @@
#include "nel/misc/file.h" #include "nel/misc/file.h"
#include "nel/misc/hierarchical_timer.h" #include "nel/misc/hierarchical_timer.h"
// std.
#include <fstream>
using namespace NLMISC; using namespace NLMISC;
using namespace std; using namespace std;
@ -85,8 +82,6 @@ void CLandscapeIGManager::initIG(UScene *scene, const std::string &igDesc, UDriv
string igFile = CPath::lookup(igDesc); string igFile = CPath::lookup(igDesc);
//ifstream file(igFile.c_str(), ios::in);
CIFile file; CIFile file;
// Shape to add should be empty ! // Shape to add should be empty !

View file

@ -35,3 +35,7 @@ ENDIF(WITH_NEL_CEGUI)
IF(WITH_PACS) IF(WITH_PACS)
ADD_SUBDIRECTORY(pacs) ADD_SUBDIRECTORY(pacs)
ENDIF(WITH_PACS) ENDIF(WITH_PACS)
IF(WITH_NEL_TOOLS)
ADD_SUBDIRECTORY(pipeline)
ENDIF(WITH_NEL_TOOLS)

View file

@ -304,7 +304,7 @@ namespace NLGUI
return; return;
} }
FILE *fp = fopen (tmpdest.c_str(), "wb"); FILE *fp = nlfopen (tmpdest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
@ -411,7 +411,7 @@ namespace NLGUI
return false; return false;
} }
FILE *fp = fopen (tmpdest.c_str(), "wb"); FILE *fp = nlfopen (tmpdest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
curl_easy_cleanup(curl); curl_easy_cleanup(curl);

View file

@ -27,7 +27,6 @@
#include <ctime> #include <ctime>
#include <deque> #include <deque>
#include <exception> #include <exception>
#include <fstream>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <limits> #include <limits>

View file

@ -207,16 +207,11 @@ CAsyncFileManager::CFileLoad::CFileLoad (const std::string& sFileName, uint8 **p
// *************************************************************************** // ***************************************************************************
void CAsyncFileManager::CFileLoad::run (void) void CAsyncFileManager::CFileLoad::run (void)
{ {
FILE *f = fopen (_FileName.c_str(), "rb"); FILE *f = nlfopen (_FileName, "rb");
if (f != NULL) if (f != NULL)
{ {
uint8 *ptr; uint32 filesize=CFile::getFileSize (f);
long filesize=CFile::getFileSize (f); uint8 *ptr = new uint8[filesize];
//fseek (f, 0, SEEK_END);
//long filesize = ftell (f);
//nlSleep(5);
//fseek (f, 0, SEEK_SET);
ptr = new uint8[filesize];
if (fread (ptr, filesize, 1, f) != 1) if (fread (ptr, filesize, 1, f) != 1)
nlwarning("AFM: Couldn't read '%s'", _FileName.c_str()); nlwarning("AFM: Couldn't read '%s'", _FileName.c_str());
fclose (f); fclose (f);
@ -253,16 +248,11 @@ void CAsyncFileManager::CMultipleFileLoad::run (void)
{ {
for (uint32 i = 0; i < _FileNames.size(); ++i) 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) if (f != NULL)
{ {
uint8 *ptr; uint32 filesize=CFile::getFileSize (f);
long filesize=CFile::getFileSize (f); uint8 *ptr = new uint8[filesize];
//fseek (f, 0, SEEK_END);
//long filesize = ftell (f);
//nlSleep(5);
//fseek (f, 0, SEEK_SET);
ptr = new uint8[filesize];
if (fread (ptr, filesize, 1, f) != 1) if (fread (ptr, filesize, 1, f) != 1)
nlwarning("AFM: Couldn't read '%s'", _FileNames[i].c_str()); nlwarning("AFM: Couldn't read '%s'", _FileNames[i].c_str());
fclose (f); fclose (f);

View file

@ -136,7 +136,7 @@ bool CBigFile::add (const std::string &sBigFileName, uint32 nOptions)
CHandleFile &handle= _ThreadFileArray.get(bnp.ThreadFileId); CHandleFile &handle= _ThreadFileArray.get(bnp.ThreadFileId);
// Open the big file. // Open the big file.
handle.File = fopen (sBigFileName.c_str(), "rb"); handle.File = nlfopen (sBigFileName, "rb");
if (handle.File == NULL) if (handle.File == NULL)
return false; return false;
@ -197,7 +197,7 @@ bool CBigFile::BNP::readHeader()
// Only external use // Only external use
if (InternalUse || BigFileName.empty()) return false; if (InternalUse || BigFileName.empty()) return false;
FILE *f = fopen (BigFileName.c_str(), "rb"); FILE *f = nlfopen (BigFileName, "rb");
if (f == NULL) return false; if (f == NULL) return false;
bool res = readHeader(f); bool res = readHeader(f);
@ -348,7 +348,7 @@ bool CBigFile::BNP::appendHeader()
// Only external use // Only external use
if (InternalUse || BigFileName.empty()) return false; if (InternalUse || BigFileName.empty()) return false;
FILE *f = fopen (BigFileName.c_str(), "ab"); FILE *f = nlfopen (BigFileName, "ab");
if (f == NULL) return false; if (f == NULL) return false;
uint32 nNbFile = (uint32)SFiles.size(); uint32 nNbFile = (uint32)SFiles.size();
@ -438,10 +438,10 @@ bool CBigFile::BNP::appendFile(const std::string &filename)
SFiles.push_back(ftmp); SFiles.push_back(ftmp);
OffsetFromBeginning += ftmp.Size; OffsetFromBeginning += ftmp.Size;
FILE *f1 = fopen(BigFileName.c_str(), "ab"); FILE *f1 = nlfopen(BigFileName, "ab");
if (f1 == NULL) return false; if (f1 == NULL) return false;
FILE *f2 = fopen(filename.c_str(), "rb"); FILE *f2 = nlfopen(filename, "rb");
if (f2 == NULL) if (f2 == NULL)
{ {
fclose(f1); fclose(f1);
@ -473,7 +473,7 @@ bool CBigFile::BNP::unpack(const std::string &sDestDir, TUnpackProgressCallback
// Only external use // Only external use
if (InternalUse || BigFileName.empty()) return false; if (InternalUse || BigFileName.empty()) return false;
FILE *bnp = fopen (BigFileName.c_str(), "rb"); FILE *bnp = nlfopen (BigFileName, "rb");
if (bnp == NULL) if (bnp == NULL)
return false; return false;
@ -506,7 +506,7 @@ bool CBigFile::BNP::unpack(const std::string &sDestDir, TUnpackProgressCallback
return false; return false;
} }
out = fopen (filename.c_str(), "wb"); out = nlfopen (filename, "wb");
if (out != NULL) if (out != NULL)
{ {
nlfseek64 (bnp, rBNPFile.Pos, SEEK_SET); nlfseek64 (bnp, rBNPFile.Pos, SEEK_SET);
@ -681,7 +681,7 @@ FILE* CBigFile::getFile (const std::string &sFileName, uint32 &rFileSize,
*/ */
if(handle.File== NULL) if(handle.File== NULL)
{ {
handle.File = fopen (bnp->BigFileName.c_str(), "rb"); handle.File = nlfopen (bnp->BigFileName, "rb");
if (handle.File == NULL) if (handle.File == NULL)
{ {
nlwarning ("bnp: can't fopen big file '%s' error %d '%s'", bnp->BigFileName.c_str(), errno, strerror(errno)); nlwarning ("bnp: can't fopen big file '%s' error %d '%s'", bnp->BigFileName.c_str(), errno, strerror(errno));

View file

@ -84,6 +84,20 @@ void MakeWhite(CBitmap &bitmaps)
} }
#endif // NEL_ALL_BITMAP_WHITE #endif // NEL_ALL_BITMAP_WHITE
CBitmap::CBitmap()
{
_MipMapCount = 1;
_Width = 0;
_Height = 0;
PixelFormat = RGBA;
_LoadGrayscaleAsAlpha = true;
}
CBitmap::~CBitmap()
{
}
/*-------------------------------------------------------------------*\ /*-------------------------------------------------------------------*\
load 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 (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 if(PixelFormat==DXTC1 && _DDSSurfaceDesc[21]>0) //AlphaBitDepth
{ {
PixelFormat = DXTC1Alpha; PixelFormat = DXTC1Alpha;
} }
//#endif
if(PixelFormat!= DXTC1 && PixelFormat!= DXTC1Alpha && PixelFormat!= DXTC3 && PixelFormat!= DXTC5) if(PixelFormat!= DXTC1 && PixelFormat!= DXTC1Alpha && PixelFormat!= DXTC3 && PixelFormat!= DXTC5)
{ {

View file

@ -199,11 +199,11 @@ bool CCmdArgs::parse(const std::string &args)
std::vector<std::string> argv; std::vector<std::string> argv;
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
char str[4096]; wchar_t str[4096];
uint len = GetModuleFileNameA(NULL, str, 4096); uint len = GetModuleFileNameW(NULL, str, 4096);
if (len && len < 4096) if (len && len < 4096)
argv.push_back(str); argv.push_back(wideToUtf8(str));
#endif #endif
std::string::size_type pos1 = 0, pos2 = 0; std::string::size_type pos1 = 0, pos2 = 0;

View file

@ -506,6 +506,21 @@ string secondsToHumanReadable (uint32 time)
return toString ("%u%s", res, divTable[div]); 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) uint32 fromHumanReadable (const std::string &str)
{ {
if (str.size() == 0) if (str.size() == 0)
@ -710,50 +725,54 @@ bool abortProgram(uint32 pid)
#endif #endif
} }
bool launchProgram(const std::string &programName, const std::string &arguments, bool log)
{
#ifdef NL_OS_WINDOWS #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(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi)); memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si); si.cb = sizeof(si);
// Enable nlassert/nlstop to display the error reason & callstack // Enable nlassert/nlstop to display the error reason & callstack
const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS"); const char *SE_TRANSLATOR_IN_MAIN_MODULE = "NEL_SE_TRANS";
TCHAR envBuf [2];
if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) != 0) 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; std::string args;
// a .bat file must have first parameter to NULL and use 2nd parameter to pass filename // a .bat file must have first parameter to NULL and use 2nd parameter to pass filename
if (CFile::getExtension(programName) == "bat") if (CFile::getExtension(programName) == "bat")
{ {
sProgramName = NULL;
args = "\"" + programName + "\" " + arguments; args = "\"" + programName + "\" " + arguments;
} }
else else
{ {
ucstring ucProgramName;
ucProgramName.fromUtf8(programName);
sProgramName = new wchar_t[MAX_PATH];
wcscpy(sProgramName, (wchar_t*)ucProgramName.c_str());
args = arguments; 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()); delete [] sProgramName;
CloseHandle( pi.hProcess ); sProgramName = NULL;
CloseHandle( pi.hThread );
return true;
} }
else
if (!res)
{ {
if (log) if (log)
{ {
@ -763,8 +782,26 @@ bool launchProgram(const std::string &programName, const std::string &arguments,
CloseHandle( pi.hProcess ); CloseHandle( pi.hProcess );
CloseHandle( pi.hThread ); 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 #else
#ifdef NL_OS_MAC #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 launchProgramAndWaitForResult(const std::string &programName, const std::string &arguments, bool log)
{ {
sint res = 0;
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
STARTUPINFOA si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si)); if (!createProcess(programName, arguments, log, pi)) return -1;
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)
{
SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL );
}
const char *sProgramName = programName.c_str();
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
{
args = arguments;
}
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. // Successfully created the process. Wait for it to finish.
WaitForSingleObject(pi.hProcess, INFINITE); WaitForSingleObject(pi.hProcess, INFINITE);
// Get the exit code. // Get the exit code.
DWORD exitCode = 0; DWORD exitCode = 0;
ok = GetExitCodeProcess(pi.hProcess, &exitCode); BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode);
//nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str()); //nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str());
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
if (ok) if (ok) return (sint)exitCode;
{
res = (sint)exitCode;
}
else
{
if (log) if (log)
nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str()); 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); return -1;
CloseHandle(pi.hThread);
}
#else #else
// program name is the only required string // program name is the only required string
std::string command = programName; std::string command = programName;
@ -947,13 +936,13 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st
if (!arguments.empty()) command += " " + arguments; if (!arguments.empty()) command += " " + arguments;
// execute the command // execute the command
res = system(command.c_str()); sint res = system(command.c_str());
if (res && log) if (res && log)
nlwarning ("LAUNCH: Failed launched '%s' with arg '%s' return code %d", programName.c_str(), arguments.c_str(), res); nlwarning ("LAUNCH: Failed launched '%s' with arg '%s' return code %d", programName.c_str(), arguments.c_str(), res);
#endif
return res; return res;
#endif
} }
std::string getCommandOutput(const std::string &command) 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 ) int nlfseek64( FILE *stream, sint64 offset, int origin )
{ {

View file

@ -600,7 +600,7 @@ void CConfigFile::save () const
// Avoid any problem, Force Locale to default // Avoid any problem, Force Locale to default
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
FILE *fp = fopen (getFilename().c_str (), "w"); FILE *fp = nlfopen (getFilename(), "w");
if (fp == NULL) if (fp == NULL)
{ {
nlwarning ("CF: Couldn't create %s file", getFilename().c_str ()); nlwarning ("CF: Couldn't create %s file", getFilename().c_str ());

View file

@ -42,7 +42,7 @@ bool CCPUTimeStat::getCPUTicks(uint64& user, uint64& nice, uint64& system, uint6
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
const char* statfile = "/proc/stat"; const char* statfile = "/proc/stat";
FILE* f = fopen(statfile, "r"); FILE* f = nlfopen(statfile, "r");
if (f == NULL) if (f == NULL)
return false; return false;
@ -66,7 +66,7 @@ bool CCPUTimeStat::getPIDTicks(uint64& utime, uint64& stime, uint64& cutime, uin
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
std::string statfile = NLMISC::toString("/proc/%u/stat", pid); std::string statfile = NLMISC::toString("/proc/%u/stat", pid);
FILE* f = fopen(statfile.c_str(), "r"); FILE* f = nlfopen(statfile, "r");
if (f == NULL) if (f == NULL)
return false; return false;

View file

@ -310,9 +310,9 @@ static DWORD __stdcall GetModuleBase(HANDLE hProcess, DWORD dwReturnAddress)
&memoryBasicInfo, sizeof(memoryBasicInfo))) &memoryBasicInfo, sizeof(memoryBasicInfo)))
{ {
DWORD cch = 0; 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); szFile, MAX_PATH);
if (cch && (lstrcmpA(szFile, "DBFN")== 0)) if (cch && (lstrcmpA(szFile, "DBFN")== 0))
@ -527,9 +527,9 @@ public:
string progname; string progname;
if(!shortExc.empty() || !longExc.empty()) if(!shortExc.empty() || !longExc.empty())
{ {
char name[1024]; wchar_t name[1024];
GetModuleFileNameA (NULL, name, 1023); GetModuleFileNameW (NULL, name, 1023);
progname = CFile::getFilename(name); progname = CFile::getFilename(wideToUtf8(name));
progname += " "; 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 // 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 // (otherwise there would be one distinct bool by module, and the last
// _set_se_translator would overwrite the previous ones) // _set_se_translator would overwrite the previous ones)
const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS"); const char *SE_TRANSLATOR_IN_MAIN_MODULE = "NEL_SE_TRANS";
TCHAR envBuf [2]; char envBuf [2];
if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) == 0) if ( GetEnvironmentVariableA( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) == 0)
{ {
_set_se_translator(exceptionTranslator); _set_se_translator(exceptionTranslator);
SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, _T("1") ); SetEnvironmentVariableA( SE_TRANSLATOR_IN_MAIN_MODULE, "1" );
} }
} }
# endif // NL_OS_WINDOWS # endif // NL_OS_WINDOWS

View file

@ -93,7 +93,7 @@ bool loadStringFile(const std::string filename, vector<TStringInfo> &stringInfos
return true; return true;
} }
*/ */
/* FILE *fp = fopen(filename.c_str(), "rb"); /* FILE *fp = nlfopen(filename, "rb");
if (fp == NULL) if (fp == NULL)
{ {

View file

@ -216,7 +216,7 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
static bool consoleModeTest = false; static bool consoleModeTest = false;
if (!consoleModeTest) 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; consoleMode = handle != INVALID_HANDLE_VALUE;
if (consoleMode) if (consoleMode)
CloseHandle (handle); CloseHandle (handle);
@ -286,20 +286,14 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
// WARNING: READ THIS !!!!!!!!!!!!!!!! /////////////////////////// // WARNING: READ THIS !!!!!!!!!!!!!!!! ///////////////////////////
// If at the release time, it freezes here, it's a microsoft bug: // If at the release time, it freezes here, it's a microsoft bug:
// http://support.microsoft.com/support/kb/articles/q173/2/60.asp // http://support.microsoft.com/support/kb/articles/q173/2/60.asp
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(str2).c_str()); OutputDebugStringW(utf8ToWide(str2));
} }
else else
{ {
/*OutputDebugString(ss2.str().c_str());
OutputDebugString("\n\t\t\t");
OutputDebugString("message end: ");
OutputDebugString(&message[strlen(message) - 1024]);
OutputDebugString("\n");*/
sint count = 0; sint count = 0;
uint n = (uint)strlen(message); uint n = (uint)strlen(message);
std::string s(&str2.c_str()[0], (str2.size() - n)); std::string s(&str2.c_str()[0], (str2.size() - n));
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str()); OutputDebugStringW(utf8ToWide(s));
for(;;) for(;;)
{ {
@ -307,15 +301,15 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
if((n - count) < maxOutString ) if((n - count) < maxOutString )
{ {
s = std::string(&message[count], (n - count)); s = std::string(&message[count], (n - count));
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str()); OutputDebugStringW(utf8ToWide(s));
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8("\n").c_str()); OutputDebugStringW(L"\n");
break; break;
} }
else else
{ {
s = std::string(&message[count] , count + maxOutString); s = std::string(&message[count] , count + maxOutString);
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str()); OutputDebugStringW(utf8ToWide(s));
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8("\n\t\t\t").c_str()); OutputDebugStringW(L"\n\t\t\t");
count += maxOutString; count += maxOutString;
} }
} }
@ -329,13 +323,13 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
if (pos+1000 < args.CallstackAndLog.size ()) if (pos+1000 < args.CallstackAndLog.size ())
{ {
splited = args.CallstackAndLog.substr (pos, 1000); splited = args.CallstackAndLog.substr (pos, 1000);
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(splited).c_str()); OutputDebugStringW(utf8ToWide(splited));
pos += 1000; pos += 1000;
} }
else else
{ {
splited = args.CallstackAndLog.substr (pos); splited = args.CallstackAndLog.substr (pos);
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(splited).c_str()); OutputDebugStringW(utf8ToWide(splited));
break; break;
} }
} }
@ -491,7 +485,7 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes
if (_FilePointer == (FILE*)1) if (_FilePointer == (FILE*)1)
{ {
_FilePointer = fopen (_FileName.c_str(), "at"); _FilePointer = nlfopen (_FileName, "at");
if (_FilePointer == NULL) if (_FilePointer == NULL)
printf ("Can't open log file '%s': %s\n", _FileName.c_str(), strerror (errno)); 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 } // NLMISC

View file

@ -45,32 +45,32 @@ bool CDummyWindow::init(HINSTANCE hInstance, WNDPROC winProc)
{ {
release(); release();
static const char *INVISIBLE_WINDOW_CLASS = "nl_invisible_wnd_class"; static const char *INVISIBLE_WINDOW_CLASS = "nl_invisible_wnd_class";
WNDCLASSEX wc; WNDCLASSEXA wc;
wc.cbSize = sizeof(WNDCLASSEX); wc.cbSize = sizeof(WNDCLASSEXA);
if (!GetClassInfoEx(hInstance, INVISIBLE_WINDOW_CLASS, &wc)) if (!GetClassInfoExA(hInstance, INVISIBLE_WINDOW_CLASS, &wc))
{ {
wc.cbSize = sizeof(WNDCLASSEX); wc.cbSize = sizeof(WNDCLASSEXA);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = nlDefaultWinProc; wc.lpfnWndProc = nlDefaultWinProc;
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
wc.cbWndExtra = 0; wc.cbWndExtra = 0;
wc.hInstance = hInstance; wc.hInstance = hInstance;
wc.hIcon = 0; wc.hIcon = NULL;
wc.hCursor = 0; wc.hCursor = NULL;
wc.hbrBackground = 0; wc.hbrBackground = NULL;
wc.lpszMenuName = 0; wc.lpszMenuName = NULL;
wc.lpszClassName = INVISIBLE_WINDOW_CLASS; wc.lpszClassName = INVISIBLE_WINDOW_CLASS;
wc.hIconSm = 0; wc.hIconSm = NULL;
RegisterClassEx(&wc); RegisterClassExA(&wc);
} }
_HWnd = CreateWindow(INVISIBLE_WINDOW_CLASS, "", WS_POPUP, _HWnd = CreateWindowA(INVISIBLE_WINDOW_CLASS, "", WS_POPUP,
CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,
NULL, 0, NULL, 0,
hInstance, 0); hInstance, 0);
if (_HWnd) if (_HWnd)
{ {
if (winProc) SetWindowLongPtr(_HWnd, GWLP_WNDPROC, (LONG_PTR) winProc); if (winProc) SetWindowLongPtrA(_HWnd, GWLP_WNDPROC, (LONG_PTR) winProc);
return true; return true;
} }
return false; return false;

View file

@ -32,7 +32,7 @@ NL_LIB_HANDLE nlLoadLibrary(const std::string &libName)
{ {
NL_LIB_HANDLE res = 0; NL_LIB_HANDLE res = 0;
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
res = LoadLibrary(libName.c_str()); res = LoadLibraryW(utf8ToWide(libName));
#elif defined(NL_OS_UNIX) #elif defined(NL_OS_UNIX)
res = dlopen(libName.c_str(), RTLD_NOW); res = dlopen(libName.c_str(), RTLD_NOW);
#else #else

View file

@ -445,7 +445,7 @@ void cbInvalidEntityNamesFilename(const std::string &invalidEntityNamesFilename)
return; return;
} }
FILE *fp = fopen (fn.c_str(), "r"); FILE *fp = nlfopen (fn, "r");
if (fp == NULL) if (fp == NULL)
{ {
nlwarning ("EIT: Can't load filename '%s' for invalid entity names filename", fn.c_str()); nlwarning ("EIT: Can't load filename '%s' for invalid entity names filename", fn.c_str());

View file

@ -243,7 +243,7 @@ bool CIFile::open(const std::string &path, bool text)
_IsInXMLPackFile = false; _IsInXMLPackFile = false;
_BigFileOffset = 0; _BigFileOffset = 0;
_AlwaysOpened = false; _AlwaysOpened = false;
_F = fopen (path.c_str(), mode); _F = nlfopen (path, mode);
if (_F != NULL) if (_F != NULL)
{ {
/* /*
@ -598,7 +598,7 @@ bool COFile::open(const std::string &path, bool append, bool text, bool useTempF
return false; return false;
} }
_F=fopen(fileToOpen.c_str(), mode); _F = nlfopen(fileToOpen, mode);
return _F!=NULL; return _F!=NULL;
} }

View file

@ -567,7 +567,7 @@ void CI18N::readTextFile(const string &filename,
if (!readContext.IfStack.empty()) 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() );
} }
} }

View file

@ -96,7 +96,7 @@ namespace NLMISC
nlassert(_Id == 0); // init done twice nlassert(_Id == 0); // init done twice
release(); release();
// create a system wide mutex // 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; if (!_SharedMemMutex) return false;
_Id = id; _Id = id;
return true; return true;
@ -197,7 +197,7 @@ namespace NLMISC
cds.lpData = (PVOID) msgOut.buffer(); cds.lpData = (PVOID) msgOut.buffer();
for(;;) 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; if (result) break;
// retry ... // retry ...
Sleep(30); Sleep(30);

View file

@ -59,9 +59,9 @@ void CLog::setDefaultProcessName ()
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
if ((*_ProcessName).empty()) if ((*_ProcessName).empty())
{ {
char name[1024]; wchar_t name[1024];
GetModuleFileName (NULL, name, 1023); GetModuleFileNameW(NULL, name, 1023);
(*_ProcessName) = CFile::getFilename(name); (*_ProcessName) = CFile::getFilename(wideToUtf8(name));
} }
#else #else
if ((*_ProcessName).empty()) if ((*_ProcessName).empty())

View file

@ -165,10 +165,9 @@ static DWORD __stdcall GetModuleBase(HANDLE hProcess, DWORD dwReturnAddress)
DWORD cch = 0; DWORD cch = 0;
char szFile[MAX_PATH] = { 0 }; char szFile[MAX_PATH] = { 0 };
cch = GetModuleFileNameA((HINSTANCE)memoryBasicInfo.AllocationBase, cch = GetModuleFileNameA((HINSTANCE)memoryBasicInfo.AllocationBase, szFile, MAX_PATH);
szFile, MAX_PATH);
if (cch && (lstrcmp(szFile, "DBFN")== 0)) if (cch && (lstrcmpA(szFile, "DBFN")== 0))
{ {
char mn[] = { 'M', 'N', 0x00 }; char mn[] = { 'M', 'N', 0x00 };
#ifdef NL_OS_WIN64 #ifdef NL_OS_WIN64
@ -227,28 +226,28 @@ static void displayCallStack (CLog *log)
if (symbolPath.empty()) if (symbolPath.empty())
{ {
CHAR tmpPath[stringSize]; wchar_t tmpPath[stringSize];
symbolPath = "."; symbolPath = ".";
if (GetEnvironmentVariable ("_NT_SYMBOL_PATH", tmpPath, stringSize)) if (GetEnvironmentVariableW (L"_NT_SYMBOL_PATH", tmpPath, stringSize))
{ {
symbolPath += ";"; 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 += ";";
symbolPath += tmpPath; symbolPath += wideToUtf8(tmpPath);
} }
if (GetEnvironmentVariable ("SYSTEMROOT", tmpPath, stringSize)) if (GetEnvironmentVariableW (L"SYSTEMROOT", tmpPath, stringSize))
{ {
symbolPath += ";"; symbolPath += ";";
symbolPath += tmpPath; symbolPath += wideToUtf8(tmpPath);
symbolPath += ";"; symbolPath += ";";
symbolPath += tmpPath; symbolPath += wideToUtf8(tmpPath);
symbolPath += "\\system32"; symbolPath += "\\system32";
} }
} }

View file

@ -159,7 +159,7 @@ bool CSharedMutex::createByName( const char *objectName )
#ifdef NL_DEBUG #ifdef NL_DEBUG
nlassert( _Mutex == NULL ); nlassert( _Mutex == NULL );
#endif #endif
_Mutex = (void *) CreateMutex( NULL, FALSE, objectName ); _Mutex = (void *) CreateMutexA( NULL, FALSE, objectName );
//nldebug( "Creating mutex %s: handle %p", objectName, _Mutex ); //nldebug( "Creating mutex %s: handle %p", objectName, _Mutex );
return ( _Mutex != NULL ); return ( _Mutex != NULL );
} }

View file

@ -681,11 +681,11 @@ std::string CPath::getCurrentPath ()
std::string CFileContainer::getCurrentPath () std::string CFileContainer::getCurrentPath ()
{ {
char buffer [1024];
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return standardizePath(_getcwd(buffer, 1024), false); wchar_t buffer[1024];
return standardizePath(wideToUtf8(_wgetcwd(buffer, 1024)), false);
#else #else
char buffer [1024];
return standardizePath(getcwd(buffer, 1024), false); return standardizePath(getcwd(buffer, 1024), false);
#endif #endif
} }
@ -700,7 +700,7 @@ bool CFileContainer::setCurrentPath (const std::string &path)
int res; int res;
//nldebug("Change current path to '%s' (current path is '%s')", path.c_str(), getCurrentPath().c_str()); //nldebug("Change current path to '%s' (current path is '%s')", path.c_str(), getCurrentPath().c_str());
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
res = _chdir(path.c_str()); res = _wchdir(utf8ToWide(path));
#else #else
res = chdir(path.c_str()); res = chdir(path.c_str());
#endif #endif
@ -756,11 +756,11 @@ std::string CFileContainer::getFullPath (const std::string &path, bool addFinalS
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
# define dirent WIN32_FIND_DATA # define dirent WIN32_FIND_DATAW
# define DIR void # define DIR void
static string sDir; static string sDir;
static WIN32_FIND_DATA findData; static WIN32_FIND_DATAW findData;
static HANDLE hFind; static HANDLE hFind;
DIR *opendir (const char *path) DIR *opendir (const char *path)
@ -792,13 +792,12 @@ dirent *readdir (DIR *dir)
// first visit in this directory : FindFirstFile() // first visit in this directory : FindFirstFile()
if (hFind == NULL) if (hFind == NULL)
{ {
string fullPath = CPath::standardizePath(sDir) + "*"; hFind = FindFirstFileW (utf8ToWide(CPath::standardizePath(sDir) + "*"), &findData);
hFind = FindFirstFileA (fullPath.c_str(), &findData);
} }
// directory already visited : FindNextFile() // directory already visited : FindNextFile()
else else
{ {
if (!FindNextFileA (hFind, &findData)) if (!FindNextFileW (hFind, &findData))
return NULL; return NULL;
} }
@ -845,7 +844,7 @@ string getname (dirent *de)
{ {
nlassert (de != NULL); nlassert (de != NULL);
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return de->cFileName; return wideToUtf8(de->cFileName);
#else #else
return de->d_name; return de->d_name;
#endif // NL_OS_WINDOWS #endif // NL_OS_WINDOWS
@ -1269,7 +1268,7 @@ void CFileContainer::addSearchBigFile (const string &sBigFilename, bool recurse,
// Open and read the big file header // Open and read the big file header
nlassert(!_MemoryCompressed); nlassert(!_MemoryCompressed);
FILE *Handle = fopen (sBigFilename.c_str(), "rb"); FILE *Handle = nlfopen (sBigFilename, "rb");
if (Handle == NULL) if (Handle == NULL)
{ {
nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't open file, skip it", sBigFilename.c_str(), recurse, alternative); 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 // Open and read the xmlpack file header
FILE *Handle = fopen (sXmlpackFilename.c_str(), "rb"); FILE *Handle = nlfopen (sXmlpackFilename, "rb");
if (Handle == NULL) if (Handle == NULL)
{ {
nlwarning ("PATH: CPath::addSearchXmlpackFile(%s, %d, %d): can't open file, skip it", sXmlpackFilename.c_str(), recurse, alternative); 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"); nlwarning("not a ms windows platform");
return ""; return "";
#else #else
char winDir[MAX_PATH]; wchar_t winDir[MAX_PATH];
UINT numChar = ::GetWindowsDirectory(winDir, MAX_PATH); UINT numChar = GetWindowsDirectoryW(winDir, MAX_PATH);
if (numChar > MAX_PATH || numChar == 0) if (numChar > MAX_PATH || numChar == 0)
{ {
nlwarning("Couldn't retrieve windows directory"); nlwarning("Couldn't retrieve windows directory");
return ""; return "";
} }
return CPath::standardizePath(winDir); return CPath::standardizePath(wideToUtf8(winDir));
#endif #endif
} }
@ -1789,18 +1788,18 @@ std::string CFileContainer::getApplicationDirectory(const std::string &appName,
if (appPath.empty()) if (appPath.empty())
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
char buffer[MAX_PATH]; wchar_t buffer[MAX_PATH];
#ifdef CSIDL_LOCAL_APPDATA #ifdef CSIDL_LOCAL_APPDATA
if (local) if (local)
{ {
SHGetSpecialFolderPathA(NULL, buffer, CSIDL_LOCAL_APPDATA, TRUE); SHGetSpecialFolderPathW(NULL, buffer, CSIDL_LOCAL_APPDATA, TRUE);
} }
else else
#endif #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) #elif defined(NL_OS_MAC)
appPath = CPath::standardizePath(getenv("HOME")); appPath = CPath::standardizePath(getenv("HOME"));
appPath += "/Library/Application Support/"; appPath += "/Library/Application Support/";
@ -1918,7 +1917,7 @@ string CFile::getPath (const string &filename)
bool CFile::isDirectory (const string &filename) bool CFile::isDirectory (const string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
DWORD res = GetFileAttributes(filename.c_str()); DWORD res = GetFileAttributesW(utf8ToWide(filename));
if (res == INVALID_FILE_ATTRIBUTES) if (res == INVALID_FILE_ATTRIBUTES)
{ {
// nlwarning ("PATH: '%s' is not a valid file or directory name", filename.c_str ()); // 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) bool CFile::isExists (const string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return (GetFileAttributes(filename.c_str()) != INVALID_FILE_ATTRIBUTES); return GetFileAttributesW(utf8ToWide(filename)) != INVALID_FILE_ATTRIBUTES;
#else // NL_OS_WINDOWS #else // NL_OS_WINDOWS
struct stat buf; struct stat buf;
return stat (filename.c_str (), &buf) == 0; return stat (filename.c_str (), &buf) == 0;
@ -1950,7 +1949,7 @@ bool CFile::isExists (const string &filename)
bool CFile::createEmptyFile (const std::string& filename) bool CFile::createEmptyFile (const std::string& filename)
{ {
FILE *file = fopen (filename.c_str(), "wb"); FILE *file = nlfopen (filename, "wb");
if (file) if (file)
{ {
@ -1964,7 +1963,14 @@ bool CFile::createEmptyFile (const std::string& filename)
bool CFile::fileExists (const string& filename) bool CFile::fileExists (const string& filename)
{ {
//H_AUTO(FileExists); //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) #if defined (NL_OS_WINDOWS)
struct _stat buf; struct _stat buf;
int result = _stat (filename.c_str (), &buf); int result = _wstat (utf8ToWide(filename), &buf);
#elif defined (NL_OS_UNIX) #elif defined (NL_OS_UNIX)
struct stat buf; struct stat buf;
int result = stat (filename.c_str (), &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 // Use the WIN32 API to read the file times in UTC
// create a file handle (this does not open the file) // 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) if (h == INVALID_HANDLE_VALUE)
{ {
nlwarning("Can't get modification date on file '%s' : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str()); 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 // Use the WIN32 API to set the file times in UTC
// create a file handle (this does not open the file) // 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) 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()); nlwarning("Can't set modification date on file '%s' (error accessing file) : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str());
@ -2219,7 +2225,7 @@ uint32 CFile::getFileCreationDate(const std::string &filename)
#if defined (NL_OS_WINDOWS) #if defined (NL_OS_WINDOWS)
struct _stat buf; struct _stat buf;
int result = _stat (fn.c_str (), &buf); int result = _wstat(utf8ToWide(fn), &buf);
#elif defined (NL_OS_UNIX) #elif defined (NL_OS_UNIX)
struct stat buf; struct stat buf;
int result = stat(fn.c_str (), &buf); int result = stat(fn.c_str (), &buf);
@ -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 sdest = CPath::standardizePath(dest,false);
std::string ssrc = CPath::standardizePath(src,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 (progress) progress->progress(0.f);
if(copyFile) if(copyFile)
{ {
@ -2311,13 +2314,13 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c
{ {
totalSize = CFile::getFileSize(ssrc); totalSize = CFile::getFileSize(ssrc);
} }
FILE *fp1 = fopen(ssrc.c_str(), "rb"); FILE *fp1 = nlfopen(ssrc, "rb");
if (fp1 == NULL) if (fp1 == NULL)
{ {
nlwarning ("PATH: CopyMoveFile error: can't fopen in read mode '%s'", ssrc.c_str()); nlwarning ("PATH: CopyMoveFile error: can't fopen in read mode '%s'", ssrc.c_str());
return false; return false;
} }
FILE *fp2 = fopen(sdest.c_str(), "wb"); FILE *fp2 = nlfopen(sdest, "wb");
if (fp2 == NULL) if (fp2 == NULL)
{ {
nlwarning ("PATH: CopyMoveFile error: can't fopen in read write mode '%s'", sdest.c_str()); 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 else
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
if (MoveFile(ssrc.c_str(), sdest.c_str()) == 0) if (MoveFileW(utf8ToWide(ssrc), utf8ToWide(sdest)) == 0)
{ {
sint lastError = NLMISC::getLastError(); sint lastError = NLMISC::getLastError();
nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)", 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) bool CFile::quickFileCompare(const std::string &fileName0, const std::string &fileName1)
{ {
// make sure the files both exist // make sure the files both exist
if (!fileExists(fileName0.c_str()) || !fileExists(fileName1.c_str())) if (!fileExists(fileName0) || !fileExists(fileName1))
return false; return false;
// compare time stamps // compare time stamps
if (getFileModificationDate(fileName0.c_str()) != getFileModificationDate(fileName1.c_str())) if (getFileModificationDate(fileName0) != getFileModificationDate(fileName1))
return false; return false;
// compare file sizes // compare file sizes
if (getFileSize(fileName0.c_str()) != getFileSize(fileName1.c_str())) if (getFileSize(fileName0) != getFileSize(fileName1))
return false; return false;
// everything matched so return true // 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) bool CFile::thoroughFileCompare(const std::string &fileName0, const std::string &fileName1,uint32 maxBufSize)
{ {
// make sure the files both exist // make sure the files both exist
if (!fileExists(fileName0.c_str()) || !fileExists(fileName1.c_str())) if (!fileExists(fileName0) || !fileExists(fileName1))
return false; return false;
// setup the size variable from file length of first file // setup the size variable from file length of first file
uint32 fileSize=getFileSize(fileName0.c_str()); uint32 fileSize=getFileSize(fileName0);
// compare file sizes // compare file sizes
if (fileSize != getFileSize(fileName1.c_str())) if (fileSize != getFileSize(fileName1))
return false; return false;
// allocate a couple of data buffers for our 2 files // 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) bool CFile::createDirectory(const std::string &filename)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
return _mkdir(filename.c_str())==0; return _wmkdir(utf8ToWide(filename))==0;
#else #else
// Set full permissions.... // Set full permissions....
return mkdir(filename.c_str(), 0xFFFF)==0; 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) bool CFile::setRWAccess(const std::string &filename)
{ {
#ifdef NL_OS_WINDOWS #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 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 // 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()) if (INelContext::getInstance().getAlreadyCreateSharedAmongThreads())
{ {
@ -2719,15 +2727,14 @@ bool CFile::setRWAccess(const std::string &filename)
return true; return true;
} }
#ifdef NL_OS_WINDOWS
#define unlink _unlink
#endif
bool CFile::deleteFile(const std::string &filename) bool CFile::deleteFile(const std::string &filename)
{ {
setRWAccess(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 (res == -1)
{ {
if (INelContext::getInstance().getAlreadyCreateSharedAmongThreads()) if (INelContext::getInstance().getAlreadyCreateSharedAmongThreads())
@ -2739,14 +2746,14 @@ bool CFile::deleteFile(const std::string &filename)
return true; return true;
} }
#ifdef NL_OS_WINDOWS
#define rmdir _rmdir
#endif
bool CFile::deleteDirectory(const std::string &filename) bool CFile::deleteDirectory(const std::string &filename)
{ {
setRWAccess(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) if (res == -1)
{ {
nlwarning ("PATH: Can't delete directory '%s': (errno %d) %s", filename.c_str(), errno, strerror(errno)); nlwarning ("PATH: Can't delete directory '%s': (errno %d) %s", filename.c_str(), errno, strerror(errno));

View file

@ -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)); std::string reportFile = getLogDirectory() + NLMISC::toString("nel_report_%u.log", (uint)time(NULL));
reportPath = CFile::findNewFile(reportFile); reportPath = CFile::findNewFile(reportFile);
std::ofstream f;
f.open(reportPath.c_str()); FILE *f = nlfopen(reportPath, "wb"); // write as binary so \n are preserved
if (!f.good())
if (!f)
{ {
#if NL_DEBUG_REPORT #if NL_DEBUG_REPORT
if (INelContext::isContextInitialised()) if (INelContext::isContextInitialised())
@ -94,8 +95,14 @@ TReportResult report(const std::string &title, const std::string &subject, const
} }
else else
{ {
f << body; size_t written = fwrite(body.c_str(), 1, body.length(), f);
f.close();
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);
} }
} }

View file

@ -147,7 +147,7 @@ CHashKey getSHA1(const string &filename, bool forcePath)
return CHashKey(); return CHashKey();
} }
//FILE *fp = fopen (filename.c_str(), "rb"); //FILE *fp = nlfopen (filename, "rb");
//if (fp == NULL) return CHashKey(); //if (fp == NULL) return CHashKey();
err = SHA1Reset(&sha); err = SHA1Reset(&sha);

View file

@ -51,7 +51,7 @@ void *CSharedMemory::createSharedMemory( TSharedMemId sharedMemId, uint32 size
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
// Create a file mapping backed by the virtual memory swap file (not a data file) // 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) ) 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 ); 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 #ifdef NL_OS_WINDOWS
// Open the existing file mapping by name // 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 ) if ( hMapFile == NULL )
return NULL; return NULL;
//nldebug( "SHDMEM: Opening smid %s --> mapFile %p", sharedMemId, hMapFile ); //nldebug( "SHDMEM: Opening smid %s --> mapFile %p", sharedMemId, hMapFile );

View file

@ -1743,7 +1743,7 @@ namespace NLMISC
bool CSString::readFromFile(const CSString& fileName) bool CSString::readFromFile(const CSString& fileName)
{ {
FILE* file; FILE* file;
file=fopen(fileName.c_str(),"rb"); file = nlfopen(fileName, "rb");
if (file==NULL) if (file==NULL)
{ {
clear(); clear();
@ -1766,7 +1766,7 @@ namespace NLMISC
bool CSString::writeToFile(const CSString& fileName) const bool CSString::writeToFile(const CSString& fileName) const
{ {
FILE* file; FILE* file;
file=fopen(fileName.c_str(),"wb"); file = nlfopen(fileName, "wb");
if (file==NULL) if (file==NULL)
{ {
nlwarning("Failed to open file for writing: %s",fileName.c_str()); nlwarning("Failed to open file for writing: %s",fileName.c_str());

View file

@ -638,7 +638,7 @@ string CSystemInfo::getOS()
else // Test for specific product on Windows NT 4.0 SP5 and earlier else // Test for specific product on Windows NT 4.0 SP5 and earlier
{ {
HKEY hKey; HKEY hKey;
TCHAR szProductType[BUFSIZE]; char szProductType[BUFSIZE];
DWORD dwBufLen=BUFSIZE; DWORD dwBufLen=BUFSIZE;
LONG lRet; LONG lRet;
@ -652,18 +652,18 @@ string CSystemInfo::getOS()
RegCloseKey( hKey ); RegCloseKey( hKey );
if ( lstrcmpi( _T("WINNT"), szProductType) == 0 ) if ( lstrcmpiA( "WINNT", szProductType) == 0 )
OSString += " Workstation"; OSString += " Workstation";
if ( lstrcmpi( _T("LANMANNT"), szProductType) == 0 ) if ( lstrcmpiA( "LANMANNT", szProductType) == 0 )
OSString += " Server"; OSString += " Server";
if ( lstrcmpi( _T("SERVERNT"), szProductType) == 0 ) if ( lstrcmpiA( "SERVERNT", szProductType) == 0 )
OSString += " Advanced Server"; OSString += " Advanced Server";
} }
} }
std::string servicePack; 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; HKEY hKey;
LONG lRet; LONG lRet;
@ -768,7 +768,7 @@ string CSystemInfo::getProc ()
{ {
// get processor name // get processor name
valueSize = 1024; 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) if (result == ERROR_SUCCESS)
ProcString = value; ProcString = value;
else else
@ -778,7 +778,7 @@ string CSystemInfo::getProc ()
// get processor identifier // get processor identifier
valueSize = 1024; 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) if (result == ERROR_SUCCESS)
ProcString += value; ProcString += value;
else else
@ -788,7 +788,7 @@ string CSystemInfo::getProc ()
// get processor vendor // get processor vendor
valueSize = 1024; 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) if (result == ERROR_SUCCESS)
ProcString += value; ProcString += value;
else else
@ -797,7 +797,7 @@ string CSystemInfo::getProc ()
ProcString += " / "; ProcString += " / ";
// get processor frequency // 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) if (result == ERROR_SUCCESS)
{ {
uint32 freq = *(int *)value; uint32 freq = *(int *)value;
@ -1062,7 +1062,7 @@ uint64 CSystemInfo::availableHDSpace (const string &filename)
return (uint64)(stfs.f_bavail * stst.st_blksize); return (uint64)(stfs.f_bavail * stst.st_blksize);
#else #else
ULARGE_INTEGER freeSpace = {0}; 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; if (!bRes) return 0;
return (uint64)freeSpace.QuadPart; return (uint64)freeSpace.QuadPart;
@ -1387,12 +1387,12 @@ bool CSystemInfo::getVideoInfo (std::string &deviceName, uint64 &driverVersion)
} }
// Version dll link // Version dll link
HMODULE hmVersion = LoadLibrary (_T("version")); HMODULE hmVersion = LoadLibraryA ("version.dll");
if (hmVersion) if (hmVersion)
{ {
BOOL (WINAPI* _GetFileVersionInfo)(LPTSTR, DWORD, DWORD, LPVOID) = NULL; BOOL (WINAPI* _GetFileVersionInfo)(LPSTR, DWORD, DWORD, LPVOID) = NULL;
DWORD (WINAPI* _GetFileVersionInfoSize)(LPTSTR, LPDWORD) = NULL; DWORD (WINAPI* _GetFileVersionInfoSize)(LPSTR, LPDWORD) = NULL;
BOOL (WINAPI* _VerQueryValue)(const LPVOID, LPTSTR, LPVOID*, PUINT) = NULL; BOOL (WINAPI* _VerQueryValue)(const LPVOID, LPSTR, LPVOID*, PUINT) = NULL;
*(FARPROC*)&_GetFileVersionInfo = GetProcAddress(hmVersion, "GetFileVersionInfoA"); *(FARPROC*)&_GetFileVersionInfo = GetProcAddress(hmVersion, "GetFileVersionInfoA");
*(FARPROC*)&_GetFileVersionInfoSize = GetProcAddress(hmVersion, "GetFileVersionInfoSizeA"); *(FARPROC*)&_GetFileVersionInfoSize = GetProcAddress(hmVersion, "GetFileVersionInfoSizeA");
*(FARPROC*)&_VerQueryValue = GetProcAddress(hmVersion, "VerQueryValueA"); *(FARPROC*)&_VerQueryValue = GetProcAddress(hmVersion, "VerQueryValueA");

View file

@ -273,14 +273,14 @@ bool CSystemUtils::isScreensaverEnabled()
// SystemParametersInfoA(SPI_GETSCREENSAVEACTIVE, 0, &bRetValue, 0); // SystemParametersInfoA(SPI_GETSCREENSAVEACTIVE, 0, &bRetValue, 0);
// res = (bRetValue == TRUE); // res = (bRetValue == TRUE);
HKEY hKeyScreenSaver = NULL; 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) if (lReturn == ERROR_SUCCESS)
{ {
DWORD dwType = 0L; DWORD dwType = 0L;
DWORD dwSize = KeyMaxLength; DWORD dwSize = KeyMaxLength;
unsigned char Buffer[KeyMaxLength] = {0}; 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 SCRNSAVE.EXE is present, check also if it's empty
if (lReturn == ERROR_SUCCESS) if (lReturn == ERROR_SUCCESS)
res = (Buffer[0] != '\0'); res = (Buffer[0] != '\0');
@ -315,19 +315,19 @@ string CSystemUtils::getRegKey(const string &Entry)
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
HKEY hkey; 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 dwType = 0L;
DWORD dwSize = KeyMaxLength; DWORD dwSize = KeyMaxLength;
unsigned char Buffer[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()); nlwarning("Can't get the reg key '%s'", Entry.c_str());
} }
else else
{ {
ret = (char*)Buffer; ret = wideToUtf8(Buffer);
} }
RegCloseKey(hkey); RegCloseKey(hkey);
} }
@ -346,10 +346,12 @@ bool CSystemUtils::setRegKey(const string &ValueName, const string &Value)
HKEY hkey; HKEY hkey;
DWORD dwDisp; DWORD dwDisp;
char nstr[] = { 0x00 }; wchar_t nstr[] = { 0x00 };
if (RegCreateKeyExA(HKEY_CURRENT_USER, RootKey.c_str(), 0, nstr, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) if (RegCreateKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, 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; res = true;
RegCloseKey(hkey); RegCloseKey(hkey);
} }
@ -453,7 +455,7 @@ static void EnumerateUsingDXGI(IDXGIFactory *pDXGIFactory)
{ {
SAdapter adapter; SAdapter adapter;
adapter.id = index; adapter.id = index;
adapter.name = ucstring((ucchar*)desc.Description).toUtf8(); adapter.name = wideToUtf8(desc.Description);
adapter.memory = desc.DedicatedVideoMemory / 1024; adapter.memory = desc.DedicatedVideoMemory / 1024;
adapter.found = true; adapter.found = true;

View file

@ -32,12 +32,12 @@ namespace NLMISC
void CWin32Util::localizeWindow(HWND wnd) void CWin32Util::localizeWindow(HWND wnd)
{ {
if (!wnd) return; if (!wnd) return;
int textLength = GetWindowTextLength(wnd); sint textLength = GetWindowTextLengthW(wnd);
if (textLength > 0) if (textLength > 0)
{ {
std::vector<char> str(textLength + 1); wchar_t str[1024];
GetWindowText(wnd, &str[0], textLength + 1); GetWindowTextW(wnd, str, 1024);
std::string winText(str.begin(), str.end() - 1); std::string winText = wideToUtf8(str);
if (CI18N::hasTranslation(winText)) if (CI18N::hasTranslation(winText))
{ {
SetWindowTextW(wnd, (const WCHAR *) CI18N::get(winText).c_str()); SetWindowTextW(wnd, (const WCHAR *) CI18N::get(winText).c_str());

View file

@ -40,7 +40,7 @@ using namespace std;
namespace NLMISC { namespace NLMISC {
static CHARFORMAT2 CharFormat; static CHARFORMAT2A CharFormat;
CWinDisplayer::CWinDisplayer(const char *displayerName) : CWindowDisplayer(displayerName), Exit(false) 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); CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtr (hWnd, GWLP_USERDATA);
// get the text as unicode string // get the text as unicode string
GetWindowTextW(cwd->_HInputEdit, wText, 20000); GetWindowTextW(cwd->_HInputEdit, wText, 20000);
ucstring ucs((ucchar*)wText);
// and convert it to UTF-8 encoding. // and convert it to UTF-8 encoding.
TextSend = ucs.toUtf8(); TextSend = wideToUtf8(wText);
SendMessage (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)""); SendMessageA (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)"");
const char *pos2 = TextSend.c_str(); const char *pos2 = TextSend.c_str();
string str; string str;
while (*pos2 != '\0') while (*pos2 != '\0')
@ -193,14 +192,13 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// get the text as unicode string // get the text as unicode string
GetWindowTextW(cwd->_HInputEdit, wText, 20000); GetWindowTextW(cwd->_HInputEdit, wText, 20000);
ucstring ucs((ucchar*)wText);
// and convert it to UTF-8 encoding // and convert it to UTF-8 encoding
string str = ucs.toUtf8(); string str = wideToUtf8(wText);
nlassert (cwd->Log != NULL); nlassert (cwd->Log != NULL);
ICommand::expand (str, *cwd->Log); 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; return 1;
} }
@ -209,7 +207,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
if (pmf->wParam == VK_UP) if (pmf->wParam == VK_UP)
{ {
CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrW (hWnd, GWLP_USERDATA); CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrA (hWnd, GWLP_USERDATA);
if (cwd->_PosInHistory > 0) if (cwd->_PosInHistory > 0)
cwd->_PosInHistory--; cwd->_PosInHistory--;
@ -221,7 +219,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ucs.fromUtf8(cwd->_History[cwd->_PosInHistory]); ucs.fromUtf8(cwd->_History[cwd->_PosInHistory]);
// set the text as unicode string // set the text as unicode string
SetWindowTextW(cwd->_HInputEdit, (LPCWSTR)ucs.c_str()); 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) 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]); ucs.fromUtf8(cwd->_History[cwd->_PosInHistory]);
// set the text as unicode string // set the text as unicode string
SetWindowTextW(cwd->_HInputEdit, (LPCWSTR)ucs.c_str()); 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 // create a button for command and label for variables
if (access.value()[i].Value[0] == '@') 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 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; 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; access.value()[i].NeedUpdate = false;
} }
} }
@ -427,14 +425,14 @@ void CWinDisplayer::open (string titleBar, bool iconified, sint x, sint y, sint
dwStyle |= WS_HSCROLL; 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); _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 :) // 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.cbSize = sizeof(CharFormat);
CharFormat.dwMask = CFM_COLOR; CharFormat.dwMask = CFM_COLOR;
SendMessage(_HEdit,EM_GETCHARFORMAT,(WPARAM)0,(LPARAM)&CharFormat); SendMessageA(_HEdit,EM_GETCHARFORMAT,(WPARAM)0,(LPARAM)&CharFormat);
CharFormat.dwEffects &= ~CFE_AUTOCOLOR; CharFormat.dwEffects &= ~CFE_AUTOCOLOR;
// create the input edit control // 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); LRESULT dwEvent = SendMessageW(_HInputEdit, EM_GETEVENTMASK, (WPARAM)0, (LPARAM)0);
dwEvent |= ENM_MOUSEEVENTS | ENM_KEYEVENTS | ENM_CHANGE; 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 // resize the window
RECT rc; RECT rc;
@ -477,8 +475,8 @@ void CWinDisplayer::clear ()
bool focus = (GetFocus() == _HEdit); bool focus = (GetFocus() == _HEdit);
if (focus) if (focus)
{ {
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL); SendMessageA(_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_AUTOHSCROLL);
} }
// get number of line // get number of line
@ -534,13 +532,13 @@ void CWinDisplayer::display_main ()
bool focus = (GetFocus() == _HEdit); bool focus = (GetFocus() == _HEdit);
if (focus) if (focus)
{ {
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL); SendMessageA(_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_AUTOHSCROLL);
} }
// store old selection // store old selection
DWORD startSel, endSel; 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 // 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) if (nblineremove == _HistorySize)
{ {
SendMessage (_HEdit, WM_SETTEXT, 0, (LPARAM) ""); SendMessageA (_HEdit, WM_SETTEXT, 0, (LPARAM) "");
startSel = endSel = -1; startSel = endSel = -1;
} }
else else
@ -594,13 +592,13 @@ void CWinDisplayer::display_main ()
str += ucstring::makeFromUtf8((*it).second); str += ucstring::makeFromUtf8((*it).second);
} }
SendMessage (_HEdit, EM_SETSEL, -1, -1); SendMessageA(_HEdit, EM_SETSEL, -1, -1);
if ((col>>24) == 0) if ((col>>24) == 0)
{ {
// there s a specific color // there s a specific color
CharFormat.crTextColor = RGB ((col>>16)&0xFF, (col>>8)&0xFF, col&0xFF); 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 // add the string to the edit control
@ -608,17 +606,17 @@ void CWinDisplayer::display_main ()
} }
// restore old selection // 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) if (bottom)
SendMessage(_HEdit,WM_VSCROLL,(WPARAM)SB_BOTTOM,(LPARAM)0L); SendMessageA(_HEdit,WM_VSCROLL,(WPARAM)SB_BOTTOM,(LPARAM)0L);
if (focus) if (focus)
{ {
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOVSCROLL); SendMessageA(_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_AUTOHSCROLL);
} }
} }

View file

@ -277,10 +277,10 @@ uint64 CWinThread::getCPUMask()
std::string CWinThread::getUserName() std::string CWinThread::getUserName()
{ {
char userName[512]; wchar_t userName[512];
DWORD size = 512; DWORD size = 512;
GetUserName (userName, &size); GetUserNameW (userName, &size);
return (const char*)userName; return wideToUtf8(userName);
} }
// **** Process // **** Process
@ -333,10 +333,10 @@ class CPSAPILib
{ {
public: public:
typedef BOOL (WINAPI *EnumProcessesFunPtr)(DWORD *lpidProcess, DWORD cb, DWORD *cbNeeded); 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); typedef BOOL (WINAPI *EnumProcessModulesFunPtr)(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded);
EnumProcessesFunPtr EnumProcesses; EnumProcessesFunPtr EnumProcesses;
GetModuleFileNameExAFunPtr GetModuleFileNameExA; GetModuleFileNameExWFunPtr GetModuleFileNameExW;
EnumProcessModulesFunPtr EnumProcessModules; EnumProcessModulesFunPtr EnumProcessModules;
public: public:
CPSAPILib(); CPSAPILib();
@ -353,7 +353,7 @@ CPSAPILib::CPSAPILib()
_LoadFailed = false; _LoadFailed = false;
_PSAPILibHandle = NULL; _PSAPILibHandle = NULL;
EnumProcesses = NULL; EnumProcesses = NULL;
GetModuleFileNameExA = NULL; GetModuleFileNameExW = NULL;
EnumProcessModules = NULL; EnumProcessModules = NULL;
} }
@ -373,7 +373,7 @@ bool CPSAPILib::init()
if (_LoadFailed) return false; if (_LoadFailed) return false;
if (!_PSAPILibHandle) if (!_PSAPILibHandle)
{ {
_PSAPILibHandle = LoadLibrary("psapi.dll"); _PSAPILibHandle = LoadLibraryA("psapi.dll");
if (!_PSAPILibHandle) if (!_PSAPILibHandle)
{ {
nlwarning("couldn't load psapi.dll, possibly not supported by os"); nlwarning("couldn't load psapi.dll, possibly not supported by os");
@ -381,10 +381,10 @@ bool CPSAPILib::init()
return false; return false;
} }
EnumProcesses = (EnumProcessesFunPtr) GetProcAddress(_PSAPILibHandle, "EnumProcesses"); EnumProcesses = (EnumProcessesFunPtr) GetProcAddress(_PSAPILibHandle, "EnumProcesses");
GetModuleFileNameExA = (GetModuleFileNameExAFunPtr) GetProcAddress(_PSAPILibHandle, "GetModuleFileNameExA"); GetModuleFileNameExW = (GetModuleFileNameExWFunPtr) GetProcAddress(_PSAPILibHandle, "GetModuleFileNameExW");
EnumProcessModules = (EnumProcessModulesFunPtr) GetProcAddress(_PSAPILibHandle, "EnumProcessModules"); EnumProcessModules = (EnumProcessModulesFunPtr) GetProcAddress(_PSAPILibHandle, "EnumProcessModules");
if (!EnumProcesses || if (!EnumProcesses ||
!GetModuleFileNameExA || !GetModuleFileNameExW ||
!EnumProcessModules !EnumProcessModules
) )
{ {
@ -453,12 +453,12 @@ bool CWinProcess::enumProcessModules(uint32 processId, std::vector<std::string>
} }
moduleNames.clear(); moduleNames.clear();
std::vector<std::string> resultModuleNames; std::vector<std::string> resultModuleNames;
char moduleName[MAX_PATH + 1]; wchar_t moduleName[MAX_PATH + 1];
for (uint m = 0; m < prcModules.size(); ++m) 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); CloseHandle(hProcess);
@ -563,7 +563,7 @@ public:
PROCESS_INFORMATION processInfo; PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo = {0}; STARTUPINFO startupInfo = {0};
startupInfo.cb = sizeof(STARTUPINFO); startupInfo.cb = sizeof(STARTUPINFO);
if (CreateProcess(programName.c_str(), const_cast<LPTSTR>(arguments.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo)) if (CreateProcessW(programName.c_str(), const_cast<LPTSTR>(arguments.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo))
{ {
WatchTask = new CProcessWatchTask(processInfo.hProcess); WatchTask = new CProcessWatchTask(processInfo.hProcess);
WatchThread = IThread::create(WatchTask); WatchThread = IThread::create(WatchTask);

View file

@ -93,7 +93,7 @@ namespace NLMISC
TXMLPackInfo &packInfo = _XMLPacks[packId]; TXMLPackInfo &packInfo = _XMLPacks[packId];
// open the xml pack for later access // 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 // open the xml pack for parsing
CIFile packFile; CIFile packFile;
@ -182,7 +182,7 @@ namespace NLMISC
fileInfo.FileName = CStringMapper::map(subFileName); fileInfo.FileName = CStringMapper::map(subFileName);
fileInfo.FileOffset = (uint32)(beginOfFile - buffer.begin()); fileInfo.FileOffset = (uint32)(beginOfFile - buffer.begin());
fileInfo.FileSize = (uint32)(endOfFile - beginOfFile); 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)); packInfo._XMLFiles.insert(make_pair(fileInfo.FileName, fileInfo));
// advance to next line // advance to next line
@ -264,7 +264,7 @@ namespace NLMISC
rFileOffset = fileInfo.FileOffset; rFileOffset = fileInfo.FileOffset;
rCacheFileOnOpen = false; rCacheFileOnOpen = false;
rAlwaysOpened = false; rAlwaysOpened = false;
FILE *fp = fopen(parts[0].c_str(), "rb"); FILE *fp = nlfopen(parts[0], "rb");
return fp; return fp;
} }

View file

@ -271,7 +271,7 @@ bool sendEmail (const string &smtpServer, const string &from, const string &to,
char dst_buf[dst_buf_size + 1]; char dst_buf[dst_buf_size + 1];
size_t size; size_t size;
FILE *src_stream = fopen (attachedFile.c_str(), "rb"); FILE *src_stream = nlfopen (attachedFile, "rb");
if (src_stream == NULL) if (src_stream == NULL)
{ {
nlwarning ("EMAIL: Can't attach file '%s' to the email because the file can't be open", attachedFile.c_str()); 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 // 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); // fwrite (formatedBody.c_str(), 1, formatedBody.size(), fp);
// fclose (fp); } // fclose (fp); }

View file

@ -575,7 +575,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName,
if (haveLongArg("writepid")) if (haveLongArg("writepid"))
{ {
// use legacy C primitives // use legacy C primitives
FILE *fp = fopen("pid.state", "wt"); FILE *fp = nlfopen("pid.state", "wt");
if (fp) if (fp)
{ {
fprintf(fp, "%u", getpid()); fprintf(fp, "%u", getpid());
@ -600,7 +600,6 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName,
ListeningPort = servicePort; ListeningPort = servicePort;
// setReportEmailFunction ((void*)sendEmail);
// setDefaultEmailParams ("gw.nevrax.com", "", "cado@nevrax.com"); // setDefaultEmailParams ("gw.nevrax.com", "", "cado@nevrax.com");
@ -623,7 +622,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName,
else else
{ {
// create the basic .cfg that link the default one // create the basic .cfg that link the default one
FILE *fp = fopen (cfn.c_str(), "w"); FILE *fp = nlfopen (cfn, "w");
if (fp == NULL) if (fp == NULL)
{ {
nlerror ("SERVICE: Can't create config file '%s'", cfn.c_str()); nlerror ("SERVICE: Can't create config file '%s'", cfn.c_str());

View file

@ -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)

View file

@ -16,7 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <nel/misc/types_nl.h> #include <nel/misc/types_nl.h>
#include "database_config.h" #include "nel/pipeline/database_config.h"
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
@ -25,6 +25,8 @@
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
namespace NLPIPELINE {
TPathString CDatabaseConfig::s_RootPath; TPathString CDatabaseConfig::s_RootPath;
NLMISC::CConfigFile *CDatabaseConfig::s_ConfigFile = NULL; NLMISC::CConfigFile *CDatabaseConfig::s_ConfigFile = NULL;
CDatabaseConfig CDatabaseConfig::s_Instance; CDatabaseConfig CDatabaseConfig::s_Instance;
@ -104,4 +106,6 @@ void CDatabaseConfig::release()
cleanup(); cleanup();
} }
} /* namespace NLPIPELINE */
/* end of file */ /* end of file */

View file

@ -0,0 +1,238 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2015 Winch Gate Property Limited
// Author: Jan Boon <jan.boon@kaetemi.be>
//
// 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 <http://www.gnu.org/licenses/>.
#include <nel/misc/types_nl.h>
#include "nel/pipeline/project_config.h"
#ifdef NL_OS_WINDOWS
# include <Windows.h>
#else
# include <stdlib.h>
#endif
#include <algorithm>
#include <nel/misc/debug.h>
#include <nel/misc/path.h>
#include <nel/misc/config_file.h>
using namespace std;
using namespace NLMISC;
namespace NLPIPELINE {
TPathString CProjectConfig::s_AssetConfigPath;
TPathString CProjectConfig::s_ProjectConfigPath;
std::vector<NLMISC::CConfigFile *> CProjectConfig::s_ConfigFiles;
std::vector<TPathString> 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<TPathString> s_SearchPaths;
void CProjectConfig::cleanup()
{
for (std::vector<NLMISC::CConfigFile *>::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<TPathString> 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<std::string> files;
CPath::getPathContent(CPath::getApplicationDirectory("NeL", true) + "/projects", false, false, true, files);
for (std::vector<std::string>::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<std::string, CConfigFile *> configFiles;
for (std::vector<TPathString>::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<NLMISC::CConfigFile *>::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 */

View file

@ -25,8 +25,7 @@
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
#include "stdmisc.h" #include "nel/pipeline/tool_logger.h"
#include "nel/misc/tool_logger.h"
// STL includes // STL includes
@ -35,11 +34,11 @@
// Project includes // 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. // Tool logger is fully implemented in header so small tools do not need to link to this library unnecessarily.
void dummy_tool_logger_cpp() { } void dummy_tool_logger_cpp() { }
} /* namespace NLMISC */ } /* namespace NLPIPELINE */
/* end of file */ /* end of file */

View file

@ -110,16 +110,19 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st
CIFile ifile; CIFile ifile;
ifile.setCacheFileOnOpen(false); ifile.setCacheFileOnOpen(false);
ifile.allowBNPCacheFileOnOpen(false); ifile.allowBNPCacheFileOnOpen(false);
ifile.open(lookup); if (ifile.open(lookup))
return CAudioDecoderVorbis::getInfo(&ifile, artist, title); return CAudioDecoderVorbis::getInfo(&ifile, artist, title);
nlwarning("Unable to open: '%s'", filepath.c_str());
} }
else else
{ {
nlwarning("Music file type unknown: '%s'", type_lower.c_str()); nlwarning("Music file type unknown: '%s'", type_lower.c_str());
}
artist.clear(); title.clear(); artist.clear(); title.clear();
return false; return false;
} }
}
/// Get audio/container extensions that are currently supported by the nel sound library. /// Get audio/container extensions that are currently supported by the nel sound library.
void IAudioDecoder::getMusicExtensions(std::vector<std::string> &extensions) void IAudioDecoder::getMusicExtensions(std::vector<std::string> &extensions)

View file

@ -266,8 +266,7 @@ void CSoundDriverXAudio2::getDevices(std::vector<std::string> &devices)
for (uint i = 0; i < deviceCount; ++i) for (uint i = 0; i < deviceCount; ++i)
{ {
_XAudio2->GetDeviceDetails(i, &deviceDetails); _XAudio2->GetDeviceDetails(i, &deviceDetails);
std::basic_string<WCHAR> deviceNameW = deviceDetails.DisplayName; std::string deviceName = wideToUtf8(deviceDetails.DisplayName);
std::string deviceName = std::string(deviceNameW.begin(), deviceNameW.end());
nldebug("XA2: - %s", deviceName.c_str()); nldebug("XA2: - %s", deviceName.c_str());
devices.push_back(deviceName); devices.push_back(deviceName);
} }
@ -289,8 +288,7 @@ uint CSoundDriverXAudio2::getDeviceIndex(const std::string &device, XAUDIO2_DEVI
for (uint i = 0; i < deviceCount; ++i) for (uint i = 0; i < deviceCount; ++i)
{ {
_XAudio2->GetDeviceDetails(i, deviceDetails); _XAudio2->GetDeviceDetails(i, deviceDetails);
std::basic_string<WCHAR> deviceNameW = deviceDetails->DisplayName; std::string deviceName = wideToUtf8(deviceDetails->DisplayName);
std::string deviceName = std::string(deviceNameW.begin(), deviceNameW.end());
if (deviceName == device) if (deviceName == device)
return i; return i;
} }

View file

@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES(${assimp_INCLUDE_DIRS})
NL_TARGET_LIB(mesh_utils ${SRCS} ${HDRS}) 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_DEFAULT_PROPS(mesh_utils "NeL, Tools, 3D: Mesh Utils")
NL_ADD_RUNTIME_FLAGS(mesh_utils) NL_ADD_RUNTIME_FLAGS(mesh_utils)

View file

@ -28,7 +28,7 @@
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/misc/tool_logger.h> #include <nel/pipeline/tool_logger.h>
#include <nel/3d/mesh.h> #include <nel/3d/mesh.h>
#include <nel/3d/texture_file.h> #include <nel/3d/texture_file.h>

View file

@ -28,7 +28,7 @@
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/misc/tool_logger.h> #include <nel/pipeline/tool_logger.h>
#include <nel/3d/mesh.h> #include <nel/3d/mesh.h>

View file

@ -19,7 +19,8 @@
#include "mesh_utils.h" #include "mesh_utils.h"
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/tool_logger.h> #include <nel/pipeline/tool_logger.h>
#include <nel/pipeline/project_config.h>
#include <nel/misc/sstring.h> #include <nel/misc/sstring.h>
#include <nel/misc/file.h> #include <nel/misc/file.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
@ -28,7 +29,6 @@
#include <nel/3d/mesh.h> #include <nel/3d/mesh.h>
#include <nel/3d/texture_file.h> #include <nel/3d/texture_file.h>
#include "database_config.h"
#include "scene_meta.h" #include "scene_meta.h"
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
@ -231,7 +231,7 @@ void exportShapes(CMeshUtilsContext &context)
if (nodeContext.Shape) if (nodeContext.Shape)
{ {
std::string shapePath = NLMISC::CPath::standardizePath(context.Settings.DestinationDirectoryPath, true) + it->first + ".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; NLMISC::COFile f;
if (f.open(shapePath, false, false, true)) 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); std::string knownPath = NLMISC::CPath::lookup(fileName, false, false, false);
if (!knownPath.empty()) 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 else
{ {
@ -289,17 +289,17 @@ int exportScene(const CMeshUtilsSettings &settings)
context.ToolLogger.initDepend(settings.ToolDependLog); context.ToolLogger.initDepend(settings.ToolDependLog);
if (!settings.ToolErrorLog.empty()) if (!settings.ToolErrorLog.empty())
context.ToolLogger.initError(settings.ToolErrorLog); 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 // 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."); 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; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(settings.SourceFilePath, 0 const aiScene *scene = importer.ReadFile(settings.SourceFilePath, 0
| aiProcess_Triangulate | aiProcess_Triangulate
@ -321,7 +321,7 @@ int exportScene(const CMeshUtilsSettings &settings)
context.InternalScene = scene; context.InternalScene = scene;
if (context.SceneMeta.load(context.Settings.SourceFilePath)) 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); validateInternalNodeNames(context, context.InternalScene->mRootNode);

View file

@ -20,7 +20,7 @@
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/misc/tool_logger.h> #include <nel/pipeline/tool_logger.h>
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;

View file

@ -23,7 +23,7 @@
#include "scene_meta.h" #include "scene_meta.h"
#include <nel/misc/sstring.h> #include <nel/misc/sstring.h>
#include <nel/misc/tool_logger.h> #include <nel/pipeline/tool_logger.h>
#include <nel/misc/smart_ptr.h> #include <nel/misc/smart_ptr.h>
#include <nel/misc/matrix.h> #include <nel/misc/matrix.h>
@ -67,7 +67,7 @@ struct CMeshUtilsContext
const CMeshUtilsSettings &Settings; const CMeshUtilsSettings &Settings;
NLMISC::CToolLogger ToolLogger; NLPIPELINE::CToolLogger ToolLogger;
const NL_SCENE_INTERNAL_TYPE *InternalScene; const NL_SCENE_INTERNAL_TYPE *InternalScene;
CSceneMeta SceneMeta; CSceneMeta SceneMeta;

View file

@ -63,7 +63,7 @@ QVariant tiles_model::data(const QModelIndex &index, int role) const
#ifdef USE_QT5 #ifdef USE_QT5
QPixmap pixpix = wiwi.grab(wiwi.contentsRect()); QPixmap pixpix = wiwi.grab(wiwi.contentsRect());
#else #else
QPixmap::grabWidget(wiwi, wiwi.contentsRect()); QPixmap pixpix = QPixmap::grabWidget(&wiwi, wiwi.contentsRect());
#endif #endif
return pixpix; return pixpix;
} }
@ -78,7 +78,6 @@ QVariant tiles_model::data(const QModelIndex &index, int role) const
void tiles_model::sort ( int column, Qt::SortOrder order) void tiles_model::sort ( int column, Qt::SortOrder order)
{ {
qSort(tiles.begin(), tiles.end(), caseInsensitiveLessThan); qSort(tiles.begin(), tiles.end(), caseInsensitiveLessThan);
} }

View file

@ -72,7 +72,7 @@ private:
+ " </PRIMITIVE>\n" + " </PRIMITIVE>\n"
+ "</NEL_LIGO_PRIMITIVE_CLASS>"; + "</NEL_LIGO_PRIMITIVE_CLASS>";
FILE *fp = fopen(CLASS_FILE_NAME, "wt"); FILE *fp = NLMISC::nlfopen(CLASS_FILE_NAME, "wt");
nlassert(fp != NULL); nlassert(fp != NULL);
size_t s = fwrite(classfile.data(), 1, classfile.size(), fp); size_t s = fwrite(classfile.data(), 1, classfile.size(), fp);
nlassert(s == classfile.size()); nlassert(s == classfile.size());

View file

@ -19,6 +19,7 @@
#include <nel/misc/file.h> #include <nel/misc/file.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/misc/common.h>
// Test suite for NLMISC::CFile behavior // Test suite for NLMISC::CFile behavior
struct CUTMiscFile : public Test::Suite struct CUTMiscFile : public Test::Suite
@ -49,7 +50,7 @@ private:
void copyFileSize(uint fileSize) void copyFileSize(uint fileSize)
{ {
// create a source file (using standard c code) // create a source file (using standard c code)
FILE *fp = fopen(_SrcFile.c_str(), "wb"); FILE *fp = NLMISC::nlfopen(_SrcFile, "wb");
nlverify(fp != NULL); nlverify(fp != NULL);
for (uint i=0; i<fileSize; ++i) for (uint i=0; i<fileSize; ++i)
@ -63,7 +64,7 @@ private:
NLMISC::CFile::copyFile(_DstFile, _SrcFile, false); NLMISC::CFile::copyFile(_DstFile, _SrcFile, false);
// verify the resulting file // verify the resulting file
fp = fopen(_DstFile.c_str(), "rb"); fp = NLMISC::nlfopen(_DstFile, "rb");
TEST_ASSERT(fp != NULL); TEST_ASSERT(fp != NULL);
if (fp) if (fp)
{ {
@ -108,7 +109,7 @@ private:
void moveFileSize(size_t fileSize) void moveFileSize(size_t fileSize)
{ {
// remove the destination if any // remove the destination if any
FILE *fp = fopen(_DstFile.c_str(), "rb"); FILE *fp = NLMISC::nlfopen(_DstFile, "rb");
if (fp != NULL) if (fp != NULL)
{ {
fclose(fp); fclose(fp);
@ -116,7 +117,7 @@ private:
} }
// create a source file (using standard c code) // create a source file (using standard c code)
fp = fopen(_SrcFile.c_str(), "wb"); fp = NLMISC::nlfopen(_SrcFile, "wb");
nlverify(fp != NULL); nlverify(fp != NULL);
for (uint i=0; i<fileSize; ++i) for (uint i=0; i<fileSize; ++i)
@ -130,12 +131,12 @@ private:
NLMISC::CFile::moveFile(_DstFile, _SrcFile); NLMISC::CFile::moveFile(_DstFile, _SrcFile);
// verify the resulting file // verify the resulting file
fp = fopen(_SrcFile.c_str(), "rb"); fp = NLMISC::nlfopen(_SrcFile, "rb");
TEST_ASSERT_MSG(fp == NULL, "The source file is not removed"); TEST_ASSERT_MSG(fp == NULL, "The source file is not removed");
if (fp) if (fp)
fclose(fp); fclose(fp);
fp = fopen(_DstFile.c_str(), "rb"); fp = NLMISC::nlfopen(_DstFile, "rb");
TEST_ASSERT(fp != NULL); TEST_ASSERT(fp != NULL);
if (fp) if (fp)
{ {

View file

@ -104,29 +104,31 @@ void CCDBSynchronised::read( const string &fileName )
int linecount=1; int linecount=1;
#endif #endif
if( _Database == 0 ) if (_Database == NULL)
{ {
throw CCDBSynchronised::EDBNotInit(); throw CCDBSynchronised::EDBNotInit();
} }
ifstream f(fileName.c_str(), ios::in); CIFile f;
if( !f.is_open() )
if (!f.open(fileName, true))
{ {
nlerror("can't open file : %s\n", fileName.c_str()); nlerror("can't open file : %s\n", fileName.c_str());
} }
while(!f.eof()) while(!f.eof())
{ {
string line; char line[1024];
getline(f,line,'\n'); f.getline(line, 1024);
#ifdef _DEBUG #ifdef _DEBUG
nlinfo("%s:%i", fileName.c_str(), linecount); nlinfo("%s:%i", fileName.c_str(), linecount);
linecount++; linecount++;
#endif #endif
char * token; char * token;
char * buffer = new char[line.size()+1]; char * buffer = new char[strlen(line)+1];
strcpy(buffer,line.c_str()); strcpy(buffer, line);
// value // value
token = strtok(buffer," \t"); token = strtok(buffer," \t");
@ -156,15 +158,22 @@ void CCDBSynchronised::read( const string &fileName )
//----------------------------------------------- //-----------------------------------------------
void CCDBSynchronised::write( const string &fileName ) void CCDBSynchronised::write( const string &fileName )
{ {
bool res = false;
if( _Database != 0 ) if( _Database != 0 )
{ {
FILE * f; FILE * f = nlfopen(fileName, "w");
f = fopen(fileName.c_str(),"w"); if (f)
{
ICDBNode::CTextId id; ICDBNode::CTextId id;
_Database->write(id,f); _Database->write(id,f);
fclose(f); fclose(f);
res = true;
} }
else }
if (!res)
{ {
nlwarning("<CCDBSynchronised::write> can't write %s : the database has not been initialized",fileName.c_str()); nlwarning("<CCDBSynchronised::write> can't write %s : the database has not been initialized",fileName.c_str());
} }

View file

@ -175,7 +175,7 @@ int main(int argc, char **argv)
Args.setVersion(getDisplayVersion()); Args.setVersion(getDisplayVersion());
Args.setDescription("Ryzom client"); 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("login", "Login to use", true, false);
Args.addAdditionalArg("password", "Password to use", true, false); Args.addAdditionalArg("password", "Password to use", true, false);
Args.addAdditionalArg("shard_id", "Shard ID 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<uint32>::max(); LoginShardId = std::numeric_limits<uint32>::max();
// if client_default.cfg is not in current directory, use application default directory // 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"); std::string currentPath = CPath::getApplicationDirectory("Ryzom");
// append config ID to directory // append profile ID to directory
if (Args.haveArg("c")) if (Args.haveArg("p"))
currentPath = NLMISC::CPath::standardizePath(currentPath) + Args.getArg("c").front(); currentPath = NLMISC::CPath::standardizePath(currentPath) + Args.getArg("p").front();
if (!CFile::isExists(currentPath)) CFile::createDirectory(currentPath); if (!CFile::isExists(currentPath)) CFile::createDirectory(currentPath);

View file

@ -877,6 +877,7 @@ void CClientConfig::setValues()
// defined in client_default.cfg // defined in client_default.cfg
READ_STRING_FV(ConditionsTermsURL) READ_STRING_FV(ConditionsTermsURL)
READ_STRING_FV(NamingPolicyURL)
READ_STRING_FV(LoginSupportURL) READ_STRING_FV(LoginSupportURL)
#ifndef RZ_NO_CLIENT #ifndef RZ_NO_CLIENT
@ -1921,7 +1922,7 @@ void CClientConfig::init(const string &configFileName)
if(!CFile::fileExists(configFileName)) if(!CFile::fileExists(configFileName))
{ {
// create the basic .cfg // create the basic .cfg
FILE *fp = fopen(configFileName.c_str(), "w"); FILE *fp = nlfopen(configFileName, "w");
if (fp == NULL) if (fp == NULL)
nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str()); nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str());

View file

@ -160,6 +160,7 @@ struct CClientConfig
string CreateAccountURL; string CreateAccountURL;
string EditAccountURL; string EditAccountURL;
string ConditionsTermsURL; string ConditionsTermsURL;
string NamingPolicyURL;
string BetaAccountURL; string BetaAccountURL;
string ForgetPwdURL; string ForgetPwdURL;
string FreeTrialURL; string FreeTrialURL;

View file

@ -695,7 +695,7 @@ NLMISC_COMMAND(bugReport, "Call the bug report tool with dump", "<AddScreenshot>
if (ClientCfg.Local) if (ClientCfg.Local)
sys += "ShardName OFFLINE "; 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) if (fp != NULL)
{ {
string res = addSlashR(getDebugInformation()); string res = addSlashR(getDebugInformation());

View file

@ -15,9 +15,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdpch.h" #include "stdpch.h"
#include <curl/curl.h>
#include "http_client_curl.h" #include "http_client_curl.h"
#include <curl/curl.h>
#include <openssl/ssl.h>
using namespace NLMISC; using namespace NLMISC;
using namespace NLNET; using namespace NLNET;
using namespace std; 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" 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<uint8> 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) bool CCurlHttpClient::verifyServer(bool verify)
{ {
curl_easy_setopt(_Curl, CURLOPT_SSL_VERIFYHOST, verify ? 2 : 0); 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_SSL_VERIFYPEER, verify ? 1 : 0);
curl_easy_setopt(_Curl, CURLOPT_SSLCERTTYPE, "PEM"); 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 // 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); curl_easy_setopt(_Curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);
nldebug("cert path '%s'", path.c_str()); // 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_CAINFO, path.c_str());
curl_easy_setopt(_Curl, CURLOPT_CAPATH, NULL); curl_easy_setopt(_Curl, CURLOPT_CAPATH, NULL);
return true; return true;
} }

View file

@ -271,7 +271,7 @@ static INT_PTR CALLBACK ExitClientErrorDialogProc(HWND hwndDlg, UINT uMsg, WPARA
GetWindowRect (GetDesktopWindow (), &rectDesktop); 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); 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)); 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; break;
case WM_COMMAND: case WM_COMMAND:

View file

@ -3937,13 +3937,15 @@ public:
s += getSystemInformation(); s += getSystemInformation();
string progname; string progname;
char name[1024] = ""; std::string moduleName;
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
GetModuleFileName (NULL, name, 1023); wchar_t name[1024];
GetModuleFileNameW(NULL, name, 1023);
moduleName = wideToUtf8(name);
#else #else
// TODO for Linux // TODO for Linux
#endif #endif
progname = CFile::getFilename(name); progname = CFile::getFilename(moduleName);
progname += " "; progname += " ";
progname += "Statistic Report"; progname += "Statistic Report";

View file

@ -2704,7 +2704,7 @@ void CInterfaceManager::log(const ucstring &str, const std::string &cat)
{ {
// Open file with the name of the player // Open file with the name of the player
const string fileName= "save/log_" + PlayerSelectedFileName + ".txt"; const string fileName= "save/log_" + PlayerSelectedFileName + ".txt";
FILE *f = fopen(fileName.c_str(), "at"); FILE *f = nlfopen(fileName, "at");
if (f != NULL) if (f != NULL)
{ {
const string finalString = string(NLMISC::IDisplayer::dateToHumanString()) + " (" + NLMISC::toUpper(cat) + ") * " + str.toUtf8(); const string finalString = string(NLMISC::IDisplayer::dateToHumanString()) + " (" + NLMISC::toUpper(cat) + ") * " + str.toUtf8();

View file

@ -196,11 +196,6 @@ public:
InitMouseWithCursor (true); InitMouseWithCursor (true);
Driver->showCursor (true); Driver->showCursor (true);
if (false) //supportUnicode())
{
}
else
{
bool oggSupported = false; bool oggSupported = false;
bool mp3Supported = false; bool mp3Supported = false;
@ -219,12 +214,12 @@ public:
std::vector<std::string> filters; std::vector<std::string> filters;
// supported formats // supported formats
filters.push_back("All Supported Files"); filters.push_back("All Supported Files"); // TODO: translate
std::string filter; std::string filter;
if (mp3Supported) filter += "*.mp3;*.mp2;*.mp1;"; if (mp3Supported) filter += "*.mp3;*.mp2;*.mp1;";
if (oggSupported) filter += "*.ogg;"; if (oggSupported) filter += "*.ogg;";
filter += "*.m3u"; filter += "*.m3u;*.m3u8";
filters.push_back(filter); filters.push_back(filter);
@ -243,8 +238,8 @@ public:
} }
// playlist // playlist
filters.push_back("Playlist Files (*.m3u)"); filters.push_back("Playlist Files (*.m3u;*.m3u8)");
filters.push_back("*.m3u"); filters.push_back("*.m3u;*.m3u8");
// all files // all files
filters.push_back("All Files (*.*)"); filters.push_back("All Files (*.*)");
@ -252,23 +247,23 @@ public:
filters.push_back(""); filters.push_back("");
static char szFilter[1024] = { '\0' }; static wchar_t szFilter[1024] = { '\0' };
uint offset = 0; uint offset = 0;
for(uint i = 0; i < filters.size(); ++i) for(uint i = 0; i < filters.size(); ++i)
{ {
strcpy(szFilter + offset, filters[i].c_str()); wcscpy(szFilter + offset, utf8ToWide(filters[i]));
// move offset to string length + 1 for \0 // move offset to string length + 1 for \0
offset += filters[i].length() + 1; offset += filters[i].length() + 1;
} }
// Filename buffer // Filename buffer
char buffer[65535]; wchar_t buffer[1024];
buffer[0]=0; buffer[0]=0;
OPENFILENAME ofn; OPENFILENAMEW ofn;
memset (&ofn, 0, sizeof(OPENFILENAME)); memset (&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME); ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = Driver ? Driver->getDisplay():NULL; ofn.hwndOwner = Driver ? Driver->getDisplay():NULL;
@ -277,25 +272,27 @@ public:
ofn.nFilterIndex = 0; ofn.nFilterIndex = 0;
ofn.lpstrFile = buffer; ofn.lpstrFile = buffer;
ofn.nMaxFile = sizeof(buffer); ofn.nMaxFile = sizeof(buffer);
ofn.lpstrTitle = "Play songs"; ofn.lpstrTitle = (wchar_t*)NLMISC::CI18N::get("uiPlaySongs").c_str();
ofn.Flags = OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING|OFN_EXPLORER; ofn.Flags = OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING|OFN_EXPLORER;
if (Driver) if (Driver)
Driver->beginDialogMode(); Driver->beginDialogMode();
if (GetOpenFileName (&ofn)) if (GetOpenFileNameW (&ofn))
{ {
bool useUtf8 = false;
// Skip the directory name // Skip the directory name
const char *bufferPtr = buffer; const wchar_t *bufferPtr = buffer;
// Multi filename ? // Multi filename ?
string path; string path;
if (ofn.nFileOffset>strlen(buffer)) if (ofn.nFileOffset>wcslen(buffer))
{ {
// Backup the path and point to the next filename // Backup the path and point to the next filename
path = buffer; path = wideToUtf8(buffer);
path += "\\"; path += "\\";
bufferPtr+=strlen(bufferPtr)+1; bufferPtr += wcslen(bufferPtr)+1;
} }
// Get selected files and playlists // Get selected files and playlists
@ -304,23 +301,34 @@ public:
while (*bufferPtr) while (*bufferPtr)
{ {
// Concat the directory name with the filename // Concat the directory name with the filename
if (toLower(CFile::getExtension(bufferPtr)) == "m3u") std::string ext = toLower(CFile::getExtension(wideToUtf8(bufferPtr)));
playlists.push_back (path+bufferPtr); if (ext == "m3u" || ext == "m3u8")
{
playlists.push_back (path + wideToUtf8(bufferPtr));
}
else else
filenames.push_back (path+bufferPtr); {
bufferPtr+=strlen(bufferPtr)+1; filenames.push_back (path + wideToUtf8(bufferPtr));
}
bufferPtr += wcslen(bufferPtr) + 1;
} }
// Sort songs by filename // Sort songs by filename
sort (filenames.begin(), filenames.end()); sort (filenames.begin(), filenames.end());
static uint8 utf8Header[] = { 0xefu, 0xbbu, 0xbfu };
// Add playlist // Add playlist
uint i; uint i;
for (i=0; i<playlists.size(); i++) for (i=0; i<playlists.size(); i++)
{ {
// Get the path of the playlist // Get the path of the playlist
string basePlaylist = CFile::getPath (playlists[i]); string basePlaylist = CFile::getPath (playlists[i]);
FILE *file = fopen (playlists[i].c_str(), "r"); FILE *file = nlfopen (playlists[i], "r");
bool useUtf8 = CFile::getExtension(playlists[i]) == "m3u8";
if (file) if (file)
{ {
char line[512]; char line[512];
@ -328,8 +336,15 @@ public:
{ {
// Not a comment line // Not a comment line
string lineStr = trim(std::string(line)); string lineStr = trim(std::string(line));
// id a UTF-8 BOM header is present, parse as UTF-8
if (!useUtf8 && lineStr.length() >= 3 && memcmp(line, utf8Header, 3) == 0)
useUtf8 = true;
if (!useUtf8) lineStr = ucstring(line).toUtf8();
if (lineStr[0] != '#') if (lineStr[0] != '#')
filenames.push_back (basePlaylist+lineStr); filenames.push_back (CPath::makePathAbsolute(lineStr, basePlaylist));
} }
fclose (file); fclose (file);
} }
@ -350,7 +365,6 @@ public:
if (Driver) if (Driver)
Driver->endDialogMode(); Driver->endDialogMode();
}
// Restore mouse // Restore mouse
InitMouseWithCursor (wasHardware); InitMouseWithCursor (wasHardware);

View file

@ -1787,7 +1787,7 @@ class CAHReboot : public IActionHandler
} }
catch (const std::exception &e) 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 // TODO: for Linux and Mac OS
#endif #endif
/* if (sParams == "cfg_EditAccountURL")
if (sParams == "cfg_CreateAccountURL")
{
url = ClientCfg.CreateAccountURL;
if (!installTag.empty())
{
url += string("/?from=")+installTag;
}
}
else */if (sParams == "cfg_EditAccountURL")
{ {
url = ClientCfg.EditAccountURL; url = ClientCfg.EditAccountURL;
} }
@ -1896,6 +1886,10 @@ class CAHOpenURL : public IActionHandler
{ {
url = ClientCfg.ConditionsTermsURL; url = ClientCfg.ConditionsTermsURL;
} }
else if (sParams == "cfg_NamingPolicyURL")
{
url = ClientCfg.NamingPolicyURL;
}
else else
{ {
nlwarning("no URL found"); nlwarning("no URL found");

View file

@ -119,14 +119,20 @@ CPatchManager::CPatchManager() : State("t_state"), DataScanState("t_data_scan_st
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
UpdateBatchFilename = "updt_nl.bat"; UpdateBatchFilename = "updt_nl.bat";
UpgradeBatchFilename = "upgd_nl.bat";
#else #else
UpdateBatchFilename = "updt_nl.sh"; UpdateBatchFilename = "updt_nl.sh";
UpgradeBatchFilename = "upgd_nl.sh";
#endif #endif
// use application directory by default std::string rootPath;
std::string rootPath = Args.getProgramPath();
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 // use current directory
rootPath = CPath::getCurrentPath(); rootPath = CPath::getCurrentPath();
@ -698,7 +704,7 @@ bool CPatchManager::getThreadState (ucstring &stateOut, vector<ucstring> &stateL
// verbose log // verbose log
if (isVerboseLog() && !stateLogOut.empty()) if (isVerboseLog() && !stateLogOut.empty())
for (uint32 i = 0; i < stateLogOut.size(); ++i) for (uint32 i = 0; i < stateLogOut.size(); ++i)
nlinfo("%s", stateLogOut[i].toString().c_str()); nlinfo("%s", stateLogOut[i].toUtf8().c_str());
return changed; return changed;
} }
@ -733,6 +739,18 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
const CBNPCategorySet &rDescCats = descFile.getCategories(); const CBNPCategorySet &rDescCats = descFile.getCategories();
OptionalCat.clear(); 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 (uint32 i = 0; i < rDescCats.categoryCount(); ++i)
{ {
// For all optional categories check if there is a 'file to patch' in it // 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()) if (!rCat.getUnpackTo().empty())
for (uint32 j = 0; j < rCat.fileCount(); ++j) 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()); nlwarning("\tFileName = %s", rFilename.c_str());
// Extract to patch // Extract to patch
vector<string> vFilenames; vector<string> vFilenames;
bool result = false; bool result = false;
try try
{ {
result = bnpUnpack(rFilename, ClientPatchPath, vFilenames); result = bnpUnpack(rFilename, SrcPath, vFilenames);
} }
catch(...) catch(...)
{ {
@ -766,45 +784,59 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
{ {
for (uint32 fff = 0; fff < vFilenames.size (); fff++) 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 // this file must be moved
#ifdef NL_OS_WINDOWS string fullDstPath = CPath::standardizePath(rCat.getUnpackTo()); // to be sure there is a / at the end
SrcPath = CPath::standardizeDosPath(SrcPath); NLMISC::CFile::createDirectoryTree(fullDstPath);
DstPath = CPath::standardizeDosPath(DstPath);
#endif
std::string SrcName = SrcPath + vFilenames[fff]; std::string FileName = vFilenames[fff];
std::string DstName = DstPath + vFilenames[fff];
bool succeeded = false; bool succeeded = false;
if (!useBatchFile) if (!useBatchFile)
{ {
// don't check result, because it's possible the olk file doesn't exist // 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 // 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; succeeded = true;
} }
// if we didn't succeed to delete or move the file, create a batch file anyway // if we didn't succeed to delete or move the file, create a batch file anyway
if (!succeeded) 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 // write windows .bat format else write sh format
#ifdef NL_OS_WINDOWS #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(":loop%u\n", nblab);
content += toString("attrib -r -a -s -h \"%s\"\n", DstName.c_str()); content += toString("attrib -r -a -s -h %s\n", realDstPath.c_str());
content += toString("del \"%s\"\n", DstName.c_str()); content += toString("del %s\n", realDstPath.c_str());
content += toString("if exist \"%s\" goto loop%u\n", DstName.c_str(), nblab); content += toString("if exist %s goto loop%u\n", realDstPath.c_str(), nblab);
content += toString("move \"%s\" \"%s\"\n", SrcName.c_str(), DstPath.c_str()); content += toString("move %s %s\n", realSrcPath.c_str(), realDstPath.c_str());
#else #else
content += toString("rm -rf \"%s\"\n", DstName.c_str()); content += toString("rm -rf %s\n", realDstPath.c_str());
content += toString("mv %s \"%s\"\n", SrcName.c_str(), DstPath.c_str()); // TODO: add test of returned $?
content += toString("mv %s %s\n", realSrcPath.c_str(), realDstPath.c_str());
#endif #endif
content += "\n";
} }
nblab++; nblab++;
@ -851,10 +883,10 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
content += patchContent; content += patchContent;
content += toString("rd /Q /S \"" + patchDirectory + "\"\n"); content += toString("rd /Q /S \"%s\"\n", patchDirectory.c_str());
content += toString("if exist \"" + patchDirectory + "\" goto looppatch\n"); content += toString("if exist \"%s\" goto looppatch\n", patchDirectory.c_str());
#else #else
content += toString("rm -rf \"" + patchDirectory + "\"\n"); content += toString("rm -rf \"%s\"\n", patchDirectory.c_str());
#endif #endif
} }
else else
@ -869,7 +901,7 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
std::string batchFilename = ClientRootPath + UpdateBatchFilename; std::string batchFilename = ClientRootPath + UpdateBatchFilename;
FILE *fp = fopen (batchFilename.c_str(), "wt"); FILE *fp = nlfopen (batchFilename, "wt");
if (fp == NULL) if (fp == NULL)
{ {
@ -877,30 +909,70 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
throw Exception (err); throw Exception (err);
} }
string contentPrefix;
//use bat if windows if not use sh //use bat if windows if not use sh
#ifdef NL_OS_WINDOWS #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 #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 #endif
contentPrefix += "\n";
// append content of script // 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) if (wantRyzomRestart)
{ {
string contentSuffix;
#ifdef NL_OS_WINDOWS #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 #else
// wait until client is not in memory // wait until client not in memory anymore
fprintf(fp, "until ! pgrep %s > /dev/null; do sleep 1; done\n", CFile::getFilename(RyzomFilename).c_str()); 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 // 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 // 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 #endif
fputs(contentSuffix.c_str(), fp);
} }
bool writeError = ferror(fp) != 0; bool writeError = ferror(fp) != 0;
@ -940,12 +1012,20 @@ void CPatchManager::executeBatchFile()
batchFilename += UpdateBatchFilename; batchFilename += UpdateBatchFilename;
#ifdef NL_OS_UNIX // make script executable
// make script executable under UNIX CFile::setRWAccess(batchFilename);
chmod(batchFilename.c_str(), S_IRWXU);
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 #endif
std::string arguments = LoginLogin + " " + LoginPassword; // append login and password
arguments += " " + LoginLogin + " " + LoginPassword;
if (!r2Mode) 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) + ")"; s = CI18N::get("uiAttribErr") + " " + CFile::getFilename(filename) + " (" + toString(errno) + "," + strerror(errno) + ")";
setState(true, s); 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"); s = CI18N::get("uiDelNoFile");
setState(true, s); setState(true, s);
return s.toString(); return s.toUtf8();
} }
if (!NLMISC::CFile::deleteFile(filename)) if (!NLMISC::CFile::deleteFile(filename))
@ -1048,8 +1128,8 @@ string CPatchManager::deleteFile (const string &filename, bool bThrowException,
if(bWarning) if(bWarning)
setState(true, s); setState(true, s);
if(bThrowException) if(bThrowException)
throw Exception (s.toString()); throw Exception (s.toUtf8());
return s.toString(); return s.toUtf8();
} }
return ""; return "";
} }
@ -1064,7 +1144,7 @@ void CPatchManager::renameFile (const string &src, const string &dst)
{ {
s = CI18N::get("uiRenameErr") + " " + src + " -> " + dst + " (" + toString(errno) + "," + strerror(errno) + ")"; s = CI18N::get("uiRenameErr") + " " + src + " -> " + dst + " (" + toString(errno) + "," + strerror(errno) + ")";
setState(true, s); 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); setRWAccess(dest, false);
NLMISC::CFile::deleteFile(dest.c_str()); NLMISC::CFile::deleteFile(dest.c_str());
} }
FILE *fp = fopen (dest.c_str(), "wb"); FILE *fp = nlfopen (dest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, 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); string dest = filename.substr(0, filename.size ()-4);
setRWAccess(dest, false); setRWAccess(dest, false);
//if(isVerboseLog()) nlinfo("Calling fopen('%s','wb')", dest.c_str()); //if(isVerboseLog()) nlinfo("Calling nlfopen('%s','wb')", dest.c_str());
FILE *fp = fopen (dest.c_str(), "wb"); FILE *fp = nlfopen (dest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
string err = toString("Can't open file '%s' : code=%d %s, (error code 32)", dest.c_str(), errno, strerror(errno)); 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 // change the file time
if(nDate != 0) if(nDate != 0)
{ {
// _utimbuf utb;
// utb.actime = utb.modtime = nDate;
setRWAccess(sFilename, false); setRWAccess(sFilename, false);
ucstring s = CI18N::get("uiChangeDate") + " " + NLMISC::CFile::getFilename(sFilename) + " " + toString(NLMISC::CFile::getFileModificationDate (sFilename)) + ucstring s = CI18N::get("uiChangeDate") + " " + NLMISC::CFile::getFilename(sFilename) + " " + timestampToHumanReadable(NLMISC::CFile::getFileModificationDate (sFilename)) +
" -> " + toString(nDate); " -> " + timestampToHumanReadable(nDate);
setState(true,s); setState(true,s);
if (!NLMISC::CFile::setFileModificationDate(sFilename, nDate)) if (!NLMISC::CFile::setFileModificationDate(sFilename, nDate))
// if (_utime (sFilename.c_str (), &utb) == -1)
{ {
int err = NLMISC::getLastError(); 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); 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); setState(true,s);
} }
} }
@ -1744,7 +1821,7 @@ bool CPatchManager::bnpUnpack(const string &srcBigfile, const string &dstPath, v
if (!bnpFile.readHeader()) if (!bnpFile.readHeader())
{ {
ucstring s = CI18N::get("uiUnpackErrHead") + " " + SourceName; ucstring s = CI18N::get("uiUnpackErrHead") + " " + CFile::getFilename(SourceName);
setState(true,s); setState(true,s);
return false; return false;
} }
@ -1783,14 +1860,14 @@ int CPatchManager::validateProgress(void *foo, double t, double d, double /* ult
if (units.empty()) 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("uiKb").toUtf8());
units.push_back(CI18N::get("uiMb").toUtf8()); units.push_back(CI18N::get("uiMb").toUtf8());
} }
CPatchManager *pPM = CPatchManager::getInstance(); CPatchManager *pPM = CPatchManager::getInstance();
double pour1 = t!=0.0?d*100.0/t:0.0; 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)); NLMISC::bytesToHumanReadableUnits((uint64)d, units).c_str(), NLMISC::bytesToHumanReadableUnits((uint64)t, units).c_str(), pour1));
pPM->setState(false, sTranslate); pPM->setState(false, sTranslate);
if (foo) if (foo)
@ -1805,7 +1882,7 @@ void CPatchManager::MyPatchingCB::progress(float f)
{ {
CPatchManager *pPM = CPatchManager::getInstance(); CPatchManager *pPM = CPatchManager::getInstance();
double p = 100.0*f; 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); pPM->setState(false, sTranslate);
} }
@ -1981,7 +2058,7 @@ void CPatchManager::clearDataScanLog()
// *************************************************************************** // ***************************************************************************
void CPatchManager::getCorruptedFileInfo(const SFileToPatch &ftp, ucstring &sTranslate) 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") + ")"; toString("%.1f ", (float)ftp.FinalFileSize/1000000.f) + CI18N::get("uiMb") + ")";
} }
@ -2068,7 +2145,7 @@ void CCheckThread::run ()
for (i = 0; i < rDescFiles.fileCount(); ++i) for (i = 0; i < rDescFiles.fileCount(); ++i)
{ {
CPatchManager::SFileToPatch ftp; 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); pPM->setState(true, sTranslate);
// get list of patch to apply to this file. don't to a full checksum test if possible // 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()); nlwarning(rDescFiles.getFile(i).getFileName().c_str());
@ -2192,7 +2269,7 @@ void CCheckThread::run ()
if (bnpFile.readHeader()) if (bnpFile.readHeader())
{ {
// read the file inside the bnp and calculate the sha1 // 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) if (bnp != NULL)
{ {
for (uint32 k = 0; k < bnpFile.SFiles.size(); ++k) for (uint32 k = 0; k < bnpFile.SFiles.size(); ++k)
@ -3068,7 +3145,7 @@ bool CPatchManager::extract(const std::string& patchPath,
uint nblab = 0; uint nblab = 0;
pPM->deleteFile(updateBatchFilename, false, false); pPM->deleteFile(updateBatchFilename, false, false);
FILE *fp = fopen (updateBatchFilename.c_str(), "wt"); FILE *fp = nlfopen (updateBatchFilename, "wt");
if (fp == 0) if (fp == 0)
{ {

View file

@ -433,6 +433,7 @@ private:
/// Now deprecated : the launcher is the client ryzom /// Now deprecated : the launcher is the client ryzom
std::string RyzomFilename; std::string RyzomFilename;
std::string UpdateBatchFilename; std::string UpdateBatchFilename;
std::string UpgradeBatchFilename;
// Where the client get all delta and desc file // Where the client get all delta and desc file
std::string ClientPatchPath; // Temporary path std::string ClientPatchPath; // Temporary path

View file

@ -95,7 +95,7 @@ bool CXDPFileReader::init(const std::string &sFilename, sint32 nLowerBound, sint
{ {
// First open the file with a normal function // First open the file with a normal function
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
int fd = _open(sFilename.c_str(), _O_BINARY | _O_RDONLY); int fd = _wopen(utf8ToWide(sFilename), _O_BINARY | _O_RDONLY);
#else #else
int fd = open(sFilename.c_str(), O_RDONLY); int fd = open(sFilename.c_str(), O_RDONLY);
#endif #endif
@ -143,7 +143,7 @@ bool CXDPFileReader::init(const std::string &sFilename, sint32 nLowerBound, sint
} }
else else
{ {
_File = fopen(sFilename.c_str(), "rb"); _File = nlfopen(sFilename, "rb");
if (_File == NULL) if (_File == NULL)
return false; return false;
fseek(_File, nLowerBound, SEEK_SET); 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()); errorMsg = toString("output file %s already exists", sFileOutput.c_str());
return ApplyResult_Error; return ApplyResult_Error;
} }
FILE *outFILE = fopen(sFileOutput.c_str(), "wb"); FILE *outFILE = nlfopen(sFileOutput, "wb");
if (outFILE == NULL) if (outFILE == NULL)
{ {
errorMsg = toString("cant create %s", sFileOutput.c_str()); errorMsg = toString("cant create %s", sFileOutput.c_str());
@ -572,7 +572,7 @@ CXDeltaPatch::TApplyResult CXDeltaPatch::apply(const std::string &sFileToPatch,
bool ftpPresent = false; bool ftpPresent = false;
if (pFromSource) if (pFromSource)
{ {
ftpFILE = fopen(sFileToPatch.c_str(), "rb"); ftpFILE = nlfopen(sFileToPatch, "rb");
if (ftpFILE == NULL) if (ftpFILE == NULL)
{ {
errorMsg = toString("expecting file %s", sFileToPatch.c_str()); errorMsg = toString("expecting file %s", sFileToPatch.c_str());

View file

@ -84,7 +84,7 @@ static void setPermanentBanFileMarker(const std::string &path, bool on)
// simply touch a file // simply touch a file
COFile f(path); COFile f(path);
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
SetFileAttributes(path.c_str(), FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM); SetFileAttributesW(utf8ToWide(path), FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
#endif #endif
} }
catch(const EStream &e) catch(const EStream &e)
@ -141,7 +141,7 @@ static void markBNPFile(std::string &path)
uint32 nFileSize=CFile::getFileSize(path); uint32 nFileSize=CFile::getFileSize(path);
if (!nFileSize) return; if (!nFileSize) return;
FILE *f = fopen(path.c_str(), "rb+"); FILE *f = nlfopen(path, "rb+");
if (!f) return; if (!f) return;
// Result // Result
if (nlfseek64 (f, nFileSize-4, SEEK_SET) != 0) if (nlfseek64 (f, nFileSize-4, SEEK_SET) != 0)

View file

@ -1384,7 +1384,7 @@ bool CClientEditionModule::loadUserComponent(const std::string& filename, bool m
uint32 timeStamp = 0; uint32 timeStamp = 0;
if (! compressed) if (! compressed)
{ {
FILE* file = fopen(filename.c_str(),"rb"); FILE* file = nlfopen(filename, "rb");
if (!file) if (!file)
{ {
nlwarning("Try to open an invalid file %s (access error)", filename.c_str()); 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 else
{ {
// Get Uncompressed File length (4 last byte of a gz) // Get Uncompressed File length (4 last byte of a gz)
FILE* file = fopen(filename.c_str(),"rb"); FILE* file = nlfopen(filename, "rb");
if (!file) if (!file)
{ {
nlwarning("Try to open an invalid file %s (access error)", filename.c_str()); 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) if (!mustCompress)
{ {
{ {
FILE* output = fopen(uncompressedName.c_str(), "wb"); FILE* output = nlfopen(uncompressedName, "wb");
if (output) if (output)
{ {
fwrite(component->UncompressedData, sizeof(char) , component->UncompressedDataLength, output); fwrite(component->UncompressedData, sizeof(char) , component->UncompressedDataLength, output);

View file

@ -154,7 +154,7 @@ bool unpack7Zip(const std::string &sevenZipFile, const std::string &destFileName
SzArEx_GetFileNameUtf16(&db, 0, &filename[0]); SzArEx_GetFileNameUtf16(&db, 0, &filename[0]);
// write the extracted file // write the extracted file
FILE *outputHandle = fopen(destFileName.c_str(), "wb+"); FILE *outputHandle = nlfopen(destFileName, "wb+");
if (outputHandle == 0) if (outputHandle == 0)
{ {

View file

@ -1020,7 +1020,7 @@ void CSheetManager::dumpVisualSlots()
// *************************************************************************** // ***************************************************************************
void CSheetManager::dumpVisualSlotsIndex() 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 ) if( vsIndexFile )
{ {
for (uint i=0; i < SLOTTYPE::NB_SLOT; ++i) for (uint i=0; i < SLOTTYPE::NB_SLOT; ++i)

View file

@ -1028,17 +1028,18 @@ void CSoundManager::loadProperties(const string &soundName, USource *source)
// Search for the file. // Search for the file.
string filePath = CPath::lookup(soundName+".sdf"); string filePath = CPath::lookup(soundName+".sdf");
ifstream file(filePath.c_str(), ios::in);
CIFile file;
// Try to open the file. // Try to open the file.
if(file.is_open()) if (file.open(filePath))
{ {
char tmpBuff[260]; char tmpBuff[260];
char delimiterBox[] = "\t "; char delimiterBox[] = "\t ";
// While the end of the file is not reached. // While the end of the file is not reached.
while(!file.eof()) 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); file.getline(tmpBuff, 260);
char *token = strtok(tmpBuff, delimiterBox); char *token = strtok(tmpBuff, delimiterBox);
while(token != NULL) while(token != NULL)

View file

@ -65,7 +65,7 @@ public:
/*bool write(char *filename) /*bool write(char *filename)
{ {
FILE *outf=fopen(filename,"wb"); FILE *outf=nlfopen(filename, "wb");
if (outf==NULL) if (outf==NULL)
return false; return false;

View file

@ -26,11 +26,11 @@ using namespace NLMISC;
/****************************************************************\ /****************************************************************\
buildTableFormat() buildTableFormat()
\****************************************************************/ \****************************************************************/
void CSTLoader::buildTableFormat( string fileName, list<pair<string,TDataType> >& tableFormat ) void CSTLoader::buildTableFormat(const string &fileName, list<pair<string,TDataType> >& 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()); nlerror("can't open file : %s\n", fileName.c_str());
} }
@ -40,7 +40,7 @@ void CSTLoader::buildTableFormat( string fileName, list<pair<string,TDataType> >
//================ //================
char readBuffer[4096]; char readBuffer[4096];
char * token; char * token;
_File->getline(readBuffer, 4096); if (fgets(readBuffer, 4096, _File) == NULL) return;
// extract first token // extract first token
//==================== //====================
@ -102,13 +102,17 @@ void CSTLoader::readData( list<list<string> >& data )
char * token; char * token;
bool firstToken = true; bool firstToken = true;
while( !_File->eof() ) while( !feof(_File) )
{ {
// list of current object values // list of current object values
list<string> lineData; list<string> lineData;
// read a line // read a line
_File->getline(readBuffer, 4096); if (fgets(readBuffer, 4096, _File) == NULL)
{
// EOF
break;
}
// check all tokens of the current line // check all tokens of the current line
do do
@ -146,16 +150,16 @@ void CSTLoader::readData( list<list<string> >& data )
/****************************************************************\ /****************************************************************\
generateDerivedClasses() generateDerivedClasses()
\****************************************************************/ \****************************************************************/
void CSTLoader::generateDerivedClasses(ofstream &file, std::list< std::pair<std::string, TDataType> > &format, std::list< std::list< std::string> > &data ) void CSTLoader::generateDerivedClasses(const std::list< std::pair<std::string, TDataType> > &format, const std::list< std::list< std::string> > &data )
{ {
std::string content;
std::list< std::list< std::string> >::const_iterator it_dl = data.begin();
std::list< std::list< std::string> >::iterator it_dl = data.begin();
while ( it_dl != data.end() ) while ( it_dl != data.end() )
{ {
std::list< std::pair<std::string, TDataType> >::iterator it_def = format.begin(); std::list< std::pair<std::string, TDataType> >::const_iterator it_def = format.begin();
std::list<std::string>::iterator it_val = (*it_dl).begin(); std::list<std::string>::const_iterator it_val = (*it_dl).begin();
// sint32 size = data.size(); // sint32 size = data.size();
// sint32 size2 = (*it_dl).size(); // sint32 size2 = (*it_dl).size();
@ -165,55 +169,25 @@ void CSTLoader::generateDerivedClasses(ofstream &file, std::list< std::pair<std:
if ( (*it_dl).size() ) if ( (*it_dl).size() )
{ {
file << "From Item : Define " << convertName( *it_val ) << endl; content += "From Item : Define " + convertName( *it_val ) + "\n";
it_val++; it_val++;
it_def++; it_def++;
file << "{" << endl; content += "{\n";
file << "\tComponent:" << endl; content += "\tComponent:\n";
} }
std::list< std::pair<std::string,TDataType> >::iterator it_obj = format.begin(); std::list< std::pair<std::string,TDataType> >::const_iterator it_obj = format.begin();
it_obj++; it_obj++;
while ( it_obj != format.end() ) while ( it_obj != format.end() )
{ {
file << "\t\t"; content += "\t\t" + convertFromType((*it_obj).second);
switch ( (*it_obj).second ) content += "<'" + (*it_obj).first + "', Static>;\n";
{
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;
it_obj++; 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() ) while ( it_def != format.end() && it_val != (*it_dl).end() )
{ {
@ -222,50 +196,52 @@ void CSTLoader::generateDerivedClasses(ofstream &file, std::list< std::pair<std:
std::string test2 = (*it_def).first; std::string test2 = (*it_def).first;
#endif #endif
file << "\t\t" << (*it_def).first << " = "; content += "\t\t" + (*it_def).first + " = ";
switch ( (*it_def).second ) switch ( (*it_def).second )
{ {
case UINT8: case UINT8:
file << "new uint8(" << convertName(*it_val); content += "new uint8(" + convertName(*it_val);
break; break;
case SINT8: case SINT8:
file << "new sint8(" << convertName(*it_val); content += "new sint8(" + convertName(*it_val);
break; break;
case UINT16: case UINT16:
file << "new uint16(" << convertName(*it_val); content += "new uint16(" + convertName(*it_val);
break; break;
case SINT16: case SINT16:
file << "new sint16(" << convertName(*it_val); content += "new sint16(" + convertName(*it_val);
break; break;
case UINT32: case UINT32:
file << "new uint32(" << convertName(*it_val); content += "new uint32(" + convertName(*it_val);
break; break;
case SINT32: case SINT32:
file << "new sint32(" << convertName(*it_val); content += "new sint32(" + convertName(*it_val);
break; break;
case FLOAT: case FLOAT:
file << "new Float(" <<convertName(*it_val); content += "new Float(" + convertName(*it_val);
break; break;
case STRING: case STRING:
file << "'" << (*it_val) << "'"; content += "'" + (*it_val) + "'";
break; break;
case BOOL: case BOOL:
file << "new Bool(" << (*it_val); content += "new Bool(" + (*it_val);
break; break;
default: default:
file << "ERROR: unsuported type " << (*it_def).second << std::endl; content += "ERROR: unsuported type " + toString((uint)(*it_def).second) + "\n";
break; break;
} }
file << ");" << endl; content += ");\n";
it_def++; it_def++;
it_val++; it_val++;
} }
file << "\tEnd" << endl; content += "\tEnd\n";
file << "}" << endl; content += "}\n";
it_dl++; it_dl++;
} }
fwrite(content.c_str(), 1, content.length(), _File);
} }
@ -274,15 +250,15 @@ void CSTLoader::generateDerivedClasses(ofstream &file, std::list< std::pair<std:
/****************************************************************\ /****************************************************************\
init() init()
\****************************************************************/ \****************************************************************/
void CSTLoader::init(string fileName, const map<string,TDataType>& fileFormat) void CSTLoader::init(const string &fileName, const map<string,TDataType>& fileFormat)
{ {
_FileFormat = fileFormat; _FileFormat = fileFormat;
_FileName = fileName; _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()); nlerror("can't open file : %s\n", fileName.c_str());
} }
@ -291,7 +267,8 @@ void CSTLoader::init(string fileName, const map<string,TDataType>& fileFormat)
// read first line // read first line
char readBuffer[4096]; char readBuffer[4096];
char * token; char * token;
_File->getline(readBuffer, 4096);
if (fgets(readBuffer, 4096, _File) == NULL) return;
// extract first token // extract first token
token = strtok(readBuffer, _Seps.c_str()); token = strtok(readBuffer, _Seps.c_str());
@ -316,7 +293,7 @@ void CSTLoader::init(string fileName, const map<string,TDataType>& fileFormat)
\****************************************************************/ \****************************************************************/
bool CSTLoader::readLine() bool CSTLoader::readLine()
{ {
if( _File->eof() ) if (feof(_File))
{ {
return false; return false;
} }
@ -333,7 +310,7 @@ bool CSTLoader::readLine()
_Tokens.clear(); _Tokens.clear();
// read a line // 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 the line is empty we consider we are at end of file
if( strlen(readBuffer) == 0) if( strlen(readBuffer) == 0)
@ -429,3 +406,21 @@ bool CSTLoader::readLine()
return true; 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 "";
}

View file

@ -25,7 +25,6 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <string> #include <string>
#include <fstream>
/** /**
@ -55,7 +54,7 @@ public:
private: private:
/// cst file /// cst file
std::ifstream * _File; FILE *_File;
/// name of the cst file (used for debug information) /// name of the cst file (used for debug information)
std::string _FileName; std::string _FileName;
@ -101,7 +100,7 @@ public:
* \param fileName the name of the file * \param fileName the name of the file
* \param fileFormat the name of the columns and their data type * \param fileFormat the name of the columns and their data type
*/ */
void buildTableFormat( std::string fileName, std::list<std::pair< std::string,TDataType> >& tableFormat ); void buildTableFormat( const std::string &fileName, std::list<std::pair< std::string,TDataType> >& tableFormat );
/** /**
@ -117,7 +116,7 @@ public:
* \param fileName the name of the file * \param fileName the name of the file
* \param fileFormat the name of the columns and their data type * \param fileFormat the name of the columns and their data type
*/ */
void init( std::string fileName, const std::map<std::string,TDataType>& fileFormat); void init( const std::string &fileName, const std::map<std::string,TDataType>& fileFormat);
/** /**
@ -213,77 +212,50 @@ public:
/// close file /// close file
void close() void close()
{ {
_File->close(); fclose(_File);
delete _File; _File = NULL;
} }
void Load(std::string fileName,std::ofstream &script_file) void Load(const std::string &fileName)
{ {
// Generates the base class // Generates the base class
std::list< std::pair<std::string,TDataType> > format; std::list< std::pair<std::string,TDataType> > format;
buildTableFormat( fileName, format ); buildTableFormat( fileName, format );
generateBaseClass( script_file, format); generateBaseClass( format);
// Generates a derived class for each type of object // Generates a derived class for each type of object
std::list< std::list<std::string> > data; std::list< std::list<std::string> > data;
readData( data ); readData( data );
generateDerivedClasses( script_file, format, data ); generateDerivedClasses( format, data );
} }
void generateBaseClass(std::ofstream &file, std::list< std::pair<std::string,TDataType> > &/* format */) void generateBaseClass(const std::list< std::pair<std::string,TDataType> > &/* format */)
{ {
file << "From Agent : Define Item" << std::endl; std::string content;
file << "{" << std::endl; content += "From Agent : Define Item\n";
/* file << "\tComponent:" << std::endl; content += "{\n";
/* content += "\tComponent:\n";
std::list< std::pair<std::string,TDataType> >::iterator it_obj = format.begin(); std::list< std::pair<std::string,TDataType> >::iterator it_obj = format.begin();
it_obj++; it_obj++;
while ( it_obj != format.end() ) while ( it_obj != format.end() )
{ {
file << "\t\t"; content += "\t\t" + convertFromType((*it_obj).second);
switch ( (*it_obj).second ) content += "<'" + (*it_obj).first + "', Static>;\n";
{
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;
it_obj++; it_obj++;
} }
file << "\tEnd" << std::endl;*/ content += "\tEnd\n"; */
file << "}" << std::endl; content += "}\n";
file << std::endl; content += "\n";
fwrite(content.c_str(), 1, content.length(), _File);
} }
void generateDerivedClasses(std::ofstream &, std::list< std::pair<std::string, TDataType> > &, std::list< std::list< std::string> > &); void generateDerivedClasses(const std::list< std::pair<std::string, TDataType> > &, const std::list< std::list< std::string> > &);
TDataType convertType(std::string type_str) TDataType convertType(const std::string &type_str)
{ {
if ( type_str == "UINT8") if ( type_str == "UINT8")
return UINT8; return UINT8;
@ -306,11 +278,13 @@ public:
return (TDataType)0; 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; int i = 0;
char buffer[1024]; char buffer[1024];
std::string::iterator it_c = name.begin(); std::string::const_iterator it_c = name.begin();
while ( it_c != name.end() ) while ( it_c != name.end() )
{ {
char c = *it_c; char c = *it_c;

View file

@ -26,13 +26,6 @@
#include "utils.h" #include "utils.h"
#include "file_description_container.h" #include "file_description_container.h"
#ifdef NL_OS_WINDOWS
#include <time.h>
#include <sys/types.h>
//#include <sys/stat.h>
#include <stdio.h>
#endif
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// namespaces // namespaces
@ -110,23 +103,10 @@ void CFileDescriptionContainer::addFile(const string& fileName, uint32 timeStamp
void CFileDescriptionContainer::addFile(const string& fileName) 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)) if (CFile::fileExists(fileName))
{ {
addFile(fileName,CFile::getFileModificationDate(fileName),CFile::getFileSize(fileName)); addFile(fileName,CFile::getFileModificationDate(fileName),CFile::getFileSize(fileName));
} }
//#endif
} }
void CFileDescriptionContainer::addFileSpec(const string& fileSpec,bool recurse) void CFileDescriptionContainer::addFileSpec(const string& fileSpec,bool recurse)

View file

@ -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; _ArgOffset=oldArgOffset;
_TokenOffset=oldTokenOffset; _TokenOffset=oldTokenOffset;
_ReadingStructStack=oldRSS; _ReadingStructStack=oldRSS;
@ -1117,10 +1117,11 @@ bool CPersistentDataRecord::readFromFile(const std::string &fileName)
{ {
H_AUTO(pdrReadFromFile) H_AUTO(pdrReadFromFile)
// TODO: see why code is different under Linux and Windows
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
// open the file // 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); DROP_IF( inf==NULL, "Failed to open input file " << fileName, return false);
// get the file size // get the file size

View file

@ -671,14 +671,6 @@ struct TTypeLimits<uint32>
}; };
static uint32 floor(uint32 value) { return value; } static uint32 floor(uint32 value) { return value; }
}; };
/*
#ifdef NL_OS_WINDOWS
template <>
struct TTypeLimits<unsigned int> : public TTypeLimits<uint32>
{
};
#endif
*/
template <> template <>
struct TTypeLimits<uint64> struct TTypeLimits<uint64>
{ {
@ -728,12 +720,7 @@ struct TTypeLimits<sint32>
}; };
static sint32 floor(sint32 value) { return value; } static sint32 floor(sint32 value) { return value; }
}; };
/*#ifdef NL_OS_WINDOWS
template <>
struct TTypeLimits<int> : public TTypeLimits<sint32>
{
};
#endif*/
template <> template <>
struct TTypeLimits<sint64> struct TTypeLimits<sint64>
{ {

View file

@ -40,6 +40,8 @@
#include "creature_manager/creature_manager.h" #include "creature_manager/creature_manager.h"
#include "world_instances.h" #include "world_instances.h"
#include "server_share/used_continent.h"
#include "game_share/shard_names.h"
using namespace NLMISC; using namespace NLMISC;
using namespace NLNET; using namespace NLNET;
@ -1007,36 +1009,39 @@ NLMISC_COMMAND(getTarget, "get target of player", "<uid>")
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
NLMISC_COMMAND(getMoney, "get money of player", "<uid>") NLMISC_COMMAND(getMoney, "get money of player", "<uid>")
{ {
GET_ACTIVE_CHARACTER GET_ACTIVE_CHARACTER
string value = toString("%"NL_I64"u", c->getMoney()); string value = toString("%"NL_I64"u", c->getMoney());
log.displayNL(value.c_str()); log.displayNL(value.c_str());
return true;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
NLMISC_COMMAND(getPvpPoints, "get pvp points of player", "<uid>") NLMISC_COMMAND(getPvpPoints, "get pvp points of player", "<uid>")
{ {
GET_ACTIVE_CHARACTER GET_ACTIVE_CHARACTER
string value = toString("%u", c->getPvpPoint()); string value = toString("%u", c->getPvpPoint());
log.displayNL(value.c_str()); log.displayNL(value.c_str());
return true;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
NLMISC_COMMAND(getCivCultOrg, "get civ cult and organization of player", "<uid>") NLMISC_COMMAND(getCivCultOrg, "get civ cult and organization of player", "<uid>")
{ {
GET_ACTIVE_CHARACTER GET_ACTIVE_CHARACTER
std::pair<PVP_CLAN::TPVPClan, PVP_CLAN::TPVPClan> allegiance = c->getAllegiance(); std::pair<PVP_CLAN::TPVPClan, PVP_CLAN::TPVPClan> allegiance = c->getAllegiance();
log.displayNL("%s|%s|%u", PVP_CLAN::toString(allegiance.first).c_str(), PVP_CLAN::toString(allegiance.second).c_str(), c->getOrganization()); log.displayNL("%s|%s|%u", PVP_CLAN::toString(allegiance.first).c_str(), PVP_CLAN::toString(allegiance.second).c_str(), c->getOrganization());
return true;
} }

View file

@ -1,6 +1,7 @@
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${QT_INCLUDES} ${QT_INCLUDES}
${LIBXML2_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser) ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser)
FILE(GLOB SRC *.cpp *.h) FILE(GLOB SRC *.cpp *.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}) 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_DEFAULT_PROPS(studio_plugin_georges_editor "Tools: Studio Plugin: Georges Editor")
NL_ADD_RUNTIME_FLAGS(studio_plugin_georges_editor) NL_ADD_RUNTIME_FLAGS(studio_plugin_georges_editor)

View file

@ -19,6 +19,9 @@
#include "nel/gui/interface_group.h" #include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h" #include "nel/gui/widget_manager.h"
#include <libxml/xmlstring.h>
#include <libxml/tree.h>
namespace GUIEditor namespace GUIEditor
{ {
bool WidgetSerializer::serialize( const std::string &masterGroup ) bool WidgetSerializer::serialize( const std::string &masterGroup )

View file

@ -1,6 +1,7 @@
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${QT_INCLUDES} ${QT_INCLUDES}
${LIBXML2_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdparty/qtpropertybrowser
) )
@ -59,6 +60,7 @@ TARGET_LINK_LIBRARIES( studio_plugin_world_editor
qt_property_browser qt_property_browser
${QT_LIBRARIES} ${QT_LIBRARIES}
${QT_QTOPENGL_LIBRARY} ${QT_QTOPENGL_LIBRARY}
${LIBXML2_LIBRARIES}
) )
NL_DEFAULT_PROPS(studio_plugin_world_editor "Tools: Studio Plugin: World Editor") NL_DEFAULT_PROPS(studio_plugin_world_editor "Tools: Studio Plugin: World Editor")

View file

@ -41,6 +41,10 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QPersistentModelIndex> #include <QPersistentModelIndex>
// libxml
#include <libxml/xmlstring.h>
#include <libxml/tree.h>
namespace WorldEditor namespace WorldEditor
{ {

View file

@ -26,8 +26,7 @@
#include <nel/ligo/primitive_utils.h> #include <nel/ligo/primitive_utils.h>
#include <nel/ligo/ligo_config.h> #include <nel/ligo/ligo_config.h>
#include <libxml/tree.h>
// Qt includes
namespace WorldEditor namespace WorldEditor
{ {