port over some usability-fixes from lynx3d on the vmapextractor and remove an old header-relic

--HG--
branch : trunk
This commit is contained in:
click
2010-06-13 20:36:07 +02:00
parent 5c8ccefef5
commit 8a2a82d1e8
7 changed files with 37 additions and 30 deletions
+5 -4
View File
@@ -1,3 +1,4 @@
#include "vmapexport.h"
#include "adtfile.h" #include "adtfile.h"
#include <algorithm> #include <algorithm>
@@ -69,12 +70,12 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
//printf("xMap = %s\n", xMap.c_str()); //printf("xMap = %s\n", xMap.c_str());
//printf("yMap = %s\n", yMap.c_str()); //printf("yMap = %s\n", yMap.c_str());
const char dirname[] = "Buildings/dir_bin"; std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE *dirfile; FILE *dirfile;
dirfile = fopen(dirname, "ab"); dirfile = fopen(dirname.c_str(), "ab");
if(!dirfile) if(!dirfile)
{ {
printf("Can't open dirfile!'%s'\n", dirname); printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false; return false;
} }
@@ -125,7 +126,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
// nothing do // nothing do
char szLocalFile[1024]; char szLocalFile[1024];
snprintf(szLocalFile, 1024, "./Buildings/%s", s); snprintf(szLocalFile, 1024, "%s/%s", szWorkDirWmo, s);
FILE * output = fopen(szLocalFile,"rb"); FILE * output = fopen(szLocalFile,"rb");
if(!output) if(!output)
{ {
+1 -1
View File
@@ -134,7 +134,7 @@ ModelInstance::ModelInstance(MPQFile &f,const char* ModelInstName, uint32 mapID,
sc = scale / 1024.0f; sc = scale / 1024.0f;
char tempname[512]; char tempname[512];
sprintf(tempname, "./Buildings/%s", ModelInstName); sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
FILE *input; FILE *input;
input = fopen(tempname, "r+b"); input = fopen(tempname, "r+b");
+1 -1
View File
@@ -57,7 +57,7 @@ MPQFile::MPQFile(const char* filename):
// HACK: in patch.mpq some files don't want to open and give 1 for filesize // HACK: in patch.mpq some files don't want to open and give 1 for filesize
if (size<=1) { if (size<=1) {
printf("warning: file %s has size %d; cannot read.\n", filename, size); // printf("info: file %s has size %d; considered dummy file.\n", filename, size);
eof = true; eof = true;
buffer = 0; buffer = 0;
return; return;
+23 -17
View File
@@ -1,16 +1,3 @@
/*****************************************************************************/
/* StormLibTest.cpp Copyright (c) Ladislav Zezula 2003 */
/*---------------------------------------------------------------------------*/
/* This module uses very brutal test methods for StormLib. It extracts all */
/* files from the archive with Storm.dll and with stormlib and compares them,*/
/* then tries to build a copy of the entire archive, then removes a few files*/
/* from the archive and adds them back, then compares the two archives, ... */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 25.03.03 1.00 Lad The first version of StormLibTest.cpp */
/*****************************************************************************/
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
@@ -68,8 +55,7 @@ bool preciseVectorData = false;
// Constants // Constants
//static const char * szWorkDirMaps = ".\\Maps"; //static const char * szWorkDirMaps = ".\\Maps";
static const char * szWorkDirWmo = "./Buildings"; const char * szWorkDirWmo = "./Buildings";
// Local testing functions // Local testing functions
static void clreol() static void clreol()
@@ -114,7 +100,7 @@ void ReadLiquidTypeTableDBC()
for(uint32 x = 0; x < LiqType_count; ++x) for(uint32 x = 0; x < LiqType_count; ++x)
LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3); LiqType[dbc.getRecord(x).getUInt(0)] = dbc.getRecord(x).getUInt(3);
printf("Done! (%u LiqTypes loaded)\n", LiqType_count); printf("Done! (%u LiqTypes loaded)\n", (unsigned int)LiqType_count);
} }
int ExtractWmo() int ExtractWmo()
@@ -236,18 +222,22 @@ void ParsMapFiles()
WDTFile WDT(fn,map_ids[i].name); WDTFile WDT(fn,map_ids[i].name);
if(WDT.init(id, map_ids[i].id)) if(WDT.init(id, map_ids[i].id))
{ {
printf("Processing Map %u\n[", map_ids[i].id);
for (int x=0; x<64; ++x) for (int x=0; x<64; ++x)
{ {
for (int y=0; y<64; ++y) for (int y=0; y<64; ++y)
{ {
if (ADTFile*ADT = WDT.GetMap(x,y)) if (ADTFile *ADT = WDT.GetMap(x,y))
{ {
//sprintf(id_filename,"%02u %02u %03u",x,y,map_ids[i].id);//!!!!!!!!! //sprintf(id_filename,"%02u %02u %03u",x,y,map_ids[i].id);//!!!!!!!!!
ADT->init(map_ids[i].id, x, y); ADT->init(map_ids[i].id, x, y);
delete ADT; delete ADT;
} }
} }
printf("#");
fflush(stdout);
} }
printf("]\n");
} }
} }
} }
@@ -451,6 +441,22 @@ int main(int argc, char ** argv)
if(!processArgv(argc, argv, versionString)) if(!processArgv(argc, argv, versionString))
return 1; return 1;
// some simple check if working dir is dirty
else
{
std::string sdir = std::string(szWorkDirWmo) + "/dir";
std::string sdir_bin = std::string(szWorkDirWmo) + "/dir_bin";
struct stat status;
if (!stat(sdir.c_str(), &status) || !stat(sdir_bin.c_str(), &status))
{
printf("Your output directory seems to be polluted, please use an empty directory!\n");
printf("<press return to exit>");
char garbage[2];
scanf("%c", garbage);
return 1;
}
}
printf("Extract %s. Beginning work ....\n",versionString); printf("Extract %s. Beginning work ....\n",versionString);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Create the working directory // Create the working directory
+2
View File
@@ -8,4 +8,6 @@ enum ModelFlags
MOD_HAS_BOUND = 1<<2 MOD_HAS_BOUND = 1<<2
}; };
extern const char * szWorkDirWmo;
#endif #endif
+4 -5
View File
@@ -1,5 +1,4 @@
#define __STORMLIB_SELF__ #include "vmapexport.h"
#include "wdtfile.h" #include "wdtfile.h"
#include "adtfile.h" #include "adtfile.h"
#include <cstdio> #include <cstdio>
@@ -29,12 +28,12 @@ bool WDTFile::init(char *map_id, unsigned int mapID)
char fourcc[5]; char fourcc[5];
uint32 size; uint32 size;
const char dirname[] = "Buildings/dir_bin"; std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE *dirfile; FILE *dirfile;
dirfile = fopen(dirname, "ab"); dirfile = fopen(dirname.c_str(), "ab");
if(!dirfile) if(!dirfile)
{ {
printf("Can't open dirfile!'%s'\n", dirname); printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false; return false;
} }
+1 -2
View File
@@ -1,4 +1,3 @@
#include "vmapexport.h" #include "vmapexport.h"
#include "wmo.h" #include "wmo.h"
#include "vec3d.h" #include "vec3d.h"
@@ -443,7 +442,7 @@ WMOInstance::WMOInstance(MPQFile &f,const char* WmoInstName, uint32 mapID, uint3
//-----------add_in _dir_file---------------- //-----------add_in _dir_file----------------
char tempname[512]; char tempname[512];
sprintf(tempname, "Buildings/%s", WmoInstName); sprintf(tempname, "%s/%s", szWorkDirWmo, WmoInstName);
FILE *input; FILE *input;
input = fopen(tempname, "r+b"); input = fopen(tempname, "r+b");