1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// ExtractPackage.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "BaseTypes.h"
#include "CPkgFile.h"
using namespace sqr;
#define BUFFER_SIZE 4096
void ExchangeSymbol(char* szBuf, char cSrc, char cDst)
{
char* ptr = szBuf;
while ( *ptr != '\0' )
{
if ( *ptr == cSrc )
*ptr = cDst;
++ptr;
}
}
const char* GetBaseName(const char* szPath)
{
const char* ptr = szPath;
const char* idx = NULL;
while ( *ptr != '\0' )
{
if ( *ptr == '/' )
idx = ptr;
++ptr;
}
return ++idx;
}
int _tmain(int argc, _TCHAR* argv[])
{
CPkgFile pkg;
if ( pkg.Open(L"", argv[1]) != eFE_SUCCESS )
{
printf("File not found: %s\n", argv[1]);
return 1;
}
int32 size = pkg.Size();
char* szBuf = new char[size];
pkg.Read(szBuf, size);
pkg.Close();
char szDir[BUFFER_SIZE];
GetCurrentDirectory(BUFFER_SIZE, szDir);
ExchangeSymbol(szDir, '\\', '/');
strcat(szDir, "/");
strcat(szDir, GetBaseName(argv[1]));
FILE* fp = fopen(szDir, "wb");
fwrite(szBuf, sizeof(char), size, fp);
fclose(fp);
delete[] szBuf;
return 0;
}
| |