merged from compatibility-develop

This commit is contained in:
SIELA1915 2016-03-28 02:12:19 +02:00
commit 52702f64f1
267 changed files with 15761 additions and 10184 deletions

View file

@ -118,6 +118,7 @@ ENDIF(WIN32)
FIND_PACKAGE(ZLIB REQUIRED)
FIND_PACKAGE(LibXml2 REQUIRED)
FIND_PACKAGE(PNG REQUIRED)
FIND_PACKAGE(OpenSSL REQUIRED)
FIND_PACKAGE(GIF)
FIND_PACKAGE(Jpeg)
@ -257,10 +258,6 @@ IF(WITH_QT5)
FIND_PACKAGE(Qt5LinguistTools)
FIND_PACKAGE(Qt5Network)
IF(WIN32)
FIND_PACKAGE(Qt5WinExtras)
ENDIF()
IF(QT_STATIC)
ADD_DEFINITIONS(-DQT_STATICPLUGIN)
@ -346,8 +343,6 @@ IF(WITH_QT5)
# Network
SET(QT_LIBRARIES ${QT_LIBRARIES} Qt5::Network Qt5::Xml)
FIND_PACKAGE(OpenSSL REQUIRED)
SET(QT_LIBRARIES ${QT_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES})
IF(WIN32)
@ -421,12 +416,8 @@ IF(WITH_NEL)
IF(CURL_STATIC)
SET(CURL_DEFINITIONS -DCURL_STATICLIB)
FIND_PACKAGE(OpenSSL QUIET)
IF(OPENSSL_FOUND)
SET(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
SET(CURL_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES})
ENDIF(OPENSSL_FOUND)
IF(UNIX)
# CURL depends on libidn

View file

@ -9,38 +9,64 @@ MACRO(FIND_CORRECT_LUA_VERSION)
IF(LUABIND_LIBRARY_RELEASE MATCHES "\\.so")
INCLUDE(CheckDepends)
SET(LUA52_LIBRARY "liblua5.2")
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE LUA52_LIBRARY LUALIB_FOUND)
# check for Lua 5.3
SET(LUA53_LIBRARIES liblua5.3 liblua-5.3 liblua.so.5.3)
FOREACH(_LIB ${LUA53_LIBRARIES})
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
IF(LUALIB_FOUND)
MESSAGE(STATUS "Luabind is using Lua 5.3")
FIND_PACKAGE(Lua53 REQUIRED)
BREAK()
ENDIF()
ENDFOREACH()
IF(NOT LUALIB_FOUND)
# fedora (v20)
SET(LUA52_LIBRARY "liblua-5.2")
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE LUA52_LIBRARY LUALIB_FOUND)
ENDIF(NOT LUALIB_FOUND)
# check for Lua 5.2
SET(LUA52_LIBRARIES liblua5.2 liblua-5.2 liblua.so.5.2)
FOREACH(_LIB ${LUA52_LIBRARIES})
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
IF(LUALIB_FOUND)
MESSAGE(STATUS "Luabind is using Lua 5.2")
FIND_PACKAGE(Lua52 REQUIRED)
ELSE(LUALIB_FOUND)
SET(LUA51_LIBRARY "liblua5.1")
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE LUA51_LIBRARY LUALIB_FOUND)
BREAK()
ENDIF()
ENDFOREACH()
ENDIF()
IF(NOT LUALIB_FOUND)
# check for Lua 5.1
SET(LUA51_LIBRARIES liblua5.1 liblua-5.1 liblua.so.5.1)
FOREACH(_LIB ${LUA51_LIBRARIES})
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
IF(LUALIB_FOUND)
MESSAGE(STATUS "Luabind is using Lua 5.1")
FIND_PACKAGE(Lua51 REQUIRED)
ELSE(LUALIB_FOUND)
SET(LUA50_LIBRARY "liblua5.0")
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE LUA50_LIBRARY LUALIB_FOUND)
BREAK()
ENDIF()
ENDFOREACH()
ENDIF()
IF(NOT LUALIB_FOUND)
# check for Lua 5.0
SET(LUA50_LIBRARIES liblua5.0 liblua-5.0 liblua.so.5.0)
FOREACH(_LIB ${LUA50_LIBRARIES})
CHECK_LINKED_LIBRARY(LUABIND_LIBRARY_RELEASE _LIB LUALIB_FOUND)
IF(LUALIB_FOUND)
MESSAGE(STATUS "Luabind is using Lua 5.0")
FIND_PACKAGE(Lua50 REQUIRED)
ELSE(LUALIB_FOUND)
BREAK()
ENDIF()
ENDFOREACH()
ENDIF()
IF(NOT LUALIB_FOUND)
MESSAGE(FATAL_ERROR "Can't determine Lua version used by Luabind")
ENDIF(LUALIB_FOUND)
ENDIF(LUALIB_FOUND)
ENDIF(LUALIB_FOUND)
ELSE(LUABIND_LIBRARY_RELEASE MATCHES "\\.so")
ENDIF()
ELSE()
# TODO: find a way to detect Lua version
IF(WITH_LUA53)
FIND_PACKAGE(Lua53 REQUIRED)

View file

@ -872,7 +872,7 @@ MACRO(NL_SETUP_BUILD)
ENDIF(ANDROID)
IF(APPLE)
ADD_PLATFORM_FLAGS("-gdwarf-2")
ADD_PLATFORM_FLAGS("-gdwarf-2 -D_DARWIN_UNLIMITED_STREAMS")
ENDIF(APPLE)
# Fix "relocation R_X86_64_32 against.." error on x64 platforms

View file

@ -51,7 +51,7 @@ namespace NLGUI
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
// Init part
virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup);
virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup);
virtual void updateCoords();

View file

@ -49,7 +49,7 @@ namespace NLGUI
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
// Init part
virtual bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup);
virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup);
virtual void checkCoords();
virtual void updateCoords();

View file

@ -63,6 +63,8 @@ namespace NLGUI
uint getTextId(uint i) const;
uint getTextPos(uint nId) const;
const ucstring &getTexture(uint i) const;
void setGrayed(uint i, bool g);
bool getGrayed(uint i) const;
void removeText(uint nPos);
uint getNumTexts() const {return (uint)_Texts.size();}
void sortText();
@ -132,6 +134,7 @@ namespace NLGUI
sint32 _NotLinkedToDBSelection;
std::vector<std::pair<uint, ucstring> > _Texts;
std::vector<ucstring> _Textures;
std::vector<bool> _Grayed;
// Action Handler called on combo click
std::string _AHOnSelectStart;

View file

@ -34,6 +34,7 @@ namespace NLGUI
class CCtrlButton;
class CCtrlScroll;
class CGroupList;
class CGroupMenu;
class CDBGroupComboBox;
class CGroupParagraph;
@ -189,6 +190,7 @@ namespace NLGUI
std::string DefaultFormTextGroup;
std::string DefaultFormTextAreaGroup;
std::string DefaultFormSelectGroup;
std::string DefaultFormSelectBoxMenuGroup;
std::string DefaultCheckBoxBitmapNormal;
std::string DefaultCheckBoxBitmapPushed;
std::string DefaultCheckBoxBitmapOver;
@ -345,6 +347,7 @@ namespace NLGUI
// Add a combo box in the current paragraph
CDBGroupComboBox *addComboBox(const std::string &templateName, const char *name);
CGroupMenu *addSelectBox(const std::string &templateName, const char *name);
// Add a button in the current paragraph. actionHandler, actionHandlerParams and tooltip can be NULL.
CCtrlButton *addButton(CCtrlButton::EType type, const std::string &name, const std::string &normalBitmap, const std::string &pushedBitmap,
@ -409,6 +412,10 @@ namespace NLGUI
double _TimeoutValue; // the timeout in seconds
double _ConnectingTimeout;
sint _RedirectsRemaining;
// Automatic page refresh
double _LastRefreshTime;
double _NextRefreshTime;
std::string _RefreshUrl;
// minimal embeded lua script support
// Note : any embeded script is executed immediately after the closing
@ -626,6 +633,10 @@ namespace NLGUI
TextArea = NULL;
Checkbox = NULL;
ComboBox = NULL;
SelectBox = NULL;
sbRBRef = NULL;
sbMultiple = false;
sbOptionDisabled = -1;
InitialSelection = 0;
}
@ -644,6 +655,19 @@ namespace NLGUI
// Combobox group
CDBGroupComboBox *ComboBox;
// Combobox with multiple selection or display size >= 2
CGroupMenu *SelectBox;
// Single or multiple selections for SelectBox
bool sbMultiple;
// Marks OPTION element as disabled
// Only valid when parsing html
sint sbOptionDisabled;
// First radio button in SelectBox if single selection
CCtrlBaseButton *sbRBRef;
// select values (for the <select> tag)
std::vector<std::string> SelectValues;
sint InitialSelection; // initial selection for the combo box

View file

@ -346,6 +346,7 @@ namespace NLGUI
// set the minW of the RootMenu.
void setMinW(sint32 minW);
void setMinH(sint32 minH);
// Gray a line on the RootMenu
void setGrayedLine(uint line, bool g);

View file

@ -71,13 +71,13 @@ namespace NLGUI
private:
/// Drawing helpers
virtual bool drawResizer(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawRotate(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawScale(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawColorPicker(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawLink(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawBrowse(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawPan(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawResizer(CCtrlBase* /* pCB */, NLMISC::CRGBA /* col */) { return false; }
virtual bool drawRotate(CCtrlBase* /* pCB */, NLMISC::CRGBA /* col */) { return false; }
virtual bool drawScale(CCtrlBase* /* pCB */, NLMISC::CRGBA /* col */) { return false; }
virtual bool drawColorPicker(CCtrlBase* /* pCB */, NLMISC::CRGBA /* col */) { return false; }
virtual bool drawLink(CCtrlBase* /* pCB */, NLMISC::CRGBA /* col */) { return false; }
virtual bool drawBrowse(CCtrlBase* /* pCB */, NLMISC::CRGBA /* col */) { return false; }
virtual bool drawPan(CCtrlBase* /* pCB */, NLMISC::CRGBA /* col */) { return false; }
virtual bool drawCustom(CCtrlBase* pCB);
protected:

View file

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

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 char *lhs, const std::string &rhs) { return stricmp(lhs,rhs.c_str()); }
// macros helper to convert UTF-8 std::string and wchar_t*
#define wideToUtf8(str) (ucstring((ucchar*)str).toUtf8())
#define utf8ToWide(str) ((wchar_t*)ucstring::makeFromUtf8(str).c_str())
// wrapper for fopen to be able to open files with an UTF-8 filename
FILE* nlfopen(const std::string &filename, const std::string &mode);
/** Signed 64 bit fseek. Same interface as fseek
*/
int nlfseek64( FILE *stream, sint64 offset, int origin );
@ -346,6 +353,8 @@ uint32 humanReadableToBytes (const std::string &str);
/// Convert a time into a string that is easily readable by an human, for example 3600 -> "1h"
std::string secondsToHumanReadable (uint32 time);
/// Convert a UNIX timestamp to a formatted date in ISO format
std::string timestampToHumanReadable(uint32 timestamp);
/// Get a bytes or time in string format and convert it in seconds or bytes
uint32 fromHumanReadable (const std::string &str);
@ -357,6 +366,9 @@ std::string formatThousands(const std::string& s);
/// The program will be launched in the current directory
bool launchProgram (const std::string &programName, const std::string &arguments, bool log = true);
/// Same but with an array of strings for arguments
bool launchProgramArray (const std::string &programName, const std::vector<std::string> &arguments, bool log = true);
/// This function executes a program and wait for result (used for example for crash report).
/// The program will be launched in the current directory
sint launchProgramAndWaitForResult (const std::string &programName, const std::string &arguments, bool log = true);
@ -369,6 +381,10 @@ std::string getCommandOutput(const std::string &command);
/// Authorized characters in names are A-Z, a-z, 0-9 and _
std::string expandEnvironmentVariables(const std::string &s);
/// Functions to convert a string with arguments to array or array to string (will espace strings with spaces)
bool explodeArguments(const std::string &str, std::vector<std::string> &args);
std::string joinArguments(const std::vector<std::string> &args);
/// This function kills a program using his pid (on unix, it uses the kill() POSIX function)
bool killProgram(uint32 pid);

View file

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

View file

@ -127,6 +127,9 @@ public:
/// Returns the code of the language ("fr", "en", ...) defined on system
static std::string getSystemLanguageCode ();
/// Define the code of the language ("fr", "en", ...) defined on system
static bool setSystemLanguageCode (const std::string &languageCode);
/// Find a string in the selected language and return his association.
static const ucstring &get (const std::string &label);
@ -230,6 +233,7 @@ private:
static std::vector<std::string> _LanguageCodes;
static std::vector<ucstring> _LanguageNames;
static std::string _SystemLanguageCode;
static bool _LanguagesNamesLoaded;

View file

@ -236,9 +236,6 @@ private:
// If not NULL, binary mode detected, use this stream in serials
IStream *_BinaryStream;
// System dependant structure for locale
void* _Locale;
};

View file

@ -181,9 +181,6 @@ private:
// Error message
std::string _ErrorString;
// System dependant structure for locale
void* _Locale;
};

View file

@ -722,7 +722,6 @@ struct CFile
/** Try to set the file access to read/write if not already set.
* return true if the file doesn't exist or if the file already have RW access.
* Work actually only on Windows and returns always true on other platforms.
* \return true if RW access is granted
*/
static bool setRWAccess(const std::string &filename);

View file

@ -24,7 +24,9 @@
struct sockaddr_in;
struct sockaddr_in6;
struct in_addr;
struct in6_addr;
#ifdef NL_OS_WINDOWS
@ -89,17 +91,25 @@ public:
/// Sets hostname and port (ex: www.nevrax.com:80)
void setNameAndPort( const std::string& hostNameAndPort );
/** Sets internal socket address directly (contents is copied).
/** Sets internal IPv4 socket address directly (contents is copied).
* It also retrieves the host name if CInetAddress::RetrieveNames is true.
*/
void setSockAddr( const sockaddr_in* saddr );
/** Sets internal IPv6 socket address directly (contents is copied).
* It also retrieves the host name if CInetAddress::RetrieveNames is true.
*/
void setSockAddr6( const sockaddr_in6* saddr6 );
/// Returns if object (address and port) is valid
bool isValid() const;
/// Returns internal socket address (read only)
/// Returns internal IPv4 socket address (read only)
const sockaddr_in *sockAddr() const;
/// Returns internal IPv6 socket address (read only)
const sockaddr_in6 *sockAddr6() const;
/// Returns internal IP address
uint32 internalIPAddress() const;
@ -140,9 +150,12 @@ public:
protected:
/// Constructor with ip address, port=0
/// Constructor with IPv4 address, port=0
CInetAddress( const in_addr *ip, const char *hostname = 0);
/// Constructor with IPv6 address, port=0
CInetAddress( const in6_addr *ip, const char *hostname = 0);
/// Update _HostName from _SockAddr
void updateHostName();
@ -153,6 +166,7 @@ private:
std::string _HostName;
sockaddr_in *_SockAddr;
sockaddr_in6 *_SockAddr6;
bool _Valid;
};

View file

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

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/>.
*/
#ifndef NLMISC_TOOL_LOGGER_H
#define NLMISC_TOOL_LOGGER_H
#ifndef NLPIPELINE_TOOL_LOGGER_H
#define NLPIPELINE_TOOL_LOGGER_H
#include <nel/misc/types_nl.h>
// STL includes
@ -39,6 +39,7 @@
// NeL includes
#include <nel/misc/time_nl.h>
#include <nel/misc/string_common.h>
#include <nel/misc/common.h>
// Project includes
@ -47,16 +48,16 @@
#endif
#ifdef NL_DEBUG_H
#define tlerror(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLMISC::ERROR, path, error, ## __VA_ARGS__)
#define tlwarning(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLMISC::WARNING, path, error, ## __VA_ARGS__)
#define tlmessage(toolLogger, path, error, ...) nlinfo(error, ## __VA_ARGS__), toolLogger.writeError(NLMISC::MESSAGE, path, error, ## __VA_ARGS__)
#define tlerror(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLPIPELINE::ERROR, path, error, ## __VA_ARGS__)
#define tlwarning(toolLogger, path, error, ...) nlwarning(error, ## __VA_ARGS__), toolLogger.writeError(NLPIPELINE::WARNING, path, error, ## __VA_ARGS__)
#define tlmessage(toolLogger, path, error, ...) nlinfo(error, ## __VA_ARGS__), toolLogger.writeError(NLPIPELINE::MESSAGE, path, error, ## __VA_ARGS__)
#else
#define tlerror(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::ERROR, path, error, ## __VA_ARGS__)
#define tlwarning(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::WARNING, path, error, ## __VA_ARGS__)
#define tlmessage(toolLogger, path, error, ...) toolLogger.writeError(NLMISC::MESSAGE, path, error, ## __VA_ARGS__)
#define tlerror(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::ERROR, path, error, ## __VA_ARGS__)
#define tlwarning(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::WARNING, path, error, ## __VA_ARGS__)
#define tlmessage(toolLogger, path, error, ...) toolLogger.writeError(NLPIPELINE::MESSAGE, path, error, ## __VA_ARGS__)
#endif
namespace NLMISC {
namespace NLPIPELINE {
enum TError
{
@ -102,7 +103,7 @@ public:
{
releaseError();
m_ErrorLog = fopen(errorLog.c_str(), "wt");
m_ErrorLog = NLMISC::nlfopen(errorLog, "wt");
fwrite(s_ErrorHeader.c_str(), 1, s_ErrorHeader.length(), m_ErrorLog);
fwrite("\n", 1, 1, m_ErrorLog);
fflush(m_ErrorLog);
@ -113,7 +114,7 @@ public:
{
releaseDepend();
m_DependLog = fopen(dependLog.c_str(), "wt");
m_DependLog = NLMISC::nlfopen(dependLog, "wt");
fwrite(s_DependHeader.c_str(), 1, s_DependHeader.length(), m_DependLog);
fwrite("\n", 1, 1, m_DependLog);
// fflush(m_DependLog);
@ -203,8 +204,8 @@ public:
}
}; /* class CToolLogger */
} /* namespace NLMISC */
} /* namespace NLPIPELINE */
#endif /* #ifndef NLMISC_TOOL_LOGGER_H */
#endif /* #ifndef NLPIPELINE_TOOL_LOGGER_H */
/* end of file */

View file

@ -23,6 +23,7 @@
#include "nel/misc/types_nl.h"
#include "nel/misc/file.h"
#include "nel/misc/common.h"
#include "nel/misc/path.h"
#include "nel/misc/bitmap.h"
#include "nel/misc/events.h"
@ -115,7 +116,7 @@ void LoadSceneScript (const char *ScriptName, CScene* pScene, vector<SDispCS> &D
float posx, posy, posz;
float roti, rotj, rotk;
FILE *f = fopen (CPath::lookup(ScriptName).c_str(),"rb");
FILE *f = nlfopen (CPath::lookup(ScriptName), "rb");
fseek (f, 0, SEEK_END);
uint file_size = ftell (f);
fseek (f, 0, SEEK_SET);

View file

@ -60,7 +60,7 @@ public:
nlinfo ("init() was called");
// fp = fopen (NLMISC::CFile::findNewFile("stat.csv").c_str(), "wt");
// fp = nlfopen (NLMISC::CFile::findNewFile("stat.csv"), "wt");
}
bool update ()

View file

@ -33,6 +33,7 @@
#endif
#include "nel/misc/common.h"
#include "nel/misc/debug.h"
#include "nel/misc/mem_stream.h"
#include "nel/misc/path.h"
@ -276,11 +277,11 @@ void CClient::updatePong (sint64 pingTime, sint64 pongTime, uint32 pongNumber, u
}
string fn = StatPathName + ConnectionName + "_" + ha + "_" + getDate() + ".pong";
FILE *fp = fopen (fn.c_str(), "rt");
FILE *fp = nlfopen (fn, "rt");
if (fp == NULL)
{
// new file, add the header
FILE *fp = fopen (fn.c_str(), "wt");
FILE *fp = nlfopen (fn, "wt");
if (fp != NULL)
{
fprintf (fp, "#%s\t%s\t%s\t%s\n", "PingTime", "PongTime", "Delta", "PingNumber");
@ -292,7 +293,7 @@ void CClient::updatePong (sint64 pingTime, sint64 pongTime, uint32 pongNumber, u
fclose (fp);
}
fp = fopen (fn.c_str(), "at");
fp = nlfopen (fn, "at");
if (fp == NULL)
{
nlwarning ("Can't open pong file name '%s'", fn.c_str());

View file

@ -21,6 +21,7 @@
#include "nel/misc/types_nl.h"
#include "nel/misc/debug.h"
#include "nel/misc/common.h"
#include "nel/misc/mem_stream.h"
#include "nel/misc/time_nl.h"
#include "nel/misc/config_file.h"
@ -112,7 +113,7 @@ void exit (const string &reason)
void createConfigFile()
{
FILE *fp = fopen ("client.cfg", "wt");
FILE *fp = nlfopen ("client.cfg", "wt");
if (fp == NULL)
{
InfoLog->displayRawNL ("Can't create client.cfg");
@ -159,7 +160,7 @@ void checkConnectionName ()
void loadConfigFile ()
{
FILE *fp = fopen ("client.cfg", "rt");
FILE *fp = nlfopen ("client.cfg", "rt");
if (fp == NULL)
{
createConfigFile();

View file

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

View file

@ -40,8 +40,6 @@ NL_ADD_LIB_SUFFIX(${NLDRV_OGL_LIB})
NL_ADD_RUNTIME_FLAGS(${NLDRV_OGL_LIB})
IF(WIN32)
INCLUDE_DIRECTORIES(BEFORE ${DXSDK_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(${NLDRV_OGL_LIB} ${DXSDK_DINPUT_LIBRARY} ${DXSDK_GUID_LIBRARY})
ADD_DEFINITIONS(-DDRIVER_OPENGL_EXPORTS)
ENDIF()

View file

@ -1203,6 +1203,7 @@ sint CDriverGL::getTotalVideoMemory() const
{
H_AUTO_OGL(CDriverGL_getTotalVideoMemory);
#ifndef USE_OPENGLES
if (_Extensions.NVXGPUMemoryInfo)
{
GLint memoryInKiB = 0;
@ -1306,6 +1307,10 @@ sint CDriverGL::getTotalVideoMemory() const
}
#endif
#else
// TODO: implement for OpenGL ES
#endif
return -1;
}
@ -2527,7 +2532,7 @@ void CDriverGL::retrieveATIDriverVersion()
// get from the registry
HKEY parentKey;
// open key about current video card
LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &parentKey);
LONG result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &parentKey);
if (result == ERROR_SUCCESS)
{
// find last config
@ -2541,7 +2546,7 @@ void CDriverGL::retrieveATIDriverVersion()
for(;;)
{
nameBufferSize = sizeof(subKeyName) / sizeof(subKeyName[0]);
result = RegEnumKeyEx(parentKey, keyIndex, subKeyName, &nameBufferSize, NULL, NULL, NULL, &lastWriteTime);
result = RegEnumKeyExA(parentKey, keyIndex, subKeyName, &nameBufferSize, NULL, NULL, NULL, &lastWriteTime);
if (result == ERROR_NO_MORE_ITEMS) break;
if (result == ERROR_SUCCESS)
{
@ -2577,14 +2582,14 @@ void CDriverGL::retrieveATIDriverVersion()
if (configFound)
{
HKEY subKey;
result = RegOpenKeyEx(parentKey, latestSubKeyName, 0, KEY_READ, &subKey);
result = RegOpenKeyExA(parentKey, latestSubKeyName, 0, KEY_READ, &subKey);
if (result == ERROR_SUCCESS)
{
// see if it is a radeon card
DWORD valueType;
char driverDesc[256];
DWORD driverDescBufSize = sizeof(driverDesc) / sizeof(driverDesc[0]);
result = RegQueryValueEx(subKey, "DriverDesc", NULL, &valueType, (unsigned char *) driverDesc, &driverDescBufSize);
result = RegQueryValueExA(subKey, "DriverDesc", NULL, &valueType, (unsigned char *) driverDesc, &driverDescBufSize);
if (result == ERROR_SUCCESS && valueType == REG_SZ)
{
toLower(driverDesc);
@ -2592,7 +2597,7 @@ void CDriverGL::retrieveATIDriverVersion()
{
char driverVersion[256];
DWORD driverVersionBufSize = sizeof(driverVersion) / sizeof(driverVersion[0]);
result = RegQueryValueEx(subKey, "DriverVersion", NULL, &valueType, (unsigned char *) driverVersion, &driverVersionBufSize);
result = RegQueryValueExA(subKey, "DriverVersion", NULL, &valueType, (unsigned char *) driverVersion, &driverVersionBufSize);
if (result == ERROR_SUCCESS && valueType == REG_SZ)
{
int subVersionNumber[4];

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)
{
std::string vpText;

View file

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

View file

@ -38,8 +38,6 @@ NL_ADD_LIB_SUFFIX(${NLDRV_OGLES_LIB})
NL_ADD_RUNTIME_FLAGS(${NLDRV_OGLES_LIB})
IF(WIN32)
INCLUDE_DIRECTORIES(BEFORE ${DXSDK_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(${NLDRV_OGLES_LIB} ${DXSDK_DINPUT_LIBRARY} ${DXSDK_GUID_LIBRARY})
ADD_DEFINITIONS(/DDRIVER_OPENGLES_EXPORTS)
ENDIF()

View file

@ -22,6 +22,7 @@
#include "nel/misc/debug.h"
#include "nel/misc/common.h"
#include "nel/misc/path.h"
#include "nel/misc/file.h"
#include "nel/3d/font_generator.h"
@ -81,6 +82,93 @@ CFontGenerator *newCFontGenerator(const std::string &fontFileName)
return new CFontGenerator(fontFileName);
}
// Freetype will call this function to get a buffer in data
static unsigned long nlFreetypeStreamIo(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count)
{
// if count is 0, we don't need to do anything
if (count > 0)
{
// get a pointer on our CIFile
CIFile *file = (CIFile*)stream->descriptor.pointer;
// try to seek to offset
if (file->seek(offset, IStream::begin))
{
try
{
// try to fill buffer with data from file
file->serialBuffer(buffer, count);
}
catch(const EFile &e)
{
nlwarning("Unable to read %u bytes from position %u of %s", (uint)count, (uint)offset, file->getStreamName().c_str());
count = 0;
}
}
else
{
nlwarning("Unable to seek to position %u of %s", (uint)offset, file->getStreamName().c_str());
count = 0;
}
}
return count;
}
// Freetype will call this function when it won't need to access to file anymore
static void nlFreetypeStreamClose(FT_Stream stream)
{
if (!stream) return;
// get a pointer on our CIFile
CIFile *file = (CIFile*)stream->descriptor.pointer;
if (file)
{
// close and delete file
file->close();
delete file;
stream->descriptor.pointer = NULL;
}
// free Freetype stream structure
free(stream);
}
// helper to open a font and use our functions to handle BNP files and UTF-8 filenames
static bool createFreetypeStream(const std::string &filename, FT_Open_Args &args)
{
CIFile *file = new CIFile();
if (!file->open(filename))
{
nlwarning("Unable to open %s", filename.c_str());
return false;
}
args.flags = FT_OPEN_STREAM;
args.stream = (FT_Stream)malloc(sizeof(*args.stream));
if (args.stream == NULL)
{
nlwarning("Unable to allocate FT_Stream for %s", filename.c_str());
delete file;
return false;
}
args.stream->base = NULL; // only used for memory streams
args.stream->size = file->getFileSize();
args.stream->pos = 0;
args.stream->descriptor.pointer = file;
args.stream->pathname.pointer = NULL; // filename is already managed by CIFile
args.stream->read = nlFreetypeStreamIo;
args.stream->close = nlFreetypeStreamClose;
return true;
}
/*
* Constructor
*/
@ -102,7 +190,14 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri
}
++_LibraryInit;
error = FT_New_Face (_Library, fontFileName.c_str (), 0, &_Face);
FT_Open_Args args;
if (!createFreetypeStream(fontFileName, args))
{
nlerror ("createFreetypeStream failed with file '%s'", fontFileName.c_str());
}
error = FT_Open_Face(_Library, &args, 0, &_Face);
if (error)
{
nlerror ("FT_New_Face() failed with file '%s': %s", fontFileName.c_str(), getFT2Error(error));
@ -117,7 +212,12 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri
if (!fontEx.empty())
{
error = FT_Attach_File (_Face, fontEx.c_str ());
if (!createFreetypeStream(fontEx, args))
{
nlerror ("createFreetypeStream failed with file '%s'", fontFileName.c_str());
}
error = FT_Attach_Stream(_Face, &args);
if (error)
{
nlwarning ("FT_Attach_File() failed with file '%s': %s", fontEx.c_str(), getFT2Error(error));

View file

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

View file

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

View file

@ -262,6 +262,7 @@ namespace NLGUI
dirt();
_Texts.clear();
_Textures.clear();
_Grayed.clear();
}
// ***************************************************************************
@ -270,6 +271,7 @@ namespace NLGUI
dirt();
_Texts.push_back(make_pair((uint)_Texts.size(), text));
_Textures.push_back(std::string());
_Grayed.push_back(false);
}
// ***************************************************************************
@ -292,9 +294,11 @@ namespace NLGUI
{
_Texts[t+1] = _Texts[t];
_Textures[t+1] = _Textures[t];
_Grayed[t+1] = _Grayed[t];
}
_Texts[i] = make_pair(i, text);
_Textures[i] = std::string();
_Grayed[i] = false;
}
else if(i==_Texts.size())
addText(text);
@ -308,6 +312,24 @@ namespace NLGUI
_Textures[i]= texture;
}
// ***************************************************************************
void CDBGroupComboBox::setGrayed(uint i, bool g)
{
dirt();
if(i<_Grayed.size())
_Grayed[i] = g;
}
// ***************************************************************************
bool CDBGroupComboBox::getGrayed(uint i) const
{
if(i<_Grayed.size())
return _Grayed[i];
else
return false;
}
// ***************************************************************************
void CDBGroupComboBox::removeText(uint nPos)
{
@ -316,6 +338,7 @@ namespace NLGUI
{
_Texts.erase( _Texts.begin()+nPos );
_Textures.erase( _Textures.begin()+nPos );
_Grayed.erase ( _Grayed.begin()+nPos );
}
}
@ -365,7 +388,6 @@ namespace NLGUI
return null;
}
// ***************************************************************************
void CDBGroupComboBox::setSelection(sint32 val)
{
@ -619,6 +641,7 @@ namespace NLGUI
}
groupMenu->addLine(getText(i), "combo_box_select_end", toString(i),
"", std::string(), getTexture(i).toString(), checkable);
groupMenu->setGrayedLine(i, getGrayed(i));
}

View file

@ -26,6 +26,7 @@
#include "nel/gui/libwww.h"
#include "nel/gui/group_html.h"
#include "nel/gui/group_list.h"
#include "nel/gui/group_menu.h"
#include "nel/gui/group_container.h"
#include "nel/gui/view_link.h"
#include "nel/gui/ctrl_scroll.h"
@ -304,7 +305,7 @@ namespace NLGUI
return;
}
FILE *fp = fopen (tmpdest.c_str(), "wb");
FILE *fp = nlfopen(tmpdest, "wb");
if (fp == NULL)
{
curl_easy_cleanup(curl);
@ -315,7 +316,8 @@ namespace NLGUI
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true);
curl_easy_setopt(curl, CURLOPT_URL, finalUrl.c_str());
curl_easy_setopt(curl, CURLOPT_FILE, fp);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_multi_add_handle(MultiCurl, curl);
Curls.push_back(CDataDownload(curl, finalUrl, dest, fp, ImgType, img, "", "", style));
@ -411,7 +413,7 @@ namespace NLGUI
return false;
}
FILE *fp = fopen (tmpdest.c_str(), "wb");
FILE *fp = nlfopen (tmpdest, "wb");
if (fp == NULL)
{
curl_easy_cleanup(curl);
@ -422,7 +424,8 @@ namespace NLGUI
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FILE, fp);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_multi_add_handle(MultiCurl, curl);
Curls.push_back(CDataDownload(curl, url, dest, fp, BnpType, NULL, script, md5sum));
@ -1137,6 +1140,40 @@ namespace NLGUI
}
}
break;
case HTML_META:
if (_ReadingHeadTag)
{
bool httpEquiv = present[HTML_META_HTTP_EQUIV] && value[HTML_META_HTTP_EQUIV];
bool httpContent = present[HTML_META_CONTENT] && value[HTML_META_CONTENT];
if (httpEquiv && httpContent)
{
// only first http-equiv="refresh" should be handled
if (_RefreshUrl.empty() && toLower(value[HTML_META_HTTP_EQUIV]) == "refresh")
{
const CWidgetManager::SInterfaceTimes &times = CWidgetManager::getInstance()->getInterfaceTimes();
double timeSec = times.thisFrameMs / 1000.0f;
string content(value[HTML_META_CONTENT]);
string::size_type pos = content.find_first_of(";");
if (pos == string::npos)
{
fromString(content, _NextRefreshTime);
_RefreshUrl = _URL;
}
else
{
fromString(content.substr(0, pos), _NextRefreshTime);
pos = toLower(content).find("url=");
if (pos != string::npos)
_RefreshUrl = content.substr(pos + 4);
}
_NextRefreshTime += timeSec;
}
}
}
break;
case HTML_A:
{
CStyleParams style;
@ -1691,15 +1728,50 @@ namespace NLGUI
case HTML_SELECT:
if (!(_Forms.empty()))
{
CStyleParams style;
// A select box
string name;
bool multiple = false;
sint32 size = 0;
if (present[HTML_SELECT_NAME] && value[HTML_SELECT_NAME])
name = value[HTML_SELECT_NAME];
if (present[HTML_SELECT_SIZE] && value[HTML_SELECT_SIZE])
fromString(value[HTML_SELECT_SIZE], size);
if (present[HTML_SELECT_MULTIPLE] && value[HTML_SELECT_MULTIPLE])
multiple = true;
if (present[HTML_SELECT_STYLE] && value[HTML_SELECT_STYLE])
getStyleParams(value[HTML_SELECT_STYLE], style);
CDBGroupComboBox *cb = addComboBox(DefaultFormSelectGroup, name.c_str());
CGroupHTML::CForm::CEntry entry;
entry.Name = name;
entry.sbMultiple = multiple;
if (size > 1 || multiple)
{
entry.InitialSelection = -1;
CGroupMenu *sb = addSelectBox(DefaultFormSelectBoxMenuGroup, name.c_str());
if (sb)
{
if (size < 1)
size = 4;
if (style.Width > -1)
sb->setMinW(style.Width);
if (style.Height > -1)
sb->setMinH(style.Height);
sb->setMaxVisibleLine(size);
}
entry.SelectBox = sb;
}
else
{
CDBGroupComboBox *cb = addComboBox(DefaultFormSelectGroup, name.c_str());
entry.ComboBox = cb;
}
_Forms.back().Entries.push_back (entry);
}
break;
@ -1713,17 +1785,14 @@ namespace NLGUI
_SelectOptionStr.clear();
std::string optionValue;
bool selected = false;
if (present[HTML_OPTION_VALUE] && value[HTML_OPTION_VALUE])
optionValue = value[HTML_OPTION_VALUE];
if (present[HTML_OPTION_SELECTED] && value[HTML_OPTION_SELECTED])
selected = nlstricmp(value[HTML_OPTION_SELECTED], "selected") == 0;
_Forms.back().Entries.back().SelectValues.push_back(optionValue);
if (selected)
{
_Forms.back().Entries.back().InitialSelection = (sint)_Forms.back().Entries.back().SelectValues.size() - 1;
}
if (present[HTML_OPTION_SELECTED])
_Forms.back().Entries.back().InitialSelection = (sint)_Forms.back().Entries.back().SelectValues.size() - 1;
if (present[HTML_OPTION_DISABLED])
_Forms.back().Entries.back().sbOptionDisabled = (sint)_Forms.back().Entries.back().SelectValues.size() - 1;
}
}
_SelectOption = true;
@ -2242,7 +2311,65 @@ namespace NLGUI
CDBGroupComboBox *cb = _Forms.back().Entries.back().ComboBox;
if (cb)
{
uint lineIndex = cb->getNumTexts();
cb->addText(_SelectOptionStr);
if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex)
{
cb->setGrayed(lineIndex, true);
}
}
else
{
CGroupMenu *sb = _Forms.back().Entries.back().SelectBox;
if (sb)
{
uint lineIndex = sb->getNumLine();
sb->addLine(_SelectOptionStr, "", "");
if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex)
{
sb->setGrayedLine(lineIndex, true);
}
else
{
// create option line checkbox, CGroupMenu is taking ownership of the checbox
CInterfaceGroup *ig = CWidgetManager::getInstance()->getParser()->createGroupInstance("menu_checkbox", "", NULL, 0);
if (ig)
{
CCtrlButton *cb = dynamic_cast<CCtrlButton *>(ig->getCtrl("b"));
if (cb)
{
if (_Forms.back().Entries.back().sbMultiple)
{
cb->setType(CCtrlButton::ToggleButton);
cb->setTexture(DefaultCheckBoxBitmapNormal);
cb->setTexturePushed(DefaultCheckBoxBitmapPushed);
cb->setTextureOver(DefaultCheckBoxBitmapOver);
}
else
{
cb->setType(CCtrlButton::RadioButton);
cb->setTexture(DefaultRadioButtonBitmapNormal);
cb->setTexturePushed(DefaultRadioButtonBitmapPushed);
cb->setTextureOver(DefaultRadioButtonBitmapOver);
if (_Forms.back().Entries.back().sbRBRef == NULL)
_Forms.back().Entries.back().sbRBRef = cb;
cb->initRBRefFromRadioButton(_Forms.back().Entries.back().sbRBRef);
}
cb->setPushed(_Forms.back().Entries.back().InitialSelection == lineIndex);
sb->setUserGroupLeft(lineIndex, ig);
}
else
{
nlwarning("Failed to get 'b' element from 'menu_checkbox' template");
delete ig;
}
}
}
}
}
}
break;
@ -2422,6 +2549,9 @@ namespace NLGUI
_GroupListAdaptor = NULL;
_DocumentUrl = "";
_UrlFragment.clear();
_RefreshUrl.clear();
_NextRefreshTime = 0.0;
_LastRefreshTime = 0.0;
// Register
CWidgetManager::getInstance()->registerClockMsgTarget(this);
@ -2464,6 +2594,7 @@ namespace NLGUI
DefaultFormTextGroup = "edit_box_widget";
DefaultFormTextAreaGroup = "edit_box_widget_multiline";
DefaultFormSelectGroup = "html_form_select_widget";
DefaultFormSelectBoxMenuGroup = "html_form_select_box_menu_widget";
DefaultCheckBoxBitmapNormal = "checkbox_normal.tga";
DefaultCheckBoxBitmapPushed = "checkbox_pushed.tga";
DefaultCheckBoxBitmapOver = "checkbox_over.tga";
@ -3403,7 +3534,34 @@ namespace NLGUI
bool CGroupHTML::handleEvent (const NLGUI::CEventDescriptor& eventDesc)
{
bool traited = CGroupScrollText::handleEvent (eventDesc);
bool traited = false;
if (eventDesc.getType() == NLGUI::CEventDescriptor::mouse)
{
const NLGUI::CEventDescriptorMouse &mouseEvent = (const NLGUI::CEventDescriptorMouse &)eventDesc;
if (mouseEvent.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousewheel)
{
// Check if mouse wheel event was on any of multiline select box widgets
// Must do this before CGroupScrollText
for (uint i=0; i<_Forms.size() && !traited; i++)
{
for (uint j=0; j<_Forms[i].Entries.size() && !traited; j++)
{
if (_Forms[i].Entries[j].SelectBox)
{
if (_Forms[i].Entries[j].SelectBox->handleEvent(eventDesc))
{
traited = true;
break;
}
}
}
}
}
}
if (!traited)
traited = CGroupScrollText::handleEvent (eventDesc);
if (eventDesc.getType() == NLGUI::CEventDescriptor::system)
{
@ -3413,8 +3571,15 @@ namespace NLGUI
// Handle now
handle ();
}
if (systemEvent.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::activecalledonparent)
{
if (!((NLGUI::CEventDescriptorActiveCalledOnParent &) systemEvent).getActive())
{
// stop refresh when window gets hidden
_NextRefreshTime = 0;
}
}
}
return traited;
}
@ -3550,6 +3715,7 @@ namespace NLGUI
CViewText *viewText = new CViewText ("", (string("Error : ")+msg).c_str());
viewText->setColor (ErrorColor);
viewText->setModulateGlobalColor(ErrorColorGlobalColor);
viewText->setMultiLine (true);
getParagraph()->addChild (viewText);
if(!_TitlePrefix.empty())
setTitle (_TitlePrefix);
@ -3985,6 +4151,45 @@ namespace NLGUI
return NULL;
}
// ***************************************************************************
CGroupMenu *CGroupHTML::addSelectBox(const std::string &templateName, const char *name)
{
// In a paragraph ?
if (!_Paragraph)
{
newParagraph (0);
paragraphChange ();
}
// Not added ?
std::vector<std::pair<std::string,std::string> > templateParams;
templateParams.push_back(std::pair<std::string,std::string> ("id", name));
CInterfaceGroup *group = CWidgetManager::getInstance()->getParser()->createGroupInstance(templateName.c_str(),
getParagraph()->getId(), &(templateParams[0]), (uint)templateParams.size());
// Group created ?
if (group)
{
// Set the content
CGroupMenu *sb = dynamic_cast<CGroupMenu *>(group);
if (!sb)
{
nlwarning("'%s' template has bad type, CGroupMenu expected", templateName.c_str());
delete sb;
return NULL;
}
else
{
getParagraph()->addChild (sb);
paragraphChange ();
return sb;
}
}
// No group created
return NULL;
}
// ***************************************************************************
CCtrlButton *CGroupHTML::addButton(CCtrlButton::EType type, const std::string &/* name */, const std::string &normalBitmap, const std::string &pushedBitmap,
@ -4409,6 +4614,21 @@ namespace NLGUI
// handle curl downloads
checkDownloads();
// handle refresh timer
if (_NextRefreshTime > 0 && _NextRefreshTime <= (times.thisFrameMs / 1000.0f) )
{
// there might be valid uses for 0sec refresh, but two in a row is probably a mistake
if (_NextRefreshTime - _LastRefreshTime >= 1.0)
{
_LastRefreshTime = _NextRefreshTime;
doBrowse(_RefreshUrl.c_str());
}
else
nlwarning("Ignore second 0sec http-equiv refresh in a row (url '%s')", _URL.c_str());
_NextRefreshTime = 0;
}
if (_Connecting)
{
// Check timeout if needed
@ -4523,6 +4743,24 @@ namespace NLGUI
entryData.fromUtf8(form.Entries[i].SelectValues[cb->getSelection()]);
addEntry = true;
}
else if (form.Entries[i].SelectBox)
{
CGroupMenu *sb = form.Entries[i].SelectBox;
CGroupSubMenu *rootMenu = sb->getRootMenu();
if (rootMenu)
{
for(uint j=0; j<rootMenu->getNumLine(); ++j)
{
CInterfaceGroup *ig = rootMenu->getUserGroupLeft(j);
if (ig)
{
CCtrlBaseButton *cb = dynamic_cast<CCtrlBaseButton *>(ig->getCtrl("b"));
if (cb && cb->getPushed())
formfields.add(form.Entries[i].Name, form.Entries[i].SelectValues[j]);
}
}
}
}
// This is a hidden value
else
{
@ -4782,6 +5020,8 @@ namespace NLGUI
//
_Browsing = true;
_DocumentUrl = _URL;
_NextRefreshTime = 0;
_RefreshUrl.clear();
// clear content
beginBuild();
@ -5679,5 +5919,6 @@ namespace NLGUI
return ret;
}
}

View file

@ -2496,6 +2496,17 @@ namespace NLGUI
}
}
// ------------------------------------------------------------------------------------------------
void CGroupMenu::setMinH(sint32 minH)
{
if ( _RootMenu )
{
_RootMenu->_GroupList->setMinH(minH-_RootMenu->getResizeFromChildHMargin());
_RootMenu->_GroupList->setH(minH-_RootMenu->getResizeFromChildHMargin());
_RootMenu->setH(minH-_RootMenu->getResizeFromChildHMargin());
}
}
// ------------------------------------------------------------------------------------------------
void CGroupMenu::setGrayedLine(uint line, bool g)
{

View file

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

View file

@ -152,6 +152,7 @@ FILE(GLOB NLMISC_BITMAP
FILE(GLOB NLMISC_CRYPT
md5.cpp ../../include/nel/misc/md5.h
sha1.cpp ../../include/nel/misc/sha1.h
../../include/nel/misc/wang_hash.h
)
SOURCE_GROUP("" FILES ${SRC} ${HEADERS})
@ -200,12 +201,6 @@ ELSE(WITH_STATIC OR WIN32)
TARGET_LINK_LIBRARIES(nelmisc ${PNG_LIBRARY})
ENDIF(WITH_STATIC OR WIN32)
# For DirectInput (di_event_emitter)
IF(WIN32)
INCLUDE_DIRECTORIES(BEFORE ${DXSDK_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(nelmisc ${DXSDK_DINPUT_LIBRARY} ${DXSDK_GUID_LIBRARY} winmm dbghelp)
ENDIF(WIN32)
IF(UNIX)
TARGET_LINK_LIBRARIES(nelmisc -lc -ldl)
IF(NOT APPLE)

View file

@ -19,6 +19,8 @@
#include "nel/misc/dynloadlib.h"
#include "nel/misc/command.h"
#include <locale.h>
#ifdef DEBUG_NEW
#define new DEBUG_NEW
#endif
@ -85,6 +87,9 @@ void INelContext::contextReady()
_NelContext = this;
*(_getInstance()) = this;
// set numeric locale to C to avoid the use of decimal separators different of a dot
char *locale = setlocale(LC_NUMERIC, "C");
// register any pending thinks
// register local instance counter in the global instance counter manager

View file

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

View file

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

View file

@ -84,6 +84,20 @@ void MakeWhite(CBitmap &bitmaps)
}
#endif // NEL_ALL_BITMAP_WHITE
CBitmap::CBitmap()
{
_MipMapCount = 1;
_Width = 0;
_Height = 0;
PixelFormat = RGBA;
_LoadGrayscaleAsAlpha = true;
}
CBitmap::~CBitmap()
{
}
/*-------------------------------------------------------------------*\
load
\*-------------------------------------------------------------------*/
@ -541,17 +555,10 @@ uint8 CBitmap::readDDS(NLMISC::IStream &f, uint mipMapSkip)
(very) bad rendered with this fix so we have to deactivate it the for moment
*/
//#ifdef NL_OS_WINDOWS
// if(PixelFormat==DXTC1) //AlphaBitDepth
// {
// PixelFormat = DXTC1Alpha;
// }
//#else
if(PixelFormat==DXTC1 && _DDSSurfaceDesc[21]>0) //AlphaBitDepth
{
PixelFormat = DXTC1Alpha;
}
//#endif
if(PixelFormat!= DXTC1 && PixelFormat!= DXTC1Alpha && PixelFormat!= DXTC3 && PixelFormat!= DXTC5)
{
@ -3099,11 +3106,17 @@ bool CBitmap::blit(const CBitmap *src, sint32 x, sint32 y)
// Private :
float CBitmap::getColorInterp (float x, float y, float colorInXY00, float colorInXY10, float colorInXY01, float colorInXY11) const
{
if (colorInXY00 == colorInXY10
&& colorInXY00 == colorInXY01
&& colorInXY00 == colorInXY11)
return colorInXY00; // Fix rounding error for alpha 255...
float res = colorInXY00*(1.0f-x)*(1.0f-y) +
colorInXY10*( x)*(1.0f-y) +
colorInXY01*(1.0f-x)*( y) +
colorInXY11*( x)*( y);
clamp (res, 0.0f, 255.0f);
clamp(res, 0.0f, 255.0f);
return res;
}

View file

@ -199,45 +199,16 @@ bool CCmdArgs::parse(const std::string &args)
std::vector<std::string> argv;
#ifdef NL_OS_WINDOWS
char str[4096];
uint len = GetModuleFileNameA(NULL, str, 4096);
wchar_t str[4096];
uint len = GetModuleFileNameW(NULL, str, 4096);
// first argument should be full path to executable
if (len && len < 4096)
argv.push_back(str);
argv.push_back(wideToUtf8(str));
#endif
std::string::size_type pos1 = 0, pos2 = 0;
do
{
// Look for the first non space character
pos1 = args.find_first_not_of (" ", pos2);
if(pos1 == std::string::npos) break;
// Look for the first space or "
pos2 = args.find_first_of (" \"", pos1);
if(pos2 != std::string::npos)
{
// " ?
if(args[pos2] == '"')
{
// Look for the final \"
pos2 = args.find_first_of ("\"", pos2+1);
if(pos2 != std::string::npos)
{
// Look for the first space
pos2 = args.find_first_of (" ", pos2+1);
}
}
}
// Compute the size of the string to extract
std::string::difference_type length = (pos2 != std::string::npos) ? pos2-pos1 : std::string::npos;
std::string tmp = args.substr (pos1, length);
argv.push_back (tmp);
}
while(pos2 != std::string::npos);
// convert string with arguments to array
explodeArguments(args, argv);
return parse(argv);
}

View file

@ -506,6 +506,21 @@ string secondsToHumanReadable (uint32 time)
return toString ("%u%s", res, divTable[div]);
}
std::string timestampToHumanReadable(uint32 timestamp)
{
char buffer[30];
time_t dtime = timestamp;
tm *tms = localtime(&dtime);
if (tms)
{
strftime(buffer, 30, "%Y-%m-%d %H:%M:%S", tms);
return std::string(buffer);
}
return "";
}
uint32 fromHumanReadable (const std::string &str)
{
if (str.size() == 0)
@ -710,50 +725,54 @@ bool abortProgram(uint32 pid)
#endif
}
bool launchProgram(const std::string &programName, const std::string &arguments, bool log)
{
#ifdef NL_OS_WINDOWS
STARTUPINFOA si;
PROCESS_INFORMATION pi;
static bool createProcess(const std::string &programName, const std::string &arguments, bool log, PROCESS_INFORMATION &pi)
{
STARTUPINFOW si;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si);
// Enable nlassert/nlstop to display the error reason & callstack
const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS");
TCHAR envBuf [2];
if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) != 0)
const char *SE_TRANSLATOR_IN_MAIN_MODULE = "NEL_SE_TRANS";
char envBuf[2];
if (GetEnvironmentVariableA(SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2) != 0)
{
SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL );
SetEnvironmentVariableA(SE_TRANSLATOR_IN_MAIN_MODULE, NULL);
}
const char *sProgramName = programName.c_str();
wchar_t *sProgramName = NULL;
std::string args;
// a .bat file must have first parameter to NULL and use 2nd parameter to pass filename
if (CFile::getExtension(programName) == "bat")
{
sProgramName = NULL;
args = "\"" + programName + "\" " + arguments;
}
else
{
ucstring ucProgramName;
ucProgramName.fromUtf8(programName);
sProgramName = new wchar_t[MAX_PATH];
wcscpy(sProgramName, (wchar_t*)ucProgramName.c_str());
args = arguments;
}
BOOL res = CreateProcessA(sProgramName, (char*)args.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
BOOL res = CreateProcessW(sProgramName, utf8ToWide(args), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
if (res)
if (sProgramName)
{
//nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str());
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
delete [] sProgramName;
sProgramName = NULL;
}
else
if (!res)
{
if (log)
{
@ -763,13 +782,31 @@ bool launchProgram(const std::string &programName, const std::string &arguments,
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return false;
}
return true;
}
#endif
bool launchProgram(const std::string &programName, const std::string &arguments, bool log)
{
#ifdef NL_OS_WINDOWS
PROCESS_INFORMATION pi;
if (!createProcess(programName, arguments, log, pi)) return false;
//nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str());
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
#else
#ifdef NL_OS_MAC
// special OS X case with bundles
if (toLower(programName).find(".app") != std::string::npos)
if (toLower(CFile::getExtension(programName)) == ".app")
{
// we need to open bundles with "open" command
std::string command = NLMISC::toString("open \"%s\"", programName.c_str());
@ -794,6 +831,7 @@ bool launchProgram(const std::string &programName, const std::string &arguments,
#endif
static bool firstLaunchProgram = true;
if (firstLaunchProgram)
{
// The aim of this is to avoid defunct process.
@ -814,15 +852,7 @@ bool launchProgram(const std::string &programName, const std::string &arguments,
// convert one arg into several args
vector<string> args;
string::size_type pos1 = 0, pos2 = 0;
do
{
pos1 = arguments.find_first_not_of (" ", pos2);
if (pos1 == string::npos) break;
pos2 = arguments.find_first_of (" ", pos1);
args.push_back (arguments.substr (pos1, pos2-pos1));
}
while (pos2 != string::npos);
explodeArguments(arguments, args);
// Store the size of each arg
vector<char *> argv(args.size()+2);
@ -867,78 +897,136 @@ bool launchProgram(const std::string &programName, const std::string &arguments,
return false;
}
sint launchProgramAndWaitForResult(const std::string &programName, const std::string &arguments, bool log)
bool launchProgramArray (const std::string &programName, const std::vector<std::string> &arguments, bool log)
{
sint res = 0;
#ifdef NL_OS_WINDOWS
STARTUPINFOA si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
std::string argumentsJoined = joinArguments(arguments);
si.cb = sizeof(si);
if (!createProcess(programName, argumentsJoined, log, pi)) return false;
// Enable nlassert/nlstop to display the error reason & callstack
const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS");
TCHAR envBuf [2];
if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) != 0)
//nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str());
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
#else
#ifdef NL_OS_MAC
// special OS X case with bundles
if (toLower(CFile::getExtension(programName)) == "app")
{
SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL );
// we need to open bundles with "open" command
std::string command = NLMISC::toString("open \"%s\"", programName.c_str());
std::string argumentsJoined = joinArguments(arguments);
// append arguments if any
if (!argumentsJoined.empty())
{
command += NLMISC::toString(" --args %s", argumentsJoined.c_str());
}
const char *sProgramName = programName.c_str();
int res = system(command.c_str());
std::string args;
if (!res) return true;
// a .bat file must have first parameter to NULL and use 2nd parameter to pass filename
if (CFile::getExtension(programName) == "bat")
if (log)
{
sProgramName = NULL;
args = "\"" + programName + "\" " + arguments;
nlwarning ("LAUNCH: Failed launched '%s' with arg '%s' return code %d", programName.c_str(), argumentsJoined.c_str(), res);
}
return false;
}
#endif
static bool firstLaunchProgram = true;
if (firstLaunchProgram)
{
// The aim of this is to avoid defunct process.
//
// From "man signal":
//------
// According to POSIX (3.3.1.3) it is unspecified what happens when SIGCHLD is set to SIG_IGN. Here
// the BSD and SYSV behaviours differ, causing BSD software that sets the action for SIGCHLD to
// SIG_IGN to fail on Linux.
//------
//
// But it works fine on my GNU/Linux so I do this because it's easier :) and I don't know exactly
// what to do to be portable.
signal(SIGCHLD, SIG_IGN);
firstLaunchProgram = false;
}
// Store the size of each arg
vector<char *> argv(arguments.size()+2);
uint i = 0;
argv[i] = (char *)programName.c_str();
for (; i < arguments.size(); i++)
{
argv[i+1] = (char *) arguments[i].c_str();
}
argv[i+1] = NULL;
int status = vfork ();
/////////////////////////////////////////////////////////
/// WARNING : NO MORE INSTRUCTION AFTER VFORK !
/// READ VFORK manual
/////////////////////////////////////////////////////////
if (status == -1)
{
char *err = strerror (errno);
if (log)
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), joinArguments(arguments).c_str(), errno, err);
}
else if (status == 0)
{
// Exec (the only allowed instruction after vfork)
status = execvp(programName.c_str(), &argv.front());
if (status == -1)
{
perror("Failed launched");
_exit(EXIT_FAILURE);
}
}
else
{
args = arguments;
//nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str());
return true;
}
#endif
BOOL ok = CreateProcessA(sProgramName, (char*)args.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
return false;
}
sint launchProgramAndWaitForResult(const std::string &programName, const std::string &arguments, bool log)
{
#ifdef NL_OS_WINDOWS
PROCESS_INFORMATION pi;
if (!createProcess(programName, arguments, log, pi)) return -1;
if (ok)
{
// Successfully created the process. Wait for it to finish.
WaitForSingleObject(pi.hProcess, INFINITE);
// Get the exit code.
DWORD exitCode = 0;
ok = GetExitCodeProcess(pi.hProcess, &exitCode);
BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode);
//nldebug("LAUNCH: Successful launch '%s' with arg '%s'", programName.c_str(), arguments.c_str());
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
if (ok)
{
res = (sint)exitCode;
}
else
{
if (ok) return (sint)exitCode;
if (log)
nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str());
}
}
else
{
if (log)
{
sint lastError = getLastError();
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), lastError, formatErrorMessage(lastError).c_str());
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
return -1;
#else
// program name is the only required string
std::string command = programName;
@ -947,13 +1035,13 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st
if (!arguments.empty()) command += " " + arguments;
// execute the command
res = system(command.c_str());
sint res = system(command.c_str());
if (res && log)
nlwarning ("LAUNCH: Failed launched '%s' with arg '%s' return code %d", programName.c_str(), arguments.c_str(), res);
#endif
return res;
#endif
}
std::string getCommandOutput(const std::string &command)
@ -1050,6 +1138,75 @@ std::string expandEnvironmentVariables(const std::string &s)
return ret;
}
bool explodeArguments(const std::string &str, std::vector<std::string> &args)
{
if (str.empty()) return false;
std::string::size_type pos1 = 0, pos2 = 0;
do
{
// Look for the first non space character
pos1 = str.find_first_not_of (" ", pos2);
if (pos1 == std::string::npos) break;
// Look for the first space or "
pos2 = str.find_first_of (" \"", pos1);
if (pos2 != std::string::npos)
{
// " ?
if (str[pos2] == '"')
{
// Look for the final \"
pos2 = str.find_first_of ("\"", pos2+1);
if (pos2 != std::string::npos)
{
// Look for the first space
pos2 = str.find_first_of (" ", pos2+1);
}
}
}
// Compute the size of the string to extract
std::string::difference_type length = (pos2 != std::string::npos) ? pos2-pos1 : std::string::npos;
std::string tmp = str.substr (pos1, length);
// remove escape " from argument
if (tmp.length() > 1 && tmp[0] == '"' && tmp[tmp.length()-1] == '"') tmp = tmp.substr(1, tmp.length()-2);
args.push_back (tmp);
}
while(pos2 != std::string::npos);
return true;
}
std::string joinArguments(const std::vector<std::string> &args)
{
std::string res;
for(uint i = 0, len = (uint)args.size(); i < len; ++i)
{
const std::string &arg = args[i];
// prepend space
if (!res.empty()) res += " ";
// escape only if spaces or empty argument
if (arg.empty() || arg.find(' ') != std::string::npos)
{
res += "\"" + arg + "\"";
}
else
{
res += arg;
}
}
return res;
}
/*
* Display the bits (with 0 and 1) composing a byte (from right to left)
*/
@ -1099,6 +1256,14 @@ void displayDwordBits( uint32 b, uint nbits, sint beginpos, bool displayBegin, N
}
}
FILE* nlfopen(const std::string &filename, const std::string &mode)
{
#ifdef NL_OS_WINDOWS
return _wfopen(utf8ToWide(filename), utf8ToWide(mode));
#else
return fopen(filename.c_str(), mode.c_str());
#endif
}
int nlfseek64( FILE *stream, sint64 offset, int origin )
{

View file

@ -316,6 +316,13 @@ CConfigFile::~CConfigFile ()
void CConfigFile::load (const string &fileName, bool lookupPaths )
{
char *locale = setlocale(LC_NUMERIC, NULL);
if (!locale || strcmp(locale, "C"))
{
nlerror("Numeric locale not defined to C, an external library possibly redefined it!");
}
if(fileName.empty())
{
nlwarning ("CF: Can't load a empty file name configfile");
@ -597,10 +604,14 @@ bool CConfigFile::exists (const std::string &varName)
void CConfigFile::save () const
{
// Avoid any problem, Force Locale to default
setlocale(LC_ALL, "C");
char *locale = setlocale(LC_NUMERIC, NULL);
FILE *fp = fopen (getFilename().c_str (), "w");
if (!locale || strcmp(locale, "C"))
{
nlerror("Numeric locale not defined to C, an external library possibly redefined it!");
}
FILE *fp = nlfopen (getFilename(), "w");
if (fp == NULL)
{
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
const char* statfile = "/proc/stat";
FILE* f = fopen(statfile, "r");
FILE* f = nlfopen(statfile, "r");
if (f == NULL)
return false;
@ -66,7 +66,7 @@ bool CCPUTimeStat::getPIDTicks(uint64& utime, uint64& stime, uint64& cutime, uin
#ifdef NL_OS_UNIX
std::string statfile = NLMISC::toString("/proc/%u/stat", pid);
FILE* f = fopen(statfile.c_str(), "r");
FILE* f = nlfopen(statfile, "r");
if (f == NULL)
return false;

View file

@ -310,9 +310,9 @@ static DWORD __stdcall GetModuleBase(HANDLE hProcess, DWORD dwReturnAddress)
&memoryBasicInfo, sizeof(memoryBasicInfo)))
{
DWORD cch = 0;
char szFile[MAX_PATH] = { 0 };
wchar_t szFile[MAX_PATH] = { 0 };
cch = GetModuleFileNameA((HINSTANCE)memoryBasicInfo.AllocationBase,
cch = GetModuleFileNameW((HINSTANCE)memoryBasicInfo.AllocationBase,
szFile, MAX_PATH);
if (cch && (lstrcmpA(szFile, "DBFN")== 0))
@ -527,9 +527,9 @@ public:
string progname;
if(!shortExc.empty() || !longExc.empty())
{
char name[1024];
GetModuleFileNameA (NULL, name, 1023);
progname = CFile::getFilename(name);
wchar_t name[1024];
GetModuleFileNameW (NULL, name, 1023);
progname = CFile::getFilename(wideToUtf8(name));
progname += " ";
}
@ -1171,12 +1171,12 @@ void createDebug (const char *logPath, bool logInFile, bool eraseLastLog)
// Use an environment variable to share the value among the EXE and its child DLLs
// (otherwise there would be one distinct bool by module, and the last
// _set_se_translator would overwrite the previous ones)
const TCHAR *SE_TRANSLATOR_IN_MAIN_MODULE = _T("NEL_SE_TRANS");
TCHAR envBuf [2];
if ( GetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) == 0)
const char *SE_TRANSLATOR_IN_MAIN_MODULE = "NEL_SE_TRANS";
char envBuf [2];
if ( GetEnvironmentVariableA( SE_TRANSLATOR_IN_MAIN_MODULE, envBuf, 2 ) == 0)
{
_set_se_translator(exceptionTranslator);
SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, _T("1") );
SetEnvironmentVariableA( SE_TRANSLATOR_IN_MAIN_MODULE, "1" );
}
}
# endif // NL_OS_WINDOWS

View file

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

View file

@ -216,7 +216,7 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
static bool consoleModeTest = false;
if (!consoleModeTest)
{
HANDLE handle = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
HANDLE handle = CreateFileA ("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
consoleMode = handle != INVALID_HANDLE_VALUE;
if (consoleMode)
CloseHandle (handle);
@ -286,20 +286,14 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
// WARNING: READ THIS !!!!!!!!!!!!!!!! ///////////////////////////
// If at the release time, it freezes here, it's a microsoft bug:
// http://support.microsoft.com/support/kb/articles/q173/2/60.asp
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(str2).c_str());
OutputDebugStringW(utf8ToWide(str2));
}
else
{
/*OutputDebugString(ss2.str().c_str());
OutputDebugString("\n\t\t\t");
OutputDebugString("message end: ");
OutputDebugString(&message[strlen(message) - 1024]);
OutputDebugString("\n");*/
sint count = 0;
uint n = (uint)strlen(message);
std::string s(&str2.c_str()[0], (str2.size() - n));
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str());
OutputDebugStringW(utf8ToWide(s));
for(;;)
{
@ -307,15 +301,15 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
if((n - count) < maxOutString )
{
s = std::string(&message[count], (n - count));
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str());
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8("\n").c_str());
OutputDebugStringW(utf8ToWide(s));
OutputDebugStringW(L"\n");
break;
}
else
{
s = std::string(&message[count] , count + maxOutString);
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(s).c_str());
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8("\n\t\t\t").c_str());
OutputDebugStringW(utf8ToWide(s));
OutputDebugStringW(L"\n\t\t\t");
count += maxOutString;
}
}
@ -329,13 +323,13 @@ void CStdDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mess
if (pos+1000 < args.CallstackAndLog.size ())
{
splited = args.CallstackAndLog.substr (pos, 1000);
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(splited).c_str());
OutputDebugStringW(utf8ToWide(splited));
pos += 1000;
}
else
{
splited = args.CallstackAndLog.substr (pos);
OutputDebugStringW((LPCWSTR)ucstring::makeFromUtf8(splited).c_str());
OutputDebugStringW(utf8ToWide(splited));
break;
}
}
@ -491,7 +485,7 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes
if (_FilePointer == (FILE*)1)
{
_FilePointer = fopen (_FileName.c_str(), "at");
_FilePointer = nlfopen (_FileName, "at");
if (_FilePointer == NULL)
printf ("Can't open log file '%s': %s\n", _FileName.c_str(), strerror (errno));
}
@ -702,58 +696,4 @@ void CMsgBoxDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *m
}
}
/***************************************************************/
/******************* THE FOLLOWING CODE IS COMMENTED OUT *******/
/***************************************************************
void CStdDisplayer::display (const std::string& str)
{
// printf("%s", str.c_str ());
cout << str;
#ifdef NL_OS_WINDOWS
// display the string in the debugger is the application is started with the debugger
if (IsDebuggerPresent ())
OutputDebugString(str.c_str ());
#endif
}
void CFileDisplayer::display (const std::string& str)
{
if (_FileName.size () == 0) return;
ofstream ofs (_FileName.c_str (), ios::out | ios::app);
if (ofs.is_open ())
{
ofs << str;
ofs.close();
}
// FILE *fp = fopen (_FileName.c_str (), "a");
// if (fp == NULL) return;
// fprintf (fp, "%s", str.c_str ());
// fclose (fp);
}
void CMsgBoxDisplayer::display (const std::string& str)
{
#ifdef NL_OS_WINDOWS
CSystemUtils::copyTextToClipboard(str);
string strf = str;
strf += "\n\n(this message was copied in the clipboard)";
MessageBox (NULL, strf.c_str (), "", MB_OK | MB_ICONEXCLAMATION);
#endif
}
**************************************************************************/
} // NLMISC

View file

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

View file

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

View file

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

View file

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

View file

@ -43,6 +43,7 @@ string CI18N::_SelectedLanguageCode;
CI18N::ILoadProxy *CI18N::_LoadProxy = 0;
vector<string> CI18N::_LanguageCodes;
vector<ucstring> CI18N::_LanguageNames;
std::string CI18N::_SystemLanguageCode;
bool CI18N::noResolution = false;
void CI18N::setLoadProxy(ILoadProxy *loadProxy)
@ -57,14 +58,14 @@ void CI18N::initLanguages()
_LanguageCodes.push_back("en");
_LanguageCodes.push_back("fr");
_LanguageCodes.push_back("de");
_LanguageCodes.push_back("ru");
_LanguageCodes.push_back("es");
// _LanguageCodes.push_back("ru");
// _LanguageCodes.push_back("es");
_LanguageNames.push_back(ucstring("English"));
_LanguageNames.push_back(ucstring("French"));
_LanguageNames.push_back(ucstring("German"));
_LanguageNames.push_back(ucstring("Russian"));
_LanguageNames.push_back(ucstring("Spanish"));
// _LanguageNames.push_back(ucstring("Russian"));
// _LanguageNames.push_back(ucstring("Spanish"));
_LanguagesNamesLoaded = true;
}
@ -248,10 +249,8 @@ bool CI18N::isLanguageCodeSupported(const std::string &lang)
std::string CI18N::getSystemLanguageCode ()
{
static std::string s_cachedSystemLanguage;
if (!s_cachedSystemLanguage.empty())
return s_cachedSystemLanguage;
if (!_SystemLanguageCode.empty())
return _SystemLanguageCode;
#ifdef NL_OS_MAC
// under OS X, locale is only defined in console, not in UI
@ -293,7 +292,7 @@ std::string CI18N::getSystemLanguageCode ()
}
else
{
nlerror("Unable to convert CFStringRef to string");
nlwarning("Unable to convert CFStringRef to string");
}
delete [] tmp;
@ -306,34 +305,138 @@ std::string CI18N::getSystemLanguageCode ()
CFRelease(langCF);
}
// only keep language code if supported by NeL
if (!lang.empty() && isLanguageCodeSupported(lang))
if (!lang.empty())
{
s_cachedSystemLanguage = lang;
// fix language code if country is specified
std::string::size_type pos = lang.find('-');
if (pos != std::string::npos)
lang = lang.substr(0, pos);
// only keep language code if supported by NeL
if (isLanguageCodeSupported(lang))
{
_SystemLanguageCode = lang;
break;
}
}
}
// don't need languages array anymore
CFRelease(langs);
}
#endif
// use system locale (works under Linux and Windows)
if (s_cachedSystemLanguage.empty())
#ifdef NL_OS_WINDOWS
// use user locale under Windows (since Vista)
if (_SystemLanguageCode.empty())
{
std::string lang = NLMISC::toLower(std::string(setlocale(LC_CTYPE, "")));
// GetUserDefaultLocaleName prototype
typedef int (WINAPI* GetUserDefaultLocaleNamePtr)(LPWSTR lpLocaleName, int cchLocaleName);
// get pointer on GetUserDefaultLocaleName, kernel32.dll is always in memory so no need to call LoadLibrary
GetUserDefaultLocaleNamePtr nlGetUserDefaultLocaleName = (GetUserDefaultLocaleNamePtr)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetUserDefaultLocaleName");
// only use it if found
if (nlGetUserDefaultLocaleName)
{
// get user locale
wchar_t buffer[LOCALE_NAME_MAX_LENGTH];
sint res = nlGetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH);
// convert wide string to std::string
std::string lang = wideToUtf8(buffer);
// only keep 2 first characters
if (lang.size() > 1)
s_cachedSystemLanguage = lang.substr(0, 2);
_SystemLanguageCode = lang.substr(0, 2);
}
}
#endif
// use system locale (works under OS X, Linux and Windows)
if (_SystemLanguageCode.empty())
{
// get default locale
char *locale = setlocale(LC_CTYPE, "");
if (locale)
{
std::string lang(locale);
#ifdef NL_OS_WINDOWS
// be sure supported languages are initialized
initLanguages();
// locales names are different under Windows, for example: French_France.1252
for(uint i = 0; i < _LanguageNames.size(); ++i)
{
std::string name = _LanguageNames[i].toUtf8();
// so we compare the language name with the supported ones
if (lang.compare(0, name.length(), name) == 0)
{
// found, so use its code
_SystemLanguageCode = _LanguageCodes[i];
break;
}
}
#else
// only keep 2 first characters
if (lang.size() > 1)
_SystemLanguageCode = NLMISC::toLower(lang).substr(0, 2);
#endif
}
}
// english is default language
if (s_cachedSystemLanguage.empty())
s_cachedSystemLanguage = "en";
if (_SystemLanguageCode.empty())
_SystemLanguageCode = "en";
return s_cachedSystemLanguage;
return _SystemLanguageCode;
}
bool CI18N::setSystemLanguageCode (const std::string &languageCode)
{
// be sure supported languages are initialized
initLanguages();
std::string lang = NLMISC::toLower(languageCode);
// specified language is really a code (2 characters)
if (lang.length() == 2)
{
// check if language code is supported
for(uint i = 0; i < _LanguageCodes.size(); ++i)
{
std::string code = NLMISC::toLower(_LanguageCodes[i]);
if (lang == code)
{
// found, so use it
_SystemLanguageCode = lang;
return true;
}
}
}
// specified language is something else
else
{
// check if language name is supported
for(uint i = 0; i < _LanguageNames.size(); ++i)
{
std::string name = NLMISC::toLower(_LanguageNames[i].toUtf8());
if (name == lang)
{
// found, so use its code
_SystemLanguageCode = _LanguageCodes[i];
return true;
}
}
}
return false;
}
void CI18N::removeCComment(ucstring &commentedString)
@ -567,7 +670,7 @@ void CI18N::readTextFile(const string &filename,
if (!readContext.IfStack.empty())
{
nlwarning("Preprocess: Missing %u closing #endif after parsing %s", readContext.IfStack.size(), filename.c_str() );
nlwarning("Preprocess: Missing %u closing #endif after parsing %s", (uint)readContext.IfStack.size(), filename.c_str() );
}
}

View file

@ -24,11 +24,6 @@
// Include from libxml2
#include <libxml/xmlerror.h>
#if defined(NL_OS_WINDOWS) && defined(NL_COMP_VC_VERSION) && NL_COMP_VC_VERSION >= 80
#define USE_LOCALE_ATOF
#include <locale.h>
#endif
using namespace std;
#define NLMISC_READ_BUFFER_SIZE 1024
@ -46,26 +41,10 @@ const char SEPARATOR = ' ';
// ***************************************************************************
#define readnumber(dest,thetype,digits,convfunc) \
#define readnumber(dest,digits) \
string number_as_string; \
serialSeparatedBufferIn( number_as_string ); \
dest = (thetype)convfunc( number_as_string.c_str() );
#ifdef USE_LOCALE_ATOF
#define readnumberlocale(dest,thetype,digits,convfunc) \
string number_as_string; \
serialSeparatedBufferIn( number_as_string ); \
dest = (thetype)convfunc( number_as_string.c_str(), (_locale_t)_Locale );
#define nl_atof _atof_l
#else
#define readnumberlocale(dest,thetype,digits,convfunc) readnumber(dest,thetype,digits,convfunc)
#define nl_atof atof
#endif
NLMISC::fromString(number_as_string, dest);
// ***************************************************************************
@ -91,13 +70,6 @@ CIXml::CIXml () : IStream (true /* Input mode */)
_ErrorString = "";
_TryBinaryMode = false;
_BinaryStream = NULL;
#ifdef USE_LOCALE_ATOF
// create C numeric locale
_Locale = _create_locale(LC_NUMERIC, "C");
#else
_Locale = NULL;
#endif
}
// ***************************************************************************
@ -113,13 +85,6 @@ CIXml::CIXml (bool tryBinaryMode) : IStream (true /* Input mode */)
_ErrorString = "";
_TryBinaryMode = tryBinaryMode;
_BinaryStream = NULL;
#ifdef USE_LOCALE_ATOF
// create C numeric locale
_Locale = _create_locale(LC_NUMERIC, "C");
#else
_Locale = NULL;
#endif
}
// ***************************************************************************
@ -128,10 +93,6 @@ CIXml::~CIXml ()
{
// Release
release ();
#ifdef USE_LOCALE_ATOF
if (_Locale) _free_locale((_locale_t)_Locale);
#endif
}
// ***************************************************************************
@ -468,7 +429,7 @@ void CIXml::serial(uint8 &b)
else
{
// Read the number
readnumber( b, uint8, 3, atoi );
readnumber( b, 3 );
}
}
@ -482,7 +443,7 @@ void CIXml::serial(sint8 &b)
}
else
{
readnumber( b, sint8, 4, atoi );
readnumber( b, 4 );
}
}
@ -496,7 +457,7 @@ void CIXml::serial(uint16 &b)
}
else
{
readnumber( b, uint16, 5, atoi );
readnumber( b, 5 );
}
}
@ -510,7 +471,7 @@ void CIXml::serial(sint16 &b)
}
else
{
readnumber( b, sint16, 6, atoi );
readnumber( b, 6 );
}
}
@ -529,7 +490,7 @@ void CIXml::serial(uint32 &b)
}
else
{
readnumber( b, uint32, 10, atoui );
readnumber( b, 10 );
}
}
@ -543,7 +504,7 @@ void CIXml::serial(sint32 &b)
}
else
{
readnumber( b, sint32, 11, atoi );
readnumber( b, 11 );
}
}
@ -557,7 +518,7 @@ void CIXml::serial(uint64 &b)
}
else
{
readnumber( b, uint64, 20, atoiInt64 );
readnumber( b, 20 );
}
}
@ -571,7 +532,7 @@ void CIXml::serial(sint64 &b)
}
else
{
readnumber( b, sint64, 20, atoiInt64 );
readnumber( b, 20 );
}
}
@ -585,7 +546,7 @@ void CIXml::serial(float &b)
}
else
{
readnumberlocale( b, float, 128, nl_atof );
readnumber( b, 128 );
}
}
@ -599,7 +560,7 @@ void CIXml::serial(double &b)
}
else
{
readnumberlocale( b, double, 128, nl_atof );
readnumber( b, 128 );
}
}

View file

@ -96,7 +96,7 @@ namespace NLMISC
nlassert(_Id == 0); // init done twice
release();
// create a system wide mutex
_SharedMemMutex = CreateMutex(NULL, FALSE, toString("NL_MUTEX_%d", (int) id).c_str());
_SharedMemMutex = CreateMutexA(NULL, FALSE, toString("NL_MUTEX_%d", (int) id).c_str());
if (!_SharedMemMutex) return false;
_Id = id;
return true;
@ -197,7 +197,7 @@ namespace NLMISC
cds.lpData = (PVOID) msgOut.buffer();
for(;;)
{
LRESULT result = ::SendMessage(targetWindow, WM_COPYDATA, (WPARAM) _Parent->_LocalWindow.getWnd(), (LPARAM) &cds);
LRESULT result = ::SendMessageA(targetWindow, WM_COPYDATA, (WPARAM) _Parent->_LocalWindow.getWnd(), (LPARAM) &cds);
if (result) break;
// retry ...
Sleep(30);

View file

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

View file

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

View file

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

View file

@ -43,22 +43,11 @@ const char SEPARATOR = ' ';
// ***************************************************************************
#ifdef USE_LOCALE_SPRINTF
#define writenumber(src,format,digits) \
char number_as_cstring [digits+1]; \
_sprintf_l( number_as_cstring, format, (_locale_t)_Locale, src ); \
serialSeparatedBufferOut( number_as_cstring );
#else
#define writenumber(src,format,digits) \
char number_as_cstring [digits+1]; \
sprintf( number_as_cstring, format, src ); \
serialSeparatedBufferOut( number_as_cstring );
#endif
// ***************************************************************************
// XML callbacks
// ***************************************************************************
@ -149,13 +138,6 @@ COXml::COXml () : IStream (false /* Output mode */)
// Push begin
_PushBegin = false;
#ifdef USE_LOCALE_SPRINTF
// create C numeric locale
_Locale = _create_locale(LC_NUMERIC, "C");
#else
_Locale = NULL;
#endif
}
// ***************************************************************************
@ -215,10 +197,6 @@ COXml::~COXml ()
{
// Flush document to the internal stream
flush ();
#ifdef USE_LOCALE_SPRINTF
if (_Locale) _free_locale((_locale_t)_Locale);
#endif
}
// ***************************************************************************

View file

@ -681,11 +681,11 @@ std::string CPath::getCurrentPath ()
std::string CFileContainer::getCurrentPath ()
{
char buffer [1024];
#ifdef NL_OS_WINDOWS
return standardizePath(_getcwd(buffer, 1024), false);
wchar_t buffer[1024];
return standardizePath(wideToUtf8(_wgetcwd(buffer, 1024)), false);
#else
char buffer [1024];
return standardizePath(getcwd(buffer, 1024), false);
#endif
}
@ -700,7 +700,7 @@ bool CFileContainer::setCurrentPath (const std::string &path)
int res;
//nldebug("Change current path to '%s' (current path is '%s')", path.c_str(), getCurrentPath().c_str());
#ifdef NL_OS_WINDOWS
res = _chdir(path.c_str());
res = _wchdir(utf8ToWide(path));
#else
res = chdir(path.c_str());
#endif
@ -756,11 +756,11 @@ std::string CFileContainer::getFullPath (const std::string &path, bool addFinalS
#ifdef NL_OS_WINDOWS
# define dirent WIN32_FIND_DATA
# define dirent WIN32_FIND_DATAW
# define DIR void
static string sDir;
static WIN32_FIND_DATA findData;
static WIN32_FIND_DATAW findData;
static HANDLE hFind;
DIR *opendir (const char *path)
@ -792,13 +792,12 @@ dirent *readdir (DIR *dir)
// first visit in this directory : FindFirstFile()
if (hFind == NULL)
{
string fullPath = CPath::standardizePath(sDir) + "*";
hFind = FindFirstFileA (fullPath.c_str(), &findData);
hFind = FindFirstFileW (utf8ToWide(CPath::standardizePath(sDir) + "*"), &findData);
}
// directory already visited : FindNextFile()
else
{
if (!FindNextFileA (hFind, &findData))
if (!FindNextFileW (hFind, &findData))
return NULL;
}
@ -845,7 +844,7 @@ string getname (dirent *de)
{
nlassert (de != NULL);
#ifdef NL_OS_WINDOWS
return de->cFileName;
return wideToUtf8(de->cFileName);
#else
return de->d_name;
#endif // NL_OS_WINDOWS
@ -1269,7 +1268,7 @@ void CFileContainer::addSearchBigFile (const string &sBigFilename, bool recurse,
// Open and read the big file header
nlassert(!_MemoryCompressed);
FILE *Handle = fopen (sBigFilename.c_str(), "rb");
FILE *Handle = nlfopen (sBigFilename, "rb");
if (Handle == NULL)
{
nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't open file, skip it", sBigFilename.c_str(), recurse, alternative);
@ -1421,7 +1420,7 @@ void CFileContainer::addSearchXmlpackFile (const string &sXmlpackFilename, bool
}
// Open and read the xmlpack file header
FILE *Handle = fopen (sXmlpackFilename.c_str(), "rb");
FILE *Handle = nlfopen (sXmlpackFilename, "rb");
if (Handle == NULL)
{
nlwarning ("PATH: CPath::addSearchXmlpackFile(%s, %d, %d): can't open file, skip it", sXmlpackFilename.c_str(), recurse, alternative);
@ -1766,14 +1765,14 @@ std::string CFileContainer::getWindowsDirectory()
nlwarning("not a ms windows platform");
return "";
#else
char winDir[MAX_PATH];
UINT numChar = ::GetWindowsDirectory(winDir, MAX_PATH);
wchar_t winDir[MAX_PATH];
UINT numChar = GetWindowsDirectoryW(winDir, MAX_PATH);
if (numChar > MAX_PATH || numChar == 0)
{
nlwarning("Couldn't retrieve windows directory");
return "";
}
return CPath::standardizePath(winDir);
return CPath::standardizePath(wideToUtf8(winDir));
#endif
}
@ -1789,18 +1788,18 @@ std::string CFileContainer::getApplicationDirectory(const std::string &appName,
if (appPath.empty())
{
#ifdef NL_OS_WINDOWS
char buffer[MAX_PATH];
wchar_t buffer[MAX_PATH];
#ifdef CSIDL_LOCAL_APPDATA
if (local)
{
SHGetSpecialFolderPathA(NULL, buffer, CSIDL_LOCAL_APPDATA, TRUE);
SHGetSpecialFolderPathW(NULL, buffer, CSIDL_LOCAL_APPDATA, TRUE);
}
else
#endif
{
SHGetSpecialFolderPathA(NULL, buffer, CSIDL_APPDATA, TRUE);
SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, TRUE);
}
appPath = CPath::standardizePath(buffer);
appPath = CPath::standardizePath(wideToUtf8(buffer));
#elif defined(NL_OS_MAC)
appPath = CPath::standardizePath(getenv("HOME"));
appPath += "/Library/Application Support/";
@ -1918,7 +1917,7 @@ string CFile::getPath (const string &filename)
bool CFile::isDirectory (const string &filename)
{
#ifdef NL_OS_WINDOWS
DWORD res = GetFileAttributes(filename.c_str());
DWORD res = GetFileAttributesW(utf8ToWide(filename));
if (res == INVALID_FILE_ATTRIBUTES)
{
// nlwarning ("PATH: '%s' is not a valid file or directory name", filename.c_str ());
@ -1941,7 +1940,7 @@ bool CFile::isDirectory (const string &filename)
bool CFile::isExists (const string &filename)
{
#ifdef NL_OS_WINDOWS
return (GetFileAttributes(filename.c_str()) != INVALID_FILE_ATTRIBUTES);
return GetFileAttributesW(utf8ToWide(filename)) != INVALID_FILE_ATTRIBUTES;
#else // NL_OS_WINDOWS
struct stat buf;
return stat (filename.c_str (), &buf) == 0;
@ -1950,7 +1949,7 @@ bool CFile::isExists (const string &filename)
bool CFile::createEmptyFile (const std::string& filename)
{
FILE *file = fopen (filename.c_str(), "wb");
FILE *file = nlfopen (filename, "wb");
if (file)
{
@ -1964,7 +1963,15 @@ bool CFile::createEmptyFile (const std::string& filename)
bool CFile::fileExists (const string& filename)
{
//H_AUTO(FileExists);
return ! ! fstream( filename.c_str(), ios::in );
FILE *file = nlfopen(filename, "rb");
if (file)
{
fclose(file);
return true;
}
return false;
}
@ -2013,7 +2020,7 @@ uint32 CFile::getFileSize (const std::string &filename)
{
#if defined (NL_OS_WINDOWS)
struct _stat buf;
int result = _stat (filename.c_str (), &buf);
int result = _wstat (utf8ToWide(filename), &buf);
#elif defined (NL_OS_UNIX)
struct stat buf;
int result = stat (filename.c_str (), &buf);
@ -2064,7 +2071,7 @@ uint32 CFile::getFileModificationDate(const std::string &filename)
// Use the WIN32 API to read the file times in UTC
// create a file handle (this does not open the file)
HANDLE h = CreateFile(fn.c_str(), 0, 0, NULL, OPEN_EXISTING, 0, 0);
HANDLE h = CreateFileW(utf8ToWide(fn), 0, 0, NULL, OPEN_EXISTING, 0, 0);
if (h == INVALID_HANDLE_VALUE)
{
nlwarning("Can't get modification date on file '%s' : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str());
@ -2134,7 +2141,7 @@ bool CFile::setFileModificationDate(const std::string &filename, uint32 modTime)
// Use the WIN32 API to set the file times in UTC
// create a file handle (this does not open the file)
HANDLE h = CreateFile(fn.c_str(), GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
HANDLE h = CreateFileW(utf8ToWide(fn), GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
if (h == INVALID_HANDLE_VALUE)
{
nlwarning("Can't set modification date on file '%s' (error accessing file) : %s", fn.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str());
@ -2219,10 +2226,10 @@ uint32 CFile::getFileCreationDate(const std::string &filename)
#if defined (NL_OS_WINDOWS)
struct _stat buf;
int result = _stat (fn.c_str (), &buf);
int result = _wstat(utf8ToWide(fn), &buf);
#elif defined (NL_OS_UNIX)
struct stat buf;
int result = stat (fn.c_str (), &buf);
int result = stat(fn.c_str (), &buf);
#endif
if (result != 0) return 0;
@ -2299,9 +2306,6 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c
std::string sdest = CPath::standardizePath(dest,false);
std::string ssrc = CPath::standardizePath(src,false);
// return copyFile ? CopyFile(dossrc.c_str(), dosdest.c_str(), failIfExists) != FALSE
// : MoveFile(dossrc.c_str(), dosdest.c_str()) != FALSE;
if (progress) progress->progress(0.f);
if(copyFile)
{
@ -2311,13 +2315,13 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c
{
totalSize = CFile::getFileSize(ssrc);
}
FILE *fp1 = fopen(ssrc.c_str(), "rb");
FILE *fp1 = nlfopen(ssrc, "rb");
if (fp1 == NULL)
{
nlwarning ("PATH: CopyMoveFile error: can't fopen in read mode '%s'", ssrc.c_str());
return false;
}
FILE *fp2 = fopen(sdest.c_str(), "wb");
FILE *fp2 = nlfopen(sdest, "wb");
if (fp2 == NULL)
{
nlwarning ("PATH: CopyMoveFile error: can't fopen in read write mode '%s'", sdest.c_str());
@ -2356,7 +2360,7 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c
else
{
#ifdef NL_OS_WINDOWS
if (MoveFile(ssrc.c_str(), sdest.c_str()) == 0)
if (MoveFileW(utf8ToWide(ssrc), utf8ToWide(sdest)) == 0)
{
sint lastError = NLMISC::getLastError();
nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)",
@ -2390,15 +2394,15 @@ bool CFile::copyFile(const std::string &dest, const std::string &src, bool failI
bool CFile::quickFileCompare(const std::string &fileName0, const std::string &fileName1)
{
// make sure the files both exist
if (!fileExists(fileName0.c_str()) || !fileExists(fileName1.c_str()))
if (!fileExists(fileName0) || !fileExists(fileName1))
return false;
// compare time stamps
if (getFileModificationDate(fileName0.c_str()) != getFileModificationDate(fileName1.c_str()))
if (getFileModificationDate(fileName0) != getFileModificationDate(fileName1))
return false;
// compare file sizes
if (getFileSize(fileName0.c_str()) != getFileSize(fileName1.c_str()))
if (getFileSize(fileName0) != getFileSize(fileName1))
return false;
// everything matched so return true
@ -2408,14 +2412,14 @@ bool CFile::quickFileCompare(const std::string &fileName0, const std::string &fi
bool CFile::thoroughFileCompare(const std::string &fileName0, const std::string &fileName1,uint32 maxBufSize)
{
// make sure the files both exist
if (!fileExists(fileName0.c_str()) || !fileExists(fileName1.c_str()))
if (!fileExists(fileName0) || !fileExists(fileName1))
return false;
// setup the size variable from file length of first file
uint32 fileSize=getFileSize(fileName0.c_str());
uint32 fileSize=getFileSize(fileName0);
// compare file sizes
if (fileSize != getFileSize(fileName1.c_str()))
if (fileSize != getFileSize(fileName1))
return false;
// allocate a couple of data buffers for our 2 files
@ -2459,7 +2463,7 @@ bool CFile::moveFile(const std::string &dest, const std::string &src)
bool CFile::createDirectory(const std::string &filename)
{
#ifdef NL_OS_WINDOWS
return _mkdir(filename.c_str())==0;
return _wmkdir(utf8ToWide(filename))==0;
#else
// Set full permissions....
return mkdir(filename.c_str(), 0xFFFF)==0;
@ -2680,11 +2684,16 @@ bool CPath::isAbsolutePath(const std::string &path)
bool CFile::setRWAccess(const std::string &filename)
{
#ifdef NL_OS_WINDOWS
ucstring ucFile;
ucFile.fromUtf8(filename);
wchar_t *wideFile = (wchar_t*)ucFile.c_str();
// if the file exists and there's no write access
if (_access (filename.c_str(), 00) == 0 && _access (filename.c_str(), 06) == -1)
if (_waccess (wideFile, 00) == 0 && _waccess (wideFile, 06) == -1)
{
// try to set the read/write access
if (_chmod (filename.c_str(), _S_IREAD | _S_IWRITE) == -1)
if (_wchmod (wideFile, _S_IREAD | _S_IWRITE) == -1)
{
if (INelContext::getInstance().getAlreadyCreateSharedAmongThreads())
{
@ -2719,15 +2728,14 @@ bool CFile::setRWAccess(const std::string &filename)
return true;
}
#ifdef NL_OS_WINDOWS
#define unlink _unlink
#endif
bool CFile::deleteFile(const std::string &filename)
{
setRWAccess(filename);
int res = unlink (filename.c_str());
#ifdef NL_OS_WINDOWS
sint res = _wunlink(utf8ToWide(filename));
#else
sint res = unlink(filename.c_str());
#endif
if (res == -1)
{
if (INelContext::getInstance().getAlreadyCreateSharedAmongThreads())
@ -2739,14 +2747,14 @@ bool CFile::deleteFile(const std::string &filename)
return true;
}
#ifdef NL_OS_WINDOWS
#define rmdir _rmdir
#endif
bool CFile::deleteDirectory(const std::string &filename)
{
setRWAccess(filename);
int res = rmdir (filename.c_str());
#ifdef NL_OS_WINDOWS
sint res = _wrmdir(utf8ToWide(filename));
#else
sint res = rmdir(filename.c_str());
#endif
if (res == -1)
{
nlwarning ("PATH: Can't delete directory '%s': (errno %d) %s", filename.c_str(), errno, strerror(errno));

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

View file

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

View file

@ -51,7 +51,7 @@ void *CSharedMemory::createSharedMemory( TSharedMemId sharedMemId, uint32 size
#ifdef NL_OS_WINDOWS
// Create a file mapping backed by the virtual memory swap file (not a data file)
HANDLE hMapFile = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, sharedMemId );
HANDLE hMapFile = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, sharedMemId );
if ( (hMapFile == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS) )
{
nlwarning( "SHDMEM: Cannot create file mapping for smid %s: error %u%s, mapFile %p", sharedMemId, GetLastError(), (GetLastError()==ERROR_ALREADY_EXISTS) ? " (already exists) ": "", hMapFile );
@ -97,7 +97,7 @@ void *CSharedMemory::accessSharedMemory( TSharedMemId sharedMemId )
#ifdef NL_OS_WINDOWS
// Open the existing file mapping by name
HANDLE hMapFile = OpenFileMapping( FILE_MAP_ALL_ACCESS, false, sharedMemId );
HANDLE hMapFile = OpenFileMappingA( FILE_MAP_ALL_ACCESS, false, sharedMemId );
if ( hMapFile == NULL )
return NULL;
//nldebug( "SHDMEM: Opening smid %s --> mapFile %p", sharedMemId, hMapFile );

View file

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

View file

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

View file

@ -231,11 +231,11 @@ bool CSystemUtils::supportUnicode()
{
init = true;
#ifdef NL_OS_WINDOWS
OSVERSIONINFO osvi;
OSVERSIONINFOA osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
// get Windows version
if (GetVersionEx(&osvi))
if (GetVersionExA(&osvi))
{
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
@ -273,14 +273,14 @@ bool CSystemUtils::isScreensaverEnabled()
// SystemParametersInfoA(SPI_GETSCREENSAVEACTIVE, 0, &bRetValue, 0);
// res = (bRetValue == TRUE);
HKEY hKeyScreenSaver = NULL;
LSTATUS lReturn = RegOpenKeyExA(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, &hKeyScreenSaver);
LSTATUS lReturn = RegOpenKeyExA(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_QUERY_VALUE, &hKeyScreenSaver);
if (lReturn == ERROR_SUCCESS)
{
DWORD dwType = 0L;
DWORD dwSize = KeyMaxLength;
unsigned char Buffer[KeyMaxLength] = {0};
lReturn = RegQueryValueExA(hKeyScreenSaver, TEXT("SCRNSAVE.EXE"), NULL, &dwType, NULL, &dwSize);
lReturn = RegQueryValueExA(hKeyScreenSaver, "SCRNSAVE.EXE", NULL, &dwType, NULL, &dwSize);
// if SCRNSAVE.EXE is present, check also if it's empty
if (lReturn == ERROR_SUCCESS)
res = (Buffer[0] != '\0');
@ -315,20 +315,21 @@ string CSystemUtils::getRegKey(const string &Entry)
#ifdef NL_OS_WINDOWS
HKEY hkey;
if(RegOpenKeyEx(HKEY_CURRENT_USER, RootKey.c_str(), 0, KEY_READ, &hkey) == ERROR_SUCCESS)
if (RegOpenKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, KEY_READ, &hkey) == ERROR_SUCCESS)
{
DWORD dwType = 0L;
DWORD dwSize = KeyMaxLength;
unsigned char Buffer[KeyMaxLength];
wchar_t Buffer[KeyMaxLength];
if(RegQueryValueEx(hkey, Entry.c_str(), NULL, &dwType, Buffer, &dwSize) != ERROR_SUCCESS)
if (RegQueryValueExW(hkey, utf8ToWide(Entry), NULL, &dwType, (LPBYTE)Buffer, &dwSize) != ERROR_SUCCESS)
{
nlwarning("Can't get the reg key '%s'", Entry.c_str());
}
else
{
ret = (char*)Buffer;
ret = wideToUtf8(Buffer);
}
RegCloseKey(hkey);
}
else
@ -346,10 +347,14 @@ bool CSystemUtils::setRegKey(const string &ValueName, const string &Value)
HKEY hkey;
DWORD dwDisp;
char nstr[] = { 0x00 };
if (RegCreateKeyExA(HKEY_CURRENT_USER, RootKey.c_str(), 0, nstr, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS)
if (RegCreateKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS)
{
if (RegSetValueExA(hkey, ValueName.c_str(), 0L, REG_SZ, (const BYTE *)Value.c_str(), (DWORD)(Value.size())+1) == ERROR_SUCCESS)
ucstring utf16Value = ucstring::makeFromUtf8(Value);
// we must use the real Unicode string size in bytes
DWORD size = (utf16Value.length() + 1) * 2;
if (RegSetValueExW(hkey, utf8ToWide(ValueName), 0L, REG_SZ, (const BYTE *)utf16Value.c_str(), size) == ERROR_SUCCESS)
res = true;
RegCloseKey(hkey);
}
@ -453,7 +458,7 @@ static void EnumerateUsingDXGI(IDXGIFactory *pDXGIFactory)
{
SAdapter adapter;
adapter.id = index;
adapter.name = ucstring((ucchar*)desc.Description).toUtf8();
adapter.name = wideToUtf8(desc.Description);
adapter.memory = desc.DedicatedVideoMemory / 1024;
adapter.found = true;

View file

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

View file

@ -40,7 +40,7 @@ using namespace std;
namespace NLMISC {
static CHARFORMAT2 CharFormat;
static CHARFORMAT2A CharFormat;
CWinDisplayer::CWinDisplayer(const char *displayerName) : CWindowDisplayer(displayerName), Exit(false)
{
@ -149,10 +149,9 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtr (hWnd, GWLP_USERDATA);
// get the text as unicode string
GetWindowTextW(cwd->_HInputEdit, wText, 20000);
ucstring ucs((ucchar*)wText);
// and convert it to UTF-8 encoding.
TextSend = ucs.toUtf8();
SendMessage (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)"");
TextSend = wideToUtf8(wText);
SendMessageA (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)"");
const char *pos2 = TextSend.c_str();
string str;
while (*pos2 != '\0')
@ -193,14 +192,13 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// get the text as unicode string
GetWindowTextW(cwd->_HInputEdit, wText, 20000);
ucstring ucs((ucchar*)wText);
// and convert it to UTF-8 encoding
string str = ucs.toUtf8();
string str = wideToUtf8(wText);
nlassert (cwd->Log != NULL);
ICommand::expand (str, *cwd->Log);
SendMessage (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)str.c_str());
SendMessageW (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)wText);
SendMessage (cwd->_HInputEdit, EM_SETSEL, str.size(), str.size());
SendMessageA (cwd->_HInputEdit, EM_SETSEL, wcslen(wText), wcslen(wText));
return 1;
}
@ -209,7 +207,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (pmf->wParam == VK_UP)
{
CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrW (hWnd, GWLP_USERDATA);
CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrA (hWnd, GWLP_USERDATA);
if (cwd->_PosInHistory > 0)
cwd->_PosInHistory--;
@ -221,7 +219,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ucs.fromUtf8(cwd->_History[cwd->_PosInHistory]);
// set the text as unicode string
SetWindowTextW(cwd->_HInputEdit, (LPCWSTR)ucs.c_str());
SendMessage (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size());
SendMessageA (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size());
}
}
else if (pmf->wParam == VK_DOWN)
@ -238,7 +236,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ucs.fromUtf8(cwd->_History[cwd->_PosInHistory]);
// set the text as unicode string
SetWindowTextW(cwd->_HInputEdit, (LPCWSTR)ucs.c_str());
SendMessage (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size());
SendMessageA (cwd->_HInputEdit, EM_SETSEL, (WPARAM)ucs.size(), (LPARAM)ucs.size());
}
}
}
@ -262,13 +260,13 @@ void CWinDisplayer::updateLabels ()
// create a button for command and label for variables
if (access.value()[i].Value[0] == '@')
{
access.value()[i].Hwnd = CreateWindowW (L"BUTTON", L"", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL);
access.value()[i].Hwnd = CreateWindowA ("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtrA(_HWnd, GWLP_HINSTANCE), NULL);
}
else
{
access.value()[i].Hwnd = CreateWindowW (L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL);
access.value()[i].Hwnd = CreateWindowA ("STATIC", "", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtrA(_HWnd, GWLP_HINSTANCE), NULL);
}
SendMessage ((HWND)access.value()[i].Hwnd, WM_SETFONT, (WPARAM)_HFont, TRUE);
SendMessageA ((HWND)access.value()[i].Hwnd, WM_SETFONT, (WPARAM)_HFont, TRUE);
needResize = true;
}
@ -290,7 +288,7 @@ void CWinDisplayer::updateLabels ()
}
}
SendMessage ((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM) n.c_str());
SendMessageW ((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM) utf8ToWide(n));
access.value()[i].NeedUpdate = false;
}
}
@ -427,14 +425,14 @@ void CWinDisplayer::open (string titleBar, bool iconified, sint x, sint y, sint
dwStyle |= WS_HSCROLL;
_HEdit = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, RICHEDIT_CLASSW, L"", dwStyle, 0, _ToolBarHeight, w, h-_ToolBarHeight-_InputEditHeight, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL);
SendMessage (_HEdit, WM_SETFONT, (WPARAM)_HFont, TRUE);
SendMessageA (_HEdit, WM_SETFONT, (WPARAM)_HFont, TRUE);
// set the edit text limit to lot of :)
SendMessage (_HEdit, EM_LIMITTEXT, -1, 0);
SendMessageA (_HEdit, EM_LIMITTEXT, -1, 0);
CharFormat.cbSize = sizeof(CharFormat);
CharFormat.dwMask = CFM_COLOR;
SendMessage(_HEdit,EM_GETCHARFORMAT,(WPARAM)0,(LPARAM)&CharFormat);
SendMessageA(_HEdit,EM_GETCHARFORMAT,(WPARAM)0,(LPARAM)&CharFormat);
CharFormat.dwEffects &= ~CFE_AUTOCOLOR;
// create the input edit control
@ -445,7 +443,7 @@ void CWinDisplayer::open (string titleBar, bool iconified, sint x, sint y, sint
LRESULT dwEvent = SendMessageW(_HInputEdit, EM_GETEVENTMASK, (WPARAM)0, (LPARAM)0);
dwEvent |= ENM_MOUSEEVENTS | ENM_KEYEVENTS | ENM_CHANGE;
SendMessage(_HInputEdit, EM_SETEVENTMASK, (WPARAM)0, (LPARAM)dwEvent);
SendMessageA(_HInputEdit, EM_SETEVENTMASK, (WPARAM)0, (LPARAM)dwEvent);
// resize the window
RECT rc;
@ -477,8 +475,8 @@ void CWinDisplayer::clear ()
bool focus = (GetFocus() == _HEdit);
if (focus)
{
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL);
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL);
SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL);
SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL);
}
// get number of line
@ -534,13 +532,13 @@ void CWinDisplayer::display_main ()
bool focus = (GetFocus() == _HEdit);
if (focus)
{
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL);
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL);
SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOVSCROLL);
SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_AND,(LPARAM)~ECO_AUTOHSCROLL);
}
// store old selection
DWORD startSel, endSel;
SendMessage (_HEdit, EM_GETSEL, (WPARAM)&startSel, (LPARAM)&endSel);
SendMessageA (_HEdit, EM_GETSEL, (WPARAM)&startSel, (LPARAM)&endSel);
// find how many lines we have to remove in the current output to add new lines
@ -554,7 +552,7 @@ void CWinDisplayer::display_main ()
if (nblineremove == _HistorySize)
{
SendMessage (_HEdit, WM_SETTEXT, 0, (LPARAM) "");
SendMessageA (_HEdit, WM_SETTEXT, 0, (LPARAM) "");
startSel = endSel = -1;
}
else
@ -594,31 +592,31 @@ void CWinDisplayer::display_main ()
str += ucstring::makeFromUtf8((*it).second);
}
SendMessage (_HEdit, EM_SETSEL, -1, -1);
SendMessageA(_HEdit, EM_SETSEL, -1, -1);
if ((col>>24) == 0)
{
// there s a specific color
CharFormat.crTextColor = RGB ((col>>16)&0xFF, (col>>8)&0xFF, col&0xFF);
SendMessage((HWND) _HEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM) &CharFormat);
SendMessageA(_HEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION, (LPARAM) &CharFormat);
}
// add the string to the edit control
SendMessageW (_HEdit, EM_REPLACESEL, FALSE, (LPARAM) str.c_str());
SendMessageW(_HEdit, EM_REPLACESEL, FALSE, (LPARAM) str.c_str());
}
// restore old selection
SendMessage (_HEdit, EM_SETSEL, startSel, endSel);
SendMessageA(_HEdit, EM_SETSEL, startSel, endSel);
SendMessage(_HEdit,EM_SETMODIFY,(WPARAM)TRUE,(LPARAM)0);
SendMessageA(_HEdit,EM_SETMODIFY,(WPARAM)TRUE,(LPARAM)0);
if (bottom)
SendMessage(_HEdit,WM_VSCROLL,(WPARAM)SB_BOTTOM,(LPARAM)0L);
SendMessageA(_HEdit,WM_VSCROLL,(WPARAM)SB_BOTTOM,(LPARAM)0L);
if (focus)
{
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOVSCROLL);
SendMessage(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOHSCROLL);
SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOVSCROLL);
SendMessageA(_HEdit,EM_SETOPTIONS,ECOOP_OR,(LPARAM)ECO_AUTOHSCROLL);
}
}

View file

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

View file

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

View file

@ -271,7 +271,7 @@ bool sendEmail (const string &smtpServer, const string &from, const string &to,
char dst_buf[dst_buf_size + 1];
size_t size;
FILE *src_stream = fopen (attachedFile.c_str(), "rb");
FILE *src_stream = nlfopen (attachedFile, "rb");
if (src_stream == NULL)
{
nlwarning ("EMAIL: Can't attach file '%s' to the email because the file can't be open", attachedFile.c_str());
@ -299,7 +299,7 @@ bool sendEmail (const string &smtpServer, const string &from, const string &to,
}
// debug, display what we send into a file
// { FILE *fp = fopen (CFile::findNewFile(getLogDirectory() + "mail.txt").c_str(), "wb");
// { FILE *fp = nlfopen (CFile::findNewFile(getLogDirectory() + "mail.txt"), "wb");
// fwrite (formatedBody.c_str(), 1, formatedBody.size(), fp);
// fclose (fp); }

View file

@ -27,8 +27,87 @@
#ifdef NL_OS_WINDOWS
# include <winsock2.h>
# include <ws2tcpip.h>
# include <ws2ipdef.h>
// for Windows 2000 compatibility
# include <wspiapi.h>
#if !defined(NTDDI_VISTA) || (NTDDI_VERSION < NTDDI_VISTA)
// inet_pton and inet_ntop not defined in winsock DLL before Vista
// taken from http://stackoverflow.com/questions/13731243/what-is-the-windows-xp-equivalent-of-inet-pton-or-inetpton
int inet_pton(int af, const char *src, void *dst)
{
struct sockaddr_storage ss;
int size = sizeof(ss);
char src_copy[INET6_ADDRSTRLEN+1];
ZeroMemory(&ss, sizeof(ss));
// stupid non-const API
strncpy (src_copy, src, INET6_ADDRSTRLEN+1);
src_copy[INET6_ADDRSTRLEN] = 0;
if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0)
{
switch(af)
{
case AF_INET:
*(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
return 1;
case AF_INET6:
*(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
return 1;
}
}
return 0;
}
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
{
struct sockaddr_storage ss;
unsigned long s = size;
ZeroMemory(&ss, sizeof(ss));
ss.ss_family = af;
switch(af)
{
case AF_INET:
((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
break;
case AF_INET6:
((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
break;
default:
return NULL;
}
// cannot directly use &size because of strict aliasing rules
return WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0 ? dst : NULL;
}
BOOLEAN IN6_IS_ADDR_UNSPECIFIED(CONST IN6_ADDR *a)
{
//
// We can't use the in6addr_any variable, since that would
// require existing callers to link with a specific library.
//
return (BOOLEAN)((a->s6_words[0] == 0) &&
(a->s6_words[1] == 0) &&
(a->s6_words[2] == 0) &&
(a->s6_words[3] == 0) &&
(a->s6_words[4] == 0) &&
(a->s6_words[5] == 0) &&
(a->s6_words[6] == 0) &&
(a->s6_words[7] == 0));
}
#endif
#elif defined NL_OS_UNIX
# include <unistd.h>
# include <sys/socket.h>
@ -58,20 +137,32 @@ bool CInetAddress::RetrieveNames = false;
CInetAddress::CInetAddress()
{
init();
// IPv4
_SockAddr->sin_port = 0; // same as htons(0)
memset( &_SockAddr->sin_addr, 0, sizeof(in_addr) ); // same as htonl(INADDR_ANY)
// IPv6
_SockAddr6->sin6_port = 0;
memset( &_SockAddr6->sin6_addr, 0, sizeof(in6_addr) ); // same as htonl(INADDR_ANY)
}
/*
* Constructor with ip address, port=0
* Constructor with IPv4 address, port=0
*/
CInetAddress::CInetAddress( const in_addr *ip, const char *hostname )
{
init();
// IPv4
_SockAddr->sin_port = 0;
memcpy( &_SockAddr->sin_addr, ip, sizeof(in_addr) );
// invalid IPv6
_SockAddr6->sin6_port = 0;
memset( &_SockAddr6->sin6_addr, 0, sizeof(in6_addr) );
// get the host name to be displayed
if(hostname)
{
@ -81,6 +172,36 @@ CInetAddress::CInetAddress( const in_addr *ip, const char *hostname )
{
updateHostName();
}
_Valid = true;
}
/*
* Constructor with IPv6 address, port=0
*/
CInetAddress::CInetAddress( const in6_addr *ip, const char *hostname )
{
init();
// IPv6
_SockAddr6->sin6_port = 0;
memcpy( &_SockAddr6->sin6_addr, ip, sizeof(in6_addr) );
// invalid IPv4
_SockAddr->sin_port = 0;
memset( &_SockAddr->sin_addr, 0, sizeof(in_addr) );
// get the host name to be displayed
if(hostname)
{
_HostName = hostname;
}
else
{
updateHostName();
}
_Valid = true;
}
@ -92,7 +213,20 @@ void CInetAddress::updateHostName()
{
char host[NI_MAXHOST];
sint status = getnameinfo((struct sockaddr *) _SockAddr, sizeof (struct sockaddr), host, NI_MAXHOST, NULL, 0, NI_NUMERICSERV);
// if unable to resolve DNS, returns an error and use IP address instead
sint status = 1;
// check if IPv4 is valid
if (_SockAddr->sin_addr.s_addr != 0)
{
// IPv4
status = getnameinfo((struct sockaddr *) _SockAddr, sizeof (sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICSERV | NI_NAMEREQD);
}
else if (!IN6_IS_ADDR_UNSPECIFIED(&_SockAddr6->sin6_addr))
{
// IPv6
status = getnameinfo((struct sockaddr *) _SockAddr6, sizeof (sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICSERV | NI_NAMEREQD);
}
if ( status )
{
@ -134,6 +268,7 @@ CInetAddress::CInetAddress( const CInetAddress& other )
init();
_HostName = other._HostName;
memcpy( _SockAddr, other._SockAddr, sizeof( *_SockAddr ) );
memcpy( _SockAddr6, other._SockAddr6, sizeof( *_SockAddr6 ) );
_Valid = other._Valid;
}
@ -145,6 +280,7 @@ CInetAddress& CInetAddress::operator=( const CInetAddress& other )
{
_HostName = other._HostName;
memcpy( _SockAddr, other._SockAddr, sizeof( *_SockAddr ) );
memcpy( _SockAddr6, other._SockAddr6, sizeof( *_SockAddr6 ) );
_Valid = other._Valid;
return *this;
}
@ -185,9 +321,15 @@ void CInetAddress::init()
_Valid = false;
// IPv4
_SockAddr = new sockaddr_in;
memset(_SockAddr, 0, sizeof(sockaddr_in));
_SockAddr->sin_family = AF_INET;
memset( _SockAddr->sin_zero, 0, 8 );
// IPv6
_SockAddr6 = new sockaddr_in6;
memset(_SockAddr6, 0, sizeof(sockaddr_in6));
_SockAddr6->sin6_family = AF_INET6;
}
@ -197,6 +339,7 @@ void CInetAddress::init()
CInetAddress::~CInetAddress()
{
delete _SockAddr;
delete _SockAddr6;
// _Valid = false;
}
@ -225,12 +368,41 @@ void CInetAddress::setNameAndPort( const std::string& hostNameAndPort )
/*
* Resolves a name
*/
CInetAddress& CInetAddress::setByName( const std::string& hostName )
CInetAddress& CInetAddress::setByName(const std::string& hostName)
{
// Try to convert directly for addresses such as a.b.c.d
in_addr iaddr;
iaddr.s_addr = inet_addr( hostName.c_str() );
if ( iaddr.s_addr == INADDR_NONE )
// invalid IPv4
memset(&_SockAddr->sin_addr, 0, sizeof(in_addr));
// invalid IPv6
memset(&_SockAddr6->sin6_addr, 0, sizeof(in6_addr));
// Try to convert directly for addresses such as a.b.c.d and a:b:c:d:e:f:g:h
in_addr ipv4;
sint res = inet_pton(AF_INET, hostName.c_str(), &ipv4);
if (res == 1)
{
// hostname is a valid IPv4
memcpy(&_SockAddr->sin_addr, &ipv4, sizeof(in_addr));
}
else
{
in6_addr ipv6;
res = inet_pton(AF_INET6, hostName.c_str(), &ipv6);
if (res == 1)
{
// hostname is a valid IPv6
memcpy(&_SockAddr6->sin6_addr, &ipv6, sizeof(in6_addr));
}
}
if (res == 1)
{
// use IPv4 or IPv6 as hostname
_HostName = hostName;
}
else
{
// Otherwise use the traditional DNS look-up
struct addrinfo hints;
@ -249,6 +421,9 @@ CInetAddress& CInetAddress::setByName( const std::string& hostName )
throw ESocket( (string("Hostname resolution failed for ")+hostName).c_str() );
}
// hostname is valid, use it
_HostName = hostName;
struct addrinfo *p = res;
// process all addresses
@ -260,20 +435,14 @@ CInetAddress& CInetAddress::setByName( const std::string& hostName )
// ipv4
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
// convert the IP to a string
_HostName = string(inet_ntoa(ipv4->sin_addr));
memcpy( &_SockAddr->sin_addr, &ipv4->sin_addr, sizeof(in_addr) );
}
else if (p->ai_family == AF_INET6)
{
// ipv6
// TODO: modify class to be able to handle IPv6
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
// struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
// convert the IP to a string
// inet_ntop(p->ai_family, addr, ipstr, sizeof(ipstr));
// memcpy( &_SockAddr->sin_addr, &ipv6->sin_addr, sizeof(in_addr) );
memcpy( &_SockAddr6->sin6_addr, &ipv6->sin6_addr, sizeof(in6_addr) );
}
// process next address
@ -283,11 +452,7 @@ CInetAddress& CInetAddress::setByName( const std::string& hostName )
// free the linked list
freeaddrinfo(res);
}
else
{
_HostName = hostName;
memcpy( &_SockAddr->sin_addr, &iaddr, sizeof(iaddr) );
}
_Valid = true;
return *this;
}
@ -296,10 +461,10 @@ CInetAddress& CInetAddress::setByName( const std::string& hostName )
/*
* Sets port
*/
void CInetAddress::setPort( uint16 port )
void CInetAddress::setPort(uint16 port)
{
_SockAddr->sin_port = htons( port );
_SockAddr->sin_port = htons(port);
_SockAddr6->sin6_port = htons(port);
}
@ -308,7 +473,10 @@ void CInetAddress::setPort( uint16 port )
*/
void CInetAddress::setSockAddr( const sockaddr_in* saddr )
{
memcpy( _SockAddr, saddr, sizeof(*saddr) );
memcpy(_SockAddr, saddr, sizeof(*saddr) );
// invalid IPv6
memset(&_SockAddr6->sin6_addr, 0, sizeof(in6_addr));
// Get host name
// Warning: when it can't find it, it take more than 4 seconds
@ -316,6 +484,28 @@ void CInetAddress::setSockAddr( const sockaddr_in* saddr )
{
updateHostName();
}
_Valid = true;
}
/* Sets internal socket address directly (contents is copied).
* It also retrieves the host name if CInetAddress::RetrieveNames is true.
*/
void CInetAddress::setSockAddr6( const sockaddr_in6* saddr6 )
{
memcpy( _SockAddr6, saddr6, sizeof(*saddr6) );
// invalid IPv4
memset(&_SockAddr->sin_addr, 0, sizeof(in_addr));
// Get host name
// Warning: when it can't find it, it take more than 4 seconds
if ( CInetAddress::RetrieveNames )
{
updateHostName();
}
_Valid = true;
}
@ -330,7 +520,7 @@ bool CInetAddress::isValid() const
/*
* Returns internal socket address (read only)
* Returns internal IPv4 socket address (read only)
*/
const sockaddr_in *CInetAddress::sockAddr() const
{
@ -338,6 +528,15 @@ const sockaddr_in *CInetAddress::sockAddr() const
}
/*
* Returns internal IPv6 socket address (read only)
*/
const sockaddr_in6 *CInetAddress::sockAddr6() const
{
return _SockAddr6;
}
/*
* Returns internal IP address
*/
@ -383,10 +582,13 @@ uint32 CInetAddress::internalNetAddress() const
*/
string CInetAddress::ipAddress() const
{
/*stringstream ss; // or use inet_ntoa
ss << inet_ntoa ( _SockAddr->sin_addr );
return ss.str();*/
const char *name = inet_ntoa ( _SockAddr->sin_addr );
// longer size is IPv6
char straddr[INET6_ADDRSTRLEN];
const char *name = inet_ntop(AF_INET, &_SockAddr->sin_addr, straddr, INET_ADDRSTRLEN);
// IPv4 is invalid, return IPv6
if (name == NULL || strcmp(name, "0.0.0.0") == 0) name = inet_ntop(AF_INET6, &_SockAddr6->sin6_addr, straddr, INET6_ADDRSTRLEN);
return name ? string (name) : "";
}
@ -414,9 +616,6 @@ uint16 CInetAddress::port() const
*/
std::string CInetAddress::asString() const
{
// stringstream ss;
// ss << hostName() << ":" << port() << " (" << ipAddress() << ")";
// return ss.str();
return hostName() + ":" + NLMISC::toString(port()) + " (" + ipAddress() + ")";
}
@ -426,9 +625,6 @@ std::string CInetAddress::asString() const
*/
std::string CInetAddress::asIPString() const
{
// stringstream ss;
// ss << ipAddress() << ":" << port();
// return ss.str();
return ipAddress() + ":" + NLMISC::toString(port());
}
@ -537,13 +733,9 @@ std::vector<CInetAddress> CInetAddress::localAddresses()
else if (p->ai_family == AF_INET6)
{
// ipv6
// TODO: modify class to be able to handle IPv6
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
// struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
// convert the IP to a string
// inet_ntop(p->ai_family, addr, ipstr, sizeof(ipstr));
// memcpy( &_SockAddr->sin_addr, &ipv6->sin_addr, sizeof(in_addr) );
vect.push_back( CInetAddress( &ipv6->sin6_addr, localhost ) );
}
// process next address

View file

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

View file

@ -14,17 +14,24 @@
// 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 NL_STDNET_H
#define NL_STDNET_H
#include "nel/misc/types_nl.h"
#ifdef NL_OS_WINDOWS
# define WIN32_LEAN_AND_MEAN
# define _WIN32_WINDOWS 0x0500
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0500
# endif
# ifndef NL_COMP_MINGW
# define WINVER 0x0500
# define NOMINMAX
# endif
# include <winsock2.h>
# include <windows.h>
#endif // NL_OS_WINDOWS
# include <WinSock2.h>
# include <Windows.h>
#endif
#include <map>
#include <set>
@ -49,7 +56,6 @@
#include <errno.h>
#include "nel/misc/debug.h"
#include "nel/misc/common.h"
#include "nel/misc/stream.h"
#include "nel/misc/time_nl.h"
@ -57,3 +63,5 @@
#include "nel/misc/variable.h"
#include "nel/misc/mem_stream.h"
#include "nel/misc/hierarchical_timer.h"
#endif

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/>.
#include <nel/misc/types_nl.h>
#include "database_config.h"
#include "nel/pipeline/database_config.h"
#include <nel/misc/debug.h>
#include <nel/misc/path.h>
@ -25,6 +25,8 @@
using namespace std;
using namespace NLMISC;
namespace NLPIPELINE {
TPathString CDatabaseConfig::s_RootPath;
NLMISC::CConfigFile *CDatabaseConfig::s_ConfigFile = NULL;
CDatabaseConfig CDatabaseConfig::s_Instance;
@ -104,4 +106,6 @@ void CDatabaseConfig::release()
cleanup();
}
} /* namespace NLPIPELINE */
/* end of file */

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

View file

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

View file

@ -195,13 +195,17 @@ uint32 CAudioDecoderVorbis::getNextBytes(uint8 *buffer, uint32 minimum, uint32 m
uint8 CAudioDecoderVorbis::getChannels()
{
vorbis_info *vi = ov_info(&_OggVorbisFile, -1);
return (uint8)vi->channels;
if (vi) return (uint8)vi->channels;
nlwarning("ov_info returned NULL");
return 0;
}
uint CAudioDecoderVorbis::getSamplesPerSec()
{
vorbis_info *vi = ov_info(&_OggVorbisFile, -1);
return (uint)vi->rate;
if (vi) return (uint)vi->rate;
nlwarning("ov_info returned NULL");
return 0;
}
uint8 CAudioDecoderVorbis::getBitsPerSample()

View file

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

View file

@ -17,6 +17,7 @@
#include "nel/misc/file.h"
#include "nel/misc/path.h"
#include "nel/misc/common.h"
#include "nel/3d/scene_group.h"
#include "nel/3d/zone.h"
#include "nel/3d/skeleton_shape.h"
@ -660,9 +661,7 @@ int main(int argc, const char *argv[])
options.insert (argv[i]);
// Open log
FILE *logStream;
logStream= fopen(std::string(getLogDirectory() + "file_info.log").c_str(), "wt");
FILE *logStream = nlfopen(getLogDirectory() + "file_info.log", "wt");
// parse dir or file ??
const char *fileName= argv[1];

View file

@ -998,7 +998,8 @@ int main(int nNbArg, char **ppArgs)
ChDir (sExeDir);
// out a text file, with list of
FILE *out= fopen(ppArgs[4], "wt");
FILE *out = NLMISC::nlfopen(ppArgs[4], "wt");
if(!out)
{
outString(string("ERROR: cannot save ")+ppArgs[4]);

View file

@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES(${assimp_INCLUDE_DIRS})
NL_TARGET_LIB(mesh_utils ${SRCS} ${HDRS})
TARGET_LINK_LIBRARIES(mesh_utils ${assimp_LIBRARIES} nelmisc nel3d)
TARGET_LINK_LIBRARIES(mesh_utils ${assimp_LIBRARIES} nelmisc nelpipeline nel3d)
NL_DEFAULT_PROPS(mesh_utils "NeL, Tools, 3D: Mesh Utils")
NL_ADD_RUNTIME_FLAGS(mesh_utils)

View file

@ -28,7 +28,7 @@
#include <nel/misc/debug.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/texture_file.h>

View file

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

View file

@ -19,7 +19,8 @@
#include "mesh_utils.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/file.h>
#include <nel/misc/path.h>
@ -28,7 +29,6 @@
#include <nel/3d/mesh.h>
#include <nel/3d/texture_file.h>
#include "database_config.h"
#include "scene_meta.h"
#include <assimp/postprocess.h>
@ -231,7 +231,7 @@ void exportShapes(CMeshUtilsContext &context)
if (nodeContext.Shape)
{
std::string shapePath = NLMISC::CPath::standardizePath(context.Settings.DestinationDirectoryPath, true) + it->first + ".shape";
context.ToolLogger.writeDepend(NLMISC::BUILD, shapePath.c_str(), "*");
context.ToolLogger.writeDepend(NLPIPELINE::BUILD, shapePath.c_str(), "*");
NLMISC::COFile f;
if (f.open(shapePath, false, false, true))
{
@ -262,7 +262,7 @@ void exportShapes(CMeshUtilsContext &context)
std::string knownPath = NLMISC::CPath::lookup(fileName, false, false, false);
if (!knownPath.empty())
{
context.ToolLogger.writeDepend(NLMISC::RUNTIME, shapePath.c_str(), knownPath.c_str());
context.ToolLogger.writeDepend(NLPIPELINE::RUNTIME, shapePath.c_str(), knownPath.c_str());
}
else
{
@ -289,17 +289,17 @@ int exportScene(const CMeshUtilsSettings &settings)
context.ToolLogger.initDepend(settings.ToolDependLog);
if (!settings.ToolErrorLog.empty())
context.ToolLogger.initError(settings.ToolErrorLog);
context.ToolLogger.writeDepend(NLMISC::BUILD, "*", NLMISC::CPath::standardizePath(context.Settings.SourceFilePath, false).c_str()); // Base input file
context.ToolLogger.writeDepend(NLPIPELINE::BUILD, "*", NLMISC::CPath::standardizePath(context.Settings.SourceFilePath, false).c_str()); // Base input file
// Apply database configuration
if (!CDatabaseConfig::init(settings.SourceFilePath))
if (!NLPIPELINE::CProjectConfig::init(settings.SourceFilePath,
NLPIPELINE::CProjectConfig::DatabaseTextureSearchPaths,
true))
{
tlerror(context.ToolLogger, context.Settings.SourceFilePath.c_str(), "Unable to find database.cfg in input path or any of its parents.");
return EXIT_FAILURE;
// return EXIT_FAILURE; We can continue but the output will not be guaranteed...
}
CDatabaseConfig::initTextureSearchDirectories();
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(settings.SourceFilePath, 0
| aiProcess_Triangulate
@ -321,7 +321,7 @@ int exportScene(const CMeshUtilsSettings &settings)
context.InternalScene = scene;
if (context.SceneMeta.load(context.Settings.SourceFilePath))
context.ToolLogger.writeDepend(NLMISC::BUILD, "*", context.SceneMeta.metaFilePath().c_str()); // Meta input file
context.ToolLogger.writeDepend(NLPIPELINE::BUILD, "*", context.SceneMeta.metaFilePath().c_str()); // Meta input file
validateInternalNodeNames(context, context.InternalScene->mRootNode);

View file

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

View file

@ -23,7 +23,7 @@
#include "scene_meta.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/matrix.h>
@ -67,7 +67,7 @@ struct CMeshUtilsContext
const CMeshUtilsSettings &Settings;
NLMISC::CToolLogger ToolLogger;
NLPIPELINE::CToolLogger ToolLogger;
const NL_SCENE_INTERNAL_TYPE *InternalScene;
CSceneMeta SceneMeta;

View file

@ -8,6 +8,7 @@
#include "nel/misc/time_nl.h"
#include "nel/misc/file.h"
#include "nel/misc/common.h"
#include "nel/misc/triangle.h"
#include "nel/misc/bsphere.h"
#include "3d/quad_tree.h"
@ -3121,8 +3122,8 @@ void CNelExport::deleteLM(INode& ZeNode)
sprintf( tmp, "%d", i );
sSaveName += tmp;
sSaveName += ".tga";
FILE *file;
if( file = fopen(sSaveName.c_str(),"rb") )
FILE *file = nlfopen(sSaveName, "rb")
if (file)
{
fclose( file );
DeleteFile( sSaveName.c_str() );
@ -3521,8 +3522,8 @@ bool CNelExport::exportScene(std::vector<INode*>& vectNode)
sprintf( tmp, "%d", i );
sSaveName += tmp;
sSaveName += ".tga";
FILE *file;
if( file = fopen(sSaveName.c_str(),"rb") )
FILE *file = nlfopen(sSaveName, "rb");
if (file)
{
fclose( file );
DeleteFile( sSaveName.c_str() );

View file

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <nel/misc/path.h>
#include <nel/misc/common.h>
#include <nel/misc/file.h>
#include <nel/misc/config_file.h>
#include <nel/3d/u_light.h>
@ -851,7 +852,7 @@ bool ShapesExporter::renderPS(UInstance &entity, const string &output_path, doub
{
if(step > 0)
{
FILE *fp = fopen(string(CPath::standardizePath(output_path)+"nb_steps.txt").c_str(), "w");
FILE *fp = nlfopen(CPath::standardizePath(output_path)+"nb_steps.txt", "w");
if(fp) { fprintf(fp, "%d", step); fclose(fp); }
}
nlinfo("PS duration %f after %f with nothing with %d steps, dt %f", duration, startTime, step, deltaTime);
@ -873,7 +874,7 @@ bool ShapesExporter::createThumbnail(const string &filename, const string &path)
uint selectedFrame = 0;
if(CFile::getExtension(filename) == "ps")
{
FILE *fp = fopen(string(CPath::standardizePath(output_path)+"nb_steps.txt").c_str(), "r");
FILE *fp = nlfopen(CPath::standardizePath(output_path)+"nb_steps.txt", "r");
if(fp)
{
char str[100];

View file

@ -18,6 +18,7 @@
#include <iostream>
#include "nel/misc/file.h"
#include "nel/misc/common.h"
#include "nel/misc/bitmap.h"
#include "nel/misc/path.h"
#include "nel/misc/debug.h"
@ -49,7 +50,7 @@ std::string getOutputFileName(const std::string &inputFileName);
uint8 getType(const std::string &sFileNameDest)
{
uint32 dds;
FILE *f = fopen(sFileNameDest.c_str(),"rb");
FILE *f = nlfopen(sFileNameDest, "rb");
if(f==NULL)
{
return NOT_DEFINED;
@ -105,7 +106,7 @@ uint8 getType(const std::string &sFileNameDest)
bool sameType(const std::string &sFileNameDest, uint8 &algo, bool wantMipMap)
{
uint32 dds;
FILE *f = fopen(sFileNameDest.c_str(),"rb");
FILE *f = nlfopen(sFileNameDest, "rb");
if(f==NULL)
{
return false;

View file

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

View file

@ -20,6 +20,7 @@
#include <iostream>
#include "nel/misc/types_nl.h"
#include "nel/misc/file.h"
#include "nel/misc/common.h"
#include "nel/3d/quad_tree.h"
#include "nel/3d/zone.h"
#include "nel/3d/landscape.h"
@ -978,7 +979,7 @@ int main(sint argc, char **argv)
}
#if WELD_LOG
fdbg = fopen("log.txt","wt");
fdbg = nlfopen("log.txt","wt");
fprintf(fdbg,"Center zone : %s\n",argv[1]);
#endif

View file

@ -20,6 +20,7 @@
#include <nel/misc/types_nl.h>
#include <nel/misc/config_file.h>
#include <nel/misc/debug.h>
#include <nel/misc/common.h>
#include <nel/misc/path.h>
#include <nel/misc/i18n.h>
@ -743,7 +744,7 @@ void displayZones()
\****************************************************************/
void writeConfigFile(const char * configFileName)
{
FILE * f = fopen(configFileName,"wt");
FILE * f = nlfopen(configFileName, "wt");
if(f==NULL)
{
@ -801,7 +802,7 @@ void writeConfigFile(const char * configFileName)
\****************************************************************/
void initViewerConfig(const char * configFileName)
{
FILE * f = fopen(configFileName,"rt");
FILE *f = nlfopen(configFileName, "rt");
if(f==NULL)
{
nlwarning("'%s' not found, default values used", configFileName);

View file

@ -3,7 +3,7 @@ ADD_SUBDIRECTORY(misc)
IF(WITH_NEL_TOOLS)
ADD_SUBDIRECTORY(memory)
ENDIF(WITH_NEL_TOOLS)
ENDIF()
# Max plugins are under the 3d directory as well.
# Allow to compile only max plugins without other tools.
@ -15,21 +15,21 @@ ENDIF()
IF(WITH_NEL_TOOLS)
IF(WITH_PACS)
ADD_SUBDIRECTORY(pacs)
ENDIF(WITH_PACS)
ENDIF()
IF(WITH_LOGIC)
ADD_SUBDIRECTORY(logic)
ENDIF(WITH_LOGIC)
ENDIF()
IF(WITH_GEORGES)
ADD_SUBDIRECTORY(georges)
ENDIF(WITH_GEORGES)
ENDIF()
IF(WITH_SOUND)
ADD_SUBDIRECTORY(sound)
ENDIF(WITH_SOUND)
ENDIF()
ENDIF()
IF(WITH_NEL_TESTS)
IF(WITH_NEL_TESTS)
ADD_SUBDIRECTORY(nel_unit_test)
ENDIF(WITH_NEL_TESTS)
ENDIF(WITH_NEL_TOOLS)
ENDIF()

View file

@ -32,6 +32,7 @@
#include "nel/misc/file.h"
#include "nel/misc/smart_ptr.h"
#include "nel/misc/command.h"
#include "nel/misc/common.h"
#include "nel/misc/path.h"
//#include "nel/memory/memory_manager.h"
#include "nel/misc/i18n.h"
@ -685,12 +686,13 @@ void convertCsvFile( const string &file, bool generate, const string& sheetType
{
const uint BUFFER_SIZE = 16*1024;
char lineBuffer[BUFFER_SIZE];
FILE *s;
vector<string> fields;
vector<string> args;
if ((s = fopen(file.c_str(), "r")) == NULL)
FILE *s = nlfopen(file, "r");
if (s == NULL)
{
fprintf(stderr, "Can't find file %s to convert\n", file.c_str());
return;

View file

@ -20,6 +20,7 @@
#include "progress_dialog.h"
#include <sys/timeb.h>
#include "nel/misc/file.h"
#include "nel/misc/common.h"
using namespace std;
using namespace NLMISC;
@ -468,11 +469,15 @@ void CData_mirrorDlg::OnOK()
if (!LogDirectory.empty())
{
string sTmp = LogDirectory + "data_mirror.txt";
FILE *f = fopen(sTmp.c_str(),"at");
FILE *f = nlfopen(sTmp ,"at");
if (f)
{
fprintf(f,"Modified file : %s\n", dest.c_str());
fclose(f);
}
}
}
// Touch
setFileTime (dest.c_str(), fileTime);
@ -503,11 +508,14 @@ void CData_mirrorDlg::OnOK()
if (!LogDirectory.empty())
{
string sTmp = LogDirectory + "data_mirror.txt";
FILE *f = fopen(sTmp.c_str(),"at");
FILE *f = nlfopen(sTmp, "at");
if (f)
{
fprintf(f,"Added file : %s\n", dest.c_str());
fclose(f);
}
}
}
// Touch
setFileTime (dest.c_str(), fileTime);
@ -535,12 +543,16 @@ void CData_mirrorDlg::OnOK()
if (!LogDirectory.empty())
{
string sTmp = LogDirectory + "data_mirror.txt";
FILE *f = fopen(sTmp.c_str(),"at");
FILE *f = nlfopen(sTmp, "at");
if (f)
{
fprintf(f,"Removed file : %s\n", dest.c_str());
fclose(f);
}
}
}
}
FILE *file = fopen ((IgnoreDirectory+"ignore_list.txt").c_str (), "w");
if (file)

View file

@ -40,6 +40,7 @@ int _getch()
#include "nel/misc/path.h"
#include "nel/misc/sheet_id.h"
#include "nel/misc/common.h"
#include <vector>
@ -86,7 +87,7 @@ int main(int argc, const char *argv[])
sort(sheets.begin(), sheets.end(), Pred);
// display.
FILE *out= fopen("sheetid.txt", "wb");
FILE *out= nlfopen("sheetid.txt", "wb");
if(out)
{
for(uint i=0;i<sheets.size();i++)

Some files were not shown because too many files have changed in this diff Show more