- extract to a subdirectory instead of the current work directory.

- add a CMake option to allow node stripping in a default build.
This commit is contained in:
Christoph Oelckers 2016-11-10 20:47:27 +01:00
parent 69de82224e
commit 97dd5ed070
3 changed files with 84 additions and 0 deletions

View file

@ -94,6 +94,15 @@ endif( NOT STRNICMP_EXISTS )
set( WADEXT_LIBS "${ZLIB_LIBRARIES}" ) set( WADEXT_LIBS "${ZLIB_LIBRARIES}" )
option( DEF_STRIP_NODES "Strip nodes from extracted maps by default." NO )
if( DEF_STRIP_NODES )
if ( MSVC )
set( ALL_C_FLAGS "${ALL_C_FLAGS} /DDEFAULT_STRIP" )
else ( MSVC )
set( ALL_C_FLAGS "${ALL_C_FLAGS} -DDEFAULT_STRIP" )
endif( MSVC )
endif()
set( HEADERS set( HEADERS
fileformat.h fileformat.h
resourcefile.h resourcefile.h

View file

@ -77,7 +77,11 @@ int main(int argc, char ** argv)
} }
else if (argc > 1) else if (argc > 1)
{ {
#ifdef DEFAULT_STRIP
ExtractWad(argv[1],DO_STRIP); ExtractWad(argv[1],DO_STRIP);
#else
ExtractWad(argv[1], 0);
#endif
} }
else else
{ {

View file

@ -24,6 +24,7 @@
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#include <stdio.h> #include <stdio.h>
#include <string>
#include "wadext.h" #include "wadext.h"
#include "ResourceFile.h" #include "ResourceFile.h"
#include "fileformat.h" #include "fileformat.h"
@ -438,11 +439,80 @@ void GenerateTextureFile(WadItemList * pTex,WadItemList * pPNam, int options)
GenerateTextureFile(buffer, (const char*)pTex->Address(), (const char *)pPNam->Address(), options, nulltex); GenerateTextureFile(buffer, (const char*)pTex->Address(), (const char *)pPNam->Address(), options, nulltex);
} }
//==========================================================================
//
// IsSeparator (taken from ZDoom)
//
// Returns true if the character is a path separator.
//
//==========================================================================
static inline bool IsSeparator(int c)
{
if (c == '/')
return true;
#ifdef WIN32
if (c == '\\' || c == ':')
return true;
#endif
return false;
}
//==========================================================================
//
// ExtractFileBase (taken from ZDoom)
//
// Returns the file part of a pathname, optionally including the extension.
//
//==========================================================================
std::string ExtractFileBase(const char *path, bool include_extension)
{
const char *src, *dot;
src = path + strlen(path) - 1;
if (src >= path)
{
// back up until a / or the start
while (src != path && !IsSeparator(*(src - 1)))
src--;
// Check for files with drive specification but no path
#if defined(_WIN32)
if (src == path && src[0] != 0)
{
if (src[1] == ':')
src += 2;
}
#endif
if (!include_extension)
{
dot = src;
while (*dot && *dot != '.')
{
dot++;
}
return std::string(src, dot - src);
}
else
{
return std::string(src);
}
}
return std::string();
}
void ExtractWad(char * wadfilename,int options) void ExtractWad(char * wadfilename,int options)
{ {
WadItemList pTex1(-1), pTex2(-1), pPnam(-1); WadItemList pTex1(-1), pTex2(-1), pPnam(-1);
OpenMainWad(wadfilename); OpenMainWad(wadfilename);
auto name = ExtractFileBase(wadfilename, false);
mkdir(name.c_str());
chdir(name.c_str());
PNames = mainwad->FindLump("PNAMES"); PNames = mainwad->FindLump("PNAMES");
getcwd(maindir, 128); getcwd(maindir, 128);
@ -543,6 +613,7 @@ void ExtractWad(char * wadfilename,int options)
} }
} }
} }
chdir("..");
} }
void ConvertTextureX() void ConvertTextureX()