- attempt to get non ascii file paths working in megaglest (Japanese etc...)

This commit is contained in:
Mark Vejvoda
2011-05-18 21:49:11 +00:00
parent 727c7b33d9
commit 60b8093f5b
34 changed files with 519 additions and 110 deletions

View File

@@ -46,7 +46,7 @@
WholeProgramOptimization="false"
AdditionalIncludeDirectories="../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/shared_lib/include/tinyxml;../../source/glest_game/ai;../../source/glest_game/facilities;../../source/glest_game/game;../../source/glest_game/global;../../source/glest_game/graphics;../../source/glest_game/gui;../../source/glest_game/main;../../source/glest_game/menu;../../source/glest_game/network;../../source/glest_game/sound;../../source/glest_game/type_instances;../../source/glest_game/types;../../source/glest_game/world;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;../../source/shared_lib/include/sound/openal;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;$(NOINHERIT);../../source/win32_deps/libircclient/include"
AdditionalUsingDirectories=""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB; UNICODE"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -139,7 +139,7 @@
WholeProgramOptimization="false"
AdditionalIncludeDirectories="../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/shared_lib/include/tinyxml;../../source/glest_game/ai;../../source/glest_game/facilities;../../source/glest_game/game;../../source/glest_game/global;../../source/glest_game/graphics;../../source/glest_game/gui;../../source/glest_game/main;../../source/glest_game/menu;../../source/glest_game/network;../../source/glest_game/sound;../../source/glest_game/type_instances;../../source/glest_game/types;../../source/glest_game/world;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;../../source/shared_lib/include/sound/openal;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;$(NOINHERIT);../../source/win32_deps/libircclient/include"
AdditionalUsingDirectories=""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS;USE_STREFLOP;STREFLOP_SSE;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE"
StringPooling="true"
ExceptionHandling="2"
RuntimeLibrary="0"

View File

@@ -41,7 +41,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude";../../source/win32_deps/lpng141;"../../source/win32_deps/jpeg-8a";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -121,7 +121,7 @@
FavorSizeOrSpeed="1"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude";../../source/win32_deps/lpng141;"../../source/win32_deps/jpeg-8a";"../../source/win32_deps/SDL-1.2.x/include";../../source/shared_lib/include/platform/sdl;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;"../../source/win32_deps/curl-7.21.3/include";../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE"
StringPooling="true"
ExceptionHandling="2"
RuntimeLibrary="0"
@@ -687,7 +687,7 @@
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\platform\win32\glob.c"
RelativePath="..\..\source\shared_lib\sources\platform\win32\glob.cpp"
>
</File>
<File

View File

@@ -13,6 +13,7 @@
#include "config.h"
#include "game_constants.h"
#include <wx/stdpaths.h>
#include <platform_util.h>
//#include <wx/filename.h>
#ifndef WIN32
@@ -799,7 +800,11 @@ void MainWindow::saveScreenshot() {
if(autoSaveScreenshotIndex >= 0) {
string saveAsFilename = autoScreenShotParams[autoSaveScreenshotIndex];
saveAsFilename.erase(0,7);
#ifdef WIN32
FILE*f = _wfopen(utf8_decode(saveAsFilename).c_str(), L"rb");
#else
FILE *f= fopen(saveAsFilename.c_str(), "rb");
#endif
if(f == NULL) {
renderer->saveScreen(saveAsFilename.c_str());
}
@@ -829,7 +834,11 @@ void MainWindow::saveScreenshot() {
for(int i=0; i < 5000; ++i) {
path = screenShotsPath;
path += string("screen") + intToStr(i) + string(".") + fileFormat;
#ifdef WIN32
FILE*f= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
FILE *f= fopen(path.c_str(), "rb");
#endif
if(f == NULL) {
renderer->saveScreen(path);
break;

View File

@@ -52,7 +52,11 @@ AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex, int useSta
//clear log file
if(logLevel>0){
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(getLogFilename()).c_str(), L"wt");
#else
FILE *f= fopen(getLogFilename().c_str(), "wt");
#endif
if(f==NULL){
throw runtime_error("Can't open file: "+getLogFilename());
}
@@ -80,7 +84,11 @@ void AiInterface::printLog(int logLevel, const string &s){
string logString= "(" + intToStr(factionIndex) + ") " + s;
//print log to file
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(getLogFilename()).c_str(), L"at");
#else
FILE *f= fopen(getLogFilename().c_str(), "at");
#endif
if(f==NULL){
throw runtime_error("Can't open file: "+getLogFilename());
}

View File

@@ -19,6 +19,7 @@
#include "graphics_interface.h"
#include "game_constants.h"
#include "game_util.h"
#include "platform_util.h"
#include "leak_dumper.h"
using namespace std;
@@ -63,7 +64,11 @@ Logger & Logger::getInstance() {
}
void Logger::add(const string str, bool renderScreen, const string statusText) {
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(fileName).c_str(), L"at+");
#else
FILE *f = fopen(fileName.c_str(), "at+");
#endif
if(f != NULL){
fprintf(f, "%s\n", str.c_str());
fclose(f);
@@ -79,7 +84,11 @@ void Logger::add(const string str, bool renderScreen, const string statusText)
void Logger::clear() {
string s = "Log file\n";
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(fileName).c_str(), L"wt+");
#else
FILE *f= fopen(fileName.c_str(), "wt+");
#endif
if(f == NULL){
throw runtime_error("Error opening log file" + fileName);
}

View File

@@ -194,10 +194,17 @@ Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> f
if(fileName.second != "" && fileExists(fileName.second) == false) {
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] attempting to auto-create cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(fileName.second).c_str(), L"w");
std::ofstream userFile(fp);
#else
std::ofstream userFile;
userFile.open(fileName.second.c_str(), ios_base::out | ios_base::trunc);
#endif
userFile.close();
#ifdef WIN32
fclose(fp);
#endif
fileLoaded.second = true;
properties.second.load(fileName.second);
}

View File

@@ -2488,6 +2488,12 @@ void Renderer::renderWater() {
SurfaceCell *tc0= map->getSurfaceCell(i, j);
SurfaceCell *tc1= map->getSurfaceCell(i, j+1);
if(tc0 == NULL) {
throw runtime_error("tc0 == NULL");
}
if(tc1 == NULL) {
throw runtime_error("tc1 == NULL");
}
int thisTeamIndex= world->getThisTeamIndex();
@@ -4458,6 +4464,8 @@ void Renderer::init2dList() {
//this list sets the state for the 2d rendering
list2d= glGenLists(1);
assertGl();
glNewList(list2d, GL_COMPILE);
//projection

Binary file not shown.

View File

@@ -104,7 +104,12 @@ string MenuStateAbout::loadAdditionalCredits(){
string result= "";
const string dir= data_path + "data/core/menu/credits.txt";
if(fileExists(dir) == true) {
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(dir).c_str(), L"r");
ifstream file(fp);
#else
ifstream file(dir.c_str());
#endif
std::string buffer;
while(!file.eof()){
getline(file, buffer);
@@ -112,6 +117,9 @@ string MenuStateAbout::loadAdditionalCredits(){
}
std::cout << buffer << std::endl;
file.close();
#ifdef WIN32
fclose(fp);
#endif
}
return result;
}

View File

@@ -2244,7 +2244,11 @@ bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loa
lastMissingMap = file;
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb");
#else
FILE *f= fopen(file.c_str(), "rb");
#endif
if(f==NULL) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
throw runtime_error("[2]Can't open file");

View File

@@ -2373,8 +2373,13 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) {
GameSettings gameSettings;
loadGameSettings(&gameSettings);
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(fileName).c_str(), L"w");
std::ofstream saveGameFile(fp);
#else
std::ofstream saveGameFile;
saveGameFile.open(fileName.c_str(), ios_base::out | ios_base::trunc);
#endif
//int factionCount= 0;
//ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
@@ -2416,6 +2421,9 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) {
saveGameFile << "FactionPlayerNameForIndex" << slotIndex << "=" << gameSettings.getNetworkPlayerName(i) << std::endl;
}
#ifdef WIN32
fclose(fp);
#endif
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
}
@@ -2635,7 +2643,11 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa
Lang &lang= Lang::getInstance();
try{
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb");
#else
FILE *f= fopen(file.c_str(), "rb");
#endif
if(f==NULL)
throw runtime_error("Can't open file");

View File

@@ -670,7 +670,11 @@ MapInfo MenuStateMods::loadMapInfo(string file) {
MapInfo mapInfo;
//memset(&mapInfo,0,sizeof(mapInfo));
try{
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb");
#else
FILE *f= fopen(file.c_str(), "rb");
#endif
if(f != NULL) {
MapFileHeader header;
@@ -1843,7 +1847,8 @@ void MenuStateMods::render() {
if(keyMapScrollBar.getElementCount() != 0) {
for(int i = keyMapScrollBar.getVisibleStart();
i <= keyMapScrollBar.getVisibleEnd(); ++i) {
bool alreadyHasMap = (std::find(mapFiles.begin(),mapFiles.end(),keyMapButtons[i]->getText()) != mapFiles.end());
string mapNameToRender = keyMapButtons[i]->getText();
bool alreadyHasMap = (std::find(mapFiles.begin(),mapFiles.end(),mapNameToRender) != mapFiles.end());
if(keyMapButtons[i]->getText() == selectedMapName) {
bool lightedOverride = true;
renderer.renderButton(keyMapButtons[i],&WHITE,&lightedOverride);

View File

@@ -202,7 +202,11 @@ Vec2i Map::getStartLocation(int locationIndex) const {
Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
Checksum mapChecksum;
try{
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
FILE *f = fopen(path.c_str(), "rb");
#endif
if(f != NULL) {
mapChecksum.addFile(path);
checksumValue.addFile(path);

View File

@@ -1677,9 +1677,13 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const {
}
else {
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(debugWorldLogFile).c_str(), L"w");
std::ofstream logFile(fp);
#else
std::ofstream logFile;
logFile.open(debugWorldLogFile.c_str(), ios_base::out | ios_base::trunc);
#endif
logFile << "World debug information:" << std::endl;
logFile << "========================" << std::endl;
@@ -1704,6 +1708,9 @@ std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const {
}
logFile.close();
#ifdef WIN32
fclose(fp);
#endif
}
return debugWorldLogFile;
}

View File

@@ -141,7 +141,12 @@ public:
template <typename T>
static inline T* readFromFileReaders(vector<FileReader<T> const *>* readers, const string& filepath) {
//try to assign file
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb");
ifstream file(fp);
#else
ifstream file(filepath.c_str(), ios::in | ios::binary);
#endif
if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message?
throw runtime_error("Could not open file " + filepath);
}
@@ -155,18 +160,39 @@ static inline T* readFromFileReaders(vector<FileReader<T> const *>* readers, con
continue;
}
if (ret != NULL) {
file.close();
#ifdef WIN32
fclose(fp);
#endif
return ret;
}
}
file.close();
#ifdef WIN32
fclose(fp);
#endif
return NULL;
}
template <typename T>
static inline T* readFromFileReaders(vector<FileReader<T> const *>* readers, const string& filepath, T* object) {
//try to assign file
ifstream file(filepath.c_str(), ios::in | ios::binary);
#ifdef WIN32
wstring wstr = utf8_decode(filepath);
FILE *fp = _wfopen(wstr.c_str(), L"rb");
int fileErrno = errno;
ifstream file(fp);
#else
ifstream file(friendly_path.c_str(), ios::in | ios::binary);
#endif
if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message?
throw runtime_error("Could not open file [" + filepath + "]");
#ifdef WIN32
DWORD error = GetLastError();
throw runtime_error("Could not open file, result: " + intToStr(error) + " - " + intToStr(fileErrno) + " [" + filepath + "]");
#else
throw runtime_error("Could not open file [" + friendly_path + "]");
#endif
}
for (typename vector<FileReader<T> const *>::const_iterator i = readers->begin(); i != readers->end(); ++i) {
T* ret = NULL;
@@ -178,9 +204,17 @@ static inline T* readFromFileReaders(vector<FileReader<T> const *>* readers, con
continue;
}
if (ret != NULL) {
file.close();
#ifdef WIN32
fclose(fp);
#endif
return ret;
}
}
file.close();
#ifdef WIN32
fclose(fp);
#endif
return NULL;
}
@@ -292,11 +326,22 @@ bool FileReader<T>::canRead(ifstream& file) const {
*/
template <typename T>
T* FileReader<T>::read(const string& filepath) const {
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb");
ifstream file(fp);
#else
ifstream file(filepath.c_str(), ios::in | ios::binary);
#endif
if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message?
throw runtime_error("Could not open file " + filepath);
}
return read(file,filepath);
T* ret = read(file,filepath);
file.close();
#ifdef WIN32
fclose(fp);
#endif
return ret;
}
/**Reads a file
@@ -306,11 +351,22 @@ T* FileReader<T>::read(const string& filepath) const {
*/
template <typename T>
T* FileReader<T>::read(const string& filepath, T* object) const {
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(filepath).c_str(), L"rb");
ifstream file(fp);
#else
ifstream file(filepath.c_str(), ios::in | ios::binary);
#endif
if (!file.is_open()) { //An error occured; TODO: Which one - throw an exception, print error message?
throw runtime_error("Could not open file " + filepath);
}
return read(file,filepath,object);
T* ret = read(file,filepath,object);
file.close();
#ifdef WIN32
fclose(fp);
#endif
return ret;
}

View File

@@ -28,6 +28,10 @@ namespace Shared{ namespace Platform{
// class PlatformExceptionHandler
// =====================================================
LPWSTR Ansi2WideString(LPCSTR lpaszString);
std::string utf8_encode(const std::wstring &wstr);
std::wstring utf8_decode(const std::string &str);
LONG WINAPI UnhandledExceptionFilter2(struct _EXCEPTION_POINTERS *ExceptionInfo);
class PlatformExceptionHandler{

View File

@@ -30,6 +30,8 @@ void Font2DGl::init(){
if(!inited){
handle= glGenLists(charCount);
assertGl();
createGlFontBitmaps(handle, type, size, width, charCount, metrics);
inited= true;
}

View File

@@ -20,6 +20,7 @@
#include "util.h"
#include "platform_common.h"
#include "opengl.h"
#include "platform_util.h"
#include "leak_dumper.h"
using namespace Shared::Platform;
@@ -27,6 +28,7 @@ using namespace Shared::PlatformCommon;
using namespace Shared::Graphics::Gl;
using namespace std;
using namespace Shared::Util;
namespace Shared{ namespace Graphics{
@@ -801,7 +803,11 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
string sourceLoader) {
try{
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
FILE *f=fopen(path.c_str(),"rb");
#endif
if (f == NULL) {
printf("In [%s::%s] cannot load file = [%s]\n",__FILE__,__FUNCTION__,path.c_str());
throw runtime_error("Error opening g3d model file [" + path + "]");
@@ -887,7 +893,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
void Model::saveG3d(const string &path, string convertTextureToFormat,
bool keepsmallest) {
string tempModelFilename = path + "cvt";
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(tempModelFilename).c_str(), L"wb");
#else
FILE *f= fopen(tempModelFilename.c_str(), "wb");
#endif
if(f == NULL) {
throw runtime_error("Cant open file for writting: [" + tempModelFilename + "]");
}

View File

@@ -101,7 +101,11 @@ PixmapIoTga::~PixmapIoTga() {
}
void PixmapIoTga::openRead(const string &path) {
#ifdef WIN32
file= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
file= fopen(path.c_str(),"rb");
#endif
if (file == NULL) {
throw runtime_error("Can't open TGA file: "+ path);
}
@@ -181,7 +185,11 @@ void PixmapIoTga::openWrite(const string &path, int w, int h, int components) {
this->h= h;
this->components= components;
#ifdef WIN32
file= _wfopen(utf8_decode(path).c_str(), L"wb");
#else
file= fopen(path.c_str(),"wb");
#endif
if (file == NULL) {
throw runtime_error("Can't open TGA file: "+ path);
}
@@ -229,7 +237,11 @@ PixmapIoBmp::~PixmapIoBmp() {
}
void PixmapIoBmp::openRead(const string &path){
#ifdef WIN32
file= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
file= fopen(path.c_str(),"rb");
#endif
if (file==NULL){
throw runtime_error("Can't open BMP file: "+ path);
}
@@ -288,7 +300,11 @@ void PixmapIoBmp::openWrite(const string &path, int w, int h, int components) {
this->h= h;
this->components= components;
#ifdef WIN32
file= _wfopen(utf8_decode(path).c_str(), L"wb");
#else
file= fopen(path.c_str(),"wb");
#endif
if (file == NULL) {
throw runtime_error("Can't open BMP file for writing: "+ path);
}
@@ -413,7 +429,11 @@ void PixmapIoPng::openWrite(const string &path, int w, int h, int components) {
this->h= h;
this->components= components;
#ifdef WIN32
file= _wfopen(utf8_decode(path).c_str(), L"wb");
#else
file= fopen(path.c_str(),"wb");
#endif
if (file == NULL) {
throw runtime_error("Can't open PNG file for writing: "+ path);
}
@@ -602,7 +622,11 @@ void PixmapIoJpg::openWrite(const string &path, int w, int h, int components) {
this->h= h;
this->components= components;
#ifdef WIN32
file= _wfopen(utf8_decode(path).c_str(), L"wb");
#else
file= fopen(path.c_str(),"wb");
#endif
if (file == NULL) {
throw runtime_error("Can't open JPG file for writing: "+ path);
}

View File

@@ -15,6 +15,7 @@
#include "math_wrapper.h"
#include <cstdlib>
#include <stdexcept>
#include "platform_util.h"
using namespace Shared::Util;
using namespace std;
@@ -682,7 +683,11 @@ void MapPreview::switchSurfaces(MapSurfaceType surf1, MapSurfaceType surf2) {
void MapPreview::loadFromFile(const string &path) {
#ifdef WIN32
FILE* f1= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
FILE *f1 = fopen(path.c_str(), "rb");
#endif
if (f1 != NULL) {
//read header
@@ -751,8 +756,11 @@ void MapPreview::loadFromFile(const string &path) {
void MapPreview::saveToFile(const string &path) {
#ifdef WIN32
FILE* f1= _wfopen(utf8_decode(path).c_str(), L"wb");
#else
FILE *f1 = fopen(path.c_str(), "wb");
#endif
if (f1 != NULL) {
//write header

View File

@@ -56,6 +56,7 @@
#include <map>
#include "randomgen.h"
#include <algorithm>
#include "platform_util.h"
#include "leak_dumper.h"
using namespace Shared::Platform;
@@ -290,7 +291,7 @@ void findAll(const vector<string> &paths, const string &fileFilter, vector<strin
findAll(path, current_results, cutExtension, errorOnNotFound);
if(current_results.size() > 0) {
for(unsigned int folder_index = 0; folder_index < current_results.size(); folder_index++) {
string &current_file = current_results[folder_index];
string current_file = current_results[folder_index];
if(keepDuplicates == true || std::find(results.begin(),results.end(),current_file) == results.end()) {
results.push_back(current_file);
}
@@ -319,16 +320,14 @@ void findAll(const string &path, vector<string> &results, bool cutExtension, boo
glob_t globbuf;
int res = glob(mypath.c_str(), 0, 0, &globbuf);
if(res < 0 && errorOnNotFound == true)
{
if(res < 0 && errorOnNotFound == true) {
if(errorOnNotFound) {
std::stringstream msg;
msg << "#1 Couldn't scan directory '" << mypath << "': " << strerror(errno);
throw runtime_error(msg.str());
}
}
else
{
else {
for(int i = 0; i < globbuf.gl_pathc; ++i) {
const char* p = globbuf.gl_pathv[i];
const char* begin = p;
@@ -370,8 +369,13 @@ bool isdir(const char *path)
}
#endif
#ifdef WIN32
struct _stat64i32 stats;
int result = _wstat(utf8_decode(friendly_path).c_str(), &stats);
#else
struct stat stats;
int result = stat(friendly_path.c_str(), &stats);
#endif
bool ret = (result == 0);
if(ret == true) {
ret = S_ISDIR(stats.st_mode); // #define S_ISDIR(mode) ((mode) & _S_IFDIR)
@@ -423,7 +427,8 @@ void removeFolder(const string path) {
//printf("~~~~~ REMOVE FOLDER [%s] in [%s]\n",item.c_str(),path.c_str());
#ifdef WIN32
int result = _rmdir(item.c_str());
//int result = _rmdir(item.c_str());
int result = _wrmdir(utf8_decode(item).c_str());
#else
int result = rmdir(item.c_str());
#endif
@@ -437,7 +442,8 @@ void removeFolder(const string path) {
}
#ifdef WIN32
int result = _rmdir(path.c_str());
//int result = _rmdir(path.c_str());
int result = _wrmdir(utf8_decode(path).c_str());
#else
int result = rmdir(path.c_str());
#endif
@@ -555,7 +561,11 @@ pair<bool,time_t> hasCachedFileCRCValue(string crcCacheFile, int32 &value) {
//bool result = false;
pair<bool,time_t> result = make_pair(false,0);
if(fileExists(crcCacheFile) == true) {
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(crcCacheFile).c_str(), L"r");
#else
FILE *fp = fopen(crcCacheFile.c_str(),"r");
#endif
if(fp != NULL) {
time_t refreshDate = 0;
int32 crcValue = 0;
@@ -589,7 +599,11 @@ pair<bool,time_t> hasCachedFileCRCValue(string crcCacheFile, int32 &value) {
}
void writeCachedFileCRCValue(string crcCacheFile, int32 &crcValue) {
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(crcCacheFile).c_str(), L"w");
#else
FILE *fp = fopen(crcCacheFile.c_str(),"w");
#endif
if(fp != NULL) {
//RandomGen random;
//int offset = random.randRange(5, 15);
@@ -1258,7 +1272,8 @@ void createDirectoryPaths(string Path) {
if ('/' == *path) {
if(isdir(DirName) == false) {
#ifdef WIN32
int result = _mkdir(DirName);
int result = _wmkdir(utf8_decode(DirName).c_str());
//int result = _mkdir(DirName);
#elif defined(__GNUC__)
int result = mkdir(DirName, S_IRWXU | S_IRWXO | S_IRWXG);
#else
@@ -1271,12 +1286,14 @@ void createDirectoryPaths(string Path) {
*dirName = '\0';
}
#ifdef WIN32
_mkdir(DirName);
//int result = _mkdir(DirName);
int result = _wmkdir(utf8_decode(DirName).c_str());
#elif defined(__GNUC__)
mkdir(DirName, S_IRWXU | S_IRWXO | S_IRWXG);
int result = mkdir(DirName, S_IRWXU | S_IRWXO | S_IRWXG);
#else
#error "Your compiler needs to support mkdir!"
#endif
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] DirName [%s] result = %d, errno = %d\n",__FILE__,__FUNCTION__,__LINE__,DirName,result,errno);
}
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight,bool isFullscreen) {
@@ -1653,7 +1670,7 @@ bool executeShellCommand(string cmd, int expectedResult) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("About to run [%s]", cmd.c_str());
#ifdef WIN32
FILE *file = _popen(cmd.c_str(),"r");
FILE *file = _wpopen(utf8_decode(cmd).c_str(),L"r");
#else
FILE *file = popen(cmd.c_str(),"r");
#endif
@@ -1699,8 +1716,13 @@ bool renameFile(string oldFile, string newFile) {
}
off_t getFileSize(string filename) {
#ifdef WIN32
struct _stat64i32 stbuf;
if(_wstat(utf8_decode(filename).c_str(), &stbuf) != -1) {
#else
struct stat stbuf;
if(stat(filename.c_str(), &stbuf) != -1) {
#endif
return stbuf.st_size;
}
return 0;
@@ -1710,7 +1732,7 @@ string executable_path(string exeName, bool includeExeNameInPath) {
string value = "";
#ifdef _WIN32
char path[MAX_PATH]="";
if( GetModuleFileName(NULL,path,MAX_PATH) == 0 ) {
if( GetModuleFileNameA(NULL,path,MAX_PATH) == 0 ) {
if(includeExeNameInPath == true) {
value = exeName;
}
@@ -1802,8 +1824,13 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace
size_t find_len = findText.length();
string tempfileName = fileName + "_tmp";
#ifdef WIN32
fp1 = _wfopen(utf8_decode(fileName).c_str(), L"r");
fp2 = _wfopen(utf8_decode(tempfileName).c_str(), L"w");
#else
fp1 = fopen(fileName.c_str(),"r");
fp2 = fopen(tempfileName.c_str(),"w");
#endif
while(fgets(buffer,MAX_LEN_SINGLE_LINE + 2,fp1)) {
buff_ptr = buffer;
@@ -1839,8 +1866,15 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace
void copyFileTo(string fromFileName, string toFileName) {
//Open an input and output stream in binary mode
#ifdef WIN32
FILE *fp1 = _wfopen(utf8_decode(fromFileName).c_str(), L"rb");
ifstream in(fp1);
FILE *fp2 = _wfopen(utf8_decode(toFileName).c_str(), L"wb");
ofstream out(fp2);
#else
ifstream in(fromFileName.c_str(),ios::binary);
ofstream out(toFileName.c_str(),ios::binary);
#endif
if(in.is_open() && out.is_open()) {
while(in.eof() == false) {
@@ -1851,6 +1885,11 @@ void copyFileTo(string fromFileName, string toFileName) {
//Close both files
in.close();
out.close();
#ifdef WIN32
fclose(fp1);
fclose(fp2);
#endif
}
// =====================================

View File

@@ -43,12 +43,12 @@ void addlog (const char * fmt, ...) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC: %s\n", buf);
if(SystemFlags::VERBOSE_MODE_ENABLED == true) {
if ( (fp = fopen ("irctest.log", "ab")) != 0 ) {
fprintf (fp, "%s\n", buf);
fclose (fp);
}
}
//if(SystemFlags::VERBOSE_MODE_ENABLED == true) {
// if ( (fp = fopen ("irctest.log", "ab")) != 0 ) {
// fprintf (fp, "%s\n", buf);
// fclose (fp);
// }
//}
}
void dump_event (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) {

View File

@@ -19,6 +19,7 @@
#include <curl/easy.h>
#include <algorithm>
#include "conversion.h"
#include "platform_util.h"
using namespace Shared::Util;
using namespace Shared::PlatformCommon;
@@ -85,7 +86,11 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread opening file for writing [%s]\n",fullFilePath.c_str());
/* open file for writing */
#ifdef WIN32
out->stream= _wfopen(utf8_decode(fullFilePath).c_str(), L"wb");
#else
out->stream = fopen(fullFilePath.c_str(), "wb");
#endif
if(out->stream == NULL) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str());
@@ -1164,7 +1169,11 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getFileFromServer(FTP_Clien
ftpfile.stream = NULL;
}
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(destFileSaveAs).c_str(), L"rt");
#else
FILE *fp = fopen(destFileSaveAs.c_str(), "rt");
#endif
if(fp != NULL) {
char szBuf[4096]="";
while(feof(fp) == false) {

View File

@@ -19,6 +19,7 @@
#include "window.h"
#include <vector>
//#include <SDL_image.h>
#include "platform_util.h"
#include "leak_dumper.h"
using namespace Shared::Graphics::Gl;
@@ -43,11 +44,15 @@ namespace Shared{ namespace Platform{
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
int charCount, FontMetrics &metrics) {
//return;
// -adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1 this is a Chinese font
std::string useRealFontName = type;
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] trying to load useRealFontName [%s], size = %d, width = %d\n",__FILE__,__FUNCTION__,__LINE__,useRealFontName.c_str(),size,width);
DWORD dwErrorGL = 0;
HDC hDC = 0;
static std::vector<std::string> systemFontList;
if(systemFontList.size() == 0) {
LOGFONT lf;
@@ -56,7 +61,16 @@ namespace Shared{ namespace Platform{
lf.lfCharSet = (BYTE)charSet;
lf.lfFaceName[0]='\0';
HDC hDC = wglGetCurrentDC();
//HGLRC hdRC =wglGetCurrentContext();
//DWORD dwErrorGL = GetLastError();
//assertGl();
hDC = wglGetCurrentDC();
dwErrorGL = GetLastError();
assertGl();
//hDC = CreateCompatibleDC(0);
//dwErrorGL = GetLastError();
::EnumFontFamiliesEx(hDC,
&lf,
(FONTENUMPROC) EnumFontFamExProc,
@@ -80,16 +94,38 @@ namespace Shared{ namespace Platform{
}
}
LPWSTR wstr = Ansi2WideString(useRealFontName.c_str());
HFONT font= CreateFont(
size, 0, 0, 0, width, FALSE, FALSE, FALSE, charSet,
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH| (useRealFontName.c_str() ? FF_DONTCARE:FF_SWISS), useRealFontName.c_str());
DEFAULT_PITCH| (useRealFontName.c_str() ? FF_DONTCARE:FF_SWISS), wstr);
delete [] wstr;
assert(font!=NULL);
HDC dc= wglGetCurrentDC();
dwErrorGL = GetLastError();
assertGl();
SelectObject(dc, font);
BOOL err= wglUseFontBitmaps(dc, 0, charCount, base);
dwErrorGL = GetLastError();
assertGl();
BOOL err= 0;
err= wglUseFontBitmaps(dc, 0, charCount, base);
dwErrorGL = GetLastError();
/*
for(int glBugRetry = 0; glBugRetry <= 10; glBugRetry++) {
err= wglUseFontBitmaps(dc, 0, charCount, base);
dwErrorGL = GetLastError();
//assertGl();
GLenum error = glGetError();
if(error == 0) {
break;
}
}
*/
assertGl();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] wglUseFontBitmaps returned = %d, charCount = %d, base = %d\n",__FILE__,__FUNCTION__,__LINE__,err,charCount,base);
@@ -131,6 +167,10 @@ namespace Shared{ namespace Platform{
DeleteObject(font);
//if(hDC != 0) {
// DeleteDC(hDC);
//}
assert(err);
}

View File

@@ -47,21 +47,23 @@
#include <stdlib.h>
#define NOMINMAX
#include <windows.h>
#include "platform_util.h"
#define NUM_ELEMENTS(ar) (sizeof(ar) / sizeof(ar[0]))
using namespace Shared::Util;
/* /////////////////////////////////////////////////////////////////////////
* Helper functions
*/
static char const *strrpbrk(char const *string, char const *strCharSet)
{
char *part = NULL;
char const *part = NULL;
char const *pch;
for(pch = strCharSet; *pch; ++pch)
{
char *p = strrchr(string, *pch);
const char *p = strrchr(string, *pch);
if(NULL != p)
{
@@ -102,7 +104,7 @@ int glob( char const *pattern
int result;
char szRelative[1 + _MAX_PATH];
char const *file_part;
WIN32_FIND_DATAA find_data;
WIN32_FIND_DATAW find_data;
HANDLE hFind;
char *buffer;
char szPattern2[1 + _MAX_PATH];
@@ -167,7 +169,8 @@ int glob( char const *pattern
bMagic0 = (leafMost == strpbrk(leafMost, "?*"));
hFind = FindFirstFileA(effectivePattern, &find_data);
std::wstring wstr = utf8_decode(effectivePattern);
hFind = FindFirstFileW(wstr.c_str(), &find_data);
buffer = NULL;
pglob->gl_pathc = 0;
@@ -234,8 +237,8 @@ int glob( char const *pattern
GLOB_NODOTSDIRS == (flags & GLOB_NODOTSDIRS))
{
/* Pattern must begin with '.' to match either dots directory */
if( 0 == lstrcmpA(".", find_data.cFileName) ||
0 == lstrcmpA("..", find_data.cFileName))
if( 0 == lstrcmpW(L".", find_data.cFileName) ||
0 == lstrcmpW(L"..", find_data.cFileName))
{
continue;
}
@@ -246,7 +249,7 @@ int glob( char const *pattern
#if 0
if(find_data.cFileName[0] >= 'A' && find_data.cFileName[0] <= 'M')
#endif /* 0 */
(void)lstrcatA(find_data.cFileName, "/");
(void)lstrcatW(find_data.cFileName, L"/");
}
}
else
@@ -261,7 +264,9 @@ int glob( char const *pattern
}
}
cch = lstrlenA(find_data.cFileName);
//cch = lstrlenW(find_data.cFileName);
string sFileName = utf8_encode(find_data.cFileName);
cch = sFileName.length();
if(NULL != file_part)
{
cch += (int)(file_part - effectivePattern);
@@ -291,12 +296,13 @@ int glob( char const *pattern
}
(void)lstrcpynA(buffer + cbCurr, szRelative, 1 + (int)(file_part - effectivePattern));
(void)lstrcatA(buffer + cbCurr, find_data.cFileName);
(void)lstrcatA(buffer + cbCurr, sFileName.c_str());
cbCurr += cch + 1;
++cMatches;
}
while(FindNextFile(hFind, &find_data) && cMatches != maxMatches);
//while(FindNextFileA(hFind, &find_data) && cMatches != maxMatches);
while(FindNextFileW(hFind, &find_data) && cMatches != maxMatches);
(void)FindClose(hFind);

View File

@@ -33,18 +33,63 @@ namespace Shared { namespace Platform {
PlatformExceptionHandler *PlatformExceptionHandler::thisPointer= NULL;
// Constructs object and convert lpaszString to Unicode
LPWSTR Ansi2WideString(LPCSTR lpaszString) {
LPWSTR lpwszString(NULL);
int nLen = ::lstrlenA(lpaszString) + 1;
lpwszString = new WCHAR[nLen];
if (lpwszString == NULL) {
return lpwszString;
}
memset(lpwszString, 0, nLen * sizeof(WCHAR));
if (::MultiByteToWideChar(CP_ACP, 0, lpaszString, nLen, lpwszString, nLen) == 0) {
// Conversation failed
return lpwszString;
}
return lpwszString;
}
// Convert a wide Unicode string to an UTF8 string
std::string utf8_encode(const std::wstring &wstr) {
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo( size_needed, 0 );
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
replaceAll(strTo, "/", "\\");
replaceAll(strTo, "\\\\", "\\");
updatePathClimbingParts(strTo);
return strTo;
}
// Convert an UTF8 string to a wide Unicode String
std::wstring utf8_decode(const std::string &str) {
string friendly_path = str;
replaceAll(friendly_path, "/", "\\");
replaceAll(friendly_path, "\\\\", "\\");
updatePathClimbingParts(friendly_path);
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), NULL, 0);
std::wstring wstrTo( size_needed, 0 );
MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), &wstrTo[0], size_needed);
return wstrTo;
}
LONG WINAPI PlatformExceptionHandler::handler(LPEXCEPTION_POINTERS pointers){
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
LPWSTR wstr = Ansi2WideString(thisPointer->dumpFileName.c_str());
HANDLE hFile = CreateFile(
thisPointer->dumpFileName.c_str(),
wstr,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
delete [] wstr;
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -158,11 +203,16 @@ void message(string message){
std::cerr << " " << message << "\n";
std::cerr << "******************************************************\n";
MessageBox(NULL, message.c_str(), "Message", MB_OK);
LPWSTR wstr = Ansi2WideString(message.c_str());
MessageBox(NULL, wstr, L"Message", MB_OK);
delete [] wstr;
}
bool ask(string message){
return MessageBox(NULL, message.c_str(), "Confirmation", MB_YESNO)==IDYES;
LPWSTR wstr = Ansi2WideString(message.c_str());
bool result = MessageBox(NULL, wstr, L"Confirmation", MB_YESNO)==IDYES;
delete [] wstr;
return result;
}
void exceptionMessage(const exception &excp){
@@ -175,7 +225,11 @@ void exceptionMessage(const exception &excp){
title= "Error: Unhandled Exception";
printf("Error detected with text: %s\n",message.c_str());
MessageBox(NULL, message.c_str(), title.c_str(), MB_ICONSTOP | MB_OK | MB_TASKMODAL);
LPWSTR wstr = Ansi2WideString(message.c_str());
LPWSTR wstr1 = Ansi2WideString(title.c_str());
MessageBox(NULL, wstr, wstr1, MB_ICONSTOP | MB_OK | MB_TASKMODAL);
delete [] wstr;
delete [] wstr1;
}
//int getScreenW(){
@@ -192,7 +246,7 @@ HICON icon;
void init_win32() {
HINSTANCE handle = ::GetModuleHandle(NULL);
icon = ::LoadIcon(handle, "IDI_ICON1");
icon = ::LoadIcon(handle, L"IDI_ICON1");
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version)

View File

@@ -16,6 +16,7 @@
#include "sound.h"
#include "util.h"
#include "platform_util.h"
#include "leak_dumper.h"
using namespace Shared::Platform;
@@ -144,7 +145,11 @@ void WavSoundFileLoader::restart(){
void OggSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
fileName = path;
#ifdef WIN32
f = _wfopen(utf8_decode(path).c_str(), L"rb");
#else
f= fopen(path.c_str(), "rb");
#endif
if(f==NULL){
throw runtime_error("Can't open ogg file: "+path);
}
@@ -195,6 +200,7 @@ void OggSoundFileLoader::close(){
delete vf;
vf= 0;
}
fclose(f);
}
void OggSoundFileLoader::restart(){

View File

@@ -24,10 +24,12 @@
#include "util.h"
#include "platform_common.h"
#include "conversion.h"
#include "platform_util.h"
#include "leak_dumper.h"
using namespace std;
using namespace Shared::PlatformCommon;
using namespace Shared::Util;
namespace Shared{ namespace Util{
@@ -131,7 +133,11 @@ bool Checksum::addFileToSum(const string &path) {
*/
bool fileExists = false;
#ifdef WIN32
FILE* file= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
FILE* file= fopen(path.c_str(), "rb");
#endif
if(file != NULL) {
fileExists = true;
addString(lastFile(path));

View File

@@ -91,7 +91,11 @@ void AllocRegistry::reset(){
}
void AllocRegistry::dump(const char *path){
#ifdef WIN32
FILE* f= = _wfopen(utf8_decode(path).c_str(), L"wt");
#else
FILE *f= fopen(path, "wt");
#endif
int leakCount=0;
size_t leakBytes=0;

View File

@@ -83,7 +83,11 @@ Profiler::~Profiler(){
}
profileLog = userData + profileLog;
}
#ifdef WIN32
FILE* f= = _wfopen(utf8_decode(profileLog).c_str(), L"w");
#else
FILE *f= fopen(profileLog.c_str(), "w");
#endif
if(f==NULL)
throw runtime_error("Can not open file: " + profileLog);

View File

@@ -18,6 +18,7 @@
#include "conversion.h"
#include "util.h"
#include "platform_common.h"
#include "platform_util.h"
#ifdef WIN32
#include <shlwapi.h>
@@ -28,6 +29,7 @@
using namespace std;
using namespace Shared::PlatformCommon;
using namespace Shared::Platform;
namespace Shared{ namespace Util{
@@ -39,14 +41,19 @@ string Properties::applicationPath = "";
void Properties::load(const string &path, bool clearCurrentProperties) {
ifstream fileStream;
char lineBuffer[maxLine]="";
string line, key, value;
size_t pos=0;
this->path= path;
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(path).c_str(), L"r");
ifstream fileStream(fp);
#else
ifstream fileStream;
fileStream.open(path.c_str(), ios_base::in);
#endif
if(fileStream.fail()){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
throw runtime_error("Can't open propertyMap file: " + path);
@@ -102,6 +109,9 @@ void Properties::load(const string &path, bool clearCurrentProperties) {
}
fileStream.close();
#ifdef WIN32
fclose(fp);
#endif
}
std::map<string,string> Properties::getTagReplacementValues(std::map<string,string> *mapExtraTagReplacementValues) {
@@ -127,11 +137,20 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
// For win32 we allow use of the appdata variable since that is the recommended
// place for application data in windows platform
#ifdef WIN32
TCHAR szPath[MAX_PATH]="";
TCHAR szPath[MAX_PATH];
// Get path for each computer, non-user specific and non-roaming data.
if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA,
NULL, 0, szPath))) {
string appPath = szPath;
//const wchar_t *wBuf = &szPath[0];
//size_t size = MAX_PATH + 1;
//char pMBBuffer[MAX_PATH + 1]="";
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath);
//string appPath = szPath;
mapTagReplacementValues["$APPDATA"] = appPath;
mapTagReplacementValues["%%APPDATA%%"] = appPath;
}
@@ -201,11 +220,19 @@ bool Properties::applyTagsToValue(string &value, std::map<string,string> *mapTag
// For win32 we allow use of the appdata variable since that is the recommended
// place for application data in windows platform
#ifdef WIN32
TCHAR szPath[MAX_PATH]="";
TCHAR szPath[MAX_PATH];
// Get path for each computer, non-user specific and non-roaming data.
if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA,
NULL, 0, szPath))) {
string appPath = szPath;
//const wchar_t *wBuf = &szPath[0];
//size_t size = MAX_PATH + 1;
//char pMBBuffer[MAX_PATH + 1]="";
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath);
//string appPath = szPath;
replaceAll(value, "$APPDATA", appPath);
replaceAll(value, "%%APPDATA%%", appPath);
}
@@ -241,10 +268,13 @@ bool Properties::applyTagsToValue(string &value, std::map<string,string> *mapTag
}
void Properties::save(const string &path){
#ifdef WIN32
FILE *fp = _wfopen(utf8_decode(path).c_str(), L"w");
ofstream fileStream(fp);
#else
ofstream fileStream;
fileStream.open(path.c_str(), ios_base::out | ios_base::trunc);
#endif
fileStream << "; === propertyMap File === \n";
fileStream << '\n';
@@ -253,6 +283,9 @@ void Properties::save(const string &path){
}
fileStream.close();
#ifdef WIN32
fclose(fp);
#endif
}
void Properties::clear(){

View File

@@ -29,12 +29,13 @@
#include "platform_common.h"
#include "conversion.h"
#include "simple_threads.h"
#include "platform_util.h"
#include "leak_dumper.h"
using namespace std;
using namespace Shared::Platform;
using namespace Shared::PlatformCommon;
using namespace Shared::Util;
namespace Shared{ namespace Util{
@@ -508,8 +509,12 @@ void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugT
}
if(currentDebugLog.fileStream == NULL) {
#ifdef WIN32
currentDebugLog.fileStream = new std::ofstream(_wfopen(utf8_decode(debugLog).c_str(), L"w"));
#else
currentDebugLog.fileStream = new std::ofstream();
currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc);
#endif
currentDebugLog.fileStreamOwner = true;
currentDebugLog.mutex = new Mutex();
}
@@ -584,7 +589,7 @@ string lastDir(const string &s) {
}
if (pos==string::npos) {
throw runtime_error(string(__FILE__)+" lastDir - i==string::npos");
throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " pos == string::npos for [" + s + "]");
}
if( pos + 1 == s.length() && s.length() > 0 &&
@@ -620,34 +625,38 @@ string cutLastFile(const string &s){
pos= i < j ? j: i;
}
if (pos==string::npos){
throw runtime_error(string(__FILE__)+"cutLastFile - i==string::npos");
}
if (pos != string::npos) {
//throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " pos == string::npos for [" + s + "]");
//}
return (s.substr(0, pos));
}
return s;
}
string cutLastExt(const string &s) {
size_t i= s.find_last_of('.');
if (i==string::npos){
throw runtime_error(string(__FILE__)+"cutLastExt - i==string::npos");
}
if (i != string::npos) {
//throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " i==string::npos for [" + s + "]");
//}
return (s.substr(0, i));
}
return s;
}
string ext(const string &s) {
size_t i;
i=s.find_last_of('.')+1;
if (i==string::npos){
throw runtime_error(string(__FILE__)+"cutLastExt - i==string::npos");
}
if (i != string::npos) {
throw runtime_error(string(__FILE__) + " line: " + intToStr(__LINE__) + " i==string::npos for [" + s + "]");
//}
return (s.substr(i, s.size()-i));
}
return "";
}
string replaceBy(const string &s, char c1, char c2){
string rs= s;
@@ -715,7 +724,11 @@ int round(float f){
// ==================== misc ====================
bool fileExists(const string &path){
#ifdef WIN32
FILE* file= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
FILE* file= fopen(path.c_str(), "rb");
#endif
if(file!=NULL){
fclose(file);
return true;

View File

@@ -61,14 +61,21 @@ int main(int argc, char **argv)
}
/* attempt to open the input and output files */
//#ifdef WIN32
// infile = _wfopen(utf8_decode(infilename).c_str(), L"rb");
//#else
infile = fopen(infilename, "rb");
if (infile == NULL)
{
//#endif
if (infile == NULL) {
printf("Could not open file \"%s\" for binary reading.\n",
infilename);
return (EXIT_FAILURE);
}
//#ifdef WIN32
// outfile = _wfopen(utf8_decode(outfilename).c_str(), L"w");
//#else
outfile = fopen(outfilename, "w");
//#endif
if (outfile == NULL)
{
printf("Could not open file \"%s\" for writing.\n",

View File

@@ -29,7 +29,6 @@
#endif
/**
* Forward function declarations.
*/
@@ -90,9 +89,12 @@ int main(int argc, char **argv)
}
/* attempt to open the output binary file */
//#ifdef WIN32
// outfile = _wfopen(utf8_decode(outfilename).c_str(), L"wb");
//#else
outfile = fopen(outfilename, "wb");
if (outfile == NULL)
{
//#endif
if (outfile == NULL) {
printf("Could not open file \"%s\" for writing!\n",
outfilename);
xmlFreeDoc(doc);