// this routine reads device notifications from a message queue and updates // the PM's internal tables appropriately. BOOL ProcessPnPMsgQueue(HANDLE hMsgQ) { BOOL fOk = FALSE; UCHAR deviceBuf[PNP_QUEUE_SIZE]; DWORD iBytesInQueue = 0; DWORD dwFlags = 0; SETFNAME(_T("ProcessPnPMsgQueue")); // read a message from the message queue -- it should be a device advertisement memset(deviceBuf, 0, PNP_QUEUE_SIZE); if ( !ReadMsgQueue(hMsgQ, deviceBuf, PNP_QUEUE_SIZE, &iBytesInQueue, 0, &dwFlags)) { // nothing in the queue PMLOGMSG(ZONE_WARN, (_T("%s: ReadMsgQueue() failed %d\r\n"), pszFname, GetLastError())); } else if(iBytesInQueue >= sizeof(DEVDETAIL)) { // process the message PDEVDETAIL pDevDetail = (PDEVDETAIL) deviceBuf; DWORD dwMessageSize = sizeof(DEVDETAIL) + pDevDetail->cbName; // check for overlarge names if(pDevDetail->cbName > ((PNP_MAX_NAMELEN - 1) * sizeof(pDevDetail->szName[0]))) { PMLOGMSG(ZONE_WARN, (_T("%s: device name longer than %d characters\r\n"), pszFname, PNP_MAX_NAMELEN - 1)); } else { // convert the device name to lower case int i; for(i = 0; i < (PNP_MAX_NAMELEN - 1) && pDevDetail->szName[i] != 0; i++) { pDevDetail->szName[i] = _totlower(pDevDetail->szName[i]); } pDevDetail->szName[i] = 0; // add or remove the device -- note that a particular interface may be // advertised more than once, so these routines must handle that possibility. if(pDevDetail->fAttached) { AddDevice(&pDevDetail->guidDevClass, pDevDetail->szName, NULL, NULL); } else { RemoveDevice(&pDevDetail->guidDevClass, pDevDetail->szName); } fOk = TRUE; } } else { // not enough bytes for a message PMLOGMSG(ZONE_WARN, (_T("%s: got runt message (%d bytes)\r\n"), pszFname, iBytesInQueue)); } return fOk; }
bool CDeskBand::CheckDisplayName(IShellFolder * shellFolder, LPITEMIDLIST pidl, LPCTSTR filter, bool bUseRegex) { STRRET str; if (SUCCEEDED(shellFolder->GetDisplayNameOf(pidl, // SHGDN_FORPARSING needed to get the extensions even if they're not shown SHGDN_INFOLDER|SHGDN_FORPARSING, &str))) { TCHAR dispname[MAX_PATH]; StrRetToBuf(&str, pidl, dispname, _countof(dispname)); if (bUseRegex) { try { const std::tr1::wregex regCheck(&filter[1], std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript); std::wstring s = dispname; return std::tr1::regex_search(s, regCheck); } catch (std::exception) { } } else { // we now have the display name of the item // i.e. the way the item is shown // since the windows file system is case-insensitive // we have to force the display name to lowercase // so the filter matches case-insensitive too TCHAR * pString = dispname; while (*pString) { *pString = _totlower(*pString); pString++; } // check if the item name matches the text of the edit control return (_tcsstr(dispname, filter) != NULL); } } return false; }
/*! アクセスキー付きの文字列の作成 @param sName ラベル @param sKey アクセスキー @return アクセスキー付きの文字列 @data 2013.12.09 novice アクセスキーと文字列の比較で小文字も有効にする @date 2014.05.04 sLabelのバッファ長を300 => _MAX_PATH*2 + 30 */ TCHAR* CKeyBind::MakeMenuLabel(const TCHAR* sName, const TCHAR* sKey) { const int MAX_LABEL_CCH = _MAX_PATH*2 + 30; static TCHAR sLabel[MAX_LABEL_CCH]; const TCHAR* p; if (sKey == NULL || sKey[0] == L'\0') { return const_cast<TCHAR*>( sName ); } else { if( !GetDllShareData().m_Common.m_sMainMenu.m_bMainMenuKeyParentheses && (((p = auto_strchr( sName, sKey[0])) != NULL) || ((p = auto_strchr( sName, _totlower(sKey[0]))) != NULL)) ){ // 欧文風、使用している文字をアクセスキーに auto_strcpy_s( sLabel, _countof(sLabel), sName ); sLabel[p-sName] = _T('&'); auto_strcpy_s( sLabel + (p-sName) + 1, _countof(sLabel), p ); } else if( (p = auto_strchr( sName, _T('(') )) != NULL && (p = auto_strchr( p, sKey[0] )) != NULL) { // (付その後にアクセスキー auto_strcpy_s( sLabel, _countof(sLabel), sName ); sLabel[p-sName] = _T('&'); auto_strcpy_s( sLabel + (p-sName) + 1, _countof(sLabel), p ); } else if (_tcscmp( sName + _tcslen(sName) - 3, _T("...") ) == 0) { // 末尾... auto_strcpy_s( sLabel, _countof(sLabel), sName ); sLabel[_tcslen(sName) - 3] = '\0'; // 末尾の...を取る auto_strcat_s( sLabel, _countof(sLabel), _T("(&") ); auto_strcat_s( sLabel, _countof(sLabel), sKey ); auto_strcat_s( sLabel, _countof(sLabel), _T(")...") ); } else { auto_sprintf_s( sLabel, _countof(sLabel), _T("%ts(&%ts)"), sName, sKey ); } return sLabel; } }
//int _tmain( int argc, TCHAR* argv[] ) int main( void ) { STARTUPINFO si; PROCESS_INFORMATION pi; TCHAR* cmd; BOOL option; BOOL opt_m; BOOL installed; HMODULE ansi; int rc = 0; int argc; LPWSTR* argv = CommandLineToArgvW( GetCommandLineW(), &argc ); if (argc > 1) { if (lstrcmp( argv[1], TEXT("--help") ) == 0 || (argv[1][0] == '-' && (argv[1][1] == '?' || argv[1][1] == 'h')) || (argv[1][0] == '/' && argv[1][1] == '?')) { help(); return rc; } if (lstrcmp( argv[1], TEXT("--version") ) == 0) { _putts( TEXT("ANSICON (" BITS "-bit) version " PVERS " (" PDATE ").") ); return rc; } } option = (argc > 1 && argv[1][0] == '-'); if (option && (_totlower( argv[1][1] ) == 'i' || _totlower( argv[1][1] ) == 'u')) { process_autorun( argv[1][1] ); return rc; } get_original_attr(); opt_m = FALSE; if (option && argv[1][1] == 'm') { WORD attr = 7; if (_istxdigit( argv[1][2] )) { attr = _istdigit( argv[1][2] ) ? argv[1][2] - '0' : (argv[1][2] | 0x20) - 'a' + 10; if (_istxdigit( argv[1][3])) { attr <<= 4; attr |= _istdigit( argv[1][3] ) ? argv[1][3] - '0' : (argv[1][3] | 0x20) - 'a' + 10; } } SetConsoleTextAttribute( hConOut, attr ); opt_m = TRUE; ++argv; --argc; option = (argc > 1 && argv[1][0] == '-'); } installed = (GetEnvironmentVariable( TEXT("ANSICON"), NULL, 0 ) != 0); if (option && argv[1][1] == 'p') { // If it's already installed, there's no need to do anything. if (installed) ; else if (GetParentProcessInfo( &pi )) { pi.hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pi.dwProcessId ); pi.hThread = OpenThread( THREAD_ALL_ACCESS, FALSE, pi.dwThreadId ); SuspendThread( pi.hThread ); Inject( &pi ); ResumeThread( pi.hThread ); CloseHandle( pi.hThread ); CloseHandle( pi.hProcess ); } else { _putts( TEXT("ANSICON: could not obtain the parent process.") ); rc = 1; } } else { ansi = 0; if (!installed) ansi = LoadLibrary( TEXT("ANSI" BITS ".dll") ); if (option && (argv[1][1] == 't' || argv[1][1] == 'T')) { BOOL title = (argv[1][1] == 'T'); if (argc == 2) { argv[2] = L"-"; ++argc; } for (; argc > 2; ++argv, --argc) { if (title) _tprintf( TEXT("==> %s <==\n"), argv[2] ); display( argv[2], title ); if (title) _puttchar( '\n' ); } } else { // Retrieve the original command line, skipping our name and the option. cmd = skip_spaces( skip_arg( skip_spaces( GetCommandLine() ) ) ); if (opt_m) cmd = skip_spaces( skip_arg( cmd ) ); if (cmd[0] == '-' && (cmd[1] == 'e' || cmd[1] == 'E')) { _fputts( cmd + 3, stdout ); if (cmd[1] == 'e') _puttchar( '\n' ); } else if (!isatty( 0 ) && *cmd == '\0') { display( TEXT("-"), FALSE ); } else { if (*cmd == '\0') { cmd = _tgetenv( TEXT("ComSpec") ); if (cmd == NULL) cmd = TEXT("cmd"); } ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); if (CreateProcess( NULL, cmd, NULL,NULL, TRUE, 0, NULL,NULL, &si, &pi )) { SetConsoleCtrlHandler( (PHANDLER_ROUTINE)CtrlHandler, TRUE ); WaitForSingleObject( pi.hProcess, INFINITE ); } else { *skip_arg( cmd ) = '\0'; _tprintf( TEXT("ANSICON: '%s' could not be executed.\n"), cmd ); rc = 1; } } } if (ansi) FreeLibrary( ansi ); } set_original_attr(); return rc; }
// Add or remove ANSICON to AutoRun. void process_autorun( TCHAR cmd ) { HKEY cmdkey; TCHAR ansicon[MAX_PATH+8]; LPTSTR autorun, ansirun; DWORD len, type, exist; BOOL inst; len = GetModuleFileName( NULL, ansicon+2, MAX_PATH ); ansicon[0] = '&'; ansicon[1] = ansicon[2+len] = '"'; _tcscpy( ansicon + 3+len, L" -p" ); len += 6; inst = (_totlower( cmd ) == 'i'); RegCreateKeyEx( (_istlower( cmd )) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, CMDKEY, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &cmdkey, &exist ); exist = 0; RegQueryValueEx( cmdkey, AUTORUN, NULL, NULL, NULL, &exist ); autorun = malloc( exist + len * sizeof(TCHAR) + sizeof(TCHAR) ); // Let's assume there's sufficient memory. if (exist > sizeof(TCHAR)) { exist += sizeof(TCHAR); RegQueryValueEx( cmdkey, AUTORUN, NULL, &type, (PBYTE)autorun, &exist ); ansirun = _tcsstr( autorun, ansicon+1 ); if (inst) { if (!ansirun) { _tcscpy( (LPTSTR)((PBYTE)autorun + exist - sizeof(TCHAR)), ansicon ); RegSetValueEx( cmdkey, AUTORUN, 0, type, (PBYTE)autorun, exist + len*sizeof(TCHAR) ); } } else { if (ansirun) { if (ansirun == autorun && exist == len*sizeof(TCHAR)) RegDeleteValue( cmdkey, AUTORUN ); else { if (ansirun > autorun && ansirun[-1] == '&') --ansirun; else if (autorun[len-1] != '&') --len; memcpy( ansirun, ansirun + len, exist - len*sizeof(TCHAR) ); RegSetValueEx( cmdkey, AUTORUN, 0, type, (PBYTE)autorun, exist - len*sizeof(TCHAR) ); } } } } else if (inst) { RegSetValueEx( cmdkey, AUTORUN, 0, REG_SZ, (PBYTE)(ansicon+1), len*sizeof(TCHAR) ); } free( autorun ); RegCloseKey( cmdkey ); }
template<class T> void ToLower(T &s) { for (typename T::iterator iter = s.begin(); iter != s.end(); iter++) *iter = TCHAR(_totlower(*iter)); }
TCHAR LowerCaseTokenizer::normalize(const TCHAR chr) const { return _totlower(chr); }
/** * name: Button_WndProc * desc: window procedure for the button class * param: hwndBtn - window handle to the button * uMsg - message to handle * wParam - message specific parameter * lParam - message specific parameter * return: message specific **/ static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) { LPBTNCTRL bct = (LPBTNCTRL)GetWindowLongPtr(hwndBtn, 0); switch (uMsg) { case WM_NCCREATE: { LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam; cs->style |= BS_OWNERDRAW; if (!(bct = (LPBTNCTRL)mir_alloc(sizeof(BTNCTRL)))) return FALSE; memset(bct, 0, sizeof(BTNCTRL)); bct->hwnd = hwndBtn; bct->stateId = PBS_NORMAL; bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); bct->dwStyle = cs->style; if (cs->style & MBS_DOWNARROW) bct->arrow = GetIconBtn(ICO_BTN_DOWNARROW); LoadTheme(bct); SetWindowLongPtr(hwndBtn, 0, (LONG_PTR)bct); if (cs->lpszName) SetWindowText(hwndBtn, cs->lpszName); } return TRUE; case WM_DESTROY: if (bct) { mir_cslock lck(csTips); if (hwndToolTips) { TOOLINFO ti; memset(&ti, 0, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR)bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti); } if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) { DestroyWindow(hwndToolTips); hwndToolTips = NULL; } } DestroyTheme(bct); mir_free(bct); } SetWindowLongPtr(hwndBtn, 0, 0); break; case WM_SETTEXT: bct->cHot = 0; if ((LPTSTR)lParam) { LPTSTR tmp = (LPTSTR)lParam; while (*tmp) { if (*tmp == '&' && *(tmp + 1)) { bct->cHot = _totlower(*(tmp + 1)); break; } tmp++; } InvalidateRect(bct->hwnd, NULL, TRUE); } break; case WM_SYSKEYUP: if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == _totlower((TCHAR)wParam)) { if (bct->dwStyle & MBS_PUSHBUTTON) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; InvalidateRect(bct->hwnd, NULL, TRUE); } else SetFocus(hwndBtn); SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn); return 0; } break; case WM_THEMECHANGED: // themed changed, reload theme object LoadTheme(bct); InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it break; case WM_SETFONT: // remember the font so we can use it later bct->hFont = (HFONT)wParam; // maybe we should redraw? break; case WM_NCPAINT: case WM_PAINT: { PAINTSTRUCT ps; HDC hdcPaint; HDC hdcMem; HBITMAP hbmMem; HDC hOld; RECT rcClient; if (hdcPaint = BeginPaint(hwndBtn, &ps)) { GetClientRect(bct->hwnd, &rcClient); hdcMem = CreateCompatibleDC(hdcPaint); hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top); hOld = (HDC)SelectObject(hdcMem, hbmMem); // If its a push button, check to see if it should stay pressed if ((bct->dwStyle & MBS_PUSHBUTTON) && bct->pbState) bct->stateId = PBS_PRESSED; if ((bct->dwStyle & MBS_FLAT) && bct->hThemeToolbar || bct->hThemeButton) PaintThemeButton(bct, hdcMem, &rcClient); else PaintButton(bct, hdcMem, &rcClient); BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hOld); DeleteObject(hbmMem); DeleteDC(hdcMem); EndPaint(hwndBtn, &ps); } } return 0; case BM_SETIMAGE: if (wParam == IMAGE_ICON) { bct->hIcon = (HICON)lParam; bct->hBitmap = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (wParam == IMAGE_BITMAP) { bct->hIcon = NULL; bct->hBitmap = (HBITMAP)lParam; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (wParam == NULL && lParam == NULL) { bct->hIcon = NULL; bct->hBitmap = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case BM_SETCHECK: if (!(bct->dwStyle & MBS_PUSHBUTTON)) break; if (wParam == BST_CHECKED) { bct->pbState = 1; bct->stateId = PBS_PRESSED; } else if (wParam == BST_UNCHECKED) { bct->pbState = 0; bct->stateId = PBS_NORMAL; } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_GETCHECK: if (bct->dwStyle & MBS_PUSHBUTTON) return bct->pbState ? BST_CHECKED : BST_UNCHECKED; return 0; case BUTTONSETDEFAULT: bct->defbutton = (wParam != 0); InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONADDTOOLTIP: if (wParam) { mir_cslock lck(csTips); if (!hwndToolTips) hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); if (lParam == MBBF_UNICODE) { TOOLINFOW ti; memset(&ti, 0, sizeof(TOOLINFOW)); ti.cbSize = sizeof(TOOLINFOW); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR)bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFOW, 0, (LPARAM)&ti)) { SendMessage(hwndToolTips, TTM_DELTOOLW, 0, (LPARAM)&ti); } ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT_PTR)bct->hwnd; ti.lpszText = (LPWSTR)wParam; SendMessage(hwndToolTips, TTM_ADDTOOLW, 0, (LPARAM)&ti); } else { TOOLINFOA ti; memset(&ti, 0, sizeof(TOOLINFOA)); ti.cbSize = sizeof(TOOLINFOA); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR)bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFOA, 0, (LPARAM)&ti)) { SendMessage(hwndToolTips, TTM_DELTOOLA, 0, (LPARAM)&ti); } ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT_PTR)bct->hwnd; ti.lpszText = (LPSTR)wParam; SendMessage(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM)&ti); } } break; case BUTTONTRANSLATE: TCHAR szButton[MAX_PATH]; GetWindowText(bct->hwnd, szButton, _countof(szButton)); SetWindowText(bct->hwnd, TranslateTS(szButton)); break; case WM_SETFOCUS: // set keybord bFocus and redraw bct->bFocus = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_KILLFOCUS: // kill bFocus and redraw bct->bFocus = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_WINDOWPOSCHANGED: InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_ENABLE: // windows tells us to enable/disable bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_MOUSELEAVE: // faked by the WM_TIMER if (bct->stateId != PBS_DISABLED) { // don't change states if disabled bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case WM_LBUTTONDOWN: if (bct->stateId != PBS_DISABLED) { // don't change states if disabled bct->stateId = PBS_PRESSED; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case WM_LBUTTONUP: if (bct->stateId != PBS_DISABLED) { // don't change states if disabled BYTE bPressed = bct->stateId == PBS_PRESSED; if (bct->dwStyle & MBS_PUSHBUTTON) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; } bct->stateId = PBS_HOT; // Tell your daddy you got clicked, if mouse is still over the button. if ((bct->dwStyle & MBS_PUSHBUTTON) || bPressed) SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn); InvalidateRect(bct->hwnd, NULL, TRUE); } break; case WM_MOUSEMOVE: if (bct->stateId == PBS_NORMAL) { bct->stateId = PBS_HOT; InvalidateRect(bct->hwnd, NULL, TRUE); } // Call timer, used to start cheesy TrackMouseEvent faker SetTimer(hwndBtn, BUTTON_POLLID, BUTTON_POLLDELAY, NULL); break; case WM_TIMER: // use a timer to check if they have did a mouseout if (wParam == BUTTON_POLLID) { RECT rc; POINT pt; GetWindowRect(hwndBtn, &rc); GetCursorPos(&pt); if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave PostMessage(hwndBtn, WM_MOUSELEAVE, 0, 0L); KillTimer(hwndBtn, BUTTON_POLLID); } } break; case WM_ERASEBKGND: return 1; } return DefWindowProc(hwndBtn, uMsg, wParam, lParam); }
void CBCGMaskEdit::OnCharPrintchar(UINT nChar, UINT nRepCnt, UINT nFlags) { ASSERT(m_strMask.IsEmpty() == m_strInputTemplate.IsEmpty()); ASSERT(m_strMask.GetLength() == m_strInputTemplate.GetLength()); ASSERT(_istprint((BCG_TCHAR) nChar) != FALSE); // ----------------------------------------------- // Processing ES_UPPERCASE and ES_LOWERCASE styles // ----------------------------------------------- DWORD dwStyle = GetStyle (); if (dwStyle & ES_UPPERCASE) { nChar = _totupper((BCG_TCHAR) nChar); } else if (dwStyle & ES_LOWERCASE) { nChar = _totlower((BCG_TCHAR) nChar); } int nStartPos, nEndPos; CEdit::GetSel(nStartPos, nEndPos); ASSERT(nStartPos>=0); ASSERT(nEndPos>=0); ASSERT(nEndPos>=nStartPos); // ----------------- // Calc group bounds // ----------------- int nGroupStart, nGroupEnd; GetGroupBounds(nGroupStart, nGroupEnd, nStartPos); // ------------ // Out of range // ------------ if ((nStartPos<0) && (nEndPos > m_str.GetLength()) || (nStartPos < nGroupStart) || (nStartPos > nGroupEnd) || (nEndPos < nGroupStart) || (nEndPos > nGroupEnd)) { MessageBeep((UINT)-1); CEdit::SetSel(nGroupStart, nGroupEnd); return; } TCHAR chChar = (TCHAR) nChar; // ----------------- // No selected chars // ----------------- if (nStartPos == nEndPos) { // Use m_strMask if (!m_strMask.IsEmpty()) { // ---------------------------------------------- // Automaticaly move the cursor to the next group // ---------------------------------------------- if (nEndPos==nGroupEnd || // at the end of group nStartPos < nGroupStart || nStartPos > nGroupEnd) // not in the middle of a group { // no space for new char if (nEndPos >= m_str.GetLength()-1) { MessageBeep((UINT)-1); return; } // can search next group else if (nEndPos < m_str.GetLength()-1) { GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE); } // if next group was found if ((nGroupStart != -1) && (nGroupStart > nEndPos)) { CEdit::SetSel(nGroupStart, nGroupStart); nStartPos = nGroupStart; nEndPos = nGroupStart; } // no more groups else { MessageBeep((UINT)-1); return; } } // ---------------------- // Check char in position // ---------------------- if (!CheckChar(chChar, nStartPos)) { MessageBeep((UINT)-1); return; } // --------------------------------- // Replace char in Editbox and m_str // --------------------------------- CEdit::SetSel(nStartPos, nEndPos+1); CEdit::ReplaceSel(CString(chChar), TRUE); m_str.SetAt(nEndPos, chChar); CEdit::SetSel(nEndPos+1, nEndPos+1); // ---------------------------------------------- // Automaticaly move the cursor to the next group // ---------------------------------------------- CEdit::GetSel(nStartPos, nEndPos); if (nEndPos==nGroupEnd) // at the end of group { // can search next group if (nEndPos < m_str.GetLength()-1) { GetGroupBounds(nGroupStart, nGroupEnd, nEndPos+1, TRUE); } // if next group was found if ((nGroupStart != -1) && (nGroupStart > nEndPos)) { CEdit::SetSel(nGroupStart, nGroupStart); nStartPos = nGroupStart; nEndPos = nGroupStart; } } } // Don't use m_strMask else { // ---------------------- // Check char in position // ---------------------- if (!CheckChar(chChar, nStartPos)) { MessageBeep((UINT)-1); return; } // Don't use m_chMask CEdit::OnChar(nChar, nRepCnt, nFlags); } } // ------------------------------- // Have one or more chars selected // ------------------------------- else { // ---------------------- // Check char in position // ---------------------- if (!CheckChar(chChar, nStartPos)) { MessageBeep((UINT)-1); return; } // ---------------------------------- // Replace chars in Editbox and m_str // ---------------------------------- if (!m_strInputTemplate.IsEmpty()) // Use m_strInputTemplate { // --------------------------------------------------- // Calc the number of literals with the same mask char // --------------------------------------------------- ASSERT(nStartPos >= 0); ASSERT(nEndPos > 0); ASSERT(nStartPos <= m_strInputTemplate.GetLength()); int nSameMaskCharsNum = 1; int nIndex = nStartPos; // an index of the first selected char TCHAR chMaskChar = m_strMask[nIndex]; BOOL bScanMore = TRUE; while (bScanMore && (nIndex + nSameMaskCharsNum < nGroupEnd)) { if (m_strMask[nIndex + nSameMaskCharsNum] == chMaskChar) { nSameMaskCharsNum++; } else { bScanMore = FALSE; } } // Make sure the selection has the same mask char if (nEndPos - nStartPos > nSameMaskCharsNum) { MessageBeep((UINT)-1); CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum); return; } // ------------------------------- // Form the shifted replace string // ------------------------------- ASSERT(nIndex >= nGroupStart); ASSERT(nIndex + nSameMaskCharsNum <= nGroupEnd); CString strReplace = m_str.Mid(nIndex, nSameMaskCharsNum); if (nSameMaskCharsNum > 0) { ASSERT(nStartPos <= m_strInputTemplate.GetLength()); ASSERT(nEndPos <= m_strInputTemplate.GetLength()); int nRange = nEndPos - nStartPos; ASSERT(nRange>0); strReplace = strReplace.Right(nSameMaskCharsNum - nRange + 1); strReplace += CString(m_chMaskInputTemplate, nRange - 1); ASSERT(strReplace.GetLength() > 0); strReplace.SetAt(0, chChar); } // ------------------------------------------- // Replace the content with the shifted string // ------------------------------------------- CEdit::SetSel(nIndex, nIndex+nSameMaskCharsNum); CEdit::ReplaceSel(strReplace, TRUE); CEdit::SetSel(nIndex, nIndex); for(int i=0; i < strReplace.GetLength(); i++) { m_str.SetAt(nIndex+i, strReplace[i]); } CEdit::SetSel(nStartPos+1, nStartPos+1); } else { // Don't use m_chMaskInputTemplate CEdit::OnChar(nChar, nRepCnt, nFlags); } } }
BOOL SetSliderIni( LPCTSTR lpszString, const int iSlider ) { if( iSlider <= 0 || iSlider > 99 || lstrlen( lpszString ) > 1000 ) return FALSE; WriteDebugLog( TEXT( "SetSliderIni" ) ); WriteDebugLog( lpszString ); TCHAR lpszExeName[ MAX_PATH * 2 ] = _T( "" ); /* - 1.1b7 int len = lstrlen( lpszTarget ); int start = -1; int end = -1; for( int i = len - 1; i >= 5; i-- ) { if( lpszTarget[ i ] == TEXT( ' ' ) && ( lpszTarget[ i - 1 ] == TEXT( 'e' ) || lpszTarget[ i - 1 ] == TEXT( 'E' ) ) && ( lpszTarget[ i - 2 ] == TEXT( 'x' ) || lpszTarget[ i - 2 ] == TEXT( 'X' ) ) && ( lpszTarget[ i - 3 ] == TEXT( 'e' ) || lpszTarget[ i - 3 ] == TEXT( 'E' ) ) && lpszTarget[ i - 4 ] == TEXT( '.' ) ) { end = i; break; } } for( ; i >=0; i-- ) { if( lpszTarget[ i ] == TEXT( '\\' ) ) { start = i + 1; break; } } if( start == -1 ) start = 0; if( end == -1 || end - start <= 0 ) { TCHAR dbg[1000]; wsprintf( dbg, TEXT("DEBUG: %s %d %d %d"), lpszTarget, start, end, end-start ); WriteDebugLog( dbg ) ; return FALSE; } lstrcpy( lpszExeName, &lpszTarget[ start ] ); lpszExeName[ end - start ] = TEXT( '\0' ); */ // +1.1b7 PathToExe( lpszString, lpszExeName, MAX_PATH * 2 ); #if !defined( _UNICODE ) if( lstrlen( lpszExeName ) >= 19 ) { lpszExeName[ 15 ] = '\0'; PathToExeEx( lpszExeName, MAX_PATH * 2 ); } #endif TCHAR lpszExeNameLower[ MAX_PATH * 2 ] = _TEXT( "" ); int len = lstrlen( lpszExeName ); for( int i = 0; i < len; i++ ) { TCHAR c = lpszExeName[ i ]; if( _istascii( c ) && _istupper( c ) ) { lpszExeNameLower[ i ] = (TCHAR) _totlower( c ); } else { lpszExeNameLower[ i ] = c; } } //lpszExeNameLower[ i ] = TEXT( '\0' ); TCHAR lpszPath[ MAX_PATH * 2 ]; GetIniPath( lpszPath ); TCHAR tmpstr[ 100 ]; wsprintf( tmpstr, TEXT( "%d" ), iSlider ); WritePrivateProfileString( TEXT( "Slider" ), lpszExeNameLower, tmpstr, lpszPath ); // to flushes the cache WritePrivateProfileString( NULL, NULL, NULL, lpszPath ); return TRUE; }
void CLogicThread::Think(CTaskDialog* Dialog,CToken* Token, int32 AlterCharPos) { SetForecast(Dialog,NULL_TEXT,NULL); if(Token->m_Type != COMMON){ return; } TokenLogicSense* tls = &m_TokenSense; int64 ParentID= ROOT_SPACE; int pos=0;//字符分析起始位置,=0表示重新分析 if(tls->BelongToken != Token){ if(Token->IsOK() && AlterCharPos == Token->Size()-1){ tls->BelongToken = Token; tls->NextCharPos = AlterCharPos; tls->LastCharID = Token->m_MemoryID; pos = AlterCharPos; ParentID = tls->LastCharID; } else{ tls->BelongToken = Token; } } else if(tls->NextCharPos){ //tls->BelongToken == Token 并且已经被正确分析过 if(AlterCharPos == tls->NextCharPos){ pos=AlterCharPos; //正常分析 ParentID = tls->LastCharID; } else if(AlterCharPos > tls->NextCharPos){ //因为前一个字符已经出错,不用分析也是错, //assert(!Token->IsOK()); //throw "AlterCharPos > NextCharPos"; return; } } #ifdef _DEBUG if(pos==0)assert(ParentID == ROOT_SPACE);//如果完全排除了错误不应该出现这种情况,以防万一, #endif int32 CharNum = Token->m_Str.size(); for(pos; pos<CharNum;pos++){ TCHAR ch = _totlower(Token->m_Str[pos]); int64 ChildID = CharToID(ch); //优先从预测表里找 if(m_ForecastText == (void*)Token && ForecastOK()){ ParentID = GetForecastResult(ChildID); } else { //不行则直接从数据库里找 ParentID = GetChildID(ParentID,ChildID,MEMORY_BODY); } if(ParentID == 0){ tls->NextCharPos = pos; Token->m_MemoryID = ERROR_2; //不能理解,但对于token来说不一定是错误,比如实时数字 //NotifyTokenError(Token,ERROR_2); return; } tls->LastCharID = ParentID; } tls->NextCharPos = pos; Token->m_MemoryID = ParentID; assert(Token->m_Type == COMMON); SetForecast(Dialog,TOKEN,Token); }
void makeEXE(HWND hwndDlg) { TCHAR buf[2048]; GetTempPath(MAX_PATH,buf); GetTempFileName(buf,_T("zne"),0,nsifilename); #ifdef _UNICODE FILE *fp=_tfopen(nsifilename,_T("w, ccs=UNICODE")); // generate a Unicode .NSI file BUGBUG: MSVCRT version specific #else FILE *fp=_tfopen(nsifilename,_T("w")); #endif if (!fp) { MessageBox(hwndDlg,_T("Error writing .NSI file"),g_errcaption,MB_OK|MB_ICONSTOP); PostMessage(g_hwnd,WM_NOTIFYENDCOMPILE,0,0); return; } _ftprintf(fp,_T("Unicode %s\n"),IsDlgButtonChecked(hwndDlg,IDC_UNICODE)?_T("true"):_T("false")); GetDlgItemText(hwndDlg,IDC_INSTNAME,buf,sizeof(buf)); _ftprintf(fp,_T("!define ZIP2EXE_NAME `%s`\n"),buf); GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf)); _ftprintf(fp,_T("!define ZIP2EXE_OUTFILE `%s`\n"),buf); if (g_compressor == 1) _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_ZLIB\n")); if (g_compressor == 2) _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_BZIP2\n")); if (g_compressor == 3) _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_LZMA\n")); if (g_compressor_solid == 1) _ftprintf(fp,_T("!define ZIP2EXE_COMPRESSOR_SOLID\n")); GetDlgItemText(hwndDlg,IDC_INSTPATH,buf,sizeof(buf)); int iswinamp=0; LPCTSTR iswinampmode=NULL; if (!_tcscmp(buf,gp_poi)) lstrcpy(buf,_T("$EXEDIR")); if (!_tcscmp(buf,gp_winamp)) { iswinamp=1; } if (!_tcscmp(buf,gp_winamp_plugins)) { iswinamp=1; _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_PLUGINS\n")); } if (!_tcscmp(buf,gp_winamp_vis)) { iswinamp=1; iswinampmode=_T("VisDir"); } if (!_tcscmp(buf,gp_winamp_dsp)) { iswinamp=1; iswinampmode=_T("DSPDir"); } if (!_tcscmp(buf,gp_winamp_skins)) { iswinamp=1; iswinampmode=_T("SkinDir"); _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_SKINS\n")); } if (iswinamp) { _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_WINAMP\n")); if (iswinampmode) { _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR_WINAMPMODE `%s`\n"),iswinampmode); } } else // set out path to $INSTDIR { _ftprintf(fp,_T("!define ZIP2EXE_INSTALLDIR `%s`\n"),buf); } _ftprintf(fp,_T("!include `${NSISDIR}\\Contrib\\zip2exe\\Base.nsh`\n")); _ftprintf(fp,_T("!include `${NSISDIR}\\Contrib\\zip2exe\\%s.nsh`\n"),g_mui?_T("Modern"):_T("Classic")); _ftprintf(fp,_T("!insertmacro SECTION_BEGIN\n")); _ftprintf(fp,_T("File /r `%s\\*.*`\n"),tempzip_path); _ftprintf(fp,_T("!insertmacro SECTION_END\n")); fclose(fp); TCHAR g_makensis_path[MAX_PATH]; TCHAR *p=g_makensis_path; GetModuleFileName(g_hInstance,g_makensis_path,sizeof(g_makensis_path)); while (*p) p++; while (p >= g_makensis_path && *p != _T('\\')) p--; _tcscpy(p+1,_T("makensis.exe")); WIN32_FIND_DATA fd; HANDLE h=FindFirstFile(g_makensis_path,&fd); if (h==INVALID_HANDLE_VALUE) { if ((p-g_makensis_path>4)&&(_totlower(*(p-1))==_T('n'))&&(_totlower(*(p-2))==_T('i'))&&(_totlower(*(p-3))==_T('b'))&&(*(p-4)==_T('\\'))) { p -= 4; _tcscpy(p+1,_T("makensis.exe")); h=FindFirstFile(g_makensis_path,&fd); if (h==INVALID_HANDLE_VALUE) { MessageBox(hwndDlg,_T("Error finding makensis.exe."),g_errcaption,MB_OK|MB_ICONSTOP); PostMessage(g_hwnd,WM_NOTIFYENDCOMPILE,0,0); return; } } } if (h!=INVALID_HANDLE_VALUE) FindClose(h); wsprintf(g_cmdline,_T("\"%s\" %s \"%s\""),g_makensis_path,g_options,nsifilename); DWORD id; g_hThread=CreateThread(NULL,0,ThreadProc,0,0,&id); }
int __cdecl _tmain( int argc, TCHAR* argv[] ) { TCHAR DestPath[MAX_PATH]; ULONG Size = MAX_PATH; TCHAR * InfPath = NULL; TCHAR DriverPackageInfPath[MAX_PATH]; DWORD Ret; TCHAR Option; BOOL NeedRebootDev = FALSE; BOOL NeedRebootDrvPkg = FALSE; DWORD Flags = 0; LPTSTR lpFilePart; int i; DWORD dw; Size = MAX_PATH; _tprintf( TEXT("Driver Installer Sample Program\n") ); if( argc < 3 ) { _tprintf( TEXT("USAGE: drvinst /i /c /r /g <inf-filename> [Flag(s)]\n") ); _tprintf( TEXT("\nOptions:\n")); _tprintf( TEXT("/i : re-install driver package and devices if presented.\n") ); _tprintf( TEXT("/u : uninstall devices and driver package.\n") ); _tprintf( TEXT("/g : get installed driver package path.\n") ); _tprintf( TEXT("\n<inf-filename> : path to the inf file.\n") ); _tprintf( TEXT("\nFlags:\n")); _tprintf( TEXT("DRIVER_PACKAGE_REPAIR: 0x00000001 ( 1)\n")); _tprintf( TEXT("DRIVER_PACKAGE_SILENT: 0x00000002 ( 2)\n")); _tprintf( TEXT("DRIVER_PACKAGE_FORCE: 0x00000004 ( 4)\n")); _tprintf( TEXT("DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT: 0x00000008 ( 8)\n")); _tprintf( TEXT("DRIVER_PACKAGE_LEGACY: 0x00000010 (16)\n")); _tprintf( TEXT("DRIVER_PACKAGE_DELETE_FILES: 0x00000020 (32)\n")); return 0; } // // Get command line choices // // // The code suppresses the warning 28193 for the call to _totlower. // This suppression is done because that function has a check return // annotation on it. However, it doesn't return an error code // and the check return annotation is really being used to indicate // that the return value of the function should be looked at and/or // assigned to a variable. The check return annotation means the return // value should always be checked in all code paths. The return value is // assigned to a variable, but the return in the for loop could cause // this function to exit before Option is ever examined. For that case, // the code doesn't need to check the value of Option so the warning // is being suppressed // #pragma warning( suppress: 28193) Option = (TCHAR)_totlower(argv[1][1]); InfPath = argv[2]; for ( i = 3; i<argc; i++ ){ dw = _ttol( argv[i] ); // // Either an error occurred during conversion of a flags parameter // into a long or a flag of 0 was specified. Either way, // this is invalid input. // if (0 == dw) { _tprintf( TEXT("An invalid flag was specified.") ); return 0; } Flags |= dw; } GetFullPathName( InfPath, MAX_PATH, DriverPackageInfPath, &lpFilePart); _tprintf( TEXT("INFO: Option \"/%c\"\n"), Option ); _tprintf( TEXT("INFO: Input file \"%s\"\n"), DriverPackageInfPath ); _tprintf( TEXT("INFO: Flags 0x%X (%u)\n\n"), Flags, Flags ); DIFXAPISetLogCallback( LogCallback, (PVOID)NULL ); Ret = ERROR_SUCCESS; if ( TEXT('u') == Option ) { _tprintf( TEXT("INFO: uninstalling devices.\n")); if ( TRUE == RemoveDevices( &NeedRebootDev ) ) { _tprintf( TEXT("SUCCESS: uninstalled devices.\n") ); } else { _tprintf( TEXT("ERROR: failed.\n") ); Ret = !ERROR_SUCCESS; } if ( ERROR_SUCCESS == Ret ) { _tprintf( TEXT("INFO: uninstalling driver package.\n")); Ret = DriverPackageUninstall( DriverPackageInfPath, Flags, NULL, &NeedRebootDrvPkg); if( ERROR_SUCCESS == Ret ){ _tprintf( TEXT("SUCCESS: uninstalled driver package %s.\n"), DriverPackageInfPath ); } else { _tprintf( TEXT("ERROR: failed with error code 0x%X\n"), Ret ); } if ( NeedRebootDev || NeedRebootDrvPkg ) { _tprintf( TEXT("INFO: Machine will have to be rebooted to complete uninstall.") ); } } } else if ( TEXT('i') == Option ) { _tprintf( TEXT("DRVINST: installing drivers.\n")); /* http://msdn.microsoft.com/en-us/library/windows/hardware/ff552293(v=vs.85).aspx */ // step1 - Checking for In-Progress Installations if ( WAIT_OBJECT_0 != CMP_WaitNoPendingInstallEvents ( 0 ) ) { _tprintf( TEXT("ERROR: There are pending installation activities or some error happened when checking CMP_WaitNoPendingInstallEvents\n") ); goto final_main; } /* step2 - Determine whether a device is plugged in. step3 - Preinstall driver packages If we use DIFx API, will save our time, otherwise we must follow the MSDN regarding step2 and step3 */ Ret = DriverPackageInstall( DriverPackageInfPath, Flags, NULL, &NeedRebootDrvPkg); if( ERROR_SUCCESS == Ret ){ _tprintf( TEXT("SUCCESS: installed package %s.\n"), DriverPackageInfPath ); } else if (ERROR_NO_MORE_ITEMS == Ret){ _tprintf( TEXT("INFO: All devices found already have a better driver than what is contained in the specified inf file. To force an install, use the ForceIfNotBetter flag.\n")); } else if (ERROR_NO_SUCH_DEVINST == Ret){ _tprintf( TEXT("INFO: There aren't any live devnodes with the DeviceId contained in the INF.\n")); } else{ _tprintf( TEXT("ERROR: failed with error code 0x%X\n"), Ret ); } if (NeedRebootDrvPkg){ _tprintf( TEXT("INFO: Machine will have to be rebooted to complete install.") ); } } else if ( TEXT('g') == Option ) { _tprintf( TEXT("TEST: getting driver package path.\n")); Ret = DriverPackageGetPath( DriverPackageInfPath, DestPath, &Size ); if ( ERROR_SUCCESS==Ret ){ _tprintf( TEXT("INFO: INF path is %s\n"), DestPath ); } else { _tprintf( TEXT("ERROR: failed with error code 0x%X\n"), Ret ); } } else { _tprintf( TEXT("ERROR: invalid command line option /%c.\n"), Option ); } final_main: DIFXAPISetLogCallback( NULL, (PVOID)NULL ); return 1; }
StringX PWSRun::getruncmd(const StringX &sxFile, bool &bfound) const { // 1. If first parameter is in quotes - assume fully qualified - don't search. // 2. If first parameter starts with '%, assume it is going to be replaced by the // corresponding environmental variable - no need to search directories. // 3. If the first parameter ends in '.xxx', and '.xxx' is in the PATHEXT variable, // search for it as-is. If not, append each of the known extensions to it and then // search. // 4. If searched and could not find, just issue 'as-is'. std::vector<StringX> vpaths; std::vector<StringX> vextns; StringX full_pgm(sxFile), sx_cwd; StringX sx_temp, sx_dirs, sx_extns; stringT path, drive, dir, fname, extn; stringT s_temp; bool bsearch_dirs(true), bsearch_extns(true); const StringX::size_type len = full_pgm.length(); bfound = false; if (len == 0) return full_pgm; // Search order: // Current working directory s_temp = pws_os::getcwd(); stringT::size_type Tlen = s_temp.length(); if (Tlen == 0 || s_temp[Tlen - 1] != _T('\\')) { s_temp += _T("\\"); } sx_cwd = StringX(s_temp.c_str()); vpaths.push_back(sx_cwd); // Windows directory s_temp = pws_os::getenv("windir", true); if (s_temp.length() > 0) vpaths.push_back(StringX(s_temp.c_str())); // Windows/System32 directory if (!s_temp.empty()) { s_temp += stringT(_T("System32")); vpaths.push_back(StringX(s_temp.c_str())); } // Directories in PATH s_temp = pws_os::getenv("PATH", true); sx_temp = s_temp.c_str(); // tokenize into separate elements using ; as the field separator for (StringX::size_type st_startpos = 0; st_startpos < sx_temp.size(); /* st_startpos advanced in body */) { StringX::size_type st_next = sx_temp.find(_T(';'), st_startpos); if (st_next == StringX::npos) st_next = sx_temp.size(); if (st_next > 0) { sx_dirs = sx_temp.substr(st_startpos, st_next - st_startpos); vpaths.push_back(sx_dirs); } st_startpos = st_next + 1; // too complex for for statement } // tokenization for loop // Apps Paths registry key - see below // Get support program extensions s_temp = pws_os::getenv("PATHEXT", false); sx_temp = s_temp.c_str(); // tokenize into separate elements using ; as the field separator for (StringX::size_type st_startpos = 0; st_startpos < sx_temp.size(); /* st_startpos advanced in body */) { StringX::size_type st_next = sx_temp.find(_T(';'), st_startpos); if (st_next == StringX::npos) st_next = sx_temp.size(); if (st_next > 0) { sx_extns = sx_temp.substr(st_startpos, st_next - st_startpos); for(StringX::size_type i = 1; i < sx_extns.size(); i++) { sx_extns[i] = _totlower(sx_extns[i]); } vextns.push_back(sx_extns); } st_startpos = st_next + 1; // too complex for for statement } // tokenization for loop // Just need drive, directory and file extension path = full_pgm.c_str(); pws_os::splitpath(path, drive, dir, fname, extn); if (!extn.empty()) { // ends with '.x-x' StringX sx_temp = StringX(extn.c_str()); for (StringX::size_type i = 1; i < extn.size(); i++) { sx_temp[i] = _totlower(sx_temp[i]); } // Check if a known command extn if (std::find(vextns.begin(), vextns.end(), sx_temp) != vextns.end()) { bsearch_extns = false; } } if (!drive.empty() || !dir.empty()) { // Don't search directories but do search extensions bsearch_dirs = false; if (drive.empty()) { // Drive not specified - so could be relative to current directory sx_temp = sx_cwd + full_pgm; if (pws_os::FileExists(sx_temp.c_str())) { full_pgm = sx_temp; bfound = true; goto exit; } // Doesn't exist - add on know program extensions for (StringX::size_type ie = 0; ie < vextns.size(); ie++) { sx_extns = vextns[ie]; if (pws_os::FileExists((sx_temp + sx_extns).c_str())) { full_pgm = full_pgm + sx_extns; bfound = true; goto exit; } } } else { // Drive specified - so should be full path. // Check if file exists as-is if (pws_os::FileExists(full_pgm.c_str())) { bfound = true; goto exit; } // Doesn't exist - add on know program extensions for (StringX::size_type ie = 0; ie < vextns.size(); ie++) { sx_extns = vextns[ie]; if (pws_os::FileExists((full_pgm + sx_extns).c_str())) { full_pgm = full_pgm + sx_extns; bfound = true; goto exit; } } } } // Now search directories! if (bsearch_dirs) { // Ensure directory ends in a '/' for (StringX::size_type id = 0; id < vpaths.size(); id++) { sx_dirs = vpaths[id]; if (sx_dirs[sx_dirs.length() - 1] != _T('\\')) sx_dirs += _T("\\"); if (bsearch_extns) { for (StringX::size_type ie = 0; ie < vextns.size(); ie++) { sx_extns = vextns[ie]; if (pws_os::FileExists((sx_dirs + full_pgm + sx_extns).c_str())) { full_pgm = sx_dirs + full_pgm + sx_extns; bfound = true; goto exit; } } } else { if (pws_os::FileExists(stringT((sx_dirs + full_pgm).c_str()))) { full_pgm = sx_dirs + full_pgm; bfound = true; goto exit; } } } } // If not found directly or within current directory structure, // we so need to search registry. // Either: we had to search extensions - // so full_pgm does not end with known program extn; // Or: we didn't have to search - // so full_pgm may end with '.exe' and we must not add if (!bfound && (bsearch_extns || (!bsearch_extns && extn == _T(".exe")))) { // Check via registry if (bsearch_extns) full_pgm += _T(".exe"); // Look for registry key bool bexists; HKEY hSubkey; StringX csSubkey = StringX(_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\")) + full_pgm; bexists = (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, csSubkey.c_str(), 0L, KEY_READ, &hSubkey) == ERROR_SUCCESS); if (bexists) { LONG rv; DWORD dwType, dwDataLen(0); rv = ::RegQueryValueEx(hSubkey, _T("Path"), NULL, &dwType, NULL, &dwDataLen); if (rv == ERROR_SUCCESS && dwType == REG_SZ) { dwDataLen++; TCHAR *pData = new TCHAR[dwDataLen]; ::memset(pData, 0, dwDataLen); rv = ::RegQueryValueEx(hSubkey, _T("Path"), NULL, &dwType, LPBYTE(pData), &dwDataLen); if (rv == ERROR_SUCCESS) { sx_temp = pData; StringX::size_type len = sx_temp.length(); if (sx_temp[len - 1] == _T(';')) sx_temp = sx_temp.substr(0, len - 1) + _T('\\'); else if (sx_temp[len - 1] != _T('\\') && sx_temp[len - 1] != _T('/')) sx_temp = sx_temp + _T('\\'); full_pgm = sx_temp + full_pgm; bfound = true; } delete[] pData; } // Get the value ::RegCloseKey(hSubkey); } } exit: return full_pgm; }
/** * Get the system region information. * Called by pthread_once(). * (Windows version) * * Country code will be stored in 'cc'. * Language code will be stored in 'lc'. */ void SystemRegionPrivate::getSystemRegion(void) { TCHAR locale[16]; int ret; // Check if LC_MESSAGES or LC_ALL is set. const char *const locale_var = get_LC_MESSAGES(); if (locale_var != nullptr && locale_var[0] != '\0') { ret = getSystemRegion_LC_MESSAGES(locale_var); if (ret == 0) { // LC_MESSAGES or LC_ALL is set and is valid. return; } // LC_MESSAGES or LC_ALL is not set or is invalid. // Continue with the Windows-specific code. // NOTE: If LC_MESSAGE or LC_ALL had a language code // but not a region code, we'll keep that portion. } // References: // - https://msdn.microsoft.com/en-us/library/windows/desktop/dd318101(v=vs.85).aspx // NOTE: LOCALE_SISO3166CTRYNAME might not work on some old versions // of Windows, but our minimum is Windows XP. // FIXME: Non-ASCII locale names will break! if (cc == 0) { ret = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, locale, ARRAY_SIZE(locale)); switch (ret) { case 3: // 2-character country code. // (ret == 3 due to the NULL terminator.) cc = (((_totupper(locale[0]) & 0xFF) << 8) | (_totupper(locale[1]) & 0xFF)); break; case 4: // 3-character country code. // (ret == 4 due to the NULL terminator.) cc = (((_totupper(locale[0]) & 0xFF) << 16) | ((_totupper(locale[1]) & 0xFF) << 8) | (_totupper(locale[2]) & 0xFF)); break; default: // Unsupported. (MSDN says the string could be up to 9 characters!) cc = 0; break; } } // NOTE: LOCALE_SISO639LANGNAME might not work on some old versions // of Windows, but our minimum is Windows XP. // FIXME: Non-ASCII locale names will break! if (lc == 0) { ret = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, locale, ARRAY_SIZE(locale)); switch (ret) { case 3: // 2-character language code. // (ret == 3 due to the NULL terminator.) lc = (((_totlower(locale[0]) & 0xFF) << 8) | (_totlower(locale[1]) & 0xFF)); break; case 4: // 3-character language code. // (ret == 4 due to the NULL terminator.) lc = (((_totlower(locale[0]) & 0xFF) << 16) | ((_totlower(locale[1]) & 0xFF) << 8) | (_totlower(locale[2]) & 0xFF)); break; default: // Unsupported. (MSDN says the string could be up to 9 characters!) lc = 0; break; } } }
//---------------------------------------------------------------------- // // WMain // // Engine. Just get command line switches and fire off a format. This // could also be done in a GUI like Explorer does when you select a // drive and run a check on it. // // We do this in UNICODE because the chkdsk command expects PWCHAR // arguments. // //---------------------------------------------------------------------- int _tmain(int argc, TCHAR *argv[]) { int badArg; DWORD media = FMIFS_HARDDISK; DWORD driveType; TCHAR fileSystem[1024]; TCHAR volumeName[1024]; TCHAR input[1024]; DWORD serialNumber; DWORD flags, maxComponent; ULARGE_INTEGER freeBytesAvailableToCaller, totalNumberOfBytes, totalNumberOfFreeBytes; #ifndef UNICODE WCHAR RootDirectoryW[MAX_PATH], FileSystemW[MAX_PATH], LabelW[MAX_PATH]; #endif TCHAR szMsg[RC_STRING_MAX_SIZE]; // // Get function pointers // if( !LoadFMIFSEntryPoints()) { LoadStringAndOem( GetModuleHandle(NULL), STRING_FMIFS_FAIL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); return -1; } // // Parse command line // if( (badArg = ParseCommandLine( argc, argv ))) { LoadStringAndOem( GetModuleHandle(NULL), STRING_UNKNOW_ARG, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, argv[badArg] ); Usage(argv[0]); return -1; } // // Get the drive's format // if( !Drive ) { LoadStringAndOem( GetModuleHandle(NULL), STRING_DRIVE_PARM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg); Usage( argv[0] ); return -1; } else { _tcscpy( RootDirectory, Drive ); } RootDirectory[2] = _T('\\'); RootDirectory[3] = _T('\0'); // // See if the drive is removable or not // driveType = GetDriveType( RootDirectory ); switch (driveType) { case DRIVE_UNKNOWN : LoadStringAndOem( GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; case DRIVE_REMOTE: case DRIVE_CDROM: LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_SUPPORT, (LPTSTR) szMsg, RC_STRING_MAX_SIZE); _tprintf(szMsg); return -1; case DRIVE_NO_ROOT_DIR: LoadString( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; case DRIVE_REMOVABLE: LoadStringAndOem( GetModuleHandle(NULL), STRING_INSERT_DISK, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, RootDirectory[0] ); _fgetts( input, sizeof(input)/2, stdin ); media = FMIFS_FLOPPY; break; case DRIVE_FIXED: case DRIVE_RAMDISK: media = FMIFS_HARDDISK; break; } // Reject attempts to format the system drive { TCHAR path[MAX_PATH + 1]; UINT rc; rc = GetWindowsDirectory(path, MAX_PATH); if (rc == 0 || rc > MAX_PATH) // todo: Report "Unable to query system directory" return -1; if (_totlower(path[0]) == _totlower(Drive[0])) { // todo: report "Cannot format system drive" LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_SUPPORT, (LPTSTR) szMsg, RC_STRING_MAX_SIZE); _tprintf(szMsg); return -1; } } // // Determine the drive's file system format // if( !GetVolumeInformation( RootDirectory, volumeName, sizeof(volumeName)/2, &serialNumber, &maxComponent, &flags, fileSystem, sizeof(fileSystem)/2)) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } if( !GetDiskFreeSpaceEx( RootDirectory, &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes )) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } LoadStringAndOem( GetModuleHandle(NULL), STRING_FILESYSTEM, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, fileSystem ); // // Make sure they want to do this // if( driveType == DRIVE_FIXED ) { if( volumeName[0] ) { while(1 ) { LoadStringAndOem( GetModuleHandle(NULL), STRING_LABEL_NAME_EDIT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, RootDirectory[0] ); _fgetts( input, sizeof(input)/2, stdin ); input[ _tcslen( input ) - 1] = 0; if( !_tcsicmp( input, volumeName )) { break; } LoadStringAndOem( GetModuleHandle(NULL), STRING_ERROR_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); } } LoadStringAndOem( GetModuleHandle(NULL), STRING_YN_FORMAT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, RootDirectory[0] ); LoadStringAndOem( GetModuleHandle(NULL), STRING_YES_NO_FAQ, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); while( 1 ) { _fgetts( input, sizeof(input)/2, stdin ); if(_strnicmp(&input[0],&szMsg[0],1) == 0) break; if(_strnicmp(&input[0],&szMsg[1],1) == 0) { _tprintf(_T("\n")); return 0; } } } // // Tell the user we're doing a long format if appropriate // if( !QuickFormat ) { LoadString( GetModuleHandle(NULL), STRING_VERIFYING, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); if( totalNumberOfBytes.QuadPart > 1024*1024*10 ) { _tprintf(_T("%s %luM\n"),szMsg, (DWORD) (totalNumberOfBytes.QuadPart/(1024*1024))); } else { _tprintf(_T("%s %.1fM\n"),szMsg, ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0)); } } else { LoadStringAndOem( GetModuleHandle(NULL), STRING_FAST_FMT, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); if( totalNumberOfBytes.QuadPart > 1024*1024*10 ) { _tprintf(_T("%s %luM\n"),szMsg, (DWORD) (totalNumberOfBytes.QuadPart/(1024*1024))); } else { _tprintf(_T("%s %.2fM\n"),szMsg, ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0)); } LoadStringAndOem( GetModuleHandle(NULL), STRING_CREATE_FSYS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); } // // Format away! // #ifndef UNICODE MultiByteToWideChar(CP_ACP, 0, RootDirectory, -1, RootDirectoryW, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, FileSystem, -1, FileSystemW, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, Label, -1, LabelW, MAX_PATH); FormatEx( RootDirectoryW, media, FileSystemW, LabelW, QuickFormat, ClusterSize, FormatExCallback ); #else FormatEx( RootDirectory, media, FileSystem, Label, QuickFormat, ClusterSize, FormatExCallback ); #endif if( Error ) return -1; LoadStringAndOem( GetModuleHandle(NULL), STRING_FMT_COMPLETE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); // // Enable compression if desired // if( CompressDrive ) { #ifndef UNICODE MultiByteToWideChar(CP_ACP, 0, RootDirectory, -1, RootDirectoryW, MAX_PATH); if( !EnableVolumeCompression( RootDirectoryW, TRUE )) { #else if( !EnableVolumeCompression( RootDirectory, TRUE )) { #endif LoadStringAndOem( GetModuleHandle(NULL), STRING_VOL_COMPRESS, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); } } // // Get the label if we don't have it // if( !GotALabel ) { LoadString( GetModuleHandle(NULL), STRING_ENTER_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf("%s", szMsg); _fgetts( input, sizeof(LabelString)/2, stdin ); input[ _tcslen(input)-1] = 0; if( !SetVolumeLabel( RootDirectory, input )) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_LABEL, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error(szMsg, GetLastError()); return -1; } } if( !GetVolumeInformation( RootDirectory, volumeName, sizeof(volumeName)/2, &serialNumber, &maxComponent, &flags, fileSystem, sizeof(fileSystem)/2)) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } // // Print out some stuff including the formatted size // if( !GetDiskFreeSpaceEx( RootDirectory, &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes )) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error(szMsg, GetLastError()); return -1; } LoadStringAndOem( GetModuleHandle(NULL), STRING_FREE_SPACE, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, totalNumberOfBytes.QuadPart, totalNumberOfFreeBytes.QuadPart ); // // Get the drive's serial number // if( !GetVolumeInformation( RootDirectory, volumeName, sizeof(volumeName)/2, &serialNumber, &maxComponent, &flags, fileSystem, sizeof(fileSystem)/2)) { LoadStringAndOem( GetModuleHandle(NULL), STRING_NO_VOLUME, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); PrintWin32Error( szMsg, GetLastError()); return -1; } LoadStringAndOem( GetModuleHandle(NULL), STRING_SERIAL_NUMBER, (LPTSTR) szMsg,RC_STRING_MAX_SIZE); _tprintf(szMsg, (unsigned int)(serialNumber >> 16), (unsigned int)(serialNumber & 0xFFFF) ); return 0; }
TCHAR* lucene_tcslwr( TCHAR* str ) { TCHAR* ret = str; for ( ; *str; str++) *str = _totlower(*str); return ret; }
static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { MButtonCtrl* bct = (MButtonCtrl *)GetWindowLongPtr(hwndDlg, 0); switch (msg) { case WM_NCCREATE: { SetWindowLongPtr(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE) | BS_OWNERDRAW); bct = (MButtonCtrl *)malloc(sizeof(MButtonCtrl)); if (bct == NULL) return FALSE; ZeroMemory(bct, sizeof(MButtonCtrl)); bct->hwnd = hwndDlg; bct->stateId = PBS_NORMAL; bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LoadTheme(bct); SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)bct); if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName); return TRUE; } case WM_DESTROY: { if (bct) { EnterCriticalSection(&csTips); if (hwndToolTips) { TOOLINFO ti; ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR)bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti); } if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) { DestroyWindow(hwndToolTips); hwndToolTips = NULL; } } if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); LeaveCriticalSection(&csTips); DestroyTheme(bct); } break; // DONT! fall thru } case WM_NCDESTROY: free(bct); SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)NULL); break; case WM_SETTEXT: { bct->cHot = 0; if ((TCHAR *)lParam) { TCHAR *tmp = (TCHAR *)lParam; while (*tmp) { if (*tmp == (TCHAR)'&' && *(tmp + 1)) { bct->cHot = _totlower(*(tmp + 1)); break; } tmp++; } InvalidateRect(bct->hwnd, NULL, TRUE); } break; } case WM_KEYUP: if (bct->stateId != PBS_DISABLED && wParam == VK_SPACE && !(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_SHIFT) & 0x8000)) { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; InvalidateRect(bct->hwnd, NULL, TRUE); } SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg); return 0; } break; case WM_SYSKEYUP: if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int)wParam)) { if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; InvalidateRect(bct->hwnd, NULL, TRUE); } SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg); return 0; } break; case WM_THEMECHANGED: { // themed changed, reload theme object if (bct->bThemed) LoadTheme(bct); InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it break; } case WM_SETFONT: { // remember the font so we can use it later bct->hFont = (HFONT)wParam; // maybe we should redraw? break; } case WM_NCPAINT: return(0); case WM_PAINT: { PAINTSTRUCT ps; HDC hdcPaint; hdcPaint = BeginPaint(hwndDlg, &ps); if (hdcPaint) { if(bct->sitem) bct->sitem->RenderThis(hdcPaint); else PaintWorker(bct, hdcPaint); EndPaint(hwndDlg, &ps); } return(0); } case BM_SETIMAGE: if (wParam == IMAGE_ICON) { ICONINFO ii; BITMAP bm; if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); GetIconInfo((HICON)lParam, &ii); GetObject(ii.hbmColor, sizeof(bm), &bm); if (bm.bmWidth != PluginConfig.m_smcxicon || bm.bmHeight != PluginConfig.m_smcyicon) { HIMAGELIST hImageList; hImageList = ImageList_Create(PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, PluginConfig.m_bIsXP ? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0); ImageList_AddIcon(hImageList, (HICON)lParam); bct->hIconPrivate = ImageList_GetIcon(hImageList, 0, ILD_NORMAL); ImageList_RemoveAll(hImageList); ImageList_Destroy(hImageList); bct->hIcon = 0; } else { bct->hIcon = (HICON)lParam; bct->hIconPrivate = 0; } DeleteObject(ii.hbmMask); DeleteObject(ii.hbmColor); bct->hBitmap = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (wParam == IMAGE_BITMAP) { bct->hBitmap = (HBITMAP)lParam; if (bct->hIconPrivate) DestroyIcon(bct->hIconPrivate); bct->hIcon = bct->hIconPrivate = NULL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; case BM_SETCHECK: if (!bct->pushBtn) break; if (wParam == BST_CHECKED) { bct->pbState = 1; bct->stateId = PBS_PRESSED; } else if (wParam == BST_UNCHECKED) { bct->pbState = 0; bct->stateId = PBS_NORMAL; } InvalidateRect(bct->hwnd, NULL, TRUE); break; case BM_GETCHECK: if (bct->pushBtn) { return bct->pbState ? BST_CHECKED : BST_UNCHECKED; } return 0; case BUTTONSETARROW: // turn arrow on/off bct->arrow = (HICON)wParam; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETDEFAULT: bct->defbutton = wParam ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASPUSHBTN: bct->pushBtn = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN: bct->flatBtn = lParam == 0 ? 1 : 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case BUTTONSETASFLATBTN + 10: bct->bThemed = lParam ? TRUE : FALSE; break; case BUTTONSETASFLATBTN + 11: bct->dimmed = lParam ? TRUE : FALSE; break; case BUTTONSETASFLATBTN + 12: bct->pContainer = (struct TContainerData *)lParam; break; case BUTTONSETASFLATBTN + 13: bct->bTitleButton = TRUE; break; case BUTTONSETASFLATBTN + 14: bct->stateId = (wParam) ? PBS_NORMAL : PBS_DISABLED; InvalidateRect(bct->hwnd, NULL, FALSE); break; case BUTTONSETASFLATBTN + 15: return bct->stateId; case BUTTONSETASTOOLBARBUTTON: bct->bToolbarButton = lParam; break; case BUTTONSETASSIDEBARBUTTON: bct->sitem = reinterpret_cast<CSideBarButton *>(lParam); break; case BUTTONSETOVERLAYICON: bct->overlay = (HICON)lParam; break; case BUTTONADDTOOLTIP: { TOOLINFO ti; if (!(char*)wParam) break; EnterCriticalSection(&csTips); if (!hwndToolTips) { hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); } ZeroMemory(&ti, sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = TTF_IDISHWND; ti.hwnd = bct->hwnd; ti.uId = (UINT_PTR)bct->hwnd; if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) { SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti); } ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; ti.uId = (UINT_PTR)bct->hwnd; ti.lpszText = (TCHAR *)wParam; SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM)&ti); SendMessage(hwndToolTips, TTM_SETMAXTIPWIDTH, 0, 300); LeaveCriticalSection(&csTips); break; } case WM_SETFOCUS: // set keybord focus and redraw bct->focus = 1; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_KILLFOCUS: // kill focus and redraw bct->focus = 0; InvalidateRect(bct->hwnd, NULL, TRUE); break; case WM_ENABLE: { // windows tells us to enable/disable bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED; InvalidateRect(bct->hwnd, NULL, TRUE); break; } case WM_MOUSELEAVE: { // faked by the WM_TIMER if (bct->stateId != PBS_DISABLED) { // don't change states if disabled bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } break; } case WM_CONTEXTMENU: if(bct->sitem) bct->sitem->invokeContextMenu(); break; case WM_MBUTTONUP: if(bct->sitem) { if(bct->sitem->getDat()) SendMessage(bct->sitem->getDat()->hwnd, WM_CLOSE, 1, 0); } break; case WM_LBUTTONDOWN: { RECT rc; if(bct->sitem) { if(bct->sitem->testCloseButton() != -1) return(TRUE); bct->stateId = PBS_PRESSED; InvalidateRect(bct->hwnd, NULL, TRUE); bct->sitem->activateSession(); } if (bct->arrow) { GetClientRect(bct->hwnd, &rc); if (LOWORD(lParam) < rc.right - 12 && bct->stateId != PBS_DISABLED) bct->stateId = PBS_PRESSED; else if(LOWORD(lParam) > rc.right - 12) { if(GetDlgCtrlID(hwndDlg) == IDOK || bct->stateId != PBS_DISABLED) { WORD w = (WORD)((int)bct->arrow & 0x0000ffff); SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(w, BN_CLICKED), (LPARAM)hwndDlg); } } InvalidateRect(bct->hwnd, NULL, TRUE); } else if (bct->stateId != PBS_DISABLED) { bct->stateId = PBS_PRESSED; InvalidateRect(bct->hwnd, NULL, TRUE); } break; } case WM_LBUTTONUP: { int showClick = 0; if (bct->sitem) { if(bct->sitem->testCloseButton() != -1) { SendMessage(bct->sitem->getDat()->hwnd, WM_CLOSE, 1, 0); return(TRUE); } } if (bct->pushBtn) { if (bct->pbState) bct->pbState = 0; else bct->pbState = 1; } if (bct->stateId != PBS_DISABLED) { // don't change states if disabled if(bct->stateId == PBS_PRESSED) showClick = 1; if (msg == WM_LBUTTONUP) bct->stateId = PBS_HOT; else bct->stateId = PBS_NORMAL; InvalidateRect(bct->hwnd, NULL, TRUE); } if(showClick) SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg); break; } case WM_MOUSEMOVE: if (bct->stateId == PBS_NORMAL) { bct->stateId = PBS_HOT; InvalidateRect(bct->hwnd, NULL, TRUE); } else if (bct->arrow && bct->stateId == PBS_HOT) { InvalidateRect(bct->hwnd, NULL, TRUE); } // Call timer, used to start cheesy TrackMouseEvent faker SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL); if(bct->sitem) { if(bct->sitem->testCloseButton() != -1) { if(bct->sitem->m_sideBar->getHoveredClose() != bct->sitem) { bct->sitem->m_sideBar->setHoveredClose(bct->sitem); InvalidateRect(hwndDlg, 0, FALSE); } } else { bct->sitem->m_sideBar->setHoveredClose(0); InvalidateRect(hwndDlg, 0, FALSE); } } break; case WM_TIMER: { // use a timer to check if they have did a mouseout if (wParam == BUTTON_POLLID) { RECT rc; POINT pt; GetWindowRect(hwndDlg, &rc); GetCursorPos(&pt); if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L); KillTimer(hwndDlg, BUTTON_POLLID); if(bct->sitem) { bct->sitem->m_sideBar->setHoveredClose(0); InvalidateRect(hwndDlg, 0, FALSE); } } } break; } case WM_ERASEBKGND: return(1); } return DefWindowProc(hwndDlg, msg, wParam, lParam); }
long CStr::FindInsensitive(const tchar chr) const { return LowerCase().Find(_totlower(chr)); }
bool CDeskBand::Filter(LPTSTR filter) { bool bReturn = false; IServiceProvider * pServiceProvider; if (SUCCEEDED(m_pSite->QueryInterface(IID_IServiceProvider, (LPVOID*)&pServiceProvider))) { IShellBrowser * pShellBrowser; if (SUCCEEDED(pServiceProvider->QueryService(SID_SShellBrowser, IID_IShellBrowser, (LPVOID*)&pShellBrowser))) { IShellView * pShellView; if (SUCCEEDED(pShellBrowser->QueryActiveShellView(&pShellView))) { IFolderView * pFolderView; if (SUCCEEDED(pShellView->QueryInterface(IID_IFolderView, (LPVOID*)&pFolderView))) { // hooray! we got the IFolderView interface! // that means the explorer is active and well :) IShellFolderView * pShellFolderView; if (SUCCEEDED(pShellView->QueryInterface(IID_IShellFolderView, (LPVOID*)&pShellFolderView))) { // the first thing we do is to deselect all already selected entries pFolderView->SelectItem(NULL, SVSI_DESELECTOTHERS); // but we also need the IShellFolder interface because // we need its GetDisplayNameOf() method IPersistFolder2 * pPersistFolder; if (SUCCEEDED(pFolderView->GetFolder(IID_IPersistFolder2, (LPVOID*)&pPersistFolder))) { LPITEMIDLIST curFolder; pPersistFolder->GetCurFolder(&curFolder); if (ILIsEqual(m_currentFolder, curFolder)) { CoTaskMemFree(curFolder); } else { CoTaskMemFree(m_currentFolder); m_currentFolder = curFolder; for (size_t i=0; i<m_noShows.size(); ++i) { CoTaskMemFree(m_noShows[i]); } m_noShows.clear(); } IShellFolder * pShellFolder; if (SUCCEEDED(pPersistFolder->QueryInterface(IID_IShellFolder, (LPVOID*)&pShellFolder))) { // our next task is to enumerate all the // items in the folder view and select those // which match the text in the edit control bool bUseRegex = (filter[0] == '\\'); try { const std::tr1::wregex regCheck(&filter[1], std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript); } catch (std::exception) { bUseRegex = false; } if (!bUseRegex) { // force the filter to lowercase TCHAR * pString = filter; while (*pString) { *pString = _totlower(*pString); pString++; } } int nCount = 0; if (SUCCEEDED(pFolderView->ItemCount(SVGIO_ALLVIEW, &nCount))) { pShellFolderView->SetRedraw(FALSE); HWND listView = GetListView32(pShellView); LRESULT viewType = 0; if (listView) { // inserting items in the list view if the list view is set to // e.g., LV_VIEW_LIST is painfully slow. So save the current view // and set it to LV_VIEW_DETAILS (which is much faster for inserting) // and restore the view after we're done. viewType = SendMessage(listView, LVM_GETVIEW, 0, 0); SendMessage(listView, LVM_SETVIEW, LV_VIEW_DETAILS, 0); } std::vector<LPITEMIDLIST> noShows; for (int i=0; i<nCount; ++i) { LPITEMIDLIST pidl; if (SUCCEEDED(pFolderView->Item(i, &pidl))) { if (CheckDisplayName(pShellFolder, pidl, filter, bUseRegex)) { // remove now shown items which are in the no-show list // this is necessary since we don't get a notification // if the shell refreshes its view for (std::vector<LPITEMIDLIST>::iterator it = m_noShows.begin(); it != m_noShows.end(); ++it ) { if (HRESULT_CODE(pShellFolder->CompareIDs(SHCIDS_CANONICALONLY, *it, pidl))==0) { m_noShows.erase(it); break; } } CoTaskMemFree(pidl); } else { UINT puItem = 0; if (pShellFolderView->RemoveObject(pidl, &puItem) == S_OK) { i--; nCount--; noShows.push_back(pidl); } } } } // now add all those items again which were removed by a previous filter string // but don't match this new one //pShellFolderView->SetObjectCount(5000, SFVSOC_INVALIDATE_ALL|SFVSOC_NOSCROLL); for (size_t i=0; i<m_noShows.size(); ++i) { LPITEMIDLIST pidlNoShow = m_noShows[i]; if (CheckDisplayName(pShellFolder, pidlNoShow, filter, bUseRegex)) { m_noShows.erase(m_noShows.begin() + i); i--; UINT puItem = (UINT)i; pShellFolderView->AddObject(pidlNoShow, &puItem); CoTaskMemFree(pidlNoShow); } } for (size_t i=0; i<noShows.size(); ++i) { m_noShows.push_back(noShows[i]); } if (listView) { SendMessage(listView, LVM_SETVIEW, viewType, 0); } pShellFolderView->SetRedraw(TRUE); } pShellFolder->Release(); } pPersistFolder->Release(); } pShellFolderView->Release(); } pFolderView->Release(); } pShellView->Release(); } pShellBrowser->Release(); } pServiceProvider->Release(); } return bReturn; }
//------------------------------------------------------------------- // Get value of *one* bytecode token. // Return: value of code. // bytecode must be checked before!! int Text2BinTranslator::iTranslateOneBytecode(BYTE* dest, LPCTSTR src, int srclen, int binmode) { int i, k = 0; TCHAR buf[50] = {0}; for (i = 4; i < srclen; i++) { if (src[i] == '>') break; else { buf[k++] = _totlower(src[i]); } } buf[k] = 0; int value; float fvalue; double dvalue; switch (src[2]) // Get value from text. { case 'd': _stscanf(buf, _T("%d"), &value); break; case 'h': _stscanf(buf, _T("%x"), &value); break; case 'l': _stscanf(buf, _T("%f"), &fvalue); break; case 'o': _stscanf(buf, _T("%lf"), &dvalue); break; } if (binmode == HexEditorWindow::ENDIAN_LITTLE) { switch (src[1]) { case 'b': dest[0] = (BYTE) value; break; case 'w': dest[0] = (BYTE)(value & 0xff); dest[1] = (BYTE)((value & 0xff00) >> 8); break; case 'l': dest[0] = (BYTE)(value & 0xff); dest[1] = (BYTE)((value & 0xff00) >> 8); dest[2] = (BYTE)((value & 0xff0000) >> 16); dest[3] = (BYTE)((value & 0xff000000) >> 24); break; case 'f': *((float*)dest) = fvalue; break; case 'd': *((double*)dest) = dvalue; break; } } else // BIGENDIAN_MODE { switch (src[1])
/** * @brief Compare two buffers byte per byte. * * This function compares two buffers pointed to by @p ptr0 and @p ptr1. * Comparing takes account diffutils options flags given to constructor. * Buffer pointers are advanced while comparing so they point to current * compare position. End of buffers are given by @p end0 and @p end1, which * may point past last valid byte in file. Offset-params tell is how far this * buffer is into the file (ie, 0 the first time called). * @param [in,out] stats0 Statistics for first side. * @param [in,out] stats1 Statistics for second side. * @param [in,out] ptr0 Pointer to begin of the first buffer. * @param [in,out] ptr1 Pointer to begin of the second buffer. * @param [in] end0 Pointer to end of the first buffer. * @param [in] end1 Pointer to end of the second buffer. * @param [in] eof0 Is first buffers end also end of the file? * @param [in] eof1 Is second buffers end also end of the file? * @param [in] offset0 Offset of the buffer begin in the first file. * @param [in] offset1 Offset of the buffer begin in the second file. * @return COMP_RESULT telling result of the compare. */ ByteComparator::COMP_RESULT ByteComparator::CompareBuffers( FileTextStats & stats0, FileTextStats & stats1, const char* &ptr0, const char* &ptr1, const char* end0, const char* end1, bool eof0, bool eof1, int64_t offset0, int64_t offset1) { ByteComparator::COMP_RESULT result = RESULT_SAME; // First, update file text statistics by doing a full scan // for 0s and all types of line delimiters TextScan(stats0, ptr0, end0, eof0, m_cr0, offset0); TextScan(stats1, ptr1, end1, eof1, m_cr1, offset1); const char *orig0 = ptr0; const char *orig1 = ptr1; // cycle through buffer data performing actual comparison while (true) { if (m_ignore_all_space) { // Skip over any whitespace on either side // skip over all whitespace while (ptr0 < end0 && iswsch(*ptr0)) { m_bol0 = false; ++ptr0; } // skip over all whitespace while (ptr1 < end1 && iswsch(*ptr1)) { m_bol1 = false; ++ptr1; } if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1)) { goto need_more; } } if (m_ignore_space_change) { // Skip over whitespace change // Also skip whitespace on one side if // either end of line or end of file on other // Handle case of whitespace on side0 // (First four cases) if (ptr0 < end0 && iswsch(*ptr0)) { // Whitespace on side0 if (ptr1 < end1) { if (iswsch(*ptr1)) { // whitespace on both sides m_wsflag = true; m_bol0 = false; ++ptr0; m_bol1 = false; ++ptr1; } else if (iseolch(*ptr1)) { // whitespace on side 0 (end of line on side 1) m_wsflag = true; m_bol0 = false; ++ptr0; } } else // ptr1 == end1 { if (!eof1) { // Whitespace on side0, don't know what is on side1 // Cannot tell if matching whitespace yet goto need_more; } else // eof1 { // Whitespace on side0, eof on side1 m_wsflag = true; m_bol0 = false; ++ptr0; } } } else { // Handle case of whitespace on side1 // but not whitespace on side0 (that was handled above) // (Remaining three cases) if (ptr1 < end1 && iswsch(*ptr1)) { // Whitespace on side1 if (ptr0 < end0) { // "whitespace on both sides" // should not come here, it should have been // handled above assert(!iswsch(*ptr0)); if (iseolch(*ptr0)) { // whitespace on side 1 (eol on side 0) m_wsflag = true; m_bol1 = false; ++ptr1; } } else // ptr0 == end0 { if (!eof0) { // Whitespace on side1, don't know what is on side0 // Cannot tell if matching whitespace yet goto need_more; } else // eof0 { // Whitespace on side1, eof on side0 m_wsflag = true; m_bol1 = false; ++ptr1; } } } } if (m_wsflag) { // skip over consecutive whitespace while (ptr0 < end0 && iswsch(*ptr0)) { m_bol0 = false; ++ptr0; } // skip over consecutive whitespace while (ptr1 < end1 && iswsch(*ptr1)) { m_bol1 = false; ++ptr1; } if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1)) { // if run out of buffer on either side // must fetch more, to continue skipping whitespace m_wsflag = true; goto need_more; } } m_wsflag = false; } if (m_ignore_eol_diff) { if (m_ignore_blank_lines) { // skip over any line delimiters on either side while (ptr0 < end0 && iseolch(*ptr0)) { // m_bol0 not used because m_ignore_eol_diff ++ptr0; } while (ptr1 < end1 && iseolch(*ptr1)) { // m_bol1 not used because m_ignore_eol_diff ++ptr1; } if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1)) { goto need_more; } } else // don't skip blank lines, but still ignore eol difference { HandleSide0Eol((char **) &ptr0, end0, eof0); HandleSide1Eol((char **) &ptr1, end1, eof1); if (m_cr0 || m_cr1) { // these flags mean possible split CR/LF goto need_more; } if (m_eol0 || m_eol1) { if ((!m_eol0 || !m_eol1) && (orig0 == end0 || orig1 == end1)) { // one side had an end-of-line, but the other didn't return RESULT_DIFF; } if (ptr0 != end0 && ptr1 != end1) // This continue statement is needed to handle blank lines continue; } } } else { // do not ignore eol differences if (m_ignore_blank_lines) { if (m_bol0) { while (ptr0 < end0 && iseolch(*ptr0)) { ++ptr0; } } if (m_bol1) { while (ptr1 < end1 && iseolch(*ptr1)) { ++ptr1; } } if ((ptr0 == end0 && !eof0) || (ptr1 == end1 && !eof1)) { goto need_more; } } } if (ptr0 == end0 || ptr1 == end1) { if (ptr0 == end0 && ptr1 == end1) { if (!eof0 || !eof1) goto need_more; else return RESULT_SAME; } else { // we are at the end on one side? if ((!(ptr0 == end0 && eof0) && !(ptr1 == end1 && eof1)) && (orig0 != end0 && orig1 != end1)) { goto need_more; } else return RESULT_DIFF; } } TCHAR c0 = *ptr0, c1 = *ptr1; if (m_ignore_case) { c0 = _istupper(c0) ? _totlower(c0) : c0; c1 = _istupper(c1) ? _totlower(c1) : c1; } if (c0 != c1) return RESULT_DIFF; // buffers are different if (ptr0 < end0 && ptr1 < end1) { m_bol0 = iseolch(c0); m_bol1 = iseolch(c1); ++ptr0; ++ptr1; continue; } goto need_more; } need_more: if (ptr0 - 1 >= orig0 && *(ptr0 - 1) == '\r') m_cr0 = true; else m_cr0 = false; if (ptr1 - 1 >= orig1 && *(ptr1 - 1) == '\r') m_cr1 = true; else m_cr1 = false; if (ptr0 == end0 && !eof0) { if (ptr1 == end1 && !eof1) return NEED_MORE_BOTH; else return NEED_MORE_0; } else if (ptr1 == end1 && !eof1) { return NEED_MORE_1; } else { return result; } }