#include "Defines.h" #include #include #include #include #include #include #include #include #include #include #pragma warning(disable: 4996) // ReSharper disable CppDeprecatedEntity // ReSharper disable CppClangTidyCertErr33C std::ofstream GLogFile; void PrintLog(const std::string& Text) { const auto Now = std::chrono::system_clock::now(); const auto Time = std::chrono::system_clock::to_time_t(Now); const long long Milliseconds = (std::chrono::duration_cast(Now.time_since_epoch()) % 1000).count(); static std::mutex Mutex; std::lock_guard Lock(Mutex); const std::tm* LocalTime = std::localtime(&Time); // NOLINT(concurrency-mt-unsafe) char Buffer[] = "[2025-06-21 20:05:04.305]: "; std::strftime(&Buffer[1], 20, "%Y-%m-%d %H:%M:%S", LocalTime); Buffer[20] = '.'; constexpr char Digits[] = "0123456789"; Buffer[21] = Digits[Milliseconds / 100 % 10]; Buffer[22] = Digits[Milliseconds / 10 % 10]; Buffer[23] = Digits[Milliseconds / 1 % 10]; GLogFile << Buffer << Text << std::endl; } int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { using namespace std::chrono_literals; const HANDLE Mutex = CreateMutex(nullptr, TRUE, "FocusIME_SingleInstance_Mutex"); if (Mutex == nullptr) { MessageBox(nullptr, "Failed to create mutex.", "FocusIME", MB_OK | MB_ICONERROR); return 1; } if (GetLastError() == ERROR_ALREADY_EXISTS) { MessageBox(nullptr, "FocusIME is already running.", "FocusIME", MB_OK | MB_ICONINFORMATION); CloseHandle(Mutex); return 0; } GLogFile.open("Log.txt", std::ios::out | std::ios::app); if (!GLogFile.is_open()) { MessageBox(nullptr, "Failed to open log file.", "FocusIME", MB_OK | MB_ICONERROR); CloseHandle(Mutex); return 1; } PrintLog("FocusIME started successfully"); MSG Message = { }; while (true) { BOOL bResult = GetMessage(&Message, nullptr, 0, 0); if (bResult > 0) { TranslateMessage(&Message); DispatchMessage (&Message); } else break; } PrintLog("FocusIME is shutting down..."); GLogFile.close(); CloseHandle(Mutex); return 0; } // ReSharper restore CppDeprecatedEntity // ReSharper restore CppClangTidyCertErr33C