#include "defs.h"\r
#include "../xkeymacs/resource.h"\r
#include <Imm.h>\r
-#pragma data_seg(".xkmcs")\r
-TCHAR CUtils::m_szApplicationName[MAX_PATH] = {'\0'};\r
-TCHAR CUtils::m_szIMEName[MAX_PATH] = _T("IME"); // IDS_IME_FILE_NAME\r
-#pragma data_seg()\r
+\r
+bool CUtils::IsConsole()\r
+{\r
+ return AppName::IsConsole();\r
+}\r
+\r
+int CUtils::GetWindowTextType(const CString& text)\r
+{\r
+ int len = text.GetAllocLength();\r
+ if (len >= 3 && text[0] == _T('*') && text[len - 1] == _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH;\r
+ else if (len >= 2 && text[0] != _T('*') && text[len - 1] == _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH_FORWARD;\r
+ else if (len >= 2 && text[0] == _T('*') && text[len - 1] != _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH_BACKWARD;\r
+ else if (len > 0 && text[0] != _T('*') && text[len - 1] != _T('*'))\r
+ return IDS_WINDOW_TEXT_MATCH_FULL;\r
+ return IDS_WINDOW_TEXT_IGNORE;\r
+}\r
+\r
+bool CUtils::IsMatchWindowText(const CString& text)\r
+{\r
+ int len = text.GetLength();\r
+ TCHAR buf[WINDOW_TEXT_LENGTH];\r
+ GetWindowText(GetForegroundWindow(), buf, sizeof(buf));\r
+ CString current(buf);\r
+ switch (GetWindowTextType(text)) {\r
+ case IDS_WINDOW_TEXT_MATCH: // *foo*\r
+ return current.Find(text.Mid(1, len - 2)) >= 0;\r
+ case IDS_WINDOW_TEXT_MATCH_FORWARD: // foo*\r
+ return current.Left(len - 1) == text.Left(len - 1);\r
+ case IDS_WINDOW_TEXT_MATCH_BACKWARD: // *foo\r
+ return current.Right(len - 1) == text.Right(len - 1);\r
+ case IDS_WINDOW_TEXT_MATCH_FULL: // foo\r
+ return current == text;\r
+ }\r
+ return true;\r
+}\r
\r
BOOL CUtils::GetFindDialogTitle(CString *szDialogTitle)\r
{\r
\r
BOOL CUtils::IsXkeymacs()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe")) || !_tcsicmp(m_szApplicationName, _T("xkeymacs64.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("xkeymacs.exe"),\r
+ _T("xkeymacs64.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsChrome()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("chrome.exe"));\r
+ return AppName::Match(_T("chrome.exe"));\r
}\r
\r
BOOL CUtils::IsAstecX()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("astecx.exe"));\r
+ return AppName::Match(_T("astecx.exe"));\r
}\r
\r
BOOL CUtils::IsBecky()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("b2.exe"));\r
+ return AppName::Match(_T("b2.exe"));\r
}\r
\r
BOOL CUtils::IsEmacs()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Emacs.exe"));\r
+ return AppName::Match(_T("Emacs.exe"));\r
}\r
\r
BOOL CUtils::IsExplorer()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("explorer.exe"));\r
+ return AppName::Match(_T("explorer.exe"));\r
}\r
\r
BOOL CUtils::IsHidemaru()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("hidemaru.exe"));\r
+ return AppName::Match(_T("hidemaru.exe"));\r
}\r
\r
BOOL CUtils::IsInternetExplorer()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("iexplore.exe"));\r
+ return AppName::Match(_T("iexplore.exe"));\r
}\r
\r
BOOL CUtils::IsLotus123()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("123w.exe"));\r
+ return AppName::Match(_T("123w.exe"));\r
}\r
\r
BOOL CUtils::IsLotusNotes()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("nlnotes.exe"));\r
+ return AppName::Match(_T("nlnotes.exe"));\r
}\r
\r
BOOL CUtils::IsLotusWordPro()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("wordpro.exe"));\r
+ return AppName::Match(_T("wordpro.exe"));\r
}\r
\r
BOOL CUtils::IsMeadow()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Meadow.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("Meadow95.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("MeadowNT.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("Meadow.exe"),\r
+ _T("Meadow95.exe"),\r
+ _T("MeadowNT.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsMicrosoftFrontPage()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("frontpg.exe"));\r
+ return AppName::Match(_T("frontpg.exe"));\r
}\r
\r
BOOL CUtils::IsMicrosoftWord()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("winword.exe"));\r
+ return AppName::Match(_T("winword.exe"));\r
}\r
\r
BOOL CUtils::IsMozilla()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("mozilla.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("firefox.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("mozilla.exe"),\r
+ _T("firefox.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsMuleForWin32()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("mule.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("mulent.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("mulecd.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("mule.exe"),\r
+ _T("mulent.exe"),\r
+ _T("mulecd.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsNetscape()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("netscp6.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("netscp.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("netscp6.exe"),\r
+ _T("netscp.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsNotepad()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("notepad.exe"));\r
+ return AppName::Match(_T("notepad.exe"));\r
}\r
\r
BOOL CUtils::IsNotepadPP()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("notepad++.exe"));\r
+ return AppName::Match(_T("notepad++.exe"));\r
}\r
\r
BOOL CUtils::IsOpera()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("opera.exe"));\r
+ return AppName::Match(_T("opera.exe"));\r
}\r
\r
BOOL CUtils::IsOutlook()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("outlook.exe"));\r
+ return AppName::Match(_T("outlook.exe"));\r
}\r
\r
BOOL CUtils::IsOutlookExpress()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("msimn.exe"));\r
+ return AppName::Match(_T("msimn.exe"));\r
}\r
\r
BOOL CUtils::IsSakuraEditor()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("sakura.exe"));\r
+ return AppName::Match(_T("sakura.exe"));\r
}\r
\r
BOOL CUtils::IsTeraTermPro()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("ttermpro.exe"));\r
+ return AppName::Match(_T("ttermpro.exe"));\r
}\r
\r
BOOL CUtils::IsVisualCpp()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("msdev.exe"));\r
+ return AppName::Match(_T("msdev.exe"));\r
}\r
\r
BOOL CUtils::IsWordpad()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("wordpad.exe"));\r
+ return AppName::Match(_T("wordpad.exe"));\r
}\r
\r
BOOL CUtils::IsXWin()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("XWin.exe"));\r
+ return AppName::Match(_T("XWin.exe"));\r
}\r
\r
BOOL CUtils::IsXyzzy()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("xyzzy.exe"));\r
-}\r
-\r
-LPCTSTR const CUtils::GetApplicationName()\r
-{\r
- return m_szApplicationName;\r
-}\r
-\r
-void CUtils::FairConsoleApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
-{\r
- if (IsFindDialog()) {\r
- return;\r
- }\r
-\r
- if (*szWindowText == '"' && _tcschr(szWindowText+1, _T('"'))) { // "foo bar" -> foo bar\r
- int len = _tcschr(szWindowText+1, _T('"')) - szWindowText - 1; // length of "foo bar"\r
- memmove(szWindowText, szWindowText + 1, len);\r
- memset(szWindowText + len, 0, WINDOW_TEXT_LENGTH - len);\r
- } else if (_tcschr(szWindowText, _T(' '))) { // foo bar -> foo\r
- LPTSTR p = _tcschr(szWindowText, _T(' '));\r
- memset(p, 0, WINDOW_TEXT_LENGTH - (p - szWindowText));\r
- }\r
-\r
- memset(szApplicationName, 0, MAX_PATH);\r
- _stprintf_s(szApplicationName, MAX_PATH, _T("%s"), szWindowText);\r
-\r
- static LPCTSTR const szExe = _T(".exe");\r
- if (_tcsnicmp(szApplicationName + _tcslen(szApplicationName) - _tcslen(szExe), szExe, _tcslen(szExe))) {\r
- _tcscat_s(szApplicationName, MAX_PATH, szExe);\r
- }\r
-}\r
-\r
-// Set real application name in the szApplicationName.\r
-void CUtils::SetCorrectApplicationName(LPTSTR szApplicationName, LPTSTR szWindowText)\r
-{\r
- if (IsConsole(szApplicationName)) {\r
- int i = 0;\r
- static LPCTSTR const szPromptName[] = {_T("Command Prompt"), _T("Mark Command Prompt"), _T("Select Command Prompt"), _T("MS-DOS Prompt"),\r
- _T("Visual Studio .NET Command Prompt"), _T("Visual Studio .NET 2003 Command Prompt"),\r
- _T("\83R\83}\83\93\83h \83v\83\8d\83\93\83v\83g"), _T("\94Í\88Í\8ew\92è \83R\83}\83\93\83h \83v\83\8d\83\93\83v\83g"), _T("\91I\91ð \83R\83}\83\93\83h \83v\83\8d\83\93\83v\83g"), _T("MS-DOS \83v\83\8d\83\93\83v\83g"),\r
- _T("Visual Studio .NET \83R\83}\83\93\83h \83v\83\8d\83\93\83v\83g"), _T("Visual Studio .NET 2003 \83R\83}\83\93\83h \83v\83\8d\83\93\83v\83g")};\r
- static LPCTSTR const szPromptPath[] = {_T("system32\\cmd.exe")}; // WindowText of Command Prompt is sometimes this style. But MS-DOS Prompt's is always MS-DOS Prompt.\r
- static LPCTSTR const szSeparator = _T(" - ");\r
-\r
- for (i = 0; i < sizeof(szPromptName) / sizeof(szPromptName[0]); ++i) {\r
- if (!_tcsicmp(szWindowText, szPromptName[i])) { // "Command Prompt"\r
- return;\r
- }\r
-\r
- TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
- _stprintf_s(sz, _T("%s%s"), szPromptName[i], szSeparator);\r
-\r
- if (!_tcsnicmp(szWindowText, sz, _tcslen(sz))) { // "Command Promp - foo"\r
- _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, szWindowText + _tcslen(sz));\r
- FairConsoleApplicationName(szApplicationName, szWindowText);\r
- return;\r
- }\r
- }\r
-\r
- for (i = 0; i < sizeof(szPromptPath) / sizeof(szPromptPath[0]); ++i) {\r
- TCHAR lower[WINDOW_TEXT_LENGTH] = {'\0'};\r
- _tcscpy_s(lower, szWindowText);\r
- _tcslwr_s(lower);\r
-\r
- if (_tcsstr(lower, szPromptPath[i])) {\r
- TCHAR sz[WINDOW_TEXT_LENGTH] = {'\0'};\r
- _stprintf_s(sz, _T("%s%s"), szPromptPath[i], szSeparator);\r
-\r
- if (_tcsstr(lower, sz)) { // "X:\WINNT\system32\cmd.exe - foo"\r
- _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, _tcsstr(lower, sz) + _tcslen(sz));\r
- FairConsoleApplicationName(szApplicationName, szWindowText);\r
- return;\r
- } else { // "X:\WINNT\system32\cmd.exe"\r
- return;\r
- }\r
- }\r
- }\r
-\r
- LPTSTR newName = NULL, newText = NULL;\r
- if (!_tcsicmp(szWindowText, _T("Cygwin Bash Shell"))\r
- || (*szWindowText == _T('~'))\r
- || (*szWindowText == _T('/'))) { // Bash\r
- newName = _T("bash.exe");\r
- newText = _T("bash");\r
- } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 8, _T(" - pdksh"))) {\r
- newName = _T("pdksh.exe");\r
- newText = _T("pdksh");\r
- } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 7, _T(" - tcsh"))) {\r
- newName = _T("tcsh.exe");\r
- newText = _T("tcsh");\r
- } else if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 6, _T(" - zsh"))) {\r
- newName = _T("zsh.exe");\r
- newText = _T("zsh");\r
- } else if (!_tcsnicmp(szWindowText, _T("MKS Korn Shell"), 14)\r
- || !_tcsnicmp(szWindowText, _T("cat"), 3)) {\r
- newName = _T("sh.exe");\r
- newText = _T("MKS Korn Shell");\r
- } else if (!_tcsnicmp(szWindowText + 1, _T(":/"), 2)\r
- || !_tcsnicmp(szWindowText + 1, _T(":\\"), 2)) {\r
- newName = _T("csh.exe");\r
- newText = _T("C Shell");\r
- } else if (_tcsstr(szWindowText, _T(" - VIM"))) {\r
- newName = _T("vim.exe");\r
- newText = _T("VIM");\r
- } else if (_tcsstr(szWindowText, _T(" - Poderosa"))) {\r
- newName = _T("Poderosa.exe");\r
- newText = _T("Poderosa");\r
- } else { // unknown console application\r
- FairConsoleApplicationName(szApplicationName, szWindowText);\r
- }\r
- if (newName) {\r
- memset(szApplicationName, 0, MAX_PATH);\r
- _tcscpy_s(szApplicationName, MAX_PATH, newName);\r
- memset(szWindowText, 0, WINDOW_TEXT_LENGTH);\r
- _tcscpy_s(szWindowText, WINDOW_TEXT_LENGTH, newText);\r
- }\r
- } else if (IsJavaW(szApplicationName)) {\r
- LPTSTR newName = NULL;\r
- if (!_tcsicmp(szWindowText + _tcslen(szWindowText) - 19, _T(" - Eclipse Platform"))) {\r
- newName = _T("eclipse.exe");\r
- } else if (!_tcsicmp(szWindowText, _T("BlueJ"))\r
- || !_tcsnicmp(szWindowText, _T("BlueJ: "), 7)) {\r
- newName = _T("bluej.exe");\r
- } else if (!_tcsicmp(szWindowText, _T("JUDE"))\r
- || !_tcsnicmp(szWindowText, _T("JUDE - "), 7)) {\r
- newName = _T("jude.exe");\r
- }\r
- if (newName) {\r
- memset(szApplicationName, 0, MAX_PATH);\r
- _tcscpy_s(szApplicationName, MAX_PATH, newName);\r
- }\r
- }\r
- return;\r
-}\r
-\r
-void CUtils::SetApplicationName(BOOL bImeComposition)\r
-{\r
-// CUtils::Log(_T("SetApplicationName: start"));\r
-\r
- memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
-\r
- if (_tcscmp(m_szIMEName, _T("IME")) == 0) { // IDS_IME_FILE_NAME\r
- HKL hKL = GetKeyboardLayout(0);\r
- if (ImmIsIME(hKL)) {\r
- if (!ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName))) {\r
- _tcsncpy_s(m_szIMEName, _T("IME"), _TRUNCATE); // IDS_IME_FILE_NAME\r
- }\r
-// CUtils::Log(_T("SetApplicationName: m_szIMEName == %s"), m_szIMEName);\r
- }\r
- }\r
-\r
- if (bImeComposition) {\r
-// CUtils::Log(_T("SetApplicationName: bImeComposition"));\r
-\r
- HKL hKL = GetKeyboardLayout(0);\r
- if (ImmIsIME(hKL)) {\r
- if (!ImmGetIMEFileName(hKL, m_szApplicationName, sizeof(m_szApplicationName))) {\r
- _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);\r
- }\r
- _tcsncpy_s(m_szIMEName, m_szApplicationName, sizeof(m_szIMEName));\r
- } else {\r
- // ImmIsIME return 0 on Word2002, Excel2002, etc. with IME2002, so...\r
- // _tcsncpy(m_szApplicationName, _T("imjp81.ime"), sizeof(m_szApplicationName));\r
- _tcsncpy_s(m_szApplicationName, m_szIMEName, _TRUNCATE);\r
- }\r
- } else {\r
-// CUtils::Log(_T("SetApplicationName: appication (%s)"), m_szApplicationName);\r
-\r
- GetModuleFileName(NULL, m_szApplicationName, sizeof(m_szApplicationName));\r
- CString szFn(m_szApplicationName);\r
- szFn.Delete(0, szFn.ReverseFind(_T('\\')) + 1);\r
- ZeroMemory(m_szApplicationName, sizeof(m_szApplicationName));\r
- _tcscpy_s(m_szApplicationName, szFn);\r
-\r
-// CUtils::Log(_T("SetApplicationName: appication [%s]"), m_szApplicationName);\r
-\r
- if (IsConsole()) {\r
-// CUtils::Log(_T("SetApplicationName: console"));\r
-\r
- memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
- _tcscpy_s(m_szApplicationName, _T("CMD.exe"));\r
- TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
- GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
- SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
- } else if (IsJavaW()) {\r
- TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
- GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
- SetCorrectApplicationName(m_szApplicationName, szWindowText);\r
- }\r
- if (!_tcsicmp(m_szApplicationName, _T("Cygwin.exe"))) {\r
-// CUtils::Log(_T("SetApplicationName: cygwin"));\r
-\r
- memset(m_szApplicationName, 0, sizeof(m_szApplicationName));\r
- _tcscpy_s(m_szApplicationName, _T("bash.exe"));\r
- }\r
-// CUtils::Log(_T("name: %s"), m_szApplicationName);\r
- }\r
+ return AppName::Match(_T("xyzzy.exe"));\r
}\r
\r
BOOL CUtils::OpenClipboard()\r
const LPVOID pMem = GlobalLock(hClipboard);\r
if (!pMem)\r
return FALSE;\r
- text = reinterpret_cast<LPCSTR>(pMem);\r
+ text = reinterpret_cast<LPCTSTR>(pMem);\r
GlobalUnlock(hClipboard);\r
EmptyClipboard();\r
CloseClipboard();\r
\r
BOOL CUtils::IsDWFM()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("dwfm.exe"));\r
+ return AppName::Match(_T("dwfm.exe"));\r
}\r
\r
BOOL CUtils::IsK2Editor()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("K2Editor.exe"));\r
+ return AppName::Match(_T("K2Editor.exe"));\r
}\r
\r
BOOL CUtils::IsEggExplorer()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("EggExp.exe"));\r
+ return AppName::Match(_T("EggExp.exe"));\r
}\r
\r
BOOL CUtils::IsDirector()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Director.exe"));\r
+ return AppName::Match(_T("Director.exe"));\r
}\r
\r
BOOL CUtils::IsExcel()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Excel.exe"));\r
+ return AppName::Match(_T("Excel.exe"));\r
}\r
\r
BOOL CUtils::IsFireworks()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Fireworks 4.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("Fireworks.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("Fireworks 4.exe"),\r
+ _T("Fireworks.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsDreamweaver()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Dreamweaver.exe"));\r
+ return AppName::Match(_T("Dreamweaver.exe"));\r
}\r
\r
BOOL CUtils::IsFlash()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Flash.exe"));\r
+ return AppName::Match(_T("Flash.exe"));\r
}\r
\r
BOOL CUtils::IsPhotoshop()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Photoshp.exe"));\r
+ return AppName::Match(_T("Photoshp.exe"));\r
}\r
\r
BOOL CUtils::IsIllustrator()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Illustrator.exe"));\r
+ return AppName::Match(_T("Illustrator.exe"));\r
}\r
\r
BOOL CUtils::IsMicrosoftPowerPoint()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("PowerPnt.exe"));\r
+ return AppName::Match(_T("PowerPnt.exe"));\r
}\r
\r
BOOL CUtils::IsReget()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Regetdx.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("Regetjr.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("Regetdx.exe"),\r
+ _T("Regetjr.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsPaint()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("mspaint.exe"));\r
-}\r
-\r
-BOOL CUtils::IsConsole()\r
-{\r
-// Log(_T("_%s_"), m_szApplicationName);\r
- return !m_szApplicationName[0]\r
- || !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("conhost.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("conime.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("csh.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("WINOA386.MOD"))\r
- || !_tcsicmp(m_szApplicationName, _T("CMD.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("bash.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("ftp.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("sh.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("telnet.exe"));\r
-}\r
-\r
-BOOL CUtils::IsConsole(LPCTSTR szApplicationName)\r
-{\r
- return !_tcsicmp(szApplicationName, _T("WINOA386.MOD"))\r
- || !_tcsicmp(szApplicationName, _T("CMD.exe"));\r
-}\r
-\r
-BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)\r
-{\r
- return !_tcsicmp(szApplicationName, _T("javaw.exe"));\r
+ return AppName::Match(_T("mspaint.exe"));\r
}\r
\r
BOOL CUtils::IsSleipnir()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Sleipnir.exe"));\r
+ return AppName::Match(_T("Sleipnir.exe"));\r
}\r
\r
BOOL CUtils::IsBash()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("bash.exe"));\r
+ return AppName::Match(_T("bash.exe"));\r
}\r
\r
static void invalid_parameter_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t)\r
{\r
va_list ap;\r
va_start(ap, fmt);\r
- TCHAR log[1024];\r
- _set_invalid_parameter_handler(invalid_parameter_handler);\r
- if (_vstprintf_s(log, fmt, ap) < 0)\r
- _tcscpy_s(log, _T("invalid format"));\r
-\r
+ TCHAR log[1024], msg[1024];\r
static int n = 0;\r
+ _set_invalid_parameter_handler(invalid_parameter_handler);\r
+ if (_vstprintf_s(msg, fmt, ap) < 0)\r
+ _tcscpy_s(msg, _T("invalid format"));\r
+ va_end(ap);\r
+ _stprintf_s(log, _T("%4d %8x: %s\t%s\r\n"), n++, GetCurrentThreadId(), AppName::GetAppName(), msg);\r
TCHAR path[MAX_PATH];\r
if (GetTempPath(MAX_PATH, path)) {\r
#ifndef _WIN64\r
- _tmakepath_s(path, NULL, path, _T("xkeylog"), _T("txt"));\r
+ _tmakepath_s(path, nullptr, path, _T("xkeylog"), _T("txt"));\r
#else\r
- _tmakepath_s(path, NULL, path, _T("xkeylog64"), _T("txt"));\r
+ _tmakepath_s(path, nullptr, path, _T("xkeylog64"), _T("txt"));\r
#endif\r
} else\r
_tcscpy_s(path, _T("c:\\xkeylog.txt"));\r
- FILE *fp;\r
- _tfopen_s(&fp, path, _T("a"));\r
- _ftprintf(fp, _T("%8d: %s\t%s\n"), n++, m_szApplicationName, log);\r
- fclose(fp);\r
+ HANDLE fh = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\r
+ if (fh == INVALID_HANDLE_VALUE)\r
+ return;\r
+ SetFilePointer(fh, 0, nullptr, FILE_END);\r
+ DWORD written;\r
+ WriteFile(fh, log, static_cast<DWORD>(strlen(log)), &written, nullptr);\r
+ CloseHandle(fh);\r
}\r
\r
BOOL CUtils::IsSh()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("sh.exe"));\r
+ return AppName::Match(_T("sh.exe"));\r
}\r
\r
BOOL CUtils::IsCsh()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("csh.exe"));\r
+ return AppName::Match(_T("csh.exe"));\r
}\r
\r
BOOL CUtils::IsVisualStudio()\r
\r
BOOL CUtils::IsAccess()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("MSACCESS.EXE"));\r
+ return AppName::Match(_T("MSACCESS.EXE"));\r
}\r
\r
BOOL CUtils::IsProject()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("WINPROJ.EXE"));\r
+ return AppName::Match(_T("WINPROJ.EXE"));\r
}\r
\r
BOOL CUtils::IsVisualBasic()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("VB6.EXE"));\r
+ return AppName::Match(_T("VB6.EXE"));\r
}\r
\r
BOOL CUtils::IsVisualBasicEditor()\r
\r
BOOL CUtils::IsEclipse()\r
{\r
- if (!_tcsicmp(m_szApplicationName, _T("eclipse.exe")))\r
- return TRUE;\r
-\r
- TCHAR szWindowText[WINDOW_TEXT_LENGTH] = {'\0'};\r
- GetWindowText(GetForegroundWindow(), szWindowText, sizeof(szWindowText));\r
-\r
- LPCTSTR szEclipse = _T(" - Eclipse Platform");\r
- LPCTSTR szFind = _T("Find/Replace");\r
-\r
- return IsJavaW()\r
- && (_tcslen(szEclipse) < _tcslen(szWindowText) && !_tcsicmp(szWindowText + _tcslen(szWindowText) - _tcslen(szEclipse), szEclipse)\r
- || _tcslen(szFind) == _tcslen(szWindowText) && !_tcsicmp(szWindowText, szFind));\r
+ return AppName::Match(_T("eclipse.exe"));\r
}\r
\r
BOOL CUtils::IsDialog()\r
\r
BOOL CUtils::IsEudora()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Eudora.exe"));\r
+ return AppName::Match(_T("Eudora.exe"));\r
}\r
\r
BOOL CUtils::IsCodeWarrior()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("IDE.exe"));\r
+ return AppName::Match(_T("IDE.exe"));\r
}\r
\r
BOOL CUtils::IseMemoPad()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("eMemoPad.exe"));\r
+ return AppName::Match(_T("eMemoPad.exe"));\r
}\r
\r
BOOL CUtils::IsStoryEditor()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("STRYEDIT.EXE"));\r
+ return AppName::Match(_T("STRYEDIT.EXE"));\r
}\r
\r
BOOL CUtils::IsNami2000()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Nami2000.exe"));\r
+ return AppName::Match(_T("Nami2000.exe"));\r
}\r
\r
BOOL CUtils::IsCorelDRAW()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("CorelDrw.exe"));\r
+ return AppName::Match(_T("CorelDrw.exe"));\r
}\r
\r
// If Clipboard data is empty, return true.\r
\r
BOOL CUtils::IsHusen()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("husen.exe"));\r
+ return AppName::Match(_T("husen.exe"));\r
}\r
\r
BOOL CUtils::IsAdobeReader()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("AcroRd32.exe"));\r
+ return AppName::Match(_T("AcroRd32.exe"));\r
}\r
\r
BOOL CUtils::IsOpenOffice()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("soffice.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("soffice.bin"));\r
+ LPCTSTR names[] = {\r
+ _T("soffice.exe"),\r
+ _T("soffice.bin"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsTuruKameMail()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("TuruKame.exe"));\r
+ return AppName::Match(_T("TuruKame.exe"));\r
}\r
\r
BOOL CUtils::IsOedit()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("oedit.exe"));\r
+ return AppName::Match(_T("oedit.exe"));\r
}\r
\r
BOOL CUtils::IsAutla()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Autla.exe"));\r
+ return AppName::Match(_T("Autla.exe"));\r
}\r
\r
BOOL CUtils::IsShuriken()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("JsvMail.exe"));\r
+ return AppName::Match(_T("JsvMail.exe"));\r
}\r
\r
BOOL CUtils::IsEdLeaf()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("edleaf.exe"));\r
+ return AppName::Match(_T("edleaf.exe"));\r
}\r
\r
BOOL CUtils::IsJmEditor()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("JmEdit.exe"))\r
- || !_tcsicmp(m_szApplicationName, _T("JmEdit2.exe"));\r
+ LPCTSTR names[] = {\r
+ _T("JmEdit.exe"),\r
+ _T("JmEdit2.exe"),\r
+ };\r
+ return AppName::Match(names);\r
}\r
\r
BOOL CUtils::IsDana()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Dana.exe"));\r
+ return AppName::Match(_T("Dana.exe"));\r
}\r
\r
BOOL CUtils::IsIPMessenger()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("ipmsg.exe"));\r
+ return AppName::Match(_T("ipmsg.exe"));\r
}\r
\r
BOOL CUtils::IsezHTML()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("ezhtml.exe"));\r
+ return AppName::Match(_T("ezhtml.exe"));\r
}\r
\r
BOOL CUtils::IsTcsh()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("tcsh.exe"));\r
+ return AppName::Match(_T("tcsh.exe"));\r
}\r
\r
BOOL CUtils::IsZsh()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("zsh.exe"));\r
+ return AppName::Match(_T("zsh.exe"));\r
}\r
\r
BOOL CUtils::IsPdksh()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("pdksh.exe"));\r
+ return AppName::Match(_T("pdksh.exe"));\r
}\r
\r
BOOL CUtils::IsFirefox()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("firefox.exe"));\r
+ return AppName::Match(_T("firefox.exe"));\r
}\r
\r
BOOL CUtils::IsPHPEditor()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("php_editor.exe"));\r
+ return AppName::Match(_T("php_editor.exe"));\r
}\r
\r
BOOL CUtils::IsTeraPad()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("TeraPad.exe"));\r
+ return AppName::Match(_T("TeraPad.exe"));\r
}\r
\r
BOOL CUtils::IsLispWorksPersonalEdition()\r
{\r
- CString szLispWorks(_T("lispworks-personal-"));\r
- return !_tcsnicmp(m_szApplicationName, szLispWorks, szLispWorks.GetLength());\r
-\r
-// return !_tcsicmp(m_szApplicationName, _T("lispworks-personal-4300.exe"));\r
+ TCHAR prefix[] = _T("lispworks-personal-");\r
+ return !_tcsnicmp(AppName::GetAppName(), prefix, _countof(prefix));\r
}\r
\r
BOOL CUtils::IsBorlandCppBuilder()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("bcb.exe"));\r
+ return AppName::Match(_T("bcb.exe"));\r
}\r
\r
BOOL CUtils::Run(CString szCommandLine, BOOL isWait)\r
\r
BOOL CUtils::IsJavaW()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("javaw.exe"));\r
+ return AppName::Match(_T("javaw.exe"));\r
}\r
\r
BOOL CUtils::IsMSDN()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("hh.exe"));\r
+ return AppName::Match(_T("hh.exe"));\r
}\r
\r
BOOL CUtils::IsVisualSlickEdit()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("vs.exe"));\r
+ return AppName::Match(_T("vs.exe"));\r
}\r
\r
BOOL CUtils::IsOpenJane()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Jane2ch.exe"));\r
+ return AppName::Match(_T("Jane2ch.exe"));\r
}\r
\r
BOOL CUtils::IsThunderbird()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("thunderbird.exe"));\r
-}\r
-\r
-int CUtils::GetWindowTextType(CString strWindowText)\r
-{\r
- int nWindowTextType = IDS_WINDOW_TEXT_IGNORE;\r
-\r
- if (3 <= strWindowText.GetLength()\r
- && strWindowText.Find(_T('*')) == 0\r
- && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH;\r
- } else if (2 <= strWindowText.GetLength()\r
- && strWindowText.Find(_T('*')) != 0\r
- && strWindowText.ReverseFind(_T('*')) == strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH_FORWARD;\r
- } else if (2 <= strWindowText.GetLength()\r
- && strWindowText.Find(_T('*')) == 0\r
- && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH_BACKWARD;\r
- } else if (!strWindowText.IsEmpty()\r
- && strWindowText.Find(_T('*')) != 0\r
- && strWindowText.ReverseFind(_T('*')) != strWindowText.GetLength() - 1) {\r
- nWindowTextType = IDS_WINDOW_TEXT_MATCH_FULL;\r
- }\r
-\r
- return nWindowTextType;\r
+ return AppName::Match(_T("thunderbird.exe"));\r
}\r
\r
BOOL CUtils::IsLunascape()\r
{\r
- return !_tcsicmp(m_szApplicationName, _T("Luna.exe"));\r
+ return AppName::Match(_T("Luna.exe"));\r
}\r
\r
BOOL CUtils::IsAtok()\r
{\r
- return !_tcsnicmp(m_szApplicationName, _T("ATOK"), 4) && !_tcsnicmp(m_szApplicationName + _tcslen(m_szApplicationName) - 4, _T(".IME"), 4);\r
+ LPCTSTR name = AppName::GetAppName();\r
+ return !_tcsnicmp(name, _T("ATOK"), 4) && !_tcsicmp(name + _tcslen(name) - 4, _T(".IME"));\r
}\r