DragonNest/Client/RCleanerCmd/RCleanerCmd.cpp

228 lines
6.1 KiB
C++
Raw Permalink Normal View History

// RCleanerCmd.cpp : <20>ܼ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>α׷<CEB1><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
//
#include "stdafx.h"
#include <conio.h>
#include <Shlwapi.h>
#include <windows.h>
#include <stdio.h>
#include "DNTableFile.h"
#include "SundriesFunc.h"
#include <string>
#include <map>
using namespace std;
void PrintError( const char *szString, ... );
void DeleteFolder( const char *pFolder, bool bDeleteReadOnly );
void CheckGridFolder( const char *pGridFolder );
std::string s_szNation;
std::map<string, string> s_mapIncludeBuildMapName;
char g_szErrorFileName[512];
int Run( int argc, _TCHAR* argv[] )
{
if( argc < 2 ) {
printf( "Argument\nRCleanerCmd [Resource Path] [Nation(null)]\n" );
return -1;
}
////////////////////////
char szResultFile[512] = { 0, };
sprintf_s( szResultFile, "RCleanerCmd_Completed.txt" );
SetFileAttributes( szResultFile, FILE_ATTRIBUTE_NORMAL );
DeleteFile( szResultFile );
////////////////////////
if( argc == 2 ) {
s_szNation = "";
}
else {
s_szNation = argv[2];
if( _stricmp( argv[2], "null" ) == NULL ) s_szNation = "";
}
// Original üũ
if( PathIsDirectory( argv[1] ) == FALSE ) {
PrintError( "Invalid Resource Path\n" );
return -1;
}
// SOX <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>.
char szOrig[512];
DNTableFileFormat *pSox = new DNTableFileFormat;
bool bValidNation = false;
if( !s_szNation.empty() ) {
sprintf_s( szOrig, "%s\\Resource_%s\\Ext\\MapTable.ext", argv[1], s_szNation.c_str() );
if( PathFileExists( szOrig ) == TRUE ) {
bValidNation = true;
if( pSox->Load( szOrig ) == false ) {
PrintError( "Ext Open Error - Nation\n" );
return -1;
}
}
}
if( !bValidNation ) {
sprintf_s( szOrig, "%s\\Resource\\Ext\\MapTable.ext", argv[1], s_szNation.c_str() );
if( pSox->Load( szOrig ) == false ) {
PrintError( "Ext Open Error - Local\n" );
return -1;
}
}
char szLabel[64];
std::string szMapName;
for( int i=0; i<pSox->GetItemCount(); i++ ) {
int nItemID = pSox->GetItemID(i);
for( int j=0; j<10; j++ ) {
sprintf_s( szLabel, "_ToolName%d", j + 1 );
szMapName = pSox->GetFieldFromLablePtr( nItemID, szLabel )->GetString();
if( pSox->GetFieldFromLablePtr( nItemID, "_IncludeBuild" )->GetInteger() == 0 ) {
bool bEnable = true;
if( szMapName.empty() ) bEnable = false;
if( (int)szMapName.size() == 1 && szMapName[0] == '.' ) bEnable = false;
if( (int)szMapName.size() == 2 && szMapName[0] == '.' && szMapName[1] == '.' ) bEnable = false;
if( bEnable ) {
// Nation<6F>ʵ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD>,
if( !s_szNation.empty() ) {
sprintf_s( szOrig, "%s\\MapData_%s\\Grid\\%s", argv[1], s_szNation.c_str(), szMapName.c_str() );
if( PathIsDirectory( szOrig ) != FALSE ) {
DeleteFolder( szOrig, true );
}
}
// <20><EFBFBD><E2BABB><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>.
sprintf_s( szOrig, "%s\\MapData\\Grid\\%s", argv[1], szMapName.c_str() );
if( PathIsDirectory( szOrig ) != FALSE ) {
DeleteFolder( szOrig, true );
}
}
}
else {
if( !szMapName.empty() )
// IncludeBuild<6C><64> <20><><EFBFBD>ԵǴ<D4B5> <20><> <20≯<EFBFBD><CCB8><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
s_mapIncludeBuildMapName[szMapName] = "";
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// Grid <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鼭, IncludeBuild<6C><64> <20><><EFBFBD>Ծȵ<D4BE> <20>ʵ<EFBFBD><CAB5><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
// Nation<6F>ʵ<EFBFBD> üũ<C3BC>ϰ<EFBFBD>,
if( !s_szNation.empty() ) {
sprintf_s( szOrig, "%s\\MapData_%s\\Grid", argv[1], s_szNation.c_str() );
if( PathIsDirectory( szOrig ) != FALSE ) {
CheckGridFolder( szOrig );
}
}
// <20><EFBFBD><E2BABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> üũ<C3BC>Ѵ<EFBFBD>.
sprintf_s( szOrig, "%s\\MapData\\Grid", argv[1] );
if( PathIsDirectory( szOrig ) != FALSE ) {
CheckGridFolder( szOrig );
}
//////////////////////////////////////////////////////////////////////////////////////////////////
FILE *fp = NULL;
fp = fopen( szResultFile, "wt" );
fprintf( fp, "Completed!" );
fclose( fp );
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
return Run( argc, argv );
}
void PrintError( const char *szString, ... )
{
va_list list;
char szTemp[65535];
va_start( list, szString );
vsprintf_s( szTemp, szString, list );
printf( szTemp );
FILE *fp;
fopen_s( &fp, g_szErrorFileName, "at" );
if( fp ) {
fprintf_s( fp, szTemp );
fclose(fp);
}
s_pDefaultOutputDebugFunc( szTemp );
va_end( list );
}
void DeleteFolder( const char *pFolder, bool bDeleteReadOnly )
{
char szFindFile[ _MAX_PATH ];
WIN32_FIND_DATA FindData;
HANDLE hFind;
strcpy_s( szFindFile, _MAX_PATH, pFolder );
strcat_s( szFindFile, _MAX_PATH, "\\*.*" );
hFind = FindFirstFile( szFindFile, &FindData );
while( hFind != INVALID_HANDLE_VALUE )
{
// svn<76><6E><EFBFBD><EFBFBD> <20>˻<EFBFBD>.
bool bSvnFolder = false;
if( strlen(FindData.cFileName) == 4 && FindData.cFileName[ 0 ] == '.' && FindData.cFileName[ 1 ] == 's' && FindData.cFileName[ 2 ] == 'v' && FindData.cFileName[ 3 ] == 'n' )
bSvnFolder = true;
if( FindData.cFileName[ 0 ] != '.' || bSvnFolder )
{
char szFullName[ _MAX_PATH ];
strcpy_s( szFullName, _MAX_PATH, pFolder );
strcat_s( szFullName, _MAX_PATH, "\\" );
strcat_s( szFullName, _MAX_PATH, FindData.cFileName );
if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
DeleteFolder( szFullName, bDeleteReadOnly );
}
else
{
if( bDeleteReadOnly ) SetFileAttributes( szFullName, FILE_ATTRIBUTE_NORMAL );
DeleteFile( szFullName );
}
}
if( !FindNextFile( hFind, &FindData ) )
{
FindClose( hFind );
RemoveDirectory( pFolder );
break;
}
}
}
void CheckGridFolder( const char *pFolder )
{
char szFindFile[ _MAX_PATH ];
WIN32_FIND_DATA FindData;
HANDLE hFind;
strcpy_s( szFindFile, _MAX_PATH, pFolder );
strcat_s( szFindFile, _MAX_PATH, "\\*.*" );
hFind = FindFirstFile( szFindFile, &FindData );
while( hFind != INVALID_HANDLE_VALUE )
{
if( FindData.cFileName[ 0 ] != '.' )
{
if( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
if( s_mapIncludeBuildMapName.find( FindData.cFileName ) == s_mapIncludeBuildMapName.end() )
{
char szFullName[ _MAX_PATH ];
strcpy_s( szFullName, _MAX_PATH, pFolder );
strcat_s( szFullName, _MAX_PATH, "\\" );
strcat_s( szFullName, _MAX_PATH, FindData.cFileName );
DeleteFolder( szFullName, true );
}
}
}
if( !FindNextFile( hFind, &FindData ) )
{
FindClose( hFind );
break;
}
}
}