* stuffextract: added autodetection of currently used locale
* fixed wrongly interpreted float fields in DBCs
This commit is contained in:
parent
2b40be9e01
commit
25c2f09525
@ -1,13 +1,56 @@
|
|||||||
|
#include "common.h"
|
||||||
#include "Locale.h"
|
#include "Locale.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include "ByteBuffer.h"
|
||||||
|
|
||||||
char *my_locale;
|
char my_locale[5];
|
||||||
|
char *cconf = "WTF/config.wtf";
|
||||||
|
char *cconfentry = "SET locale \"";
|
||||||
|
|
||||||
void SetLocale(char *loc)
|
void SetLocale(char *loc)
|
||||||
{
|
{
|
||||||
my_locale = 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)
|
char *GetLocale(void)
|
||||||
{
|
{
|
||||||
return my_locale;
|
return &my_locale[0];
|
||||||
}
|
}
|
||||||
@ -19,9 +19,10 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
char input[200];
|
char input[200];
|
||||||
printf("StuffExtract [version %u]\n\n",SE_VERSION);
|
printf("StuffExtract [version %u]\n\n",SE_VERSION);
|
||||||
printf("Enter your locale (enUS, enGB, deDE, ...): ");
|
printf("Enter your locale (enUS, enGB, deDE, ...) or leave blank to autodetect: ");
|
||||||
fgets(input,sizeof(input),stdin);
|
fgets(input,sizeof(input),stdin);
|
||||||
char loc[5];
|
char loc[5];
|
||||||
|
input[strlen(input)-1] = 0;
|
||||||
memcpy(loc,input,4); loc[4]=0;
|
memcpy(loc,input,4); loc[4]=0;
|
||||||
SetLocale(loc);
|
SetLocale(loc);
|
||||||
if(FileExists(std::string("Data/")+GetLocale()+"/locale-"+GetLocale()+".MPQ"))
|
if(FileExists(std::string("Data/")+GetLocale()+"/locale-"+GetLocale()+".MPQ"))
|
||||||
@ -49,10 +50,23 @@ int main(int argc, char *argv[])
|
|||||||
// be careful using this, that you supply correct format string
|
// be careful using this, that you supply correct format string
|
||||||
std::string AutoGetDataString(DBCFile::Iterator& it, const char* format, uint32 field)
|
std::string AutoGetDataString(DBCFile::Iterator& it, const char* format, uint32 field)
|
||||||
{
|
{
|
||||||
if(format[field]=='i' || format[field]=='f')
|
if(format[field]=='i')
|
||||||
return toString( (*it).getInt(field) );
|
{
|
||||||
if(format[field]=='s' && (*it).getUInt(field))
|
std::stringstream s;
|
||||||
|
s << (*it).getInt(field);
|
||||||
|
return s.str();
|
||||||
|
}
|
||||||
|
else if(format[field]=='f')
|
||||||
|
{
|
||||||
|
std::stringstream s;
|
||||||
|
s << (*it).getFloat(field);
|
||||||
|
return s.str();
|
||||||
|
}
|
||||||
|
else if(format[field]=='s' && (*it).getUInt(field))
|
||||||
|
{
|
||||||
return (*it).getString(field);
|
return (*it).getString(field);
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user