--- /dev/null
+#include "AppName.h"\r
+#include "Utils.h"\r
+#include <Imm.h>\r
+\r
+#pragma data_seg(".xkmcs")\r
+TCHAR AppName::m_FallbackIMEName[MAX_PATH] = _T("");\r
+#pragma data_seg()\r
+TCHAR AppName::m_AppName[MAX_PATH] = _T("");\r
+TCHAR AppName::m_IMEName[MAX_PATH] = _T("");\r
+bool AppName::m_Inited = false;\r
+bool AppName::m_IMEState = false;\r
+\r
+void AppName::Init()\r
+{\r
+ if (m_Inited)\r
+ return;\r
+ if (m_FallbackIMEName[0] == _T('\0')) {\r
+ // preserve the IME file name of the current TIF if it works as an Imm32 IME.\r
+ HKL hKL = GetKeyboardLayout(0);\r
+ if (!ImmIsIME(hKL) || !ImmGetIMEFileName(hKL, m_FallbackIMEName, MAX_PATH))\r
+ _tcscpy_s(m_FallbackIMEName, _T("IME"));\r
+ }\r
+ TCHAR path[MAX_PATH];\r
+ GetModuleFileName(NULL, path, MAX_PATH);\r
+ CString s(path);\r
+ s.Delete(0, s.ReverseFind(_T('\\')) + 1);\r
+ _tcscpy_s(m_AppName, s);\r
+ TCHAR text[WINDOW_TEXT_LENGTH];\r
+ GetWindowText(GetForegroundWindow(), text, sizeof(text));\r
+ CorrectAppName(text, m_AppName);\r
+}\r
+\r
+LPCTSTR AppName::GetAppName()\r
+{\r
+ return m_IMEState ? m_IMEName : m_AppName;\r
+}\r
+\r
+void AppName::SetIMEState(bool on)\r
+{\r
+ m_IMEState = on;\r
+ if (!on)\r
+ return;\r
+ HKL hKL = GetKeyboardLayout(0);\r
+ if (ImmIsIME(hKL)) {\r
+ if (!ImmGetIMEFileName(hKL, m_IMEName, sizeof(m_IMEName)))\r
+ _tcscpy_s(m_IMEName, _T("IME")); // TIP on TSF\r
+ return;\r
+ }\r
+ // ImmIsIME returns false if you use TSF aware applications with a TIF (aka IME).\r
+ // The following take the preserved IME file name of it.\r
+ _tcscpy_s(m_IMEName, m_FallbackIMEName);\r
+}\r
+\r
+// The code starting here is derived from work by co <cogood\81\97gmail.com>.\r
+void AppName::CorrectAppName(TCHAR (&text)[WINDOW_TEXT_LENGTH], TCHAR (&appName)[MAX_PATH])\r
+{\r
+ CString s(text);\r
+ if (IsConsole(appName)) {\r
+ RemovePrefixes(s);\r
+ int prev, sep;\r
+ for (prev = -1, sep = 0; (sep = s.Find(_T(" - "), sep)) >= 0; prev = sep, sep += 3)\r
+ ;\r
+ if (prev >= 0) {\r
+ s.Delete(0, prev + 3);\r
+ ConsoleAppName(s, appName);\r
+ _tcscpy_s(text, s);\r
+ return;\r
+ }\r
+ if (IsCmdExe(s)) {\r
+ _tcscpy_s(appName, "cmd.exe");\r
+ _tcscpy_s(text, s);\r
+ return;\r
+ }\r
+ if (s.Find(_T("Cygwin Bash Shell")) == 0 ||\r
+ s[0] == _T('~') || s[0] == _T('/')) {\r
+ _tcscpy_s(appName, _T("bash.exe"));\r
+ _tcscpy_s(text, _T("Cygwin Bash Shell"));\r
+ } else if (s.Find(_T("MKS Korn Shell")) == 0 || s.Find(_T("cat")) == 0) {\r
+ _tcscpy_s(appName, _T("sh.exe"));\r
+ } else if (s.Find(_T(":/"), 1) == 1 || s.Find(_T(":\\"), 1) == 1) {\r
+ _tcscpy_s(appName, _T("csh.exe"));\r
+ _tcscpy_s(text, "C Shell");\r
+ } else {\r
+ ConsoleAppName(s, appName);\r
+ _tcscpy_s(text, s);\r
+ }\r
+ } else if (!_tcsicmp(appName, _T("javaw.exe"))) {\r
+ if (s.Find(_T(" - Eclipse Platform")) || s == _T("Find/Replace"))\r
+ _tcscpy_s(appName, "eclipse.exe");\r
+ else if (s.Find(_T("BlueJ")))\r
+ _tcscpy_s(appName, "bluej.exe");\r
+ else if (s.Find(_T("JUDE")))\r
+ _tcscpy_s(appName, "jude.exe");\r
+ }\r
+}\r
+\r
+bool AppName::IsConsole()\r
+{\r
+ return IsConsole(m_AppName);\r
+}\r
+\r
+bool AppName::IsConsole(LPCTSTR appName)\r
+{\r
+ LPCTSTR names[] = {\r
+ "conhost.exe",\r
+ "conime.exe",\r
+ "csh.exe",\r
+ "cmd.exe",\r
+ "bash.exe",\r
+ "ftp.exe",\r
+ "sh.exe",\r
+ "telnet.exe",\r
+ };\r
+ if (!appName[0])\r
+ return true;\r
+ for (int i = 0; i < _countof(names); ++i)\r
+ if (!_tcsicmp(appName, names[i]))\r
+ return true;\r
+ return false;\r
+}\r
+\r
+bool AppName::IsCmdExe(const CString& text)\r
+{\r
+ LPCTSTR prompts[] = {\r
+ _T("command prompt"),\r
+ _T("\83R\83}\83\93\83h \83v\83\8d\83\93\83v\83g"),\r
+ _T("system32\\cmd.exe"),\r
+ _T("syswow64\\cmd.exe")\r
+ };\r
+ for (int i = 0; i < _countof(prompts); ++i)\r
+ if (text.Right(_tcslen(prompts[i])).CompareNoCase(prompts[i]) == 0)\r
+ return true;\r
+ return false;\r
+}\r
+\r
+void AppName::ConsoleAppName(CString& text, TCHAR (&appName)[MAX_PATH])\r
+{\r
+ int endQuote = text.Find(_T('"'), 1);\r
+ int space = text.Find(_T(' '), 1);\r
+ if (text[0] == _T('"') && endQuote > 0)\r
+ text = text.Mid(1, endQuote - 1); // A string surrounded by " is a command name.\r
+ else if (space >= 0)\r
+ text = text.Left(space + 1); // The first token is a command name.\r
+ int backSlash = text.ReverseFind(_T('\\')); // remove its directory.\r
+ if (backSlash >= 0)\r
+ text.Delete(0, backSlash + 1);\r
+ _tcsncpy_s(appName,\r
+ text.Right(4).CompareNoCase(_T(".exe")) == 0\r
+ ? text : text + _T(".exe"), _TRUNCATE);\r
+}\r
+\r
+void AppName::RemovePrefixes(CString& text)\r
+{\r
+ LPCTSTR prefixes[] = {\r
+ _T("\94Í\88Í\8ew\92è "), // via the edit menu\r
+ _T("\83X\83N\83\8d\81[\83\8b "), // via the edit menu\r
+ _T("\91I\91ð "), // via QuickEdit\r
+ _T("\8aÇ\97\9d\8eÒ: "), // remove it last\r
+ _T("Mark "),\r
+ _T("Scroll "),\r
+ _T("Select "),\r
+ _T("Administrator: "),\r
+ };\r
+ for (int i = 0; i < _countof(prefixes); ++i)\r
+ if (text.Find(prefixes[i]) == 0)\r
+ text.Delete(0, static_cast<int>(_tcslen(prefixes[i])));\r
+}\r
+// The derived code ends here.\r
+\r
+bool AppName::Match(LPCTSTR name)\r
+{\r
+ LPCTSTR names[1] = { name };\r
+ return Match(names);\r
+}\r
#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
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
\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
#endif\r
} else\r
_tcscpy_s(path, _T("c:\\xkeylog.txt"));\r
+\r
FILE *fp;\r
_tfopen_s(&fp, path, _T("a"));\r
- _ftprintf(fp, _T("%8d: %s\t%s\n"), n++, m_szApplicationName, log);\r
+ _ftprintf(fp, _T("%8d: %s\t%s\n"), n++, AppName::GetAppName(), log);\r
fclose(fp);\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
+ return AppName::Match(_T("thunderbird.exe"));\r
}\r
\r
int CUtils::GetWindowTextType(CString strWindowText)\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