False.Genesis 25c2f09525 * stuffextract: added autodetection of currently used locale
* fixed wrongly interpreted float fields in DBCs
2007-06-13 13:29:19 +00:00

56 lines
1.3 KiB
C++

#include "common.h"
#include "Locale.h"
#include <fstream>
#include "ByteBuffer.h"
char my_locale[5];
char *cconf = "WTF/config.wtf";
char *cconfentry = "SET locale \"";
void SetLocale(char *loc)
{
my_locale[4] = 0;
if(strlen(loc))
{
memcpy(my_locale,loc,4);
}
else
{
uint32 fs = GetFileSize(cconf);
std::fstream fh;
std::string s;
fh.open(cconf,std::ios_base::in);
if(!fh.is_open())
{
printf("ERROR: unable to detect locale, could not open '%s'\n",cconf);
return;
}
char *buf = new char[fs];
fh.read((char*)buf,fs);
fh.close();
for(uint32 i=0; i<fs; i++)
{
if(buf[i]=='\n')
{
if(s.length() >= strlen(cconfentry) && !memcmp(s.c_str(),cconfentry,strlen(cconfentry)))
{
memcpy(my_locale,s.c_str() + strlen(cconfentry), 4);
printf("Auto-detected locale '%s'\n",my_locale);
break;
}
s.clear();
}
else
{
s += buf[i];
}
}
delete [] buf;
}
}
char *GetLocale(void)
{
return &my_locale[0];
}