#include "stdafx.h" #include "FilePackSystem.h" #include "FileFinder.h" #include "File.h" #include "MemFile.h" #include "FilePack.h" #define PACK_PASSWORD _T("dkdlfltmehdwjq10aks") #define MAX_PACKS 128 class PackKey { private: char mKey[20]; public: PackKey( ); char* GetKey(){ return mKey; } int GetKeyLenth(){ return ::strlen( mKey ); } }; PackKey::PackKey() { mKey[0] = 41; mKey[1] = -82; mKey[2] = 109; mKey[3] = -73; mKey[4] = 70; mKey[5] = 77; mKey[6] = -48; mKey[7] = -10; mKey[8] = -24; mKey[9] = 92; mKey[10] = 75; mKey[11] = 106; mKey[12] = -7; mKey[13] = -114; mKey[14] = -17; mKey[15] = -73; mKey[16] = -111; mKey[17] = -65; mKey[18] = -92; mKey[19] = 0; } enum eFolder { FOLDER_BASE = 0, FOLDER_LAUNCHER, FOLDER_SOUND, FOLDER_DATA, FOLDER_MAP, FOLDER_SCRIPT, FOLDER_LANGUAGE, FOLDER_COUNT }; PackKey g_packKey; const charT* gFolderNames[FOLDER_COUNT] = { _T(".\\"), _T("Launcher\\"), _T("Sound\\"), _T("Data\\"), _T("Map\\"), _T("Script\\"), _T("Language\\") }; cFilePackSystem::cFilePackSystem() : mFileIndexMap( 16384 ) { mFilePackArray.Reserve( MAX_PACKS ); } cFilePackSystem::~cFilePackSystem() { for( unsigned int i = 0, iend = mFilePackArray.GetSize(); i < iend; ++i ) { delete (cFilePack*)mFilePackArray[i]; } mFilePackArray.Clear(); } bool cFilePackSystem::Init() { /// ÆÄÀÏ ÆÑÀ» °Ë»ö cFileFinder fileFinder; cStringT findPath; cStringT packName; cStringT pathName; for( unsigned int i = FOLDER_DATA; i < FOLDER_COUNT; ++i ) { findPath.Format( _T("%s*.pack"), gFolderNames[i] ); if( fileFinder.FindFirst( findPath.Cstr() ) == false ) continue; do { cFilePack* pack = new cFilePack; /// ÆÄÀÏ ÆÑÀ» ¿® packName.Format( _T("%s%s"), gFolderNames[i], fileFinder.GetFileName() ); if( pack->Open( packName.Cstr(), cFilePack::OPEN_READONLY ) == false ) { delete pack; MessageBox(NULL, _T("Failed Open pack file.. reinstall client."), _T("Error"), MB_OK | MB_ICONEXCLAMATION ); continue; } /// ÆÐ½º¿öµå¸¦ ¼³Á¤ //pack->SetPassword( PACK_PASSWORD ); pack->SetPasswordEx( g_packKey.GetKey(), g_packKey.GetKeyLenth() ); /// ÆÄÀÏ ÆÑÀ» Ãß°¡ unsigned int packIndex = mFilePackArray.GetSize(); unsigned int fileIndex; mFilePackArray.PushBack( pack ); /// ÆÄÀÏ À妽º¸¦ ¸Ê¿¡ Ãß°¡ cFileInPackInfo fipi; for( unsigned int j = 0, jend = pack->GetNumFiles(); j < jend; ++j ) { pack->GetFileInfo( &fipi, j ); if( fipi.IsDirectory() ) continue; fileIndex = j; fileIndex <<= 8; fileIndex += packIndex; #ifdef _UNICODE /// char cstr[MAX_PATH]; ConvertToAscii( fipi.GetPathName().Cstr(), cstr, MAX_PATH ); cString tempName = cstr; #else /// cString tempName = fipi.GetPathName().Cstr(); #endif tempName.Replace( '/', '\\' ); tempName.TrimLeft( ".\\" ); tempName.ToLower(); /// ¸íÈ®¼º °Ë»ç. fipi.pathname °ú filenameÀ» ºñ±³ÇÏ¿© ÇöÀç ¸Â´Â °æ·Î¿¡ ÀÖ´Â pack ÆÄÀÏÀ» ¿­¾ú´ÂÁö °Ë»ç. /// °ÔÀÓ ¼³Ä¡ Æú´õ ¾È¿¡ pack ÆÄÀÏÀÌ ´Ù¸¥ °÷À¸·Î ¿Å°Ü Á³°Å³ª, ´Ù¸¥ À̸§À¸·Î ÀúÀåµÇ¾ú´Ù¸é ÇöÀç pack ÆÄÀÏ ¹«½Ã. if( _tcsnicmp( packName.Cstr(), fipi.GetPathName().Cstr(), _tcslen(packName.Cstr()) - 5 ) != 0 ) break; mFileIndexMap.Insert( tempName, fileIndex ); } } while( fileFinder.FindNext() ); } fileFinder.Close(); return true; } cFileToRead* cFilePackSystem::OpenFileToRead( const cString& pathName ) { #if defined(_DEBUG) || defined(_DEVSYS) || defined(_DEVMODE) || defined(_GMTOOL) /// ·ÎÄà ½Ã½ºÅÛ¿¡¼­ ·Îµù cFileToRead* file = cFileSystem::OpenFileToRead( pathName ); if( file ) return file; /// ÆÑÅ· ½Ã½ºÅÛ¿¡¼­ ·Îµù cString tempName = pathName; tempName.Replace( '/', '\\' ); tempName.TrimLeft( ".\\" ); tempName.ToLower(); cFileIndexMap::cIterator i = mFileIndexMap.Find( tempName ); if( i == mFileIndexMap.End() ) return 0; cMemFileInPackToRead* fileInPack = new cMemFileInPackToRead; unsigned int packIndex = i->mSecond & 0xFF; int fileIndex = int(i->mSecond >> 8); if( fileInPack->Open( (cFilePack*)mFilePackArray[packIndex], fileIndex ) == false ) { delete fileInPack; return 0; } return fileInPack; #else /// ÆÑÅ· ½Ã½ºÅÛ¿¡¼­ ·Îµù cString tempName = pathName; tempName.Replace( '/', '\\' ); tempName.TrimLeft( ".\\" ); tempName.ToLower(); cFileIndexMap::cIterator i = mFileIndexMap.Find( tempName ); if( i != mFileIndexMap.End() ) { cMemFileInPackToRead* fileInPack = new cMemFileInPackToRead; unsigned int packIndex = i->mSecond & 0xFF; int fileIndex = int(i->mSecond >> 8); if( fileInPack->Open( (cFilePack*)mFilePackArray[packIndex], fileIndex ) == true ) { return fileInPack; } delete fileInPack; } return 0; #endif } cMemFileToRead* cFilePackSystem::OpenMemFileToRead( const cString& pathName ) { #if defined(_DEBUG) || defined(_DEVSYS) || defined(_DEVMODE) || defined(_GMTOOL) /// ·ÎÄà ½Ã½ºÅÛ¿¡¼­ ·Îµù cMemFileToRead* file = cFileSystem::OpenMemFileToRead( pathName ); if( file ) return file; /// ÆÑÅ· ½Ã½ºÅÛ¿¡¼­ ·Îµù cString tempName = pathName; tempName.Replace( '/', '\\' ); tempName.TrimLeft( ".\\" ); tempName.ToLower(); cFileIndexMap::cIterator i = mFileIndexMap.Find( tempName ); if( i == mFileIndexMap.End() ) return 0; cMemFileInPackToRead* fileInPack = new cMemFileInPackToRead; unsigned int packIndex = i->mSecond & 0xFF; int fileIndex = int(i->mSecond >> 8); if( fileInPack->Open( (cFilePack*)mFilePackArray[packIndex], fileIndex ) == false ) { delete fileInPack; return 0; } return fileInPack; #else /// ÆÑÅ· ½Ã½ºÅÛ¿¡¼­ ·Îµù cString tempName = pathName; tempName.Replace( '/', '\\' ); tempName.TrimLeft( ".\\" ); tempName.ToLower(); cFileIndexMap::cIterator i = mFileIndexMap.Find( tempName ); if( i != mFileIndexMap.End() ) { cMemFileInPackToRead* fileInPack = new cMemFileInPackToRead; unsigned int packIndex = i->mSecond & 0xFF; int fileIndex = int(i->mSecond >> 8); if( fileInPack->Open( (cFilePack*)mFilePackArray[packIndex], fileIndex ) == true ) { return fileInPack; } delete fileInPack; } return 0; #endif } bool cFilePackSystem::FileExist( const cString& pathName ) { cString tempName = pathName; tempName.Replace( '/', '\\' ); tempName.TrimLeft( ".\\" ); tempName.ToLower(); cFileIndexMap::cIterator i = mFileIndexMap.Find( tempName ); if( i == mFileIndexMap.End() ) { return cFileSystem::FileExist( pathName ); } return true; }