/** * Executes the application * (contains main game loop) */ int SpringApp::Run() { try { if (!Initialize()) return -1; } CATCH_SPRING_ERRORS while (!gu->globalQuit) { Watchdog::ClearTimer(WDT_MAIN); input.PushEvents(); if (gu->globalReload) { Reload(gameSetup->setupText); } else { if (!Update()) { break; } } } SaveWindowPosition(); ShutDown(); LOG("[SpringApp::%s] exitCode=%d", __FUNCTION__, GetExitCode()); return (GetExitCode()); }
void ToolRunner::PostRun() { if( m_pWrapper->CaptureOutput() && !m_pWrapper->IsTextFilter() ) { tstring exitcode(LS(IDS_TOOL_EXITCODE)); exitcode += IntToTString(GetExitCode()); exitcode += LS(IDS_TOOL_TIMETAKEN); time_t endtime; time(&endtime); endtime -= m_starttime; char buf[100]; strftime(buf, 100, "%M:%S", gmtime(&endtime)); CA2CT bufconv(buf); exitcode += bufconv; exitcode += _T("\n"); m_pWrapper->_AddToolOutput(exitcode.c_str()); } if( m_pWrapper->IsFilter() ) m_pWrapper->Revert(); }
bool proThread::IsRunning() { if(GetExitCode() == STILL_ACTIVE) { return true; } return false; }
/* user exit. session is finished */ static void ZVMExitHandle(struct NaClApp *nap, int32_t code) { assert(nap != NULL); SetUserCode(code); if(GetExitCode() == 0) SetExitState(OK_STATE); ZLOGS(LOG_DEBUG, "SESSION %d RETURNED %d", nap->manifest->node, code); ReportDtor(0); }
bool Process::IsRunning() const { bool retValue = false; if(GetExitCode() == NX_PROCESSACTIVE) retValue = true; else retValue = false; return retValue; }
intptr_t VMenu2::RunEx(const std::function<int(int Msg, void *param)>& fn) { cancel=false; closing=false; mfn=fn; Resize(true); Process(); return GetExitCode(); }
/* Стандартный диалог ввода пароля. Умеет сам запоминать последнего юзвера и пароль. Name - сюда будет помещен юзвер (max 256 символов!!!) Password - сюда будет помещен пароль (max 256 символов!!!) Title - заголовок диалога (может быть nullptr) HelpTopic - тема помощи (может быть nullptr) Flags - флаги (GNP_*) */ int GetNameAndPassword(const string& Title, string &strUserName, string &strPassword,const wchar_t *HelpTopic,DWORD Flags) { static string strLastName, strLastPassword; int ExitCode; /* 0 1 2 3 4 5 6 7 0123456789012345678901234567890123456789012345678901234567890123456789012345 |0 | |1 +------------------------------- Title -------------------------------+ | |2 | User name | | |3 | *******************************************************************| | |4 | User password | | |5 | ******************************************************************* | | |6 +---------------------------------------------------------------------+ | |7 | [ Ok ] [ Cancel ] | | |8 +---------------------------------------------------------------------+ | |9 | */ FarDialogItem PassDlgData[]= { {DI_DOUBLEBOX, 3, 1,72, 8,0,nullptr,nullptr,0,NullToEmpty(Title.data())}, {DI_TEXT, 5, 2, 0, 2,0,nullptr,nullptr,0,MSG(MNetUserName)}, {DI_EDIT, 5, 3,70, 3,0,L"NetworkUser",nullptr,DIF_FOCUS|DIF_USELASTHISTORY|DIF_HISTORY,(Flags&GNP_USELAST)?strLastName.data():strUserName.data()}, {DI_TEXT, 5, 4, 0, 4,0,nullptr,nullptr,0,MSG(MNetUserPassword)}, {DI_PSWEDIT, 5, 5,70, 5,0,nullptr,nullptr,0,(Flags&GNP_USELAST)?strLastPassword.data():strPassword.data()}, {DI_TEXT, -1, 6, 0, 6,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_BUTTON, 0, 7, 0, 7,0,nullptr,nullptr,DIF_DEFAULTBUTTON|DIF_CENTERGROUP,MSG(MOk)}, {DI_BUTTON, 0, 7, 0, 7,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MCancel)}, }; auto PassDlg = MakeDialogItemsEx(PassDlgData); { auto Dlg = Dialog::create(PassDlg); Dlg->SetPosition(-1,-1,76,10); Dlg->SetId(GetNameAndPasswordId); if (HelpTopic) Dlg->SetHelp(HelpTopic); Dlg->Process(); ExitCode=Dlg->GetExitCode(); } if (ExitCode!=6) return FALSE; // запоминаем всегда. strUserName = PassDlg[2].strData; strLastName = strUserName; strPassword = PassDlg[4].strData; strLastPassword = strPassword; return TRUE; }
intptr_t DialogBuilder::DoShowDialog() { const auto Dlg = Dialog::create(span(m_DialogItems, m_DialogItemsCount), m_handler, nullptr); Dlg->SetHelp(m_HelpTopic); Dlg->SetPosition({ -1, -1, static_cast<int>(m_DialogItems[0].X2 + 4), static_cast<int>(m_DialogItems[0].Y2 + 2) }); if (m_Mode) Dlg->SetDialogMode(m_Mode); if (m_IdExist) Dlg->SetId(m_Id); Dlg->Process(); return Dlg->GetExitCode(); }
intptr_t DialogBuilder::DoShowDialog() { const auto Dlg = Dialog::create(make_range(m_DialogItems, m_DialogItems + m_DialogItemsCount), m_handler, nullptr); Dlg->SetHelp(m_HelpTopic); Dlg->SetPosition(-1, -1, m_DialogItems [0].X2+4, m_DialogItems [0].Y2+2); if (m_Mode) Dlg->SetDialogMode(m_Mode); if (m_IdExist) Dlg->SetId(m_Id); Dlg->Process(); return Dlg->GetExitCode(); }
ChildProcess::~ChildProcess() { if (hProcess_) { DWORD exitCode = GetExitCode(); if (exitCode) outputPrintf(L"Process exit code was %08x (%lu)\n", exitCode, exitCode); CloseHandle(hProcess_); } if (hOutputAvailable_) { CloseHandle(hOutputAvailable_); } }
DWORD CProcess::WaitForProcess(DWORD dwTimeOut /*= INFINITE*/) const { DWORD dwResult = WaitForSingleObject(m_processInfo.hProcess,dwTimeOut); switch (dwResult) { case WAIT_FAILED: AfxThrowProcessException(CProcessException::generic); return WAIT_FAILED; case WAIT_TIMEOUT: AfxThrowProcessException(CProcessException::generic); return WAIT_TIMEOUT; case WAIT_OBJECT_0: return GetExitCode(); default: AfxThrowProcessException(CProcessException::generic); return ~0U; } }
void LocalSlaveProcess::Kill() { #ifdef PLATFORM_WIN32 if(hProcess && IsRunning()) { TerminateProcess(hProcess, (DWORD)-1); exit_code = 255; } #endif #ifdef PLATFORM_POSIX if(IsRunning()) { SVRLOG("\nLocalSlaveProcess::Kill, pid = " << (int)pid); exit_code = 255; kill(pid, SIGTERM); GetExitCode(); int status; if(pid && waitpid(pid, &status, 0) == pid) DecodeExitCode(status); exit_string = "Child process has been killed.\n"; } #endif Free(); }
static reply ExcDialog(const string& ModuleName, LPCWSTR Exception, LPVOID Adress) { // TODO: Far Dialog is not the best choice for exception reporting // replace with something trivial string strAddr = str_printf(L"0x%p",Adress); FarDialogItem EditDlgData[]= { {DI_DOUBLEBOX,3,1,72,8,0,nullptr,nullptr,0,MSG(MExcTrappedException)}, {DI_TEXT, 5,2, 17,2,0,nullptr,nullptr,0,MSG(MExcException)}, {DI_TEXT, 18,2, 70,2,0,nullptr,nullptr,0,Exception}, {DI_TEXT, 5,3, 17,3,0,nullptr,nullptr,0,MSG(MExcAddress)}, {DI_TEXT, 18,3, 70,3,0,nullptr,nullptr,0,strAddr.data()}, {DI_TEXT, 5,4, 17,4,0,nullptr,nullptr,0,MSG(MExcFunction)}, {DI_TEXT, 18,4, 70,4,0,nullptr,nullptr,0,From}, {DI_TEXT, 5,5, 17,5,0,nullptr,nullptr,0,MSG(MExcModule)}, {DI_EDIT, 18,5, 70,5,0,nullptr,nullptr,DIF_READONLY|DIF_SELECTONENTRY,ModuleName.data()}, {DI_TEXT, -1,6, 0,6,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_BUTTON, 0,7, 0,7,0,nullptr,nullptr,DIF_DEFAULTBUTTON|DIF_FOCUS|DIF_CENTERGROUP, MSG(PluginModule? MExcUnload : MExcTerminate)}, {DI_BUTTON, 0,7, 0,7,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MExcDebugger)}, {DI_BUTTON, 0,7, 0,7,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MIgnore)}, }; auto EditDlg = MakeDialogItemsEx(EditDlgData); auto Dlg = Dialog::create(EditDlg, ExcDlgProc); Dlg->SetDialogMode(DMODE_WARNINGSTYLE|DMODE_NOPLUGINS); Dlg->SetPosition(-1,-1,76,10); Dlg->Process(); switch (Dlg->GetExitCode()) { case 10: return reply_handle; case 11: return reply_debug; case 12: default: return reply_ignore; } }
int GetString( const wchar_t *Title, const wchar_t *Prompt, const wchar_t *HistoryName, const wchar_t *SrcText, string &strDestText, const wchar_t *HelpTopic, DWORD Flags, int *CheckBoxValue, const wchar_t *CheckBoxText, Plugin* PluginNumber, const GUID* Id ) { int Substract=5; // дополнительная величина :-) int ExitCode; bool addCheckBox=Flags&FIB_CHECKBOX && CheckBoxValue && CheckBoxText; int offset=addCheckBox?2:0; FarDialogItem StrDlgData[]= { {DI_DOUBLEBOX, 3, 1, 72, 4, 0, nullptr, nullptr, 0, L""}, {DI_TEXT, 5, 2, 0, 2, 0, nullptr, nullptr, DIF_SHOWAMPERSAND, L""}, {DI_EDIT, 5, 3, 70, 3, 0, nullptr, nullptr, DIF_FOCUS|DIF_DEFAULTBUTTON, L""}, {DI_TEXT, -1, 4, 0, 4, 0, nullptr, nullptr, DIF_SEPARATOR, L""}, {DI_CHECKBOX, 5, 5, 0, 5, 0, nullptr, nullptr, 0, L""}, {DI_TEXT, -1, 6, 0, 6, 0, nullptr, nullptr, DIF_SEPARATOR, L""}, {DI_BUTTON, 0, 7, 0, 7, 0, nullptr, nullptr, DIF_CENTERGROUP, L""}, {DI_BUTTON, 0, 7, 0, 7, 0, nullptr, nullptr, DIF_CENTERGROUP, L""}, }; auto StrDlg = MakeDialogItemsEx(StrDlgData); if (addCheckBox) { Substract-=2; StrDlg[0].Y2+=2; StrDlg[4].Selected = *CheckBoxValue != 0; StrDlg[4].strData = CheckBoxText; } if (Flags&FIB_BUTTONS) { Substract-=3; StrDlg[0].Y2+=2; StrDlg[2].Flags&=~DIF_DEFAULTBUTTON; StrDlg[5+offset].Y1=StrDlg[4+offset].Y1=5+offset; StrDlg[4+offset].Type=StrDlg[5+offset].Type=DI_BUTTON; StrDlg[4+offset].Flags=StrDlg[5+offset].Flags=DIF_CENTERGROUP; StrDlg[4+offset].Flags|=DIF_DEFAULTBUTTON; StrDlg[4+offset].strData = MSG(MOk); StrDlg[5+offset].strData = MSG(MCancel); } if (Flags&FIB_EXPANDENV) { StrDlg[2].Flags|=DIF_EDITEXPAND; } if (Flags&FIB_EDITPATH) { StrDlg[2].Flags|=DIF_EDITPATH; } if (Flags&FIB_EDITPATHEXEC) { StrDlg[2].Flags|=DIF_EDITPATHEXEC; } if (HistoryName) { StrDlg[2].strHistory=HistoryName; StrDlg[2].Flags|=DIF_HISTORY|(Flags&FIB_NOUSELASTHISTORY?0:DIF_USELASTHISTORY); } if (Flags&FIB_PASSWORD) StrDlg[2].Type=DI_PSWEDIT; if (Title) StrDlg[0].strData = Title; if (Prompt) { StrDlg[1].strData = Prompt; TruncStrFromEnd(StrDlg[1].strData, 66); if (Flags&FIB_NOAMPERSAND) StrDlg[1].Flags&=~DIF_SHOWAMPERSAND; } if (SrcText) StrDlg[2].strData = SrcText; { auto Dlg = Dialog::create(make_range(StrDlg.data(), StrDlg.data() + StrDlg.size() - Substract)); Dlg->SetPosition(-1,-1,76,offset+((Flags&FIB_BUTTONS)?8:6)); if(Id) Dlg->SetId(*Id); if (HelpTopic) Dlg->SetHelp(HelpTopic); Dlg->SetPluginOwner(PluginNumber); Dlg->Process(); ExitCode=Dlg->GetExitCode(); if (ExitCode == -2 && Global->CtrlObject->Macro.IsExecuting() != MACROSTATE_NOMACRO) Global->CtrlObject->Macro.SendDropProcess(); } if (ExitCode == 2 || ExitCode == 4 || (addCheckBox && ExitCode == 6)) { if (!(Flags&FIB_ENABLEEMPTY) && StrDlg[2].strData.empty()) return FALSE; strDestText = StrDlg[2].strData; if (addCheckBox) *CheckBoxValue=StrDlg[4].Selected; return TRUE; } return FALSE; }
static bool InputVariablesDialog(string& strStr, subst_data& SubstData, string_view const DlgTitle) { // TODO: use DialogBuilder std::vector<DialogItemEx> DlgData; DlgData.reserve(30); struct pos_item { size_t Pos; size_t EndPos; }; std::vector<pos_item> Positions; Positions.reserve(128); { DialogItemEx Item; Item.Type = DI_DOUBLEBOX; Item.X1 = 3; Item.Y1 = 1; Item.X2 = 72; Item.strData = DlgTitle; DlgData.emplace_back(Item); } string_view Range(strStr); while (!Range.empty()) { // теперича все не просто // придется сразу определить наличие операторных скобок // запомнить их позицию subst_strings Strings; const auto SkipSize = SkipInputToken(Range, &Strings); if (!SkipSize) { Range.remove_prefix(1); continue; } Positions.emplace_back(pos_item{ strStr.size() - Range.size(), strStr.size() - Range.size() + SkipSize - 1 }); { DialogItemEx Item; Item.Type = DI_TEXT; Item.X1 = 5; Item.Y1 = Item.Y2 = DlgData.size() + 1; DlgData.emplace_back(Item); } { DialogItemEx Item; Item.Type = DI_EDIT; Item.X1 = 5; Item.X2 = 70; Item.Y1 = Item.Y2 = DlgData.size() + 1; Item.Flags = DIF_HISTORY | DIF_USELASTHISTORY; Item.strHistory = concat(L"UserVar"sv, str((DlgData.size() - 1) / 2)); DlgData.emplace_back(Item); } if (!Strings.Title.All.empty()) { // Something between "!?" and '?' if (Strings.Title.All[0] == L'$') { // History between '$' and '$' const size_t HistoryBegin = 1; const auto HistoryEnd = Strings.Title.All.find(L'$', HistoryBegin); if (HistoryEnd != string_view::npos) { DlgData.back().strHistory.assign(Strings.Title.All.data(), HistoryBegin, HistoryEnd - HistoryBegin); const auto HistorySize = HistoryEnd - HistoryBegin + 2; Strings.Title.All.remove_prefix(HistorySize); } } if (!Strings.Title.Sub.empty()) { // Something between '(' and ')' DlgData[DlgData.size() - 2].strData = os::env::expand(concat(Strings.Title.prefix(), ProcessMetasymbols(Strings.Title.Sub, SubstData), Strings.Title.suffix())); } else { DlgData[DlgData.size() - 2].strData = os::env::expand(Strings.Title.All); } } if (!Strings.Text.All.empty()) { // Something between '?' and '!' if (!Strings.Text.Sub.empty()) { // Something between '(' and ')' DlgData.back().strData = concat(Strings.Text.prefix(), ProcessMetasymbols(Strings.Text.Sub, SubstData), Strings.Text.suffix()); } else { DlgData.back().strData = Strings.Text.All; } } Range.remove_prefix(SkipSize); } if (DlgData.size() == 1) return true; { DialogItemEx Item; Item.Type = DI_TEXT; Item.Flags = DIF_SEPARATOR; Item.Y1 = Item.Y2 = DlgData.size() + 1; DlgData.emplace_back(Item); } const auto OkButtonId = static_cast<int>(DlgData.size()); { DialogItemEx Item; Item.Type = DI_BUTTON; Item.Flags = DIF_DEFAULTBUTTON|DIF_CENTERGROUP; Item.Y1 = Item.Y2 = DlgData.size() + 1; Item.strData = msg(lng::MOk); DlgData.emplace_back(Item); Item.strData = msg(lng::MCancel); Item.Flags &= ~DIF_DEFAULTBUTTON; DlgData.emplace_back(Item); } // correct Dlg Title DlgData[0].Y2 = DlgData.size(); int ExitCode; { const auto Dlg = Dialog::create(DlgData); Dlg->SetPosition({ -1, -1, 76, static_cast<int>(DlgData.size() + 2) }); Dlg->SetId(UserMenuUserInputId); Dlg->Process(); ExitCode=Dlg->GetExitCode(); } if (ExitCode != OkButtonId) { return false; } string strTmpStr; for (size_t n = 0; n != strStr.size(); ++n) { const auto ItemIterator = std::find_if(CONST_RANGE(Positions, i) { return i.Pos == n; }); if (ItemIterator != Positions.cend()) { strTmpStr += DlgData[(ItemIterator - Positions.cbegin()) * 2 + 2].strData; n = ItemIterator->EndPos; } else { strTmpStr.push_back(strStr[n]); } }
void ShellMakeDir(Panel *SrcPanel) { FarList ComboList={sizeof(FarList)}; FarListItem LinkTypeItems[3]={}; ComboList.ItemsNumber=ARRAYSIZE(LinkTypeItems); ComboList.Items=LinkTypeItems; ComboList.Items[0].Text=MSG(MMakeFolderLinkNone); ComboList.Items[1].Text=MSG(MMakeFolderLinkJunction); ComboList.Items[2].Text=MSG(MMakeFolderLinkSymlink); ComboList.Items[0].Flags|=LIF_SELECTED; #if 1 //Maximus: поддержка "узких" дисплеев if (ScrX < 10) { _ASSERTE(ScrX>=10); return; } int BorderW = (72<(ScrX-1))?72:(ScrX-1); // 72 int ElemW = BorderW - 2; // 70 #endif FarDialogItem MkDirDlgData[]= { #if 1 //Maximus: поддержка "узких" дисплеев {DI_DOUBLEBOX,3,1,BorderW,10,0,nullptr,nullptr,0,MSG(MMakeFolderTitle)}, #else {DI_DOUBLEBOX,3,1,72,10,0,nullptr,nullptr,0,MSG(MMakeFolderTitle)}, #endif {DI_TEXT, 5,2, 0,2,0,nullptr,nullptr,0,MSG(MCreateFolder)}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_EDIT, 5,3,ElemW,3,0,L"NewFolder",nullptr,DIF_FOCUS|DIF_EDITEXPAND|DIF_HISTORY|DIF_USELASTHISTORY|DIF_EDITPATH,L""}, #else {DI_EDIT, 5,3,70,3,0,L"NewFolder",nullptr,DIF_FOCUS|DIF_EDITEXPAND|DIF_HISTORY|DIF_USELASTHISTORY|DIF_EDITPATH,L""}, #endif {DI_TEXT, -1,4, 0,4,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_TEXT, 5,5, 0,5,0,nullptr,nullptr,0,MSG(MMakeFolderLinkType)}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_COMBOBOX,20,5,ElemW,5,0,nullptr,nullptr,DIF_DROPDOWNLIST|DIF_LISTNOAMPERSAND|DIF_LISTWRAPMODE,L""}, #else {DI_COMBOBOX,20,5,70,5,0,nullptr,nullptr,DIF_DROPDOWNLIST|DIF_LISTNOAMPERSAND|DIF_LISTWRAPMODE,L""}, #endif {DI_TEXT, 5,6, 0,6,0,nullptr,nullptr,0,MSG(MMakeFolderLinkTarget)}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_EDIT, 20,6,ElemW,6,0,L"NewFolderLinkTarget",nullptr,DIF_DISABLE|DIF_EDITEXPAND|DIF_HISTORY|DIF_USELASTHISTORY|DIF_EDITPATH,L""}, #else {DI_EDIT, 20,6,70,6,0,L"NewFolderLinkTarget",nullptr,DIF_DISABLE|DIF_EDITEXPAND|DIF_HISTORY|DIF_USELASTHISTORY|DIF_EDITPATH,L""}, #endif {DI_CHECKBOX, 5,7, 0,7,Global->Opt->MultiMakeDir,nullptr,nullptr,0,MSG(MMultiMakeDir)}, {DI_TEXT, -1,8, 0,8,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_BUTTON, 0,9, 0,9,0,nullptr,nullptr,DIF_DEFAULTBUTTON|DIF_CENTERGROUP,MSG(MOk)}, {DI_BUTTON, 0,9, 0,9,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MCancel)}, }; auto MkDirDlg = MakeDialogItemsEx(MkDirDlgData); MkDirDlg[MKDIR_COMBOBOX_LINKTYPE].ListItems=&ComboList; std::vector<string> DirList; auto Dlg = Dialog::create(MkDirDlg, MkDirDlgProc, &DirList); #if 1 //Maximus: поддержка "узких" дисплеев Dlg->SetPosition(-1,-1,BorderW+4,12); #else Dlg->SetPosition(-1,-1,76,12); #endif Dlg->SetHelp(L"MakeFolder"); Dlg->SetId(MakeFolderId); Dlg->Process(); if (Dlg->GetExitCode()==MKDIR_OK) { string strDirName=MkDirDlg[MKDIR_EDIT].strData; string strOriginalDirName; bool SkipAll = false; FOR(const auto& i, DirList) { // TODO: almost the same code in dirmix::CreatePath() strDirName = i; strOriginalDirName = strDirName; ConvertNameToFull(strDirName, strDirName); DeleteEndSlash(strDirName); bool bSuccess = false; size_t DirOffset = 0; ParsePath(strDirName, &DirOffset); string Part; Part.reserve(strDirName.size()); for (size_t j = DirOffset; j <= strDirName.size(); ++j) { if (j == strDirName.size() || IsSlash(strDirName[j])) { Part = strDirName.substr(0, j); if (!os::fs::exists(Part) || j == strDirName.size()) // skip all intermediate dirs, but not last. { while(!(bSuccess=(os::CreateDirectory(Part, nullptr)!=FALSE)) && !SkipAll) { Global->CatchError(); int Ret = OperationFailed(strOriginalDirName, MError, MSG(MCannotCreateFolder)); if(Ret == 1) // skip { break; } else if(Ret == 2) { SkipAll = true; break; } else if (Ret < 0 || Ret == 3) // cancel { return; } } if(bSuccess) { TreeList::AddTreeName(Part); } } } } if (bSuccess) { if(MkDirDlg[MKDIR_COMBOBOX_LINKTYPE].ListPos) { string strTarget=MkDirDlg[MKDIR_EDIT_LINKPATH].strData; Unquote(strTarget); while(!CreateReparsePoint(strTarget, strDirName, MkDirDlg[MKDIR_COMBOBOX_LINKTYPE].ListPos==1?RP_JUNCTION:RP_SYMLINKDIR) && !SkipAll) { Global->CatchError(); int Ret = OperationFailed(strDirName, MError, MSG(MCopyCannotCreateLink)); if(Ret == 1) // skip { break; } else if(Ret == 2) { SkipAll = true; break; } else if (Ret < 0 || Ret == 3) // cancel { return; } } } } }
int GetSearchReplaceString( bool IsReplaceMode, const wchar_t *Title, const wchar_t *SubTitle, string& SearchStr, string& ReplaceStr, const wchar_t *TextHistoryName, const wchar_t *ReplaceHistoryName, bool* pCase, bool* pWholeWords, bool* pReverse, bool* pRegexp, bool* pPreserveStyle, const wchar_t *HelpTopic, bool HideAll, const GUID* Id) { int Result = 0; if (!TextHistoryName) TextHistoryName = L"SearchText"; if (!ReplaceHistoryName) ReplaceHistoryName = L"ReplaceText"; if (!Title) Title=MSG(IsReplaceMode?MEditReplaceTitle:MEditSearchTitle); if (!SubTitle) SubTitle=MSG(MEditSearchFor); bool Case=pCase?*pCase:false; bool WholeWords=pWholeWords?*pWholeWords:false; bool Reverse=pReverse?*pReverse:false; bool Regexp=pRegexp?*pRegexp:false; bool PreserveStyle=pPreserveStyle?*pPreserveStyle:false; #if 1 //Maximus: поддержка "узких" дисплеев int BorderW = (72<(ScrX-1))?72:(ScrX-1); int ElemW = BorderW - 2; // 70 int ElemX2 = (BorderW + 4) / 2; // 40 #endif if (IsReplaceMode) { /* 0 1 2 3 4 5 6 7 0123456789012345678901234567890123456789012345678901234567890123456789012345 00 01 +----------------------------- Replace ------------------------------+ 02 | Search for | 03 | | 04 | Replace with | 05 | | 06 +--------------------------------------------------------------------+ 07 | [ ] Case sensitive [ ] Regular expressions | 08 | [ ] Whole words [ ] Preserve style | 09 | [ ] Reverse search | 10 +--------------------------------------------------------------------+ 11 | [ Replace ] [ Cancel ] | 12 +--------------------------------------------------------------------+ 13 */ FarDialogItem ReplaceDlgData[]= { #if 1 //Maximus: поддержка "узких" дисплеев {DI_DOUBLEBOX,3,1,BorderW,12,0,nullptr,nullptr,0,Title}, #else {DI_DOUBLEBOX,3,1,72,12,0,nullptr,nullptr,0,Title}, #endif {DI_TEXT,5,2,0,2,0,nullptr,nullptr,0,SubTitle}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_EDIT,5,3,ElemW,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()}, #else {DI_EDIT,5,3,70,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()}, #endif {DI_TEXT,5,4,0,4,0,nullptr,nullptr,0,MSG(MEditReplaceWith)}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_EDIT,5,5,ElemW,5,0,ReplaceHistoryName,nullptr,(*ReplaceHistoryName?DIF_HISTORY:0)/*|DIF_USELASTHISTORY*/,ReplaceStr.data()}, #else {DI_EDIT,5,5,70,5,0,ReplaceHistoryName,nullptr,(*ReplaceHistoryName?DIF_HISTORY:0)/*|DIF_USELASTHISTORY*/,ReplaceStr.data()}, #endif {DI_TEXT,-1,6,0,6,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_CHECKBOX,5,7,0,7,Case,nullptr,nullptr,0,MSG(MEditSearchCase)}, {DI_CHECKBOX,5,8,0,8,WholeWords,nullptr,nullptr,0,MSG(MEditSearchWholeWords)}, {DI_CHECKBOX,5,9,0,9,Reverse,nullptr,nullptr,0,MSG(MEditSearchReverse)}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_CHECKBOX,ElemX2,7,0,7,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)}, #else {DI_CHECKBOX,40,7,0,7,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)}, #endif {DI_CHECKBOX,40,8,0,8,PreserveStyle,nullptr,nullptr,0,MSG(MEditSearchPreserveStyle)}, {DI_TEXT,-1,10,0,10,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_BUTTON,0,11,0,11,0,nullptr,nullptr,DIF_DEFAULTBUTTON|DIF_CENTERGROUP,MSG(MEditReplaceReplace)}, {DI_BUTTON,0,11,0,11,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MEditSearchCancel)}, }; auto ReplaceDlg = MakeDialogItemsEx(ReplaceDlgData); if (!pCase) ReplaceDlg[6].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (!pWholeWords) ReplaceDlg[7].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (!pReverse) ReplaceDlg[8].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (!pRegexp) ReplaceDlg[9].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (!pPreserveStyle) ReplaceDlg[10].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? auto Dlg = Dialog::create(ReplaceDlg); #if 1 //Maximus: поддержка "узких" дисплеев Dlg->SetPosition(-1,-1,BorderW+4,14); #else Dlg->SetPosition(-1,-1,76,14); #endif if (HelpTopic && *HelpTopic) Dlg->SetHelp(HelpTopic); if(Id) Dlg->SetId(*Id); Dlg->Process(); if(Dlg->GetExitCode() == 12) { Result = 1; SearchStr = ReplaceDlg[2].strData; ReplaceStr = ReplaceDlg[4].strData; Case=ReplaceDlg[6].Selected == BSTATE_CHECKED; WholeWords=ReplaceDlg[7].Selected == BSTATE_CHECKED; Reverse=ReplaceDlg[8].Selected == BSTATE_CHECKED; Regexp=ReplaceDlg[9].Selected == BSTATE_CHECKED; PreserveStyle=ReplaceDlg[10].Selected == BSTATE_CHECKED; } } else { /* 0 1 2 3 4 5 6 7 0123456789012345678901234567890123456789012345678901234567890123456789012345 00 01 +------------------------------ Search ------------------------------+ 02 | Search for | 03 | | 04 +--------------------------------------------------------------------+ 05 | [ ] Case sensitive [ ] Regular expressions | 06 | [ ] Whole words [ ] Reverse search | 07 +--------------------------------------------------------------------+ 08 | { Search } [ All ] [ Cancel ] | 09 +--------------------------------------------------------------------+ */ FarDialogItem SearchDlgData[]= { #if 1 //Maximus: поддержка "узких" дисплеев {DI_DOUBLEBOX,3,1,BorderW,9,0,nullptr,nullptr,0,Title}, #else {DI_DOUBLEBOX,3,1,72,9,0,nullptr,nullptr,0,Title}, #endif {DI_TEXT,5,2,0,2,0,nullptr,nullptr,0,SubTitle}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_EDIT,5,3,ElemW,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()}, #else {DI_EDIT,5,3,70,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()}, #endif {DI_TEXT,-1,4,0,4,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_CHECKBOX,5,5,0,5,Case,nullptr,nullptr,0,MSG(MEditSearchCase)}, {DI_CHECKBOX,5,6,0,6,WholeWords,nullptr,nullptr,0,MSG(MEditSearchWholeWords)}, #if 1 //Maximus: поддержка "узких" дисплеев {DI_CHECKBOX,ElemX2,5,0,5,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)}, {DI_CHECKBOX,ElemX2,6,0,6,Reverse,nullptr,nullptr,0,MSG(MEditSearchReverse)}, #else {DI_CHECKBOX,40,5,0,5,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)}, {DI_CHECKBOX,40,6,0,6,Reverse,nullptr,nullptr,0,MSG(MEditSearchReverse)}, #endif {DI_TEXT,-1,7,0,7,0,nullptr,nullptr,DIF_SEPARATOR,L""}, {DI_BUTTON,0,8,0,8,0,nullptr,nullptr,DIF_DEFAULTBUTTON|DIF_CENTERGROUP,MSG(MEditSearchSearch)}, {DI_BUTTON,0,8,0,8,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MEditSearchAll)}, {DI_BUTTON,0,8,0,8,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MEditSearchCancel)}, }; auto SearchDlg = MakeDialogItemsEx(SearchDlgData); if (!pCase) SearchDlg[4].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (!pWholeWords) SearchDlg[5].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (!pRegexp) SearchDlg[6].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (!pReverse) SearchDlg[7].Flags |= DIF_DISABLE; // DIF_HIDDEN ?? if (HideAll) SearchDlg[10].Flags |= DIF_HIDDEN; auto Dlg = Dialog::create(SearchDlg); #if 1 //Maximus: поддержка "узких" дисплеев Dlg->SetPosition(-1,-1,BorderW+4,11); #else Dlg->SetPosition(-1,-1,76,11); #endif if (HelpTopic && *HelpTopic) Dlg->SetHelp(HelpTopic); if(Id) Dlg->SetId(*Id); Dlg->Process(); int ExitCode = Dlg->GetExitCode(); if (ExitCode == 9 || ExitCode == 10) { Result = ExitCode == 9? 1 : 2; SearchStr = SearchDlg[2].strData; ReplaceStr.clear(); Case=SearchDlg[4].Selected == BSTATE_CHECKED; WholeWords=SearchDlg[5].Selected == BSTATE_CHECKED; Regexp=SearchDlg[6].Selected == BSTATE_CHECKED; Reverse=SearchDlg[7].Selected == BSTATE_CHECKED; } } if (pCase) *pCase=Case; if (pWholeWords) *pWholeWords=WholeWords; if (pReverse) *pReverse=Reverse; if (pRegexp) *pRegexp=Regexp; if (pPreserveStyle) *pPreserveStyle=PreserveStyle; return Result; }
int main(int argc, char* argv[]) { try { spring_clock::PushTickRate(); // initialize start time (can safely be done before SDL_Init // since we are not using SDL_GetTicks as our clock anymore) spring_time::setstarttime(spring_time::gettime(true)); CLogOutput::LogSystemInfo(); std::string scriptName; std::string scriptText; ParseCmdLine(argc, argv, &scriptName); GlobalConfig::Instantiate(); FileSystemInitializer::InitializeLogOutput(); FileSystemInitializer::Initialize(); // Initialize crash reporting CrashHandler::Install(); LOG("report any errors to Mantis or the forums."); LOG("loading script from file: %s", scriptName.c_str()); CGameServer* server = NULL; // server will take ownership of these boost::shared_ptr<ClientSetup> dsClientSetup(new ClientSetup()); boost::shared_ptr<GameData> dsGameData(new GameData()); boost::shared_ptr<CGameSetup> dsGameSetup(new CGameSetup()); CFileHandler fh(scriptName); if (!fh.FileExists()) throw content_error("script does not exist in given location: " + scriptName); if (!fh.LoadStringData(scriptText)) throw content_error("script cannot be read: " + scriptName); dsClientSetup->LoadFromStartScript(scriptText); if (!dsGameSetup->Init(scriptText)) { // read the script provided by cmdline LOG_L(L_ERROR, "failed to load script %s", scriptName.c_str()); return 1; } // Create the server, it will run in a separate thread UnsyncedRNG rng; const unsigned seed = time(NULL) % ((spring_gettime().toNanoSecsi() + 1) * 9007); rng.Seed(seed); dsGameData->SetRandomSeed(rng.RandInt()); // Use script provided hashes if they exist if (dsGameSetup->mapHash != 0) { dsGameData->SetMapChecksum(dsGameSetup->mapHash); dsGameSetup->LoadStartPositions(false); // reduced mode } else { dsGameData->SetMapChecksum(archiveScanner->GetArchiveCompleteChecksum(dsGameSetup->mapName)); CFileHandler f("maps/" + dsGameSetup->mapName); if (!f.FileExists()) { vfsHandler->AddArchiveWithDeps(dsGameSetup->mapName, false); } dsGameSetup->LoadStartPositions(); // full mode } if (dsGameSetup->modHash != 0) { dsGameData->SetModChecksum(dsGameSetup->modHash); } else { const std::string& modArchive = archiveScanner->ArchiveFromName(dsGameSetup->modName); const unsigned int modCheckSum = archiveScanner->GetArchiveCompleteChecksum(modArchive); dsGameData->SetModChecksum(modCheckSum); } LOG("starting server..."); dsGameData->SetSetupText(dsGameSetup->setupText); server = new CGameServer(dsClientSetup, dsGameData, dsGameSetup); while (!server->HasGameID()) { // wait until gameID has been generated or // a timeout occurs (if no clients connect) if (server->HasFinished()) { break; } spring_secs(1).sleep(); } while (!server->HasFinished()) { static bool printData = (server->GetDemoRecorder() != NULL); if (printData) { printData = false; const boost::scoped_ptr<CDemoRecorder>& demoRec = server->GetDemoRecorder(); const boost::uint8_t* gameID = (demoRec->GetFileHeader()).gameID; LOG("recording demo: %s", (demoRec->GetName()).c_str()); LOG("using mod: %s", (dsGameSetup->modName).c_str()); LOG("using map: %s", (dsGameSetup->mapName).c_str()); LOG("GameID: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", gameID[0], gameID[1], gameID[2], gameID[3], gameID[4], gameID[5], gameID[6], gameID[7], gameID[8], gameID[9], gameID[10], gameID[11], gameID[12], gameID[13], gameID[14], gameID[15]); } // wait 1 second between checks spring_secs(1).sleep(); } LOG("exiting"); delete server; FileSystemInitializer::Cleanup(); GlobalConfig::Deallocate(); spring_clock::PopTickRate(); LOG("exited"); } CATCH_SPRING_ERRORS return GetExitCode(); }
static int MainProcess( const string& EditName, const string& ViewName, const string& DestName1, const string& DestName2, int StartLine, int StartChar ) { SCOPED_ACTION(ChangePriority)(THREAD_PRIORITY_NORMAL); FarColor InitAttributes={}; console.GetTextAttributes(InitAttributes); SetRealColor(colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN)); string ename(EditName),vname(ViewName), apanel(DestName1),ppanel(DestName2); if (ConfigProvider().ShowProblems()) { ename.clear(); vname.clear(); StartLine = StartChar = -1; apanel = Global->Opt->ProfilePath; ppanel = Global->Opt->LocalProfilePath; } if (!ename.empty() || !vname.empty()) { Global->OnlyEditorViewerUsed = true; _tran(SysLog(L"create dummy panels")); Global->CtrlObject->CreateDummyFilePanels(); Global->WindowManager->PluginCommit(); Global->CtrlObject->Plugins->LoadPlugins(); Global->CtrlObject->Macro.LoadMacros(true, true); if (!ename.empty()) { const auto ShellEditor = FileEditor::create(ename, CP_DEFAULT, FFILEEDIT_CANNEWFILE | FFILEEDIT_ENABLEF6, StartLine, StartChar); _tran(SysLog(L"make shelleditor %p",ShellEditor)); if (!ShellEditor->GetExitCode()) // ???????????? { Global->WindowManager->ExitMainLoop(0); } } // TODO: Этот else убрать только после разборок с возможностью задавать несколько /e и /v в ком.строке else if (!vname.empty()) { const auto ShellViewer = FileViewer::create(vname, true); if (!ShellViewer->GetExitCode()) { Global->WindowManager->ExitMainLoop(0); } _tran(SysLog(L"make shellviewer, %p",ShellViewer)); } Global->WindowManager->EnterMainLoop(); } else { int DirCount=0; // воспользуемся тем, что ControlObject::Init() создает панели // юзая Global->Opt->* const auto& SetupPanel = [&](bool active) { ++DirCount; string strPath = active? apanel : ppanel; if (os::fs::is_file(strPath)) { CutToParent(strPath); } bool Root = false; const auto Type = ParsePath(strPath, nullptr, &Root); if(Root && (Type == root_type::drive_letter || Type == root_type::unc_drive_letter || Type == root_type::volume)) { AddEndSlash(strPath); } auto& CurrentPanelOptions = (Global->Opt->LeftFocus == active)? Global->Opt->LeftPanel : Global->Opt->RightPanel; CurrentPanelOptions.m_Type = static_cast<int>(panel_type::FILE_PANEL); // сменим моду панели CurrentPanelOptions.Visible = true; // и включим ее CurrentPanelOptions.Folder = strPath; }; if (!apanel.empty()) { SetupPanel(true); if (!ppanel.empty()) { SetupPanel(false); } } // теперь все готово - создаем панели! Global->CtrlObject->Init(DirCount); // а теперь "провалимся" в каталог или хост-файл (если получится ;-) if (!apanel.empty()) // активная панель { const auto ActivePanel = Global->CtrlObject->Cp()->ActivePanel(); const auto AnotherPanel = Global->CtrlObject->Cp()->PassivePanel(); if (!ppanel.empty()) // пассивная панель { FarChDir(AnotherPanel->GetCurDir()); if (IsPluginPrefixPath(ppanel)) { AnotherPanel->Parent()->SetActivePanel(AnotherPanel); execute_info Info; Info.Command = ppanel; Global->CtrlObject->CmdLine()->ExecString(Info); ActivePanel->Parent()->SetActivePanel(ActivePanel); } else { const auto strPath = PointToName(ppanel); if (!strPath.empty()) { if (AnotherPanel->GoToFile(strPath)) AnotherPanel->ProcessKey(Manager::Key(KEY_CTRLPGDN)); } } } FarChDir(ActivePanel->GetCurDir()); if (IsPluginPrefixPath(apanel)) { execute_info Info; Info.Command = apanel; Global->CtrlObject->CmdLine()->ExecString(Info); } else { const auto strPath = PointToName(apanel); if (!strPath.empty()) { if (ActivePanel->GoToFile(strPath)) ActivePanel->ProcessKey(Manager::Key(KEY_CTRLPGDN)); } } // !!! ВНИМАНИЕ !!! // Сначала редравим пассивную панель, а потом активную! AnotherPanel->Redraw(); ActivePanel->Redraw(); } Global->WindowManager->EnterMainLoop(); } TreeList::FlushCache(); // очистим за собой! SetScreen(0,0,ScrX,ScrY,L' ',colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN)); console.SetTextAttributes(InitAttributes); Global->ScrBuf->ResetLockCount(); Global->ScrBuf->Flush(); return 0; }
operator int() const { return GetExitCode(); }
UINT CThread::ExitInstance() { return GetExitCode(); }
void ShowProcessList() { static bool Active = false; if (Active) return; Active = true; auto ProcList = VMenu2::create(MSG(MProcessListTitle), nullptr, 0, ScrY - 4); ProcList->SetMenuFlags(VMENU_WRAPMODE); ProcList->SetPosition(-1,-1,0,0); static bool bShowImage = false; ProcInfo pi = {ProcList.get(), bShowImage}; if (EnumWindows(EnumWindowsProc,(LPARAM)&pi)) { ProcList->AssignHighlights(FALSE); ProcList->SetBottomTitle(MSG(MProcessListBottom)); ProcList->SortItems(TaskSort); ProcList->Run([&](const Manager::Key& RawKey)->int { const auto Key=RawKey.FarKey(); int KeyProcessed = 1; switch (Key) { case KEY_F1: { Help::create(L"TaskList"); break; } case KEY_NUMDEL: case KEY_DEL: { auto ProcWnd = *static_cast<HWND*>(ProcList->GetUserData(nullptr, 0)); if (ProcWnd) { wchar_t_ptr Title; int LenTitle=GetWindowTextLength(ProcWnd); if (LenTitle) { Title.reset(LenTitle + 1); if (Title && (LenTitle=GetWindowText(ProcWnd, Title.get(), LenTitle+1))) Title[LenTitle]=0; } DWORD ProcID; GetWindowThreadProcessId(ProcWnd,&ProcID); if (!Message(MSG_WARNING,2,MSG(MKillProcessTitle),MSG(MAskKillProcess), NullToEmpty(Title.get()),MSG(MKillProcessWarning),MSG(MKillProcessKill),MSG(MCancel))) { if (KillProcess(ProcID)) Sleep(500); else { Global->CatchError(); Message(MSG_WARNING|MSG_ERRORTYPE,1,MSG(MKillProcessTitle),MSG(MCannotKillProcess),MSG(MOk)); } } } } case KEY_CTRLR: case KEY_RCTRLR: { ProcList->DeleteItems(); if (!EnumWindows(EnumWindowsProc,(LPARAM)&pi)) ProcList->Close(-1); else ProcList->SortItems(TaskSort); break; } case KEY_F2: { pi.bShowImage=(bShowImage=!bShowImage); int SelectPos=ProcList->GetSelectPos(); ProcList->DeleteItems(); if (!EnumWindows(EnumWindowsProc,(LPARAM)&pi)) ProcList->Close(-1); else { ProcList->SortItems(TaskSort); ProcList->SetSelectPos(SelectPos); } break; } default: KeyProcessed = 0; } return KeyProcessed; }); if (ProcList->GetExitCode()>=0) { auto ProcWnd = *static_cast<HWND*>(ProcList->GetUserData(nullptr, 0)); if (ProcWnd) { //SetForegroundWindow(ProcWnd); // Allow SetForegroundWindow on Win98+. DWORD dwMs; // Remember the current value. BOOL bSPI = SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &dwMs, 0); if (bSPI) // Reset foreground lock timeout bSPI = SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0, 0); SetForegroundWindow(ProcWnd); if (bSPI) // Restore old value SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, ToPtr(dwMs), 0); WINDOWPLACEMENT wp = { sizeof(wp) }; if (!GetWindowPlacement(ProcWnd,&wp) || wp.showCmd!=SW_SHOWMAXIMIZED) ShowWindowAsync(ProcWnd,SW_RESTORE); } } } Active = false; }
static bool SelectLanguage(bool HelpLanguage, string& Dest) { lng Title; string_view Mask; if (HelpLanguage) { Title = lng::MHelpLangTitle; Mask=Global->HelpFileMask; } else { Title = lng::MLangTitle; Mask=LangFileMask; } const auto LangMenu = VMenu2::create(msg(Title), {}, ScrY - 4); LangMenu->SetMenuFlags(VMENU_WRAPMODE); LangMenu->SetPosition(ScrX/2-8+5*HelpLanguage,ScrY/2-4+2*HelpLanguage,0,0); for (const auto& FindData: os::fs::enum_files(path::join(Global->g_strFarPath, Mask))) { const os::fs::file LangFile(path::join(Global->g_strFarPath, FindData.FileName), FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING); if (!LangFile) continue; const auto Codepage = GetFileCodepage(LangFile, encoding::codepage::oem(), nullptr, false); string strLangName, strLangDescr; if (GetLangParam(LangFile, L"Language"sv, strLangName, &strLangDescr, Codepage)) { string strEntryName; if (!HelpLanguage || ( !GetLangParam(LangFile, L"PluginContents"sv, strEntryName, nullptr, Codepage) && !GetLangParam(LangFile, L"DocumentContents"sv, strEntryName, nullptr, Codepage))) { MenuItemEx LangMenuItem(!strLangDescr.empty()? strLangDescr : strLangName); /* $ 01.08.2001 SVS Не допускаем дубликатов! Если в каталог с ФАРом положить еще один HLF с одноименным языком, то... фигня получается при выборе языка. */ if (LangMenu->FindItem(0,LangMenuItem.Name,LIFIND_EXACTMATCH) == -1) { LangMenuItem.SetSelect(equal_icase(Dest, strLangName)); LangMenuItem.ComplexUserData = strLangName; LangMenu->AddItem(LangMenuItem); } } } } LangMenu->AssignHighlights(FALSE); LangMenu->Run(); if (LangMenu->GetExitCode()<0) return false; Dest = *LangMenu->GetComplexUserDataPtr<string>(); return true; }
void ShowProcessList() { static bool Active = false; if (Active) return; Active = true; SCOPE_EXIT{ Active = false; }; const auto ProcList = VMenu2::create(msg(lng::MProcessListTitle), {}, ScrY - 4); ProcList->SetMenuFlags(VMENU_WRAPMODE); ProcList->SetPosition({ -1, -1, 0, 0 }); bool ShowImage = false; const auto FillProcList = [&] { ProcList->clear(); ProcInfo Info{ ProcList.get(), ShowImage }; if (!EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&Info))) { rethrow_if(Info.ExceptionPtr); return false; } ProcList->SortItems([](const MenuItemEx& a, const MenuItemEx& b, SortItemParam&) { return string_sort::less(std::any_cast<const menu_data&>(a.ComplexUserData).Title, std::any_cast<const menu_data&>(b.ComplexUserData).Title); }); return true; }; if (!FillProcList()) return; ProcList->AssignHighlights(FALSE); ProcList->SetBottomTitle(msg(lng::MProcessListBottom)); ProcList->Run([&](const Manager::Key& RawKey) { const auto Key=RawKey(); int KeyProcessed = 1; switch (Key) { case KEY_F1: help::show(L"TaskList"sv); break; case KEY_NUMDEL: case KEY_DEL: { if (const auto MenuData = ProcList->GetComplexUserDataPtr<menu_data>()) { if (Message(MSG_WARNING, msg(lng::MKillProcessTitle), { msg(lng::MAskKillProcess), MenuData->Title, msg(lng::MKillProcessWarning) }, { lng::MKillProcessKill, lng::MCancel }) == Message::first_button) { const os::handle Process(OpenProcess(PROCESS_TERMINATE, FALSE, MenuData->Pid)); if (!Process || !TerminateProcess(Process.native_handle(), 0xFFFFFFFF)) { const auto ErrorState = error_state::fetch(); Message(MSG_WARNING, ErrorState, msg(lng::MKillProcessTitle), { msg(lng::MCannotKillProcess) }, { lng::MOk }); } } } } [[fallthrough]]; case KEY_CTRLR: case KEY_RCTRLR: { if (!FillProcList()) ProcList->Close(-1); break; } case KEY_F2: { // TODO: change titles, don't enumerate again ShowImage = !ShowImage; const auto SelectPos = ProcList->GetSelectPos(); if (!FillProcList()) { ProcList->Close(-1); } else { ProcList->SetSelectPos(SelectPos); } break; } default: KeyProcessed = 0; } return KeyProcessed; }); if (ProcList->GetExitCode() < 0) return; const auto MenuData = ProcList->GetComplexUserDataPtr<menu_data>(); if (!MenuData) return; SwitchToWindow(MenuData->Hwnd); }