From eee72ce77fa7682b0da13cdf587f2d58d9040432 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 20 Feb 2016 18:15:04 +0100 Subject: [PATCH] Replace ifstream and ofstream to manage UTF-8 filenames, issue #261 --- code/nel/src/misc/report.cpp | 17 ++++++++++++----- code/ryzom/client/src/cdb_synchronised.cpp | 22 ++++++++++++---------- code/ryzom/client/src/sound_manager.cpp | 5 +++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/code/nel/src/misc/report.cpp b/code/nel/src/misc/report.cpp index 261ef4d5d..f997be6e0 100644 --- a/code/nel/src/misc/report.cpp +++ b/code/nel/src/misc/report.cpp @@ -82,9 +82,10 @@ TReportResult report(const std::string &title, const std::string &subject, const { std::string reportFile = getLogDirectory() + NLMISC::toString("nel_report_%u.log", (uint)time(NULL)); reportPath = CFile::findNewFile(reportFile); - std::ofstream f; - f.open(reportPath.c_str()); - if (!f.good()) + + FILE *f = nlfopen(reportPath, "wb"); // write as binary so \n are preserved + + if (!f) { #if NL_DEBUG_REPORT if (INelContext::isContextInitialised()) @@ -94,8 +95,14 @@ TReportResult report(const std::string &title, const std::string &subject, const } else { - f << body; - f.close(); + size_t written = fwrite(body.c_str(), 1, body.length(), f); + + if (written != body.length()) + { + nlwarning("Unable to write %u bytes to %s, only %u written", (uint)body.length(), reportPath.c_str(), (uint)written); + } + + fclose(f); } } diff --git a/code/ryzom/client/src/cdb_synchronised.cpp b/code/ryzom/client/src/cdb_synchronised.cpp index fff0a4bae..d5239ce0d 100644 --- a/code/ryzom/client/src/cdb_synchronised.cpp +++ b/code/ryzom/client/src/cdb_synchronised.cpp @@ -104,29 +104,31 @@ void CCDBSynchronised::read( const string &fileName ) int linecount=1; #endif - if( _Database == 0 ) + if (_Database == NULL) { throw CCDBSynchronised::EDBNotInit(); } - ifstream f(fileName.c_str(), ios::in); - if( !f.is_open() ) + CIFile f; + + if (!f.open(fileName, true)) { nlerror("can't open file : %s\n", fileName.c_str()); } - while( !f.eof() ) + while(!f.eof()) { - string line; - getline(f,line,'\n'); + char line[1024]; + f.getline(line, 1024); + #ifdef _DEBUG - nlinfo("%s:%i",fileName.c_str(),linecount); - linecount++; + nlinfo("%s:%i", fileName.c_str(), linecount); + linecount++; #endif char * token; - char * buffer = new char[line.size()+1]; - strcpy(buffer,line.c_str()); + char * buffer = new char[strlen(line)+1]; + strcpy(buffer, line); // value token = strtok(buffer," \t"); diff --git a/code/ryzom/client/src/sound_manager.cpp b/code/ryzom/client/src/sound_manager.cpp index 4a981366d..0374a0e1a 100644 --- a/code/ryzom/client/src/sound_manager.cpp +++ b/code/ryzom/client/src/sound_manager.cpp @@ -1028,10 +1028,11 @@ void CSoundManager::loadProperties(const string &soundName, USource *source) // Search for the file. string filePath = CPath::lookup(soundName+".sdf"); - ifstream file(filePath.c_str(), ios::in); + + CIFile file; // Try to open the file. - if(file.is_open()) + if (file.open(filePath)) { char tmpBuff[260]; char delimiterBox[] = "\t ";