Index: trunk/contrib/extractor/mpq_libmpq.cpp
===================================================================
--- trunk/contrib/extractor/mpq_libmpq.cpp (revision 2)
+++ trunk/contrib/extractor/mpq_libmpq.cpp (revision 177)
@@ -72,5 +72,5 @@
         }
 
-        int fileno = blockindex;
+        uint32 fileno = blockindex;
 
         //int fileno = libmpq_file_number(&mpq_a, filename);
Index: trunk/contrib/extractor/libmpq/mpq.h
===================================================================
--- trunk/contrib/extractor/libmpq/mpq.h (revision 2)
+++ trunk/contrib/extractor/libmpq/mpq.h (revision 177)
@@ -199,5 +199,5 @@
 extern int libmpq_archive_info(mpq_archive *mpq_a, unsigned int infotype);
 //extern int libmpq_file_extract(mpq_archive *mpq_a, const int number);
-extern int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int number);
+extern int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const unsigned int number);
 extern char *libmpq_file_name(mpq_archive *mpq_a, const int number);
 extern int libmpq_file_number(mpq_archive *mpq_a, const char *name);
Index: trunk/contrib/extractor/libmpq/parser.cpp
===================================================================
--- trunk/contrib/extractor/libmpq/parser.cpp (revision 2)
+++ trunk/contrib/extractor/libmpq/parser.cpp (revision 177)
@@ -80,5 +80,5 @@
 
 	/* now search for comment in this line */
-	for (i = 0; i < strlen(line); i++) {
+	for (i = 0; i < int(strlen(line)); i++) {
 		if (line[i] == '#') {
 			pos = i - 1;
Index: trunk/contrib/extractor/libmpq/mpq.cpp
===================================================================
--- trunk/contrib/extractor/libmpq/mpq.cpp (revision 168)
+++ trunk/contrib/extractor/libmpq/mpq.cpp (revision 177)
@@ -200,5 +200,5 @@
  * This function returns some useful file information.
  */
-int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int number) {
+int libmpq_file_info(mpq_archive *mpq_a, unsigned int infotype, const int unsigned number) {
 	int blockindex = number; //-1;
 	int i = 0;
Index: trunk/contrib/extractor/mpq_libmpq.h
===================================================================
--- trunk/contrib/extractor/mpq_libmpq.h (revision 2)
+++ trunk/contrib/extractor/mpq_libmpq.h (revision 177)
@@ -52,12 +52,10 @@
     }
 
-    vector<string> GetFileList() {
-        vector<string> filelist;
-
+    void GetFileListTo(vector<string>& filelist) {
         mpq_hash hash = GetHashEntry("(listfile)");
         uint32 blockindex = hash.blockindex;
 
         if ((blockindex == 0xFFFFFFFF) || (blockindex == 0))
-            return filelist;
+            return;
 
         uint32 size = libmpq_file_info(&mpq_a, LIBMPQ_FILE_UNCOMPRESSED_SIZE, blockindex);
@@ -80,6 +78,5 @@
         }
 
-        delete buffer;
-        return filelist;
+        delete[] buffer;
     }
 };
Index: trunk/contrib/extractor/System.cpp
===================================================================
--- trunk/contrib/extractor/System.cpp (revision 2)
+++ trunk/contrib/extractor/System.cpp (revision 177)
@@ -40,5 +40,5 @@
 int extract = EXTRACT_MAP | EXTRACT_DBC;
 
-static char* const langs[]={"deDE", "enGB", "enUS", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
+static char* const langs[]={"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
 #define LANG_COUNT 12
 
@@ -168,9 +168,9 @@
     CreateDir(path);
 
-    for(int x = 0; x < ADT_RES; ++x)
-    {
-        for(int y = 0; y < ADT_RES; ++y)
-        {
-            for(int z = 0; z < map_count; ++z)
+    for(unsigned int x = 0; x < ADT_RES; ++x)
+    {
+        for(unsigned int y = 0; y < ADT_RES; ++y)
+        {
+            for(unsigned int z = 0; z < map_count; ++z)
             {
                 sprintf(mpq_filename,"World\\Maps\\%s\\%s_%u_%u.adt",map_ids[z].name,map_ids[z].name,x,y);
@@ -190,5 +190,5 @@
 //bool WMO(char* filename);
 
-void ExtractDBCFiles()
+void ExtractDBCFiles(int locale, bool basicLocale)
 {
     printf("Extracting dbc files...\n");
@@ -199,5 +199,6 @@
     for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
     {
-        vector<string> files = (*i)->GetFileList();
+        vector<string> files;
+        (*i)->GetFileListTo(files);
         for (vector<string>::iterator iter = files.begin(); iter != files.end(); ++iter)
             if (iter->rfind(".dbc") == iter->length() - strlen(".dbc"))
@@ -205,7 +206,13 @@
     }
 
-    std::string path = output_path;
+    string path = output_path;
     path += "/dbc/";
     CreateDir(path);
+    if(!basicLocale)
+    {
+        path += langs[locale];
+        path += "/";
+        CreateDir(path);
+    }
 
     // extract DBCs
@@ -213,9 +220,6 @@
     for (set<string>::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter)
     {
-        string filename = output_path;
-        filename += "/dbc/";
+        string filename = path;
         filename += (iter->c_str() + strlen("DBFilesClient\\"));
-
-        //cout << filename << endl;
 
         FILE *output=fopen(filename.c_str(),"wb");
@@ -232,9 +236,59 @@
         ++count;
     }
-    printf("Extracted %u DBC files\n", count);
-}
-
-int GetLocale()
-{
+    printf("Extracted %u DBC files\n\n", count);
+}
+
+void LoadLocaleMPQFiles(int const locale)
+{
+    char filename[512];
+
+    sprintf(filename,"%s/Data/%s/locale-%s.MPQ",input_path,langs[locale],langs[locale]);
+    new MPQArchive(filename);
+
+    for(int i = 1; i < 5; ++i)
+    {
+        char ext[3] = "";
+        if(i > 1)
+            sprintf(ext, "-%i", i);
+
+        sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext);
+        if(FileExists(filename))
+            new MPQArchive(filename);
+    }
+}
+    
+void LoadCommonMPQFiles()
+{
+    char filename[512];
+
+    sprintf(filename,"%s/Data/common.MPQ",input_path);
+    new MPQArchive(filename);
+    sprintf(filename,"%s/Data/expansion.MPQ",input_path);
+    new MPQArchive(filename);
+    for(int i = 1; i < 5; ++i)
+    {
+        char ext[3] = "";
+        if(i > 1)
+            sprintf(ext, "-%i", i);
+            if(FileExists(filename))
+                new MPQArchive(filename);
+    }
+}
+
+inline void CloseMPQFiles()
+{
+    for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close();
+        gOpenArchives.clear();
+}
+
+int main(int argc, char * arg[])
+{
+    printf("Map & DBC Extractor\n");
+    printf("===================\n\n");
+
+    HandleArgs(argc, arg);
+
+    int FirstLocale = -1;
+    
     for (int i = 0; i < LANG_COUNT; i++)
     {
@@ -244,76 +298,48 @@
         {
             printf("Detected locale: %s\n", langs[i]);
-            return i;
-        }
-    }
-
-    printf("Could not detect locale.\n");
-    return -1;
-}
-
-void LoadMPQFiles(int const locale)
-{
-    char filename[512];
-
-    sprintf(filename,"%s/Data/%s/locale-%s.MPQ",input_path,langs[locale],langs[locale]);
-    new MPQArchive(filename);
-
-    for(int i = 1; i < 5; ++i)
-    {
-        char ext[3] = "";
-        if(i > 1)
-            sprintf(ext, "-%i", i);
-
-        sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ",input_path,langs[locale],langs[locale],ext);
-        if(!FileExists(filename))
-            break;
-        new MPQArchive(filename);
-    }
-
-    //need those files only if extract maps
-    if(extract & EXTRACT_MAP)
-    {
-        sprintf(filename,"%s/Data/common.MPQ",input_path);
-        new MPQArchive(filename);
-        sprintf(filename,"%s/Data/expansion.MPQ",input_path);
-        new MPQArchive(filename);
-
-        for(int i = 1; i < 5; ++i)
-        {
-            char ext[3] = "";
-            if(i > 1)
-                sprintf(ext, "-%i", i);
-
-            sprintf(filename,"%s/Data/patch%s.MPQ",input_path,ext);
-            if(!FileExists(filename))
-                break;
-            new MPQArchive(filename);
-        }
-    }
-}
-
-int main(int argc, char * arg[])
-{
-    printf("Map & DBC Extractor\n");
-    printf("===================\n");
-
-    HandleArgs(argc, arg);
-
-    int const locale = GetLocale();
-    if(locale < 0)
-        return 1;
-
-    LoadMPQFiles(locale);
-
-    if(extract & EXTRACT_DBC)
-        ExtractDBCFiles();
-
-    if(extract & EXTRACT_MAP)
+            
+            //Open MPQs
+            LoadLocaleMPQFiles(i);
+            
+            if((extract & EXTRACT_DBC) == 0)
+            {
+                FirstLocale=i;
+                break;
+            }
+
+        //Extract DBC files
+        if(FirstLocale<0)
+        {
+            ExtractDBCFiles(i, true);
+            FirstLocale = i;
+        }
+        else 
+            ExtractDBCFiles(i, false);
+        
+            //Close MPQs
+            CloseMPQFiles();
+        }
+    }
+
+    if(FirstLocale<0)
+    {
+        printf("No locales detected\n");
+        return 0;
+    }
+    
+    if (extract & EXTRACT_MAP)
+    {
+        printf("Using locale: %s\n", langs[FirstLocale]);
+        
+        // Open MPQs
+        LoadLocaleMPQFiles(FirstLocale);
+        LoadCommonMPQFiles();
+        
+        // Extract maps
         ExtractMapsFromMpq();
 
-    //Close MPQs
-    for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
-        (*i)->close();
-    gOpenArchives.clear();
+        // Close MPQs
+        CloseMPQFiles();
+    }
 
     return 0;
