⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpqeditor.cpp

📁 mpq文件的格式就是一种压缩格式
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    strcpy(cfg.szLastMpqPath, GetProfileString(szMainOptions, "LastOpenPath", ""));
    cfg.bUseStorm = GetProfileInt(szMainOptions, "UseStormDll", FALSE);
    cfg.bMinToSystray = GetProfileInt(szMainOptions, "MinimizeToSystray", FALSE);
    cfg.bRunFirstTime = GetProfileInt(szMainOptions, "RunFirstTime", TRUE);

    // Load archiving options
    cfg.bShowOptionsOnAdd = GetProfileInt(szAddOptions, "ShowOptionsOnAdd", 1);
    cfg.lcLocale          = GetProfileInt(szAddOptions, "LocaleID", 0);
    InsertAddFlag("???", FILE_TYPE_DATA, 2, TRUE);
    InsertAddFlag("wav", FILE_TYPE_WAVE, 0, TRUE);
    InsertAddFlag("mp3", FILE_TYPE_DATA, 0, FALSE);
    InsertAddFlag("smk", FILE_TYPE_DATA, 0, FALSE);
    InsertAddFlag("bik", FILE_TYPE_DATA, 0, FALSE);
    InsertAddFlag("mpq", FILE_TYPE_DATA, 0, FALSE);
    LoadAddFlags();

    // Load name breaker options
    strcpy(cfg.szLastTriedName, GetProfileString(szNameBreaker, "LastTriedName", "A"));
    cfg.bAutoSave = GetProfileInt(szNameBreaker, "AutoSave", 1);

    // Load the window position
    cfg.rectMainWnd.left   = GetProfileInt(szWindowPos, "Left",   0);
    cfg.rectMainWnd.top    = GetProfileInt(szWindowPos, "Top",    0);
    cfg.rectMainWnd.right  = GetProfileInt(szWindowPos, "Right",  640);
    cfg.rectMainWnd.bottom = GetProfileInt(szWindowPos, "Bottom", 480);
    cfg.nShowCommand       = GetProfileInt(szWindowPos, "Show",   SW_SHOWMAXIMIZED);

    // Get default paths, if none.
    GetModuleFileName(NULL, szMyName, sizeof(szMyName)-1);
    *strrchr(szMyName, '\\') = 0;

    // .. for filelists
    if(cfg.szFileListsPath[0] == 0)
    {
        strcpy(cfg.szFileListsPath, szMyName);
        strcat(cfg.szFileListsPath, "\\FileLists");
    }
    RemoveBackslash(cfg.szFileListsPath);

    // .. for working directory
    if(cfg.szWorkPath[0] == 0)
    {
        strcpy(cfg.szWorkPath, szMyName);
        strcat(cfg.szWorkPath, "\\Work");
    }
    RemoveBackslash(cfg.szWorkPath);

    // .. for lastly used path for MPQs
    if(cfg.szLastMpqPath[0] == 0)
        strcpy(cfg.szLastMpqPath, szMyName);
    RemoveBackslash(cfg.szLastMpqPath);
}

void TMPQEditorApp::SaveConfiguration()
{
    TAddFlags * pFlags = cfg.pAddFlags;
    char szName [0x20];
    char szValue[0x20];

    // Save main options
    WriteProfileString(szMainOptions, "ExtractPath",       cfg.szWorkPath);
    WriteProfileString(szMainOptions, "FileListPath",      cfg.szFileListsPath);
    WriteProfileString(szMainOptions, "LastMpqPath",       cfg.szLastMpqPath);
    WriteProfileInt   (szMainOptions, "UseStormDll",       cfg.bUseStorm);
    WriteProfileInt   (szMainOptions, "MinimizeToSysTray", cfg.bMinToSystray);
    WriteProfileInt   (szMainOptions, "RunFirstTime",      FALSE);

    // Load archiving options
    WriteProfileInt   (szAddOptions,  "ShowOptionsOnAdd",  cfg.bShowOptionsOnAdd);
    WriteProfileInt   (szAddOptions,  "LocaleID",          cfg.lcLocale);
    for(int i = 0; i < cfg.nAddFlags; i++, pFlags++)
    {
        memset(szName, 0, sizeof(szName));
        strncpy(szName, pFlags->Ext.szExt, sizeof(TExt));
        sprintf(szValue, "%u,%u,%u", pFlags->nFileType, pFlags->nCompression, pFlags->bEncrypt);
        WriteProfileString(szAddOptions, szName, szValue);
    }

    // Save name breaker options
    WriteProfileString(szNameBreaker, "LastTriedName",     cfg.szLastTriedName);
    WriteProfileInt   (szNameBreaker, "AutoSave",          cfg.bAutoSave);

    // Save the window position
    WriteProfileInt   (szWindowPos,   "Left",              cfg.rectMainWnd.left);
    WriteProfileInt   (szWindowPos,   "Top",               cfg.rectMainWnd.top);
    WriteProfileInt   (szWindowPos,   "Right",             cfg.rectMainWnd.right);
    WriteProfileInt   (szWindowPos,   "Bottom",            cfg.rectMainWnd.bottom);
    WriteProfileInt   (szWindowPos,   "Show",              cfg.nShowCommand);
}

void TMPQEditorApp::ParseCmdLine()
{
    TMainFrame * pMainFrame = CreateMainWindow(cfg.nShowCommand);
    char * szArgs[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
    int nItem = 0;
    int nArgs = 0;
    int i;

    // Do nothing if no cmd line arguments
    if(__argc == 1)
        return;

    // Extract all arguments which are not commands
    for(i = 1; i < __argc && nArgs < 10; i++)
    {
        if(__argv[i][0] != '/' && __argv[i][0] != '-')
            szArgs[nArgs++] = __argv[i];
    }

    // Test if some command was entered
    if(__argv[1][0] == '/' || __argv[1][0] == '-')
    {
        if(!stricmp(__argv[1] + 1, "runscript"))
        {
            pMainFrame->RunMpq2000Script(szArgs[0]);
            return;
        }

        if(!stricmp(__argv[1] + 1, "namebreaker"))
        {
            pMainFrame->NameBreaker(szArgs[0], szArgs[1]);
            return;
        }

        if(!stricmp(__argv[1] + 1, "runbreaking"))
        {
            if(szArgs[4] != NULL)
                nItem = atoi(szArgs[4]);
            pMainFrame->NameBreaker(szArgs[0], szArgs[1], szArgs[2], szArgs[3], nItem);
            return;
        }
        AfxMessageBox(IDS_BADCMDLINEPARAM, MB_OK | MB_ICONERROR);
        return;
    }

    // If no special parameter, simply open the required MPQ archive
    pMainFrame->OpenMpqArchive(szArgs[0], szArgs[1]);
}

// Register itself in the system. Called when running the first time
void TMPQEditorApp::RegisterMPQEditor()
{
    HKEY  hSubKey;
    char  szAppName[MAX_PATH + 16];
    DWORD dwDisp;
    int   nError = ERROR_SUCCESS;

    // Register MPQ type
    if(nError == ERROR_SUCCESS)
    {
        nError = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".mpq", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hSubKey, &dwDisp);
        if(nError == ERROR_SUCCESS)
        {
            RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (CONST BYTE *)"mpqfile", 8);
            RegCloseKey(hSubKey);
        }
    }

    // Create default icon
    if(nError == ERROR_SUCCESS)
    {
        nError = RegCreateKeyEx(HKEY_CLASSES_ROOT, "mpqfile\\DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hSubKey, &dwDisp);
        if(nError == ERROR_SUCCESS)
        {
            GetModuleFileName(NULL, szAppName, MAX_PATH);
            strcat(szAppName, ",0");
            RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (CONST BYTE *)szAppName, strlen(szAppName)+1);
            RegCloseKey(hSubKey);
        }
    }

    // Create open handler
    if(nError == ERROR_SUCCESS)
    {
        nError = RegCreateKeyEx(HKEY_CLASSES_ROOT, "mpqfile\\shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hSubKey, &dwDisp);
        if(nError == ERROR_SUCCESS)
        {
            szAppName[0] = '"';
            GetModuleFileName(NULL, &szAppName[1], MAX_PATH);
            strcat(szAppName, "\" \"%1\"");
            RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (CONST BYTE *)szAppName, strlen(szAppName)+1);
            RegCloseKey(hSubKey);
        }
    }

    // Register MPQ editor for the "Open with" dialog
    if(nError == ERROR_SUCCESS)
    {
        nError = RegCreateKeyEx(HKEY_CLASSES_ROOT, "Applications\\MPQEditor.exe\\shell", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hSubKey, &dwDisp);
        if(nError == ERROR_SUCCESS)
        {
            RegSetValueEx(hSubKey, "FriendlyCache", 0, REG_SZ, (CONST BYTE *)"Ladik's MPQ Editor", 19);
            RegCloseKey(hSubKey);
        }
    }

    // Register MPQ editor's path
    if(nError == ERROR_SUCCESS)
    {
        nError = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\MPQEditor.exe", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hSubKey, &dwDisp);
        if(nError == ERROR_SUCCESS)
        {
            GetModuleFileName(NULL, szAppName, MAX_PATH);
            RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (CONST BYTE *)szAppName, strlen(szAppName)+1);
            RegCloseKey(hSubKey);
        }
    }

    if(nError != ERROR_SUCCESS)
        AfxMessageBox(IDS_REGISTERFAILED, MB_OK|MB_ICONERROR);
}

//-----------------------------------------------------------------------------
// Message handlers

void TMPQEditorApp::OnFileMRUFile1() 
{
    OpenRecentDocument(0);
}

void TMPQEditorApp::OnFileMRUFile2() 
{
    OpenRecentDocument(1);
}

void TMPQEditorApp::OnFileMRUFile3() 
{
    OpenRecentDocument(2);
}

void TMPQEditorApp::OnFileMRUFile4() 
{
    OpenRecentDocument(3);
}

void TMPQEditorApp::OnAppAbout() 
{
    TAboutDlg dlg;
    dlg.DoModal();
}

void TMPQEditorApp::OnHelpCmdLine() 
{
    TCmdLineArgsDlg dlg;
    dlg.DoModal();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -