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

📄 startrec.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
                                 &LineLength))
        {
            return FALSE;
        }

        if (!_tcsnicmp(szName, _T("timeout"), 7))
        {
            TimeOut = _ttoi(szValue);
        }
        
        if (!_tcsnicmp(szName, _T("default"), 7))
        {
            _tcscpy(szDefaultOS, szValue);
        }

    }while(SetupFindNextLine(&InfContext, &InfContext));

    if (!SetupFindFirstLine(hInf,
                            _T("operating systems"),
                            NULL,
                            &InfContext))
    {
        /* failed to find operating systems section */
        return FALSE;
    }

    do
    {
        if (!SetupGetStringField(&InfContext, 
                                 0, 
                                 szName,
                                 sizeof(szName) / sizeof(TCHAR),
                                 &LineLength))
        {
            return FALSE;
        }

        if (!SetupGetStringField(&InfContext, 
                                 1, 
                                 szValue,
                                 sizeof(szValue) / sizeof(TCHAR),
                                 &LineLength))
        {
            return FALSE;
        }

        SetupGetStringField(&InfContext, 
                            2, 
                            szOptions,
                            sizeof(szOptions) / sizeof(TCHAR),
                            &LineLength);

        pRecord = (PBOOTRECORD) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOTRECORD));
        if (pRecord)
        {
            pRecord->BootType = 0;
            _tcscpy(pRecord->szBootPath, szName);
            _tcscpy(pRecord->szSectionName, szValue);
            _tcscpy(pRecord->szOptions, szOptions);

            if (!_tcscmp(szName, szDefaultOS))
            {
                /* ms boot ini stores the path not the friendly name */
                _tcscpy(szDefaultOS, szValue);
            }

            lResult = SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_ADDSTRING, (WPARAM)0, (LPARAM)szValue);
            if (lResult != CB_ERR)
            {
                SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)pRecord);
            }
            else
            {
               HeapFree(GetProcessHeap(), 0, pRecord);
            }
        }

    }while(SetupFindNextLine(&InfContext, &InfContext));
    /* find default os in list */
    lResult = SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_FINDSTRING, (WPARAM)0, (LPARAM)szDefaultOS);
    if (lResult != CB_ERR)
    {
       /* set cur sel */
       SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_SETCURSEL, (WPARAM)lResult, (LPARAM)0);
    }

    SetTimeout(hwndDlg, TimeOut);
    return TRUE;
}

void DeleteBootRecords(HWND hwndDlg)
{
    LRESULT lIndex;
    LONG index;
    PBOOTRECORD pRecord;


    lIndex = SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
    if (lIndex == CB_ERR)
        return;

    for (index = 0; index <lIndex; index++)
    {
        pRecord = (PBOOTRECORD) SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_GETITEMDATA, (WPARAM)index, (LPARAM)0);
        if ((INT)pRecord != CB_ERR)
        {
            HeapFree(GetProcessHeap(), 0, pRecord);
        }
    }
    SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
}

LRESULT LoadOSList(HWND hwndDlg)
{
    DWORD dwBufSize;
    TCHAR *szSystemDrive;
    HINF hInf;

    SetDlgItemText(hwndDlg, IDC_STRRECDUMPFILE, _T("%SystemRoot%\\MiniDump"));
        
    dwBufSize = GetSystemDrive(&szSystemDrive);
    if (!dwBufSize)
        return FALSE;
    

    _tcscpy(m_szFreeldrIni, szSystemDrive);
    _tcscat(m_szFreeldrIni, _T("\\freeldr.ini"));
    if (PathFileExists(m_szFreeldrIni))
    {
        /* freeldr.ini exists */
        hInf = SetupOpenInfFile(m_szFreeldrIni, 
                                NULL,
                                INF_STYLE_OLDNT,
                                NULL);

        if (hInf != INVALID_HANDLE_VALUE)
        {
            LoadFreeldrSettings(hInf, hwndDlg);
            SetupCloseInfFile(hInf);
            m_FreeLdrIni = 1;
            return TRUE;
        }
        return FALSE;
    }
    /* try load boot.ini settings */
    _tcscpy(m_szFreeldrIni, szSystemDrive);
    _tcscat(m_szFreeldrIni, _T("\\boot.ini"));

    if (PathFileExists(m_szFreeldrIni))
    {
        /* load boot.ini settings */
        hInf = SetupOpenInfFile(m_szFreeldrIni, 
                                NULL,
                                INF_STYLE_OLDNT,
                                NULL);

        if (hInf != INVALID_HANDLE_VALUE)
        {
            LoadBootSettings(hInf, hwndDlg);
            SetupCloseInfFile(hInf);
            m_FreeLdrIni = 2;
            return TRUE;
        }
        return FALSE;
    }
    return FALSE;
}


/* Property page dialog callback */
INT_PTR CALLBACK
StartRecDlgProc(HWND hwndDlg,
                UINT uMsg,
                WPARAM wParam,
                LPARAM lParam)
{
    PBOOTRECORD pRecord;
    int iTimeout;
    LRESULT lResult;
    TCHAR szTimeout[10];

    UNREFERENCED_PARAMETER(lParam);

    switch(uMsg)
    {
        case WM_INITDIALOG:
        {
            return LoadOSList(hwndDlg);
        }
        break;

        case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case IDC_STRRECEDIT:
                {
                    ShellExecute(0, _T("open"), _T("notepad"), m_szFreeldrIni, NULL, SW_SHOWNORMAL);
                  // FIXME use CreateProcess and wait untill finished
                  //  DeleteBootRecords(hwndDlg);
                  //  LoadOSList(hwndDlg);
                    break;
                }	
                case IDOK:
                {
                    /* save timeout */
                    if (SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED)
                        iTimeout = SendDlgItemMessage(hwndDlg, IDC_STRRECLISTUPDWN, UDM_GETPOS, (WPARAM)0, (LPARAM)0);
                    else
                        iTimeout = 0;
                    _stprintf(szTimeout, _T("%i"), iTimeout);

                    lResult = SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
                    if (lResult == CB_ERR)
                    {
                        /* ? */
                        DeleteBootRecords(hwndDlg);
                        return TRUE;
                    }


                    pRecord = (PBOOTRECORD) SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_GETITEMDATA, (WPARAM)lResult, (LPARAM)0);



                    if ((INT)pRecord != CB_ERR)
                    {
                        if (m_FreeLdrIni == 1) // FreeLdrIni style
                        {
                            /* set default timeout */
                            WritePrivateProfileString(_T("FREELOADER"),
                                                      _T("TimeOut"),
                                                      szTimeout,
                                                      m_szFreeldrIni);
                            /* set default os */
                            WritePrivateProfileString(_T("FREELOADER"),
                                                      _T("DefaultOS"),
                                                      pRecord->szSectionName,
                                                      m_szFreeldrIni);

                        }
                        else if (m_FreeLdrIni == 2) // BootIni style
                        {
                            /* set default timeout */
                            WritePrivateProfileString(_T("boot loader"),
                                                      _T("timeout"),
                                                      szTimeout,
                                                      m_szFreeldrIni);
                            /* set default os */
                            WritePrivateProfileString(_T("boot loader"),
                                                      _T("default"),
                                                      pRecord->szBootPath,
                                                      m_szFreeldrIni);

                        }
                    }
                    DeleteBootRecords(hwndDlg);
                    EndDialog(hwndDlg,
                              LOWORD(wParam));
                    return TRUE;
                    break;
                }
                case IDCANCEL:
                {
                    DeleteBootRecords(hwndDlg);
                    EndDialog(hwndDlg,
                              LOWORD(wParam));
                    return TRUE;
                }
                case IDC_STRECLIST:
                {
                    if (SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED)
                        SetTimeout(hwndDlg, 30);
                    else
                        SetTimeout(hwndDlg, 0);
                }
            }
        }
        break;
    }
    return FALSE;
}

⌨️ 快捷键说明

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