📄 mpqeditor.cpp
字号:
/*****************************************************************************/
/* MPQEditor.cpp Copyright (c) Ladislav Zezula 2003 */
/*---------------------------------------------------------------------------*/
/* Defines the class behaviors for the application. */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 03.04.03 1.00 Lad The first version of MPQEditor.cpp */
/*****************************************************************************/
#include "stdafx.h"
#include "TMainFrm.h"
#include "TTreeView.h"
#include "TAboutDlg.h"
#include "TCmdLineArgsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//-----------------------------------------------------------------------------
// The one and only TMPQEditorApp object
TMPQEditorApp theApp;
TConfiguration cfg;
#ifdef _DEBUG
#define MFC_DLL_NAME _T("Mfc42d.dll")
#else
#define MFC_DLL_NAME _T("Mfc42.dll")
#endif;
//-----------------------------------------------------------------------------
// Message map
BEGIN_MESSAGE_MAP(TMPQEditorApp, CWinApp)
//{{AFX_MSG_MAP(TMPQEditorApp)
ON_COMMAND(ID_FILE_MRU_FILE1, OnFileMRUFile1)
ON_COMMAND(ID_FILE_MRU_FILE2, OnFileMRUFile2)
ON_COMMAND(ID_FILE_MRU_FILE3, OnFileMRUFile3)
ON_COMMAND(ID_FILE_MRU_FILE4, OnFileMRUFile4)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_HELP_CMDLINE, OnHelpCmdLine)
//}}AFX_MSG_MAP
// Standard file based document commands
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
// Constructor and destructor
TMPQEditorApp::TMPQEditorApp()
{}
void TMPQEditorApp::OpenRecentDocument(int nIndex)
{
TMainFrame * pMainFrame = (TMainFrame *)m_pMainWnd;
if(nIndex < m_pRecentFileList->GetSize())
{
CString m_strFileName = (*m_pRecentFileList)[nIndex];
if(pMainFrame->OpenMpqArchive(m_strFileName, FALSE) != ERROR_SUCCESS)
{
AfxMessageBox(IDS_BADRECENTFILE, MB_OK | MB_ICONERROR);
m_pRecentFileList->Remove(nIndex);
}
}
}
//-----------------------------------------------------------------------------
// TMPQEditorApp initialization
BOOL TMPQEditorApp::InitInstance()
{
char * szTemp = NULL;
// Get the name of the INI file for MPQ editor
m_pszProfileName = (char *)malloc(MAX_PATH);
GetModuleFileName(NULL, (char *)m_pszProfileName, MAX_PATH - 1);
if((szTemp = strrchr(m_pszProfileName, '.')) != NULL)
strcpy(szTemp, ".ini");
else
strcat(szTemp, ".ini");
AfxOleInit(); // Initialize OLE support
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
InitializeDLLLoad(); // Initialize own DLL loading
LoadConfiguration();
// If running the first time, ask to register
if(cfg.bRunFirstTime)
{
if(AfxMessageBox(IDS_WANTREGISTER, MB_YESNO | MB_ICONQUESTION) == IDYES)
RegisterMPQEditor();
}
// Parse the command line and do the appropriate action
ParseCmdLine();
return TRUE;
}
int TMPQEditorApp::ExitInstance()
{
SaveConfiguration();
KillDLLLoad(); // Uninitialize own DLL loading
delete cfg.pAddFlags;
return CWinApp::ExitInstance();
}
//-----------------------------------------------------------------------------
// Protected functions
// Create main frame window
TMainFrame * TMPQEditorApp::CreateMainWindow(int nCmdShow)
{
TMainFrame * pMainFrame = new TMainFrame;
pMainFrame->LoadFrame(IDR_MAINFRAME);
pMainFrame->ShowWindow(nCmdShow);
m_pMainWnd = pMainFrame;
return pMainFrame;
}
//------------------------------------------------------------------------------
// Local configuraion section names
static const char * szMainOptions = "Options";
static const char * szAddOptions = "AddFlags";
static const char * szNameBreaker = "NameBreaker";
static const char * szWindowPos = "WindowPos";
static void InsertAddFlag(const char * szExt, int nFileType, int nCompression, BOOL bEncrypt)
{
TAddFlags * pFlags = cfg.pAddFlags;
TExt Ext;
Ext.dwExt = 0;
strncpy(Ext.szExt, szExt, sizeof(DWORD));
// Test if the file type is already there
for(int i = 0; i < cfg.nAddFlags; i++, pFlags++)
{
if(pFlags->Ext.dwExt == Ext.dwExt)
{
pFlags->nFileType = nFileType;
pFlags->nCompression = nCompression;
pFlags->bEncrypt = bEncrypt;
return;
}
}
// Reallocate space (add one entry)
pFlags = new TAddFlags[cfg.nAddFlags + 1];
if(cfg.pAddFlags != NULL)
{
memcpy(pFlags, cfg.pAddFlags, sizeof(TAddFlags) * cfg.nAddFlags);
delete cfg.pAddFlags;
}
cfg.pAddFlags = pFlags;
// Insert the new entry
pFlags = cfg.pAddFlags + cfg.nAddFlags;
if(cfg.nAddFlags > 0)
*pFlags-- = cfg.pAddFlags[cfg.nAddFlags - 1];
pFlags->Ext.dwExt = Ext.dwExt;
pFlags->nFileType = nFileType;
pFlags->nCompression = nCompression;
pFlags->bEncrypt = bEncrypt;
cfg.nAddFlags++;
}
void TMPQEditorApp::LoadAddFlags()
{
int nSectionSize = 32767;
char * szSection = new char [nSectionSize];
char * szVar = szSection;
char * szTemp;
char szName[0x20];
char szValue[0x20];
// Get the whole section
nSectionSize = GetPrivateProfileSection(szAddOptions, szSection, nSectionSize, m_pszProfileName);
if(nSectionSize != 0)
{
while(*szVar != 0)
{
int nFileType = 0;
int nCompression = 1;
BOOL bEncrypt = TRUE;
// Read the variable name
while(0 < *szVar && *szVar <= 0x20)
szVar++;
strncpy(szName, szVar, sizeof(szName)-1);
if((szTemp = strchr(szName, '=')) != NULL)
*szTemp-- = 0;
while(szTemp >= szName && 0 < *szTemp && *szTemp <= 0x20)
*szTemp-- = 0;
// Ignore all values longer than 4 characters
if(strlen(szName) <= 4)
{
// Read the variable value
szTemp = strchr(szVar, '=');
if(szTemp != NULL)
{
szTemp++;
strncpy(szValue, szTemp, sizeof(szValue)-1);
}
szTemp = szValue;
// Get the file type
nFileType = strtol(szTemp, &szTemp, 10);
while(*szTemp != 0 && isdigit(*szTemp) == 0)
szTemp++;
// Get the compression
nCompression = strtol(szTemp, &szTemp, 10);
while(*szTemp != 0 && isdigit(*szTemp) == 0)
szTemp++;
// Get the encryption
nCompression = (BOOL)(strtol(szTemp, &szTemp, 10) != 0);
// Add the result in the add flags
InsertAddFlag(szName, nFileType, nCompression, bEncrypt);
}
// Move to the next variable
szVar += strlen(szVar) + 1;
}
}
delete szSection;
}
void TMPQEditorApp::LoadConfiguration()
{
CString str;
char szMyName[MAX_PATH];
ZeroMemory(&cfg, sizeof(TConfiguration));
// Load main options
strcpy(cfg.szWorkPath, GetProfileString(szMainOptions, "ExtractPath", ""));
strcpy(cfg.szFileListsPath, GetProfileString(szMainOptions, "FileListPath", ""));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -