void InitLua() { CHAR version[64]; lua = luaL_newstate(); if(lua == nullptr) { return; } luaL_openlibs(lua); luaL_newlib(lua, luaFuncs); lua_setglobal(lua, u8"crvmgr"); //skk-version _snprintf_s(version, _TRUNCATE, "%s", WCTOU8(TEXTSERVICE_NAME L" " TEXTSERVICE_VER)); lua_pushstring(lua, version); lua_setglobal(lua, u8"SKK_VERSION"); //%AppData%\\CorvusSKK\\init.lua if(luaL_dofile(lua, WCTOU8(pathinitlua)) == LUA_OK) { return; } ZeroMemory(pathinitlua, sizeof(pathinitlua)); #ifdef _DEBUG //<module directory>\\init.lua if(GetModuleFileNameW(nullptr, pathinitlua, _countof(pathinitlua)) != 0) { WCHAR *pdir = wcsrchr(pathinitlua, L'\\'); if(pdir != nullptr) { *(pdir + 1) = L'\0'; wcsncat_s(pathinitlua, fninitlua, _TRUNCATE); } } #else PWSTR knownfolderpath = nullptr; //%SystemRoot%\\IME\\IMCRVSKK\\init.lua if(SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Windows, KF_FLAG_DONT_VERIFY, nullptr, &knownfolderpath))) { _snwprintf_s(pathinitlua, _TRUNCATE, L"%s\\%s\\%s\\%s", knownfolderpath, L"IME", TEXTSERVICE_DIR, fninitlua); CoTaskMemFree(knownfolderpath); } #endif if(luaL_dofile(lua, WCTOU8(pathinitlua)) == LUA_OK) { return; } UninitLua(); }
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { MSG msg; WNDCLASSEXW wc; HWND hWnd; WSADATA wsaData; PSECURITY_DESCRIPTOR psd; SECURITY_ATTRIBUTES sa; _wsetlocale(LC_ALL, L"JPN"); CreateConfigPath(); if(ConvertStringSecurityDescriptorToSecurityDescriptorW(krnlobjsddl, SDDL_REVISION_1, &psd, NULL)) { sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = psd; sa.bInheritHandle = FALSE; hMutex = CreateMutexW(&sa, FALSE, mgrmutexname); if(hMutex == NULL || GetLastError() == ERROR_ALREADY_EXISTS) { LocalFree(psd); return 0; } LocalFree(psd); } else { return 0; } WSAStartup(WINSOCK_VERSION, &wsaData); ZeroMemory(&ftConfig, sizeof(ftConfig)); if(IsFileUpdated(pathconfigxml, &ftConfig)) { LoadConfig(); } ZeroMemory(&ftSKKDic, sizeof(ftSKKDic)); if(IsFileUpdated(pathskkdic, &ftSKKDic)) { MakeSKKDicPos(); } InitLua(); hInst = hInstance; ZeroMemory(&wc, sizeof(wc)); wc.cbSize = sizeof(wc); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInst; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = DictionaryManagerClass; RegisterClassExW(&wc); #ifdef _DEBUG hWnd = CreateWindowW(DictionaryManagerClass, TextServiceDesc, WS_OVERLAPPEDWINDOW, 0, 0, 600, 800, NULL, NULL, hInst, NULL); #else hWnd = CreateWindowW(DictionaryManagerClass, TextServiceDesc, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInst, NULL); #endif if(!hWnd) { UninitLua(); WSACleanup(); return 0; } #ifdef _DEBUG ShowWindow(hWnd, SW_MINIMIZE); #else ShowWindow(hWnd, SW_HIDE); #endif UpdateWindow(hWnd); while(GetMessageW(&msg, NULL, 0, 0)) { if(!TranslateAcceleratorW(msg.hwnd, NULL, &msg)) { TranslateMessage(&msg); DispatchMessageW(&msg); } } UninitLua(); WSACleanup(); return (int) msg.wParam; }