📄 loader.cpp
字号:
if (!Form) {
return;
}
Label1->SetVisible(false);
Label2->SetVisible(false);
Label3->SetVisible(false);
Label5->SetVisible(false);
Label1->GetPosition(Left,Top);
Left = 8 + (218 - Graph->GetTextWidth(StringTable->Loader.Version,STYLE_REGULAR) >> 1);
Label1->SetPosition(Left,Top);
Label2->GetPosition(Left,Top);
Left = 8 + (218 - Graph->GetTextWidth(StringTable->Loader.Copyright,STYLE_REGULAR) >> 1);
Label2->SetPosition(Left,Top);
Label3->GetPosition(Left,Top);
Left = 8 + (218 - Graph->GetTextWidth(StringTable->Loader.URL,STYLE_REGULAR) >> 1);
Label3->SetPosition(Left,Top);
// Label4->GetPosition(Left,Top);
// Left = 8 + (218 - Graph->GetTextWidth(StringTable->Loader.EndTimer,STYLE_REGULAR) >> 1);
// Label4->SetPosition(Left,Top);
Label5->SetCaption(StringTable->Loader.ChooseOS);
Label1->SetVisible(true);
Label2->SetVisible(true);
Label3->SetVisible(true);
Label5->SetVisible(true);
}
int CLoader::CanBoot()
{
return BootBtnPressed;
}
int CLoader::GetBootItemIndex()
{
return BootItemIndex;
}
void CLoader::SelectDefault()
{
int Index, Count;
BootItemIndex = BootItems.GetDefault();
if (Initialized) {
Count = BootItemsList->GetButtonCount();
for (Index = 0; Index < Count; ++Index) {
if (InListBootIndex[Index] == BootItemIndex) {
BootItemsList->SetChecked(Index);
return;
}
}
}
}
void CLoader::ShowBootError(const char *ErrMsg)
{
Dialogs.ShowMessageDialog(Form,StringTable->Loader.BootError,ErrMsg);
BootBtnPressed = false;
}
/*
void CLoader::CycleWindows()
// Loader - Setup - Preference - About
{
int VisibleWin[4];
int Index;
if (!Form) {
return;
}
if (GotFocus())
Index = 1;
else
if (Setup.GotFocus())
Index = 2;
else
if (Preference.GotFocus())
Index = 3;
else
if (About.GotFocus())
Index = 0;
else
return; // Shutdown is pressed, without Soft power-off
VisibleWin[0] = IsVisible();
VisibleWin[1] = Setup.IsVisible();
VisibleWin[2] = Preference.IsVisible();
VisibleWin[3] = About.IsVisible();
while (!VisibleWin[Index])
Index = (Index + 1) & 3;
switch (Index) {
case 0:
Show();
break;
case 1:
Setup.Show();
break;
case 2:
Preference.Show();
break;
case 3:
About.Show();
break;
}
} */
// event handlers
void CLoader::BootBtnClick(CLoader &Loader)
{
const CBootItem *Item;
Loader.HandleAutoSave();
Item = Loader.BootItems.Get(Loader.BootItemIndex);
if (Item->Password) {
Loader.Dialogs.SetPasswordHandler(&Loader,(TPwdProc)BootPwdProc);
Loader.Dialogs.ShowPasswordDialog(Loader.Form,StringTable->Loader.EnterPassword);
}
else
Loader.BootBtnPressed = true;
}
void CLoader::BootItemsSelect(CLoader &Loader, int ItemIndex)
{
Loader.BootItemIndex = Loader.InListBootIndex[ItemIndex];
}
void CLoader::AboutBtnClick(CLoader &Loader)
{
Loader.About.Show();
}
void CLoader::SetupBtnClick(CLoader &Loader)
{
if (!Loader.Setup.IsVisible() && Loader.XoslData.GetPassword()) {
Loader.EnterSetup = true;
Loader.Dialogs.SetPasswordHandler(&Loader,(TPwdProc)PwdProc);
Loader.Dialogs.ShowPasswordDialog(Loader.Form,StringTable->Loader.SetupPassTitle);
}
else
Loader.Setup.Show();
}
void CLoader::PreferBtnClick(CLoader &Loader)
{
if (!Loader.Preference.IsVisible() && Loader.XoslData.GetPassword()) {
Loader.EnterSetup = false;
Loader.Dialogs.SetPasswordHandler(&Loader,(TPwdProc)PwdProc);
Loader.Dialogs.ShowPasswordDialog(Loader.Form,StringTable->Loader.PreferPassTitle);
}
else {
Loader.Preference.Show();
}
}
void CLoader::PwdProc(CLoader &Loader, const char *Password)
{
unsigned long Code;
Code = EncodePassword(Password);
if (Loader.XoslData.GetPassword() == Code)
if (Loader.EnterSetup)
Loader.Setup.Show();
else
Loader.Preference.Show();
else
if (Loader.EnterSetup)
Loader.Dialogs.ShowMessageDialog(Loader.Form,StringTable->Loader.SetupPassTitle,StringTable->Loader.InvalidPassword);
else
Loader.Dialogs.ShowMessageDialog(Loader.Form,StringTable->Loader.PreferPassTitle,StringTable->Loader.InvalidPassword);
}
void CLoader::BootPwdProc(CLoader &Loader, const char *Password)
{
unsigned long Code;
Code = EncodePassword(Password);
if (Loader.BootItems.Get(Loader.BootItemIndex)->Password == Code)
Loader.BootBtnPressed = true;
else
Loader.Dialogs.ShowMessageDialog(Loader.Form,StringTable->Loader.BootPassTitle,StringTable->Loader.InvalidPassword);
}
void CLoader::BootItemsKeyPress(CLoader &Loader, unsigned short &Key)
{
if (Key == KEY_ENTER || Key == KEY_K_ENTER) {
BootBtnClick(Loader);
}
else {
if (Key != KEY_UP && Key != KEY_UP_EXT && Key != KEY_DOWN && Key != KEY_DOWN_EXT)
ButtonKeyPress(Loader,Key);
}
}
void CLoader::ButtonKeyPress(CLoader &Loader, unsigned short &Key)
{
int Index, Count;
CBootItem *Entry;
int lKey;
Count = Loader.BootItemsList->GetButtonCount();
if (!Count || !Key)
return;
// check for hotkeys
for (Index = 0; Index < Count; ++Index) {
Entry = Loader.BootItems.Get(Loader.InListBootIndex[Index]);
if (Entry->Hotkey == Key) {
Loader.BootItemsList->SetChecked(Index);
// always instantly boot
BootBtnClick(Loader);
Key = 0;
return;
}
}
// check for 1-9,a-n
lKey = tolower(Key & 0xff);
if (Key == KEY_UP || Key == KEY_UP_EXT || Key == KEY_DOWN || Key == KEY_DOWN_EXT) {
Loader.Form->FocusControl(Loader.BootItemsList);
Loader.BootItemsList->KeyPress(Key);
}
else
if ( (lKey >= '1' && lKey <= '9') ||
(lKey >= 'a' && lKey <= 'n') ) {
if (lKey >= '1' && lKey <= '9')
Index = lKey - '1';
else
Index = lKey - 'a' + 9;
if (Index < Count) {
Loader.BootItemsList->SetChecked(Index);
Loader.BootBtnClick(Loader);
}
}
else
return;
Key = 0;
}
bool CLoader::GetIgnoreNextKey()
{
return Setup.GetIgnoreNextKey() || Preference.GetIgnoreNextKey();
}
void CLoader::HandleAutoSave()
{
if (Form) {
Setup.Hide();
Preference.Hide();
}
}
void CLoader::CreateBootString(unsigned long TicksPassed)
{
int Sec, Min;
TicksPassed *= 3600;
Sec = (Timeout * 3600 - TicksPassed) >> 16;
if (Sec >= 60) {
BootString = StringTable->Loader.TimerMinPre;
Min = Sec / 60;
Sec %= 60;
BootString += Min;
if (Sec >= 10) {
BootString += ".";
}
else {
BootString += ".0";
}
BootString += Sec;
BootString += StringTable->Loader.TimerMinPost;
}
else {
BootString = StringTable->Loader.TimerSecPre;
BootString += Sec;
BootString += StringTable->Loader.TimerSecPost;
}
}
unsigned short CLoader::WaitTimeout()
{
unsigned long Time1, Time2, TimePassed, Progress;
unsigned short Key = 0;
Time1 = GetTimerTicks();
for (;;) {
Time2 = GetTimerTicks();
TimePassed = Time2 - Time1;
CreateBootString(TimePassed);
BootLabel->SetCaption(BootString);
Progress = (TimePassed * 3600) >> 12;
ProgressBar->SetProgress(Progress);
if (CKeyboard::KeyStrokeAvail()) {
Key = CKeyboard::WaitKeyStroke();
}
if (Key && Key != KEY_ENTER && Key != KEY_K_ENTER) {
#ifndef DOS_DEBUG
Label4->Hide();
BootLabel->Hide();
ProgressBar->Hide();
#endif
Graph->ShowCursor();
return Key;
}
if (TimePassed >= Timeout || Key == KEY_ENTER || Key == KEY_K_ENTER) {
return -1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -