Replace ifstream and ofstream to manage UTF-8 filenames, issue #261

This commit is contained in:
kervala 2016-02-20 18:15:04 +01:00
parent ee1d69503b
commit eee72ce77f
3 changed files with 27 additions and 17 deletions

View file

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

View file

@ -104,29 +104,31 @@ void CCDBSynchronised::read( const string &fileName )
int linecount=1; int linecount=1;
#endif #endif
if( _Database == 0 ) if (_Database == NULL)
{ {
throw CCDBSynchronised::EDBNotInit(); throw CCDBSynchronised::EDBNotInit();
} }
ifstream f(fileName.c_str(), ios::in); CIFile f;
if( !f.is_open() )
if (!f.open(fileName, true))
{ {
nlerror("can't open file : %s\n", fileName.c_str()); nlerror("can't open file : %s\n", fileName.c_str());
} }
while( !f.eof() ) while(!f.eof())
{ {
string line; char line[1024];
getline(f,line,'\n'); f.getline(line, 1024);
#ifdef _DEBUG #ifdef _DEBUG
nlinfo("%s:%i",fileName.c_str(),linecount); nlinfo("%s:%i", fileName.c_str(), linecount);
linecount++; linecount++;
#endif #endif
char * token; char * token;
char * buffer = new char[line.size()+1]; char * buffer = new char[strlen(line)+1];
strcpy(buffer,line.c_str()); strcpy(buffer, line);
// value // value
token = strtok(buffer," \t"); token = strtok(buffer," \t");

View file

@ -1028,10 +1028,11 @@ void CSoundManager::loadProperties(const string &soundName, USource *source)
// Search for the file. // Search for the file.
string filePath = CPath::lookup(soundName+".sdf"); string filePath = CPath::lookup(soundName+".sdf");
ifstream file(filePath.c_str(), ios::in);
CIFile file;
// Try to open the file. // Try to open the file.
if(file.is_open()) if (file.open(filePath))
{ {
char tmpBuff[260]; char tmpBuff[260];
char delimiterBox[] = "\t "; char delimiterBox[] = "\t ";