Converted back CREDITS to UTF-16 (why was it converted back to UTF-8? STK expects UTF-16, since that's the format our font object can handle) - fixing crash when trying to see credits in-game. Also addded better error handling in the code

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5738 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-08-15 20:42:18 +00:00
parent b1f7012cbd
commit ee1f67b19d
2 changed files with 32 additions and 2 deletions

Binary file not shown.

View File

@ -87,7 +87,7 @@ bool getWideLine(std::ifstream& file, stringw* out)
{ {
if (!file.good()) if (!file.good())
{ {
//std::cout << "File is not good!\n"; std::cerr << "getWideLine : File is not good!\n";
return false; return false;
} }
wchar_t wide_char; wchar_t wide_char;
@ -153,19 +153,40 @@ void CreditsScreen::loadedFromFile()
std::string creditsfile = file_manager->getDataDir() + "/CREDITS"; std::string creditsfile = file_manager->getDataDir() + "/CREDITS";
std::ifstream file( creditsfile.c_str() ) ; std::ifstream file( creditsfile.c_str() ) ;
if (file.fail() || !file.is_open() || file.eof())
{
fprintf(stderr, "\n/!\\ Failed to open file at '%s'\n\n", creditsfile.c_str());
return;
}
stringw line; stringw line;
// skip Unicode header // skip Unicode header
file.get(); file.get();
file.get(); file.get();
if (file.fail() || !file.is_open() || file.eof())
{
fprintf(stderr, "\n/!\\ Failed to read file at '%s', unexpected EOF\n\n", creditsfile.c_str());
assert(false);
return;
}
int lineCount = 0;
// let's assume the file is encoded as UTF-16 // let's assume the file is encoded as UTF-16
while (getWideLine( file, &line )) while (getWideLine( file, &line ))
{ {
stringc cversion = line.c_str();
printf("CREDITS line : %s\n", cversion.c_str());
line = line.trim(); line = line.trim();
if (line.size() < 1) continue; // empty line if (line.size() < 1) continue; // empty line
lineCount++;
if ((line[0] & 0xFF) == '=' && (line[line.size()-1] & 0xFF) == '=') if ((line[0] & 0xFF) == '=' && (line[line.size()-1] & 0xFF) == '=')
{ {
line = stringw( line.subString(1, line.size()-2).c_str() ); line = stringw( line.subString(1, line.size()-2).c_str() );
@ -194,6 +215,15 @@ void CreditsScreen::loadedFromFile()
getCurrentSection()->addEntry( entry ); getCurrentSection()->addEntry( entry );
} }
} // end while } // end while
if (lineCount == 0)
{
fprintf(stderr, "\n/!\\ Could not read anything from CREDITS file!\n\n");
assert(false);
return;
}
assert(m_sections.size() > 0); assert(m_sections.size() > 0);
} }