OSDN Git Service

Change the platform toolset to v140
[xkeymacs/xkeymacs.git] / xkeymacsdll / Utils.cpp
index 6b752cb..4636ec6 100644 (file)
@@ -2,28 +2,47 @@
 //\r
 //////////////////////////////////////////////////////////////////////\r
 \r
-#include "stdafx.h"\r
 #include "Utils.h"\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
-OSVERSIONINFO CUtils::m_OsVersionInfo = {sizeof(OSVERSIONINFO)};\r
-#pragma data_seg()\r
 \r
-//////////////////////////////////////////////////////////////////////\r
-// Construction/Destruction\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-CUtils::CUtils()\r
+bool CUtils::IsConsole()\r
 {\r
-\r
+       return AppName::IsConsole();\r
 }\r
 \r
-CUtils::~CUtils()\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
@@ -63,479 +82,222 @@ BOOL CUtils::IsFindDialog()
        return GetFindDialogTitle(&szDialogTitle);\r
 }\r
 \r
-BOOL CUtils::IsAstecX()\r
+BOOL CUtils::IsXkeymacs()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("astecx.exe"));\r
+       LPCTSTR names[] = {\r
+               _T("xkeymacs.exe"),\r
+               _T("xkeymacs64.exe"),\r
+       };\r
+       return AppName::Match(names);\r
 }\r
 \r
-BOOL CUtils::IsXkeymacs()\r
+BOOL CUtils::IsChrome()\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("xkeymacs.exe")) || !_tcsicmp(m_szApplicationName, _T("xkeymacs64.exe"));\r
+       return AppName::Match(_T("chrome.exe"));\r
+}\r
+\r
+BOOL CUtils::IsAstecX()\r
+{\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 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\83\83v\83\8d\83\93\83v\83g"), _T("\94Í\88Í\8ew\92è \83R\83}\83\93\83\83v\83\8d\83\93\83v\83g"), _T("\91I\91ð \83R\83}\83\93\83\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\83\83v\83\8d\83\93\83v\83g"), _T("Visual Studio .NET 2003 \83R\83}\83\93\83\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
-}\r
-\r
-void CUtils::SetIMEName()\r
-{\r
-       HKL hKL = GetKeyboardLayout(0);\r
-       if (ImmIsIME(hKL)) {\r
-               ImmGetIMEFileName(hKL, m_szIMEName, sizeof(m_szIMEName));\r
-       }\r
-}\r
-\r
-void CUtils::InitCUtils()\r
-{\r
-       GetVersionEx(&m_OsVersionInfo);\r
-       SetIMEName();\r
-}\r
-\r
-BOOL CUtils::IsXPorLater()\r
-{\r
-       return 5 < m_OsVersionInfo.dwMajorVersion\r
-               || 5 == m_OsVersionInfo.dwMajorVersion && 1 <= m_OsVersionInfo.dwMinorVersion;\r
+       return AppName::Match(_T("xyzzy.exe"));\r
 }\r
 \r
 BOOL CUtils::OpenClipboard()\r
 {\r
-       const int RETRY_COUNT = 0x10;\r
-\r
-       BOOL bOpened = FALSE;\r
-       for (int i = 0; i <= RETRY_COUNT; ++i) {\r
-               if (::OpenClipboard(NULL)) {\r
-//                     Log(_T("ok (%d)"), i);\r
-                       bOpened = TRUE;\r
-                       break;\r
-               } else {\r
-                       Sleep(1);       // for OpenOffice\r
-//                     Log(_T("CUtils::OpenClipboard: %d (%d)"), GetLastError(), i);\r
-               }\r
-       }\r
-       ASSERT(bOpened);\r
-       return bOpened;\r
+       // OpenClipboard will fail on OpenOffice.org/LibreOffice at the first time\r
+       // and we must retry multiple times.\r
+       for (int i = 0; i < 10; ++i, Sleep(1))\r
+               if (::OpenClipboard(NULL))\r
+                       return TRUE;\r
+//             else\r
+//                     Log(_T("failed to open clipboard: %d (%d)"), GetLastError(), i);\r
+       return FALSE;\r
 }\r
 \r
-BOOL CUtils::GetClipboardText(CString *szClipboardText)\r
+BOOL CUtils::GetClipboardText(CString& text)\r
 {\r
-       if (!szClipboardText) {\r
-               return FALSE;\r
-       }\r
-\r
-       szClipboardText->Empty();\r
-\r
-       if (!OpenClipboard()) {\r
-//             CUtils::Log(_T("Cannot open the Clipboard"));\r
+       text.Empty();\r
+       if (!OpenClipboard())\r
                return FALSE;\r
-       }\r
-\r
 /*\r
-       {\r
-               Log(_T("GetClipboardText"));\r
-               UINT uFormat = 0;\r
-               for (;;) {\r
-                       uFormat = EnumClipboardFormats(uFormat);\r
-                       if (uFormat) {\r
-                               Log(_T("uFormat = %d"), uFormat);\r
-                       } else {\r
-                               break;\r
-                       }\r
-               }\r
-// winuser.h\r
-//#define CF_TEXT             1\r
-//#define CF_METAFILEPICT     3\r
-//#define CF_OEMTEXT          7\r
-//#define CF_UNICODETEXT      13\r
-//#define CF_ENHMETAFILE      14\r
-//#define CF_LOCALE           16\r
-//#define CF_DSPTEXT          0x0081\r
-// OwnerLink                                           49155\r
-// Native                                                      49156\r
-// DataObject                                          49161\r
-// Embed Source                                                49163\r
-// Object Descriptor                           49166\r
-// Ole Private Data                                    49171\r
-// Rich Text Format                                    49311\r
-// Rich Text Format                                    49312\r
-// HTML Format                                         49360\r
-// HTML Format                                         49361\r
-// Link                                                                49408\r
-// RTF As Text                                         49595\r
-// Rich Text Format Without Objects    49618\r
-// Star Object Descriptor (XML)                49681\r
-// Star Embed Source (XML)                     49708\r
-// HPB HTML Format                                     49742\r
-       }\r
+       Log(_T("GetClipboardText"));\r
+       UINT uFormat = 0;\r
+       while (uFormat = EnumClipboardFormats(uFormat))\r
+               Log(_T("uFormat = %d"), uFormat);\r
 */\r
-\r
-       UINT uFormat = CF_OEMTEXT;\r
-       if (IsSakuraEditor()) {\r
-               uFormat = CF_TEXT;\r
-       }\r
-\r
-       HANDLE hClipboardText;\r
-       if ((hClipboardText = ::GetClipboardData(uFormat)) == NULL) {\r
-//             DWORD dw = GetLastError();\r
-//             CUtils::Log(_T("Unable to get Clipboard data: %d"), dw);\r
+       const HANDLE hClipboard = GetClipboardData(CF_TEXT);\r
+       if (!hClipboard) {\r
                CloseClipboard();\r
                return FALSE;\r
        }\r
-\r
-       szClipboardText->Format(_T("%s"), hClipboardText);\r
+       const LPVOID pMem = GlobalLock(hClipboard);\r
+       if (!pMem)\r
+               return FALSE;\r
+       text = reinterpret_cast<LPCTSTR>(pMem);\r
+       GlobalUnlock(hClipboard);\r
        EmptyClipboard();\r
        CloseClipboard();\r
        return TRUE;\r
 }\r
 \r
-BOOL CUtils::SetClipboardText(CString *szClipboardText)\r
+BOOL CUtils::SetClipboardText(const CString& text)\r
 {\r
-       if (!OpenClipboard()) {\r
-//             CUtils::Log(_T("Cannot open the Clipboard in SetClipboardText"));\r
+       if (!OpenClipboard())\r
                return FALSE;\r
-       }\r
-\r
-       int nLength = szClipboardText->GetLength() + 1;\r
-       HGLOBAL hClipboardText = GlobalAlloc(GHND, nLength);\r
-       if (hClipboardText == NULL) {\r
-//             CUtils::Log(_T("Failed: GlobalAlloc in SetClipboardText"));\r
+       const int nLength = text.GetLength() + 1;\r
+       const HGLOBAL hClipboard = GlobalAlloc(GHND, nLength);\r
+       if (!hClipboard)\r
                return FALSE;\r
-       }\r
-\r
-       LPTSTR lpStr = (LPTSTR)GlobalLock(hClipboardText);\r
-       lstrcpyn(lpStr, *szClipboardText, nLength);\r
-       GlobalUnlock(hClipboardText);\r
+       const LPVOID pMem = GlobalLock(hClipboard);\r
+       memcpy(pMem, LPCTSTR(text), nLength);\r
+       GlobalUnlock(hClipboard);\r
        EmptyClipboard();\r
-\r
-       UINT uFormat = CF_OEMTEXT;\r
-       if (IsSakuraEditor()) {\r
-               uFormat = CF_TEXT;\r
-       }\r
-\r
-       if ((hClipboardText = ::SetClipboardData(uFormat, hClipboardText)) == NULL) {\r
-//             DWORD dw = GetLastError();\r
-//             CUtils::Log(_T("Unable to set Clipboard data: %d"), dw);\r
+       if (SetClipboardData(CF_TEXT, hClipboard) == NULL) {\r
                CloseClipboard();\r
                return FALSE;\r
        }\r
-\r
        CloseClipboard();\r
        return TRUE;\r
 }\r
@@ -564,198 +326,130 @@ BOOL CUtils::IsDefaultIgnoreApplication()
 \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
+       return AppName::Match(_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
+BOOL CUtils::IsSleipnir()\r
 {\r
-       return !_tcsicmp(szApplicationName, _T("WINOA386.MOD"))\r
-               || !_tcsicmp(szApplicationName, _T("CMD.exe"));\r
+       return AppName::Match(_T("Sleipnir.exe"));\r
 }\r
 \r
-BOOL CUtils::IsJavaW(LPCTSTR szApplicationName)\r
+BOOL CUtils::IsBash()\r
 {\r
-       return !_tcsicmp(szApplicationName, _T("javaw.exe"));\r
+       return AppName::Match(_T("bash.exe"));\r
 }\r
 \r
-BOOL CUtils::IsSleipnir()\r
+static void invalid_parameter_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t)\r
 {\r
-       return !_tcsicmp(m_szApplicationName, _T("Sleipnir.exe"));\r
-}\r
-\r
-BOOL CUtils::IsBash()\r
-{\r
-       return !_tcsicmp(m_szApplicationName, _T("bash.exe"));\r
+       return;\r
 }\r
 \r
 // for debug\r
-void CUtils::Log(LPTSTR fmt, ...)\r
+void CUtils::Log(LPCTSTR fmt, ...)\r
 {\r
        va_list ap;\r
        va_start(ap, fmt);\r
-\r
-       static const int LOG_MAX = 0x10000;\r
-       TCHAR szLog[LOG_MAX] = {'\0'};\r
-\r
-       for (unsigned int nIndex = 0; nIndex < _tcslen(fmt); ) {\r
-               LPTSTR pNextString = fmt + nIndex;\r
-               int len = _tcslen(szLog);\r
-               LPTSTR pLogEnd = szLog + len;\r
-\r
-               if (*pNextString == _T('%')) {\r
-                       TCHAR szFormatTag[LOG_MAX] = {'0'};\r
-                       _tcscpy_s(szFormatTag, pNextString);\r
-\r
-                       switch (GetFormatTag(szFormatTag)) {\r
-                       case _T('d'):\r
-                       case _T('i'):\r
-                       case _T('o'):\r
-                       case _T('x'):\r
-                       case _T('X'):\r
-                       case _T('u'):\r
-                       case _T('c'):\r
-                               _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, int));\r
-                               break;\r
-                       case _T('s'):\r
-                               _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, LPTSTR));\r
-                               break;\r
-                       case _T('f'):\r
-                       case _T('e'):\r
-                       case _T('E'):\r
-                       case _T('g'):\r
-                       case _T('G'):\r
-                               _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, double));\r
-                               break;\r
-                       case _T('p'):\r
-                               _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, void *));\r
-                               break;\r
-                       case _T('n'):\r
-                               _stprintf_s(pLogEnd, LOG_MAX - len, szFormatTag, va_arg(ap, int *));\r
-                               break;\r
-                       case _T('%'):\r
-                       default:\r
-                               _stprintf_s(pLogEnd, LOG_MAX - len, _T("%s"), szFormatTag);\r
-                               break;\r
-                       }\r
-\r
-                       nIndex += _tcslen(szFormatTag);\r
-               } else {\r
-                       TCHAR szString[LOG_MAX] = {'0'};\r
-                       _tcscpy_s(szString, pNextString);\r
-                       LPTSTR c;\r
-                       LPTSTR pString = _tcstok_s(szString, _T("%"), &c);\r
-                       _stprintf_s(pLogEnd, LOG_MAX - len, _T("%s"), pString);\r
-\r
-                       nIndex += _tcslen(pString);\r
-               }\r
-       }\r
-\r
-       va_end(ap);\r
-\r
+       TCHAR log[1024], msg[1024];\r
        static int n = 0;\r
-       TCHAR szPath[MAX_PATH] = {'\0'};\r
-       if (GetTempPath(MAX_PATH, szPath)) {\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(szPath, NULL, szPath, _T("xkeylog"), _T("txt"));\r
+               _tmakepath_s(path, nullptr, path, _T("xkeylog"), _T("txt"));\r
 #else\r
-               _tmakepath_s(szPath, NULL, szPath, _T("xkeylog64"), _T("txt"));\r
+               _tmakepath_s(path, nullptr, path, _T("xkeylog64"), _T("txt"));\r
 #endif\r
-       } else {\r
-               _tcscpy_s(szPath, _T("c:\\xkeylog.txt"));\r
-       }\r
-       FILE *fp;\r
-       _tfopen_s(&fp, szPath, _T("a"));\r
-       _ftprintf(fp, _T("%8d: %s       %s\n"), n++, m_szApplicationName, szLog);\r
-       fflush(fp);\r
-       fclose(fp);\r
+       } else\r
+               _tcscpy_s(path, _T("c:\\xkeylog.txt"));\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
@@ -769,17 +463,17 @@ BOOL CUtils::IsVisualStudio()
 \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
@@ -807,33 +501,7 @@ BOOL CUtils::IsVisualBasicEditor()
 \r
 BOOL CUtils::IsEclipse()\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
-}\r
-\r
-int CUtils::GetClipboardTextLength()\r
-{\r
-       CString szClipboardText;\r
-       CUtils::GetClipboardText(&szClipboardText);\r
-       CUtils::SetClipboardText(&szClipboardText);\r
-\r
-//     return sz.GetLength();\r
-\r
-       int nLength = 0;\r
-       for (int i = 0; i < szClipboardText.GetLength(); ++i) {\r
-               if (szClipboardText.GetAt(i) & 0x80) {\r
-                       ++i;\r
-               }\r
-               ++nLength;\r
-       }\r
-       return nLength;\r
+       return AppName::Match(_T("eclipse.exe"));\r
 }\r
 \r
 BOOL CUtils::IsDialog()\r
@@ -845,110 +513,37 @@ BOOL CUtils::IsDialog()
        return GetParent(GetForegroundWindow()) != NULL;\r
 }\r
 \r
-int CUtils::GetFormatTag(LPTSTR szFormatTag)\r
-{\r
-       if (*(szFormatTag) != _T('%')) {\r
-               return NULL;\r
-       }\r
-\r
-       unsigned int nIndex = 1;\r
-\r
-       // flags\r
-       while (nIndex < _tcslen(szFormatTag)) {\r
-               switch (*(szFormatTag + nIndex)) {\r
-               case _T('-'):\r
-               case _T('+'):\r
-               case _T(' '):\r
-               case _T('0'):\r
-               case _T('#'):\r
-                       ++nIndex;\r
-                       continue;\r
-               default:\r
-                       break;\r
-               }\r
-\r
-               break;\r
-       }\r
-\r
-       // width\r
-       while (_istdigit(*(szFormatTag + nIndex))) {\r
-               ++nIndex;\r
-       }\r
-\r
-       // precision\r
-       if (*(szFormatTag + nIndex) == _T('.')) {\r
-               ++nIndex;\r
-               while (_istdigit(*(szFormatTag + nIndex))) {\r
-                       ++nIndex;\r
-               }\r
-       }\r
-\r
-       // prefix\r
-       switch (*(szFormatTag + nIndex)) {\r
-       case _T('h'):\r
-       case _T('l'):\r
-       case _T('L'):\r
-               ++nIndex;\r
-               break;\r
-       }\r
-\r
-       // type\r
-       switch (*(szFormatTag + nIndex)) {\r
-       case _T('d'):\r
-       case _T('i'):\r
-       case _T('o'):\r
-       case _T('x'):\r
-       case _T('X'):\r
-       case _T('u'):\r
-       case _T('c'):\r
-       case _T('s'):\r
-       case _T('f'):\r
-       case _T('e'):\r
-       case _T('E'):\r
-       case _T('g'):\r
-       case _T('G'):\r
-       case _T('p'):\r
-       case _T('n'):\r
-       case _T('%'):\r
-               *(szFormatTag + nIndex + 1) = NULL;\r
-               return *(szFormatTag + nIndex);\r
-       default:\r
-               *(szFormatTag + nIndex) = NULL;\r
-               return NULL;\r
-       }\r
-}\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 ture.\r
+// If Clipboard data is empty, return true.\r
 // You must CopyNextCharacter in previous step.\r
 // Clipboard data is destroyed.\r
 BOOL CUtils::IsEOF()\r
@@ -966,115 +561,119 @@ BOOL CUtils::IsTOF()
 \r
 BOOL CUtils::IsTOForEOF()\r
 {\r
-       CString szClipboardText;\r
-       GetClipboardText(&szClipboardText);\r
-       return szClipboardText.IsEmpty()                        // for normal application\r
-               || szClipboardText.GetLength() >= 3;    // for VC++\r
+       CString text;\r
+       GetClipboardText(text);\r
+       return text.IsEmpty() || // for normal application\r
+                       text.GetLength() >= 3; // for VC++\r
 }\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
@@ -1101,80 +700,36 @@ BOOL CUtils::Run(CString szCommandLine, BOOL isWait)
 \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
-}\r
-\r
-void CUtils::PrintWindowInfo(WINDOWINFO *pwi)\r
-{\r
-       Log(_T("windowinfo.cbSize: %d"), pwi->cbSize);\r
-       Log(_T("windowinfo.rcWindow.top: %d"), pwi->rcWindow.top);\r
-       Log(_T("windowinfo.rcWindow.bottom: %d"), pwi->rcWindow.bottom);\r
-       Log(_T("windowinfo.rcWindow.left: %d"), pwi->rcWindow.left);\r
-       Log(_T("windowinfo.rcWindow.right: %d"), pwi->rcWindow.right);\r
-       Log(_T("windowinfo.rcClient.top: %d"), pwi->rcClient.top);\r
-       Log(_T("windowinfo.rcClient.bottom: %d"), pwi->rcClient.bottom);\r
-       Log(_T("windowinfo.rcClient.left: %d"), pwi->rcClient.left);\r
-       Log(_T("windowinfo.rcClient.right: %d"), pwi->rcClient.right);\r
-       Log(_T("windowinfo.dwStyle: %d"), pwi->dwStyle);\r
-       Log(_T("windowinfo.dwExStyle: %d"), pwi->dwExStyle);\r
-       Log(_T("windowinfo.dwWindowStatus: %d"), pwi->dwWindowStatus);\r
-       Log(_T("windowinfo.cxWindowBorders: %d"), pwi->cxWindowBorders);\r
-       Log(_T("windowinfo.cyWindowBorders: %d"), pwi->cyWindowBorders);\r
-       Log(_T("windowinfo.atomWindowType: %d"), pwi->atomWindowType);\r
-       Log(_T("windowinfo.wCreatorVersion: %d"), pwi->wCreatorVersion);\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