bool CConEmuUpdate::CanUpdateInstallation() { if (UpdateDownloadSetup() == 1) { // Если через Setupper - то msi сам разберется и ругнется когда надо return true; } // Раз дошли сюда - значит ConEmu был просто "распакован" if (IsUserAdmin()) { // ConEmu запущен "Под администратором", проверки не нужны return true; } wchar_t szTestFile[MAX_PATH*2]; wcscpy_c(szTestFile, gpConEmu->ms_ConEmuExeDir); wcscat_c(szTestFile, L"\\ConEmuUpdate.check"); HANDLE hFile = CreateFile(szTestFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_TEMPORARY, NULL); if (hFile == INVALID_HANDLE_VALUE) { DWORD nErr = GetLastError(); wcscpy_c(szTestFile, L"Can't update installation folder!\r\n"); wcscat_c(szTestFile, gpConEmu->ms_ConEmuExeDir); DisplayLastError(szTestFile, nErr); return false; } CloseHandle(hFile); DeleteFile(szTestFile); // OK return true; }
bool TermX::GetSubstitute(const MOUSE_EVENT_RECORD& m, wchar_t (&szSubst)[16]) { if (m.dwEventFlags & MOUSE_WHEELED) { // If the high word of the dwButtonState member contains // a positive value, the wheel was rotated forward, away from the user. // Otherwise, the wheel was rotated backward, toward the user. short dir = (short)HIWORD(m.dwButtonState); // Ctrl/Alt/Shift DWORD mods = (m.dwControlKeyState & (LEFT_ALT_PRESSED|LEFT_CTRL_PRESSED|RIGHT_ALT_PRESSED|RIGHT_CTRL_PRESSED|SHIFT_PRESSED)); if (mods == 0) { if (dir <= 0) wcscpy_c(szSubst, L"\033[62~"); // <MouseDown> else wcscpy_c(szSubst, L"\033[63~"); // <MouseUp> return true; } else if (mods == SHIFT_PRESSED) { if (dir <= 0) wcscpy_c(szSubst, L"\033[64~"); // <S-MouseDown> else wcscpy_c(szSubst, L"\033[65~"); // <S-MouseUp> return true; } } return false; }
void ConEmuAbout::OnInfo_WhatsNew(bool bLocal) { wchar_t sFile[MAX_PATH+80]; int iExec = -1; if (bLocal) { wcscpy_c(sFile, gpConEmu->ms_ConEmuBaseDir); wcscat_c(sFile, L"\\WhatsNew-ConEmu.txt"); if (FileExists(sFile)) { iExec = (int)ShellExecute(ghWnd, L"open", sFile, NULL, NULL, SW_SHOWNORMAL); if (iExec >= 32) { return; } } } wcscpy_c(sFile, gsWhatsNew); iExec = (int)ShellExecute(ghWnd, L"open", sFile, NULL, NULL, SW_SHOWNORMAL); if (iExec >= 32) { return; } DisplayLastError(L"File 'WhatsNew-ConEmu.txt' not found, go to web page failed", iExec); }
void CConEmuUpdate::WaitAllInstances() { while (true) { bool bStillExists = false; wchar_t szMessage[255]; wcscpy_c(szMessage, L"Please, close all ConEmu instances before continue"); HWND hFind = FindWindowEx(NULL, NULL, VirtualConsoleClassMain, NULL); if (hFind) { bStillExists = true; DWORD nPID; GetWindowThreadProcessId(hFind, &nPID); _wsprintf(szMessage+_tcslen(szMessage), SKIPLEN(64) L"\nConEmu still running, PID=%u", nPID); } if (!bStillExists) { TODO("Можно бы проехаться по всем модулям запущенных процессов на предмет блокировки файлов в папках ConEmu"); } // Если никого запущенного не нашли - выходим из цикла if (!bStillExists) return; // Ругнуться int nBtn = MessageBox(NULL, szMessage, ms_DefaultTitle, MB_ICONEXCLAMATION|MB_OKCANCEL); if (nBtn == IDCANCEL) return; // "Cancel" - means stop checking } }
LRESULT CALLBACK GuiClientRetHook(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HC_ACTION) { CWPRETSTRUCT* p = (CWPRETSTRUCT*)lParam; CREATESTRUCT* pc = NULL; wchar_t szDbg[200]; szDbg[0] = 0; wchar_t szClass[127]; szClass[0] = 0; switch (p->message) { case WM_DESTROY: { user->getClassNameW(p->hwnd, szClass, countof(szClass)); msprintf(szDbg, countof(szDbg), L"WM_DESTROY on 0x%08X (%s)\n", (DWORD)p->hwnd, szClass); break; } case WM_CREATE: { pc = (CREATESTRUCT*)p->lParam; if (p->lResult == -1) { wcscpy_c(szDbg, L"WM_CREATE --FAILED--\n"); } break; } case WM_SIZE: case WM_MOVE: case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGING: { WINDOWPOS *wp = (WINDOWPOS*)p->lParam; WORD x = LOWORD(p->lParam); WORD y = HIWORD(p->lParam); if (p->hwnd == ghAttachGuiClient || p->hwnd == hMonitorWndPos) { int nDbg = 0; if (p->message == WM_WINDOWPOSCHANGING || p->message == WM_WINDOWPOSCHANGED) { if ((wp->x > 0 || wp->y > 0) && !isPressed(VK_LBUTTON)) { if (user->getParent(p->hwnd) == ghConEmuWndBack) { //_ASSERTEX(!(wp->x > 0 || wp->y > 0)); break; } } } } break; } } if (*szDbg) { DebugString(szDbg); } } return user->callNextHookEx(ghGuiClientRetHook, nCode, wParam, lParam); }
LPCWSTR ModuleName(LPCWSTR asDefault) { if (asDefault && *asDefault) return asDefault; static wchar_t szFile[32]; if (szFile[0]) return szFile; wchar_t szPath[MAX_PATH*2]; if (GetModuleFileNameW(NULL, szPath, countof(szPath))) { wchar_t *pszSlash = wcsrchr(szPath, L'\\'); if (pszSlash) pszSlash++; else pszSlash = szPath; lstrcpynW(szFile, pszSlash, countof(szFile)); } if (szFile[0] == 0) { wcscpy_c(szFile, L"Unknown"); } return szFile; }
void CConEmuInside::SetInsideParentWND(HWND hParent) { mh_InsideParentWND = hParent; if (!hParent || (hParent == INSIDE_PARENT_NOT_FOUND)) { mh_InsideParentRel = NULL; } else { ZeroStruct(m_InsideParentInfo); // Store basic information about parent process (reporting purposes) DWORD nPID = 0; if (GetWindowThreadProcessId(hParent, &nPID)) { m_InsideParentInfo.ParentPID = nPID; PROCESSENTRY32W PInfo = {}; if (GetProcessInfo(nPID, &PInfo)) { m_InsideParentInfo.ParentParentPID = PInfo.th32ParentProcessID; wcscpy_c(m_InsideParentInfo.ExeName, PInfo.szExeFile); } } mh_InitialRoot = GetParentRoot(); } }
bool CConEmuStart::FindBashLocation(CEStr& lsBash) { wchar_t szRoot[MAX_PATH+32], *pszSlash; wcscpy_c(szRoot, gpConEmu->ms_ConEmuExeDir); LPCWSTR pszPlaces[] = { L"\\msys\\1.0\\bin\\bash.exe", // Msys/MinGW L"\\bin\\bash.exe", // Git-Bash L"\\usr\\bin\\bash.exe", // Git-For-Windows NULL }; // Before ConEmu.exe was intended to be in /bin/ folder // With Git-For-Windows it may be places in /opt/bin/ subfolder // So we do searching with two steps for (size_t i = 0; i <= 1; i++) { pszSlash = wcsrchr(szRoot, L'\\'); if (pszSlash) *pszSlash = 0; for (size_t j = 0; pszPlaces[j]; j++) { lsBash = JoinPath(szRoot, pszPlaces[j]); if (FileExists(lsBash)) { return true; } } } // Last chance, without path lsBash = L"bash.exe"; return false; }
void MEvent::OnDebugNotify(MEventNotification Action) { wchar_t szInfo[MAX_PATH]; wcscpy_c(szInfo, L"MEvent: "); switch (Action) { case evn_Create: wcscat_c(szInfo, L"Create"); break; case evn_Open: wcscat_c(szInfo, L"Open"); break; case evn_Set: wcscat_c(szInfo, L"Set"); break; case evn_Reset: wcscat_c(szInfo, L"Reset"); break; case evn_Close: wcscat_c(szInfo, L"Close"); break; default: wcscat_c(szInfo, L"???"); } wcscat_c(szInfo, L": "); if (mb_NameIsNull) _wsprintf(szInfo + _tcslen(szInfo), SKIPLEN(countof(szInfo) - _tcslen(szInfo)) L"Handle=0x%p", mh_Event); else wcscat_c(szInfo, ms_EventName); DEBUGSTREVT(szInfo); szInfo[0] = 0; }
void CConEmuUpdate::GetVersionsFromIni(LPCWSTR pszUpdateVerLocation, wchar_t (&szServer)[100], wchar_t (&szInfo)[100]) { wchar_t szTest[64]; // Дописать stable/preview/alpha bool bDetected = false, bNewer; wcscpy_c(szInfo, ms_CurVersion); struct { LPCWSTR szSect, szPref, szName; } Vers[] = { {sectionConEmuStable, L"Stable:\t", L" stable" }, {sectionConEmuPreview, L"\nPreview:\t", L" preview"}, {sectionConEmuDevel, L"\nDevel:\t", L" devel" } }; szServer[0] = 0; for (size_t i = 0; i < countof(Vers); i++) { wcscat_c(szServer, Vers[i].szPref); if (GetPrivateProfileString(Vers[i].szSect, L"version", L"", szTest, countof(szTest), pszUpdateVerLocation)) { bNewer = (lstrcmp(szTest, ms_CurVersion) >= 0); if (!bDetected && bNewer) { bDetected = true; wcscat_c(szInfo, Vers[i].szName); } szTest[10] = 0; wcscat_c(szServer, szTest); if (bNewer) wcscat_c(szServer, (lstrcmp(szTest, ms_CurVersion) > 0) ? L" (newer)" : L" (equal)"); } else wcscat_c(szServer, L"<Not found>"); } }
void CTabPanelBase::UpdateTabFontInt() { if (!IsTabbarCreated()) return; LOGFONT lf = {}; lf.lfWeight = FW_DONTCARE; lf.lfCharSet = gpSet->nTabFontCharSet; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; wcscpy_c(lf.lfFaceName, gpSet->sTabFontFace); gpFontMgr->EvalLogfontSizes(lf, gpSet->nTabFontHeight, 0); wchar_t szInfo[100]; _wsprintf(szInfo, SKIPCOUNT(szInfo) L"Creating tab font name='%s' height=%i", lf.lfFaceName, lf.lfHeight); LogString(szInfo); // CreateFont HFONT hFont = CreateFontIndirect(&lf); // virtual SetTabbarFont(hFont); // Store new Font in member variable if (mh_TabFont) DeleteObject(mh_TabFont); mh_TabFont = hFont; }
int PrepareHookModule(wchar_t (&szModule)[MAX_PATH+16]) { int iRc = -251; wchar_t szNewPath[MAX_PATH+16] = {}, szAddName[32] = {}, szVer[2] = {}; INT_PTR nLen = 0; // Copy szModule to CSIDL_LOCAL_APPDATA and return new path HRESULT hr = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, szNewPath); if ((hr != S_OK) || !*szNewPath) { iRc = -251; goto wrap; } szVer[0] = MVV_4a[0]; _wsprintf(szAddName, SKIPLEN(countof(szAddName)) L"\\ConEmuHk%s.%02u%02u%02u%s.dll", WIN3264TEST(L"",L"64"), MVV_1, MVV_2, MVV_3, szVer); nLen = lstrlen(szNewPath); if (szNewPath[nLen-1] != L'\\') { szNewPath[nLen++] = L'\\'; szNewPath[nLen] = 0; } if ((nLen + lstrlen(szAddName) + 8) >= countof(szNewPath)) { iRc = -252; goto wrap; } wcscat_c(szNewPath, L"ConEmu"); if (!DirectoryExists(szNewPath)) { if (!CreateDirectory(szNewPath, NULL)) { iRc = -253; goto wrap; } } wcscat_c(szNewPath, szAddName); if (FileExists(szNewPath) && FileCompare(szNewPath, szModule)) { // OK, file exists and match the required } else { if (!CopyFile(szModule, szNewPath, FALSE)) { iRc = -254; goto wrap; } } wcscpy_c(szModule, szNewPath); iRc = 0; wrap: return iRc; }
void ConEmuAbout::TabSelected(HWND hDlg, int idx) { if (idx < 0 || idx >= countof(Pages)) return; wcscpy_c(sLastOpenTab, Pages[idx].Title); SetDlgItemText(hDlg, tAboutText, Pages[idx].Text); }
/// Update GroupBox title, replacing text *between* pszFrom and pszTo with current HotKey /// For example, gbPasteM1 has title "Paste mode #1 (Shift+Ins)", pszFrom=L"(", pszTo=L")" /// Than `Shift+Ins` would be replaced with current user defined hotkey value void CSetPgBase::setCtrlTitleByHotkey(HWND hDlg, WORD nCtrlId, int iHotkeyId, LPCWSTR pszFrom, LPCWSTR pszTo) { if (!hDlg || !nCtrlId || (nCtrlId == (WORD)IDC_STATIC) || (iHotkeyId <= 0)) { _ASSERTE(FALSE && "Invalid identifiers"); return; } if (!pszFrom || !*pszFrom) { _ASSERTE(FALSE && "Invalid anchors"); return; } wchar_t szKeyFull[128] = L""; gpSet->GetHotkeyNameById(iHotkeyId, szKeyFull, true); if (szKeyFull[0] == 0) { _ASSERTE(FALSE && "Failed to acquire HotKey"); wcscpy_c(szKeyFull, L"???"); } CEStr lsLoc; if (!CLngRc::getControl(nCtrlId, lsLoc)) { if (GetString(hDlg, nCtrlId, &lsLoc.ms_Val) <= 0) { _ASSERTE(FALSE && "No title?"); return; } } LPCWSTR ptr1, ptr2; ptr1 = wcsstr(lsLoc, pszFrom); if (!ptr1) { _ASSERTE(ptr1 && "pszFrom not found"); return; } ptr1 += wcslen(pszFrom); if (pszTo && *pszTo) { ptr2 = wcsstr(ptr1, pszTo); } if (ptr2 == ptr1) { _ASSERTE(ptr2 != ptr1 && "Invalid source string"); return; } // Trim to hotkey beginning lsLoc.ms_Val[(ptr1 - lsLoc.ms_Val)] = 0; // And create new title CEStr lsNew(lsLoc.ms_Val, szKeyFull, ptr2); // Update control text SetDlgItemText(hDlg, nCtrlId, lsNew); }
LRESULT CSetPgTasks::OnInitDialog(HWND hDlg, bool abForceReload) { mb_IgnoreCmdGroupEdit = true; wchar_t szKey[128] = L""; const ConEmuHotKey* pDefCmdKey = NULL; if (!gpSet->GetHotkeyById(vkMultiCmd, &pDefCmdKey) || !pDefCmdKey) wcscpy_c(szKey, gsNoHotkey); else pDefCmdKey->GetHotkeyName(szKey, true); CEStr lsLabel(L"Default shell (", szKey, L")"); SetDlgItemText(hDlg, cbCmdGrpDefaultCmd, lsLabel); // Not implemented yet ShowWindow(GetDlgItem(hDlg, cbCmdGrpToolbar), SW_HIDE); if (abForceReload) { int nTab = 4*4; // represent the number of quarters of the average character width for the font SendDlgItemMessage(hDlg, lbCmdTasks, LB_SETTABSTOPS, 1, (LPARAM)&nTab); LONG_PTR nStyles = GetWindowLongPtr(GetDlgItem(hDlg, lbCmdTasks), GWL_STYLE); if (!(nStyles & LBS_NOTIFY)) SetWindowLongPtr(GetDlgItem(hDlg, lbCmdTasks), GWL_STYLE, nStyles|LBS_NOTIFY); } // Сброс ранее загруженного списка (ListBox: lbCmdTasks) SendDlgItemMessage(hDlg, lbCmdTasks, LB_RESETCONTENT, 0,0); //if (abForceReload) //{ // // Обновить группы команд // gpSet->LoadCmdTasks(NULL, true); //} int nGroup = 0; wchar_t szItem[1024]; const CommandTasks* pGrp = NULL; while ((pGrp = gpSet->CmdTaskGet(nGroup))) { swprintf_c(szItem, L"%i\t", nGroup+1); int nPrefix = lstrlen(szItem); lstrcpyn(szItem+nPrefix, pGrp->pszName, countof(szItem)-nPrefix); INT_PTR iIndex = SendDlgItemMessage(hDlg, lbCmdTasks, LB_ADDSTRING, 0, (LPARAM)szItem); UNREFERENCED_PARAMETER(iIndex); //SendDlgItemMessage(hDlg, lbCmdTasks, LB_SETITEMDATA, iIndex, (LPARAM)pGrp); nGroup++; } OnComboBox(hDlg, lbCmdTasks, LBN_SELCHANGE); mb_IgnoreCmdGroupEdit = false; return 0; }
void getWindowInfo(HWND ahWnd, wchar_t (&rsInfo)[1024], bool bProcessName /*= false*/, LPDWORD pnPID /*= NULL*/) { DWORD nPID = 0; if (!ahWnd) { wcscpy_c(rsInfo, L"<NULL>"); } else if (!IsWindow(ahWnd)) { msprintf(rsInfo, countof(rsInfo), L"0x%08X: Invalid window handle", LODWORD(ahWnd)); } else { wchar_t szClass[256], szTitle[512]; wchar_t szProc[120] = L""; if (!GetClassName(ahWnd, szClass, 256)) wcscpy_c(szClass, L"<GetClassName failed>"); if (!GetWindowText(ahWnd, szTitle, 512)) szTitle[0] = 0; if (bProcessName || pnPID) { if (GetWindowThreadProcessId(ahWnd, &nPID)) { PROCESSENTRY32 pi = {}; if (bProcessName && GetProcessInfo(nPID, &pi)) { pi.szExeFile[100] = 0; msprintf(szProc, countof(szProc), L" - %s [%u]", pi.szExeFile, nPID); } } } msprintf(rsInfo, countof(rsInfo), L"0x%08X: %s - '%s'%s", LODWORD(ahWnd), szClass, szTitle, szProc); } if (pnPID) *pnPID = nPID; }
CBackgroundInfo::CBackgroundInfo(LPCWSTR inPath) { wcscpy_c(ms_BgImage, inPath ? inPath : L""); ZeroStruct(ftBgModified); nBgModifiedTick = 0; //mb_IsFade = bFade; //mb_NeedBgUpdate = false; mb_IsBackgroundImageValid = false; mp_BgImgData = NULL; CBackgroundInfo* p = this; g_Backgrounds.push_back(p); }
void UnitExpandTest() { CmdArg szExe; wchar_t szChoc[MAX_PATH] = L"powershell -NoProfile -ExecutionPolicy unrestricted -Command \"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))\" && SET PATH=%PATH%;%systemdrive%\\chocolatey\\bin"; wchar_t* pszExpanded = ExpandEnvStr(szChoc); int nLen = pszExpanded ? lstrlen(pszExpanded) : 0; BOOL bFound = FileExistsSearch(szChoc, szExe, false); wcscpy_c(szChoc, gpConEmu->ms_ConEmuExeDir); wcscat_c(szChoc, L"\\Tests\\Executables\\abcd"); bFound = FileExistsSearch(szChoc, szExe, false); // TakeCommand ConEmuComspec tcc = {cst_AutoTccCmd}; FindComspec(&tcc, false); }
LPCWSTR apiQuerySessionID() { static wchar_t szSessionId[16] = L""; if (!*szSessionId) { DWORD nSessionId = 0; BOOL bSucceeded = apiQuerySessionID(GetCurrentProcessId(), nSessionId); if (bSucceeded) swprintf_c(szSessionId, L"%u", nSessionId); else wcscpy_c(szSessionId, L"?"); } return szSessionId; }
void ConEmuAbout::TabSelected(HWND hDlg, int idx) { if (idx < 0 || idx >= countof(Pages)) return; wcscpy_c(sLastOpenTab, Pages[idx].Title); LPCWSTR pszNewText = Pages[idx].Text; CEStr lsTemp; if (gpConEmu->mp_PushInfo && gpConEmu->mp_PushInfo->mp_Active && gpConEmu->mp_PushInfo->mp_Active->pszFullMessage) { // EDIT control requires \r\n as line endings lsTemp = lstrmerge(gpConEmu->mp_PushInfo->mp_Active->pszFullMessage, L"\r\n\r\n\r\n", pszNewText); pszNewText = lsTemp.ms_Arg; } SetDlgItemText(hDlg, tAboutText, pszNewText); }
// 1-установлено через Installer, пути совпали, 2-Installer не запускался BYTE ConEmuUpdateSettings::UpdateDownloadSetup() { if (isUpdateDownloadSetup) return isUpdateDownloadSetup; // если 0 - пока не проверялся if (isSetupDetected == 0) { HKEY hk; LONG lRc; //bool bUseSetupExe = false; wchar_t szInstallDir[MAX_PATH+2], szExeDir[MAX_PATH+2]; wcscpy_c(szExeDir, gpConEmu->ms_ConEmuExeDir); wcscat_c(szExeDir, L"\\"); for (size_t i = 0; i <= 2; i++) { DWORD dwSam = KEY_READ | ((i == 0) ? 0 : (i == 1) ? KEY_WOW64_32KEY : KEY_WOW64_64KEY); LPCWSTR pszName = ((i == 0) ? WIN3264TEST(L"InstallDir",L"InstallDir_x64") : (i == 1) ? L"InstallDir" : L"InstallDir_x64"); lRc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\ConEmu", 0, dwSam, &hk); if (lRc == 0) { _ASSERTE(countof(szInstallDir)>(MAX_PATH+1)); DWORD dwSize = MAX_PATH*sizeof(*szInstallDir); if (0 == RegQueryValueEx(hk, pszName, NULL, NULL, (LPBYTE)szInstallDir, &dwSize) && *szInstallDir) { size_t nLen = _tcslen(szInstallDir); if (szInstallDir[nLen-1] != L'\\') wcscat_c(szInstallDir, L"\\"); if (lstrcmpi(szInstallDir, szExeDir) == 0) { isSetupDetected = 1; } } RegCloseKey(hk); } } if (!isSetupDetected) isSetupDetected = 2; } // Если признаки установки через "ConEmuSetup.exe" не найдены, или пути не совпали - грузим через 7z _ASSERTE(isSetupDetected!=0); return isSetupDetected ? isSetupDetected : 2; }
void CSetPgDebug::debugLogCommand(LogCommandsData* apData) { if (!apData) return; /* struct LogCommandsData { BOOL bInput, bMainThread; DWORD nTick, nDur, nCmd, nSize, nPID; wchar_t szPipe[64]; }; */ wchar_t szText[128]; HWND hList = GetDlgItem(mh_Dlg, lbActivityLog); wcscpy_c(szText, apData->bInput ? L"In" : L"Out"); LVITEM lvi = {LVIF_TEXT|LVIF_STATE}; lvi.state = lvi.stateMask = LVIS_SELECTED|LVIS_FOCUSED; lvi.pszText = szText; int nItem = ListView_InsertItem(hList, &lvi); int nMin = apData->nTick / 60000; apData->nTick -= nMin*60000; int nSec = apData->nTick / 1000; int nMS = apData->nTick % 1000; _wsprintf(szText, SKIPLEN(countof(szText)) L"%02i:%02i:%03i", nMin, nSec, nMS); ListView_SetItemText(hList, nItem, lcc_Time, szText); _wsprintf(szText, SKIPLEN(countof(szText)) apData->bInput ? L"" : L"%u", apData->nDur); ListView_SetItemText(hList, nItem, lcc_Duration, szText); _wsprintf(szText, SKIPLEN(countof(szText)) L"%u", apData->nCmd); ListView_SetItemText(hList, nItem, lcc_Command, szText); _wsprintf(szText, SKIPLEN(countof(szText)) L"%u", apData->nSize); ListView_SetItemText(hList, nItem, lcc_Size, szText); _wsprintf(szText, SKIPLEN(countof(szText)) apData->nPID ? L"%u" : L"", apData->nPID); ListView_SetItemText(hList, nItem, lcc_PID, szText); ListView_SetItemText(hList, nItem, lcc_Pipe, apData->szPipe); free(apData); }
void CommandTasks::SetName(LPCWSTR asName, int anCmdIndex) { wchar_t szCmd[16]; if (anCmdIndex == -1) { wcscpy_c(szCmd, AutoStartTaskName); asName = szCmd; } else if (!asName || !*asName) { _wsprintf(szCmd, SKIPLEN(countof(szCmd)) L"Group%i", (anCmdIndex+1)); asName = szCmd; } // Для простоты дальнейшей работы - имя должно быть заключено в угловые скобки size_t iLen = wcslen(asName); if (!pszName || ((iLen+2) >= cchNameMax)) { SafeFree(pszName); cchNameMax = iLen+16; pszName = (wchar_t*)malloc(cchNameMax*sizeof(wchar_t)); if (!pszName) { _ASSERTE(pszName!=NULL); return; } } if (asName[0] == TaskBracketLeft) { _wcscpy_c(pszName, iLen+1, asName); } else { *pszName = TaskBracketLeft; _wcscpy_c(pszName+1, iLen+1, asName); } if (asName[iLen-1] != TaskBracketRight) { iLen = wcslen(pszName); pszName[iLen++] = TaskBracketRight; pszName[iLen] = 0; } }
void CConEmuStart::SetDefaultCmd(LPCWSTR asCmd) { // !!! gpConEmu may be NULL due starting time !!! if (gpConEmu && gpConEmu->isMingwMode() && gpConEmu->isMSysStartup()) { CEStr szSearch; FindBashLocation(szSearch); swprintf_c(szDefCmd, (wcschr(szSearch, L' ') != NULL) ? L"\"%s\" --login -i" /* -new_console:n" */ : L"%s --login -i" /* -new_console:n" */, (LPCWSTR)szSearch); } else { wcscpy_c(szDefCmd, asCmd ? asCmd : L"cmd"); } }
void RemoveOldComSpecC() { wchar_t szComSpec[MAX_PATH], szComSpecC[MAX_PATH], szRealComSpec[MAX_PATH]; //110202 - comspec более не переопределяется, поэтому вернем "cmd", // если был переопреден и унаследован от старой версии conemu if (GetEnvironmentVariable(L"ComSpecC", szComSpecC, countof(szComSpecC)) && szComSpecC[0] != 0) { szRealComSpec[0] = 0; if (!GetEnvironmentVariable(L"ComSpec", szComSpec, countof(szComSpec))) szComSpec[0] = 0; #ifndef __GNUC__ #pragma warning( push ) #pragma warning(disable : 6400) #endif LPCWSTR pwszName = PointToName(szComSpec); if (lstrcmpiW(pwszName, L"ConEmuC.exe")==0 || lstrcmpiW(pwszName, L"ConEmuC64.exe")==0) { pwszName = PointToName(szComSpecC); if (lstrcmpiW(pwszName, L"ConEmuC.exe")!=0 && lstrcmpiW(pwszName, L"ConEmuC64.exe")!=0) { wcscpy_c(szRealComSpec, szComSpecC); } } #ifndef __GNUC__ #pragma warning( pop ) #endif if (szRealComSpec[0] == 0) { //\system32\cmd.exe GetComspecFromEnvVar(szRealComSpec, countof(szRealComSpec)); } SetEnvironmentVariable(L"ComSpec", szRealComSpec); SetEnvironmentVariable(L"ComSpecC", NULL); } }
// Вернуть путь к папке, содержащей ConEmuC.exe BOOL IsConEmuExeExist(LPCWSTR szExePath, wchar_t (&rsConEmuExe)[MAX_PATH+1]) { BOOL lbExeFound = FALSE; BOOL isWin64 = WIN3264TEST(IsWindows64(),TRUE); //if (szExePath[lstrlen(szExePath)-1] != L'\\') // wcscat_c(szExePath, L"\\"); _ASSERTE(szExePath && *szExePath && (szExePath[lstrlen(szExePath)-1] == L'\\')); wcscpy_c(rsConEmuExe, szExePath); wchar_t* pszName = rsConEmuExe+lstrlen(rsConEmuExe); LPCWSTR szGuiExe[2] = {L"ConEmu64.exe", L"ConEmu.exe"}; for (size_t s = 0; !lbExeFound && (s < countof(szGuiExe)); s++) { if (!s && !isWin64) continue; wcscpy_add(pszName, rsConEmuExe, szGuiExe[s]); lbExeFound = FileExists(rsConEmuExe); } return lbExeFound; }
LRESULT CSetPgDebug::OnInitDialog(HWND hDlg, bool abInitial) { if (abInitial) { checkDlgButton(hDlg, rbActivityDisabled, BST_CHECKED); HWND hList = GetDlgItem(hDlg, lbActivityLog); ListView_SetExtendedListViewStyleEx(hList,LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT); ListView_SetExtendedListViewStyleEx(hList,LVS_EX_LABELTIP|LVS_EX_INFOTIP,LVS_EX_LABELTIP|LVS_EX_INFOTIP); LVCOLUMN col = { LVCF_WIDTH|LVCF_TEXT|LVCF_FMT, LVCFMT_LEFT, gpSetCls->EvalSize(60, esf_Horizontal|esf_CanUseDpi)}; wchar_t szTitle[4]; col.pszText = szTitle; wcscpy_c(szTitle, L" "); ListView_InsertColumn(hList, 0, &col); HWND hTip = ListView_GetToolTips(hList); SetWindowPos(hTip, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); } return 0; }
void CFindPanel::OnCreateFont() { if (!mh_Edit) return; HFONT hOldFont = mh_Font; RECT rcEdit = {}; GetClientRect(mh_Edit, &rcEdit); // CreateFont LOGFONT lf = {}; lf.lfWeight = FW_DONTCARE; lf.lfCharSet = gpSet->nTabFontCharSet; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; wcscpy_c(lf.lfFaceName, gpSet->sTabFontFace); lf.lfHeight = -klMax(6,(int)(rcEdit.bottom - gpSetCls->EvalSize(3, esf_Vertical|esf_CanUseDpi))); mh_Font = CreateFontIndirect(&lf); SendMessage(mh_Edit, WM_SETFONT, (WPARAM)mh_Font, FALSE); SafeDeleteObject(hOldFont); }
void CConEmuInside::SetInsideParentWND(HWND hParent) { mh_InsideParentWND = hParent; if (!hParent || (hParent == INSIDE_PARENT_NOT_FOUND)) { mh_InsideParentRoot = NULL; mh_InsideParentRel = NULL; } else { // Store basic information about parent process (reporting purposes) DWORD nPID; PROCESSENTRY32W PInfo = {}; if (GetWindowThreadProcessId(hParent, &nPID) && GetProcessInfo(nPID, &PInfo)) { m_InsideParentInfo.ParentPID = PInfo.th32ProcessID; m_InsideParentInfo.ParentParentPID = PInfo.th32ParentProcessID; wcscpy_c(m_InsideParentInfo.ExeName, PInfo.szExeFile); } else { ZeroStruct(m_InsideParentInfo); } // Detect top parent window, to call isMeForeground HWND hRootParent = hParent; while ((GetWindowLong(hRootParent, GWL_STYLE) & WS_CHILD) != 0) { HWND hNext = GetParent(hRootParent); if (!hNext) break; hRootParent = hNext; } mh_InsideParentRoot = hRootParent; } }
int CTabBarClass::PrepareTab(CTab& pTab, CVirtualConsole *apVCon) { int iTabIcon = -1; #ifdef _DEBUG if (this != gpConEmu->mp_TabBar) { _ASSERTE(this == gpConEmu->mp_TabBar); } #endif MCHKHEAP // get file name TCHAR dummy[MAX_PATH*2]; TCHAR fileName[MAX_PATH+4]; fileName[0] = 0; TCHAR szFormat[32]; TCHAR szEllip[MAX_PATH+1]; //wchar_t /**tFileName=NULL,*/ *pszNo=NULL, *pszTitle=NULL; int nSplit = 0; int nMaxLen = 0; //gpSet->nTabLenMax - _tcslen(szFormat) + 2/* %s */; int origLength = 0; //_tcslen(tFileName); CRealConsole* pRCon = apVCon ? apVCon->RCon() : NULL; bool bIsFar = pRCon ? pRCon->isFar() : false; // Far 4040 - new "Desktop" window type has "0" index if (apVCon && (pTab->Info.nFarWindowID == 0 || pTab->Type() == fwt_Panels)) { iTabIcon = apVCon->RCon()->GetRootProcessIcon(); } LPCWSTR pszTabName = pRCon->GetTabTitle(pTab); if (pTab->Name.Empty() || (pTab->Type() == fwt_Panels)) { //_tcscpy(szFormat, _T("%s")); lstrcpyn(szFormat, bIsFar ? gpSet->szTabPanels : gpSet->szTabConsole, countof(szFormat)); nMaxLen = gpSet->nTabLenMax - _tcslen(szFormat) + 2/* %s */; lstrcpyn(fileName, pszTabName, countof(fileName)); if (gpSet->pszTabSkipWords && *gpSet->pszTabSkipWords) { StripWords(fileName, gpSet->pszTabSkipWords); } origLength = _tcslen(fileName); //if (origLength>6) { // // Чтобы в заголовке было что-то вроде "{C:\Program Fil...- Far" // // вместо "{C:\Program F...} - Far" // После добавления суффиков к заголовку фара - оно уже влезать не будет в любом случае... Так что если панели - '...' строго ставить в конце // if (lstrcmp(tFileName + origLength - 6, L" - Far") == 0) // nSplit = nMaxLen - 6; //} } else { LPTSTR tFileName = NULL; if (GetFullPathName(pszTabName, countof(dummy), dummy, &tFileName) && tFileName && *tFileName) lstrcpyn(fileName, tFileName, countof(fileName)); else lstrcpyn(fileName, pszTabName, countof(fileName)); if (pTab->Type() == fwt_Editor) { if (pTab->Flags() & fwt_ModifiedFarWnd) lstrcpyn(szFormat, gpSet->szTabEditorModified, countof(szFormat)); else lstrcpyn(szFormat, gpSet->szTabEditor, countof(szFormat)); } else if (pTab->Type() == fwt_Viewer) { lstrcpyn(szFormat, gpSet->szTabViewer, countof(szFormat)); } else { _ASSERTE(FALSE && "Must be processed in previous branch"); lstrcpyn(szFormat, bIsFar ? gpSet->szTabPanels : gpSet->szTabConsole, countof(szFormat)); } } // restrict length if (!nMaxLen) nMaxLen = gpSet->nTabLenMax - _tcslen(szFormat) + 2/* %s */; if (!origLength) origLength = _tcslen(fileName); if (nMaxLen<15) nMaxLen=15; else if (nMaxLen>=MAX_PATH) nMaxLen=MAX_PATH-1; if (origLength > nMaxLen) { /*_tcsnset(fileName, _T('\0'), MAX_PATH); _tcsncat(fileName, tFileName, 10); _tcsncat(fileName, _T("..."), 3); _tcsncat(fileName, tFileName + origLength - 10, 10);*/ //if (!nSplit) // nSplit = nMaxLen*2/3; //// 2009-09-20 Если в заголовке нет расширения (отсутствует точка) //const wchar_t* pszAdmin = gpSet->szAdminTitleSuffix; //const wchar_t* pszFrom = tFileName + origLength - (nMaxLen - nSplit); //if (!wcschr(pszFrom, L'.') && (*pszAdmin && !wcsstr(tFileName, pszAdmin))) //{ // // то троеточие ставить в конец, а не середину // nSplit = nMaxLen; //} // "{C:\Program Files} - Far 2.1283 Administrator x64" // После добавления суффиков к заголовку фара - оно уже влезать не будет в любом случае... Так что если панели - '...' строго ставить в конце nSplit = nMaxLen; _tcsncpy(szEllip, fileName, nSplit); szEllip[nSplit]=0; szEllip[nSplit] = L'\x2026' /*"…"*/; szEllip[nSplit+1] = 0; //_tcscat(szEllip, L"\x2026" /*"…"*/); //_tcscat(szEllip, tFileName + origLength - (nMaxLen - nSplit)); //tFileName = szEllip; lstrcpyn(fileName, szEllip, countof(fileName)); } // szFormat различается для Panel/Viewer(*)/Editor(*) // Пример: "%i-[%s] *" ////pszNo = wcsstr(szFormat, L"%i"); ////pszTitle = wcsstr(szFormat, L"%s"); ////if (pszNo == NULL) //// _wsprintf(fileName, SKIPLEN(countof(fileName)) szFormat, tFileName); ////else if (pszNo < pszTitle || pszTitle == NULL) //// _wsprintf(fileName, SKIPLEN(countof(fileName)) szFormat, pTab->Pos, tFileName); ////else //// _wsprintf(fileName, SKIPLEN(countof(fileName)) szFormat, tFileName, pTab->Pos); //wcscpy(pTab->Name, fileName); const TCHAR* pszFmt = szFormat; TCHAR* pszDst = dummy; TCHAR* pszStart = pszDst; TCHAR* pszEnd = dummy + countof(dummy) - 1; // в конце еще нужно зарезервировать место для '\0' if (!pszFmt || !*pszFmt) { pszFmt = _T("%s"); } *pszDst = 0; bool bRenamedTab = false; if (pTab->Flags() & fwt_Renamed) { if (wcsstr(pszFmt, L"%s") == NULL) { if (wcsstr(pszFmt, L"%n") != NULL) bRenamedTab = true; else pszFmt = _T("%s"); } } TCHAR szTmp[64]; CmdArg szArg; bool bAppendAdmin = gpSet->isAdminSuffix() && (pTab->Flags() & fwt_Elevated); while (*pszFmt && pszDst < pszEnd) { if (*pszFmt == _T('%')) { pszFmt++; LPCTSTR pszText = NULL; switch (*pszFmt) { case _T('s'): case _T('S'): pszText = fileName; break; case _T('i'): case _T('I'): _wsprintf(szTmp, SKIPLEN(countof(szTmp)) _T("%i"), pTab->Info.nIndex); pszText = szTmp; break; case _T('p'): case _T('P'): if (!apVCon || !apVCon->RCon()) { wcscpy_c(szTmp, _T("?")); } else { _wsprintf(szTmp, SKIPLEN(countof(szTmp)) _T("%u"), apVCon->RCon()->GetActivePID()); } pszText = szTmp; break; case _T('c'): case _T('C'): { int iCon = gpConEmu->isVConValid(apVCon); if (iCon > 0) _wsprintf(szTmp, SKIPLEN(countof(szTmp)) _T("%u"), iCon); else wcscpy_c(szTmp, _T("?")); pszText = szTmp; } break; case _T('n'): case _T('N'): { pszText = bRenamedTab ? fileName : pRCon ? pRCon->GetActiveProcessName() : NULL; wcscpy_c(szTmp, (pszText && *pszText) ? pszText : L"?"); pszText = szTmp; } break; case _T('d'): case _T('D'): { pszText = pRCon ? pRCon->GetConsoleCurDir(szArg) : NULL; if (!pszText || !*pszText) pszText = L"?"; } break; case _T('a'): case _T('A'): pszText = bAppendAdmin ? gpSet->szAdminTitleSuffix : NULL; bAppendAdmin = false; break; case _T('%'): pszText = L"%"; break; case 0: pszFmt--; break; } pszFmt++; if (pszText) { if ((*(pszDst-1) == L' ') && (*pszText == L' ')) pszText = SkipNonPrintable(pszText); while (*pszText && pszDst < pszEnd) { *(pszDst++) = *(pszText++); } } } else if ((pszDst > pszStart) && (*(pszDst-1) == L' ') && (*pszFmt == L' ')) { pszFmt++; // Avoid adding sequential spaces (e.g. if some macros was empty) } else { *(pszDst++) = *(pszFmt++); } } // Fin. Append smth else? if (bAppendAdmin) { LPCTSTR pszText = gpSet->szAdminTitleSuffix; if (pszText) { while (*pszText && pszDst < pszEnd) { *(pszDst++) = *(pszText++); } } } *pszDst = 0; #ifdef _DEBUG if (dummy[0] && *(pszDst-1) == L' ') *pszDst = 0; #endif pTab->SetLabel(dummy); MCHKHEAP; return iTabIcon; }