int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int /*cmdShow*/) { SetDllDirectory(L""); git_libgit2_init(); HandleCommandLine(lpCmdLine); CAutoGeneralHandle hReloadProtection = ::CreateMutex(NULL, FALSE, GetCacheMutexName()); if ((!hReloadProtection) || (GetLastError() == ERROR_ALREADY_EXISTS)) { // An instance of TGitCache is already running CTraceToOutputDebugString::Instance()(__FUNCTION__ ": TGitCache ignoring restart\n"); return 0; } CGitStatusCache::Create(); CGitStatusCache::Instance().Init(); SecureZeroMemory(szCurrentCrawledPath, sizeof(szCurrentCrawledPath)); DWORD dwThreadId; MSG msg; TCHAR szWindowClass[] = {TGIT_CACHE_WINDOW_NAME}; // create a hidden window to receive window messages. WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = 0; wcex.hCursor = 0; wcex.hbrBackground = 0; wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = 0; RegisterClassEx(&wcex); hWnd = CreateWindow(TGIT_CACHE_WINDOW_NAME, TGIT_CACHE_WINDOW_NAME, WS_CAPTION, 0, 0, 800, 300, NULL, 0, hInstance, 0); hTrayWnd = hWnd; if (hWnd == NULL) { return 0; } if (CRegStdDWORD(_T("Software\\TortoiseGit\\CacheTrayIcon"), FALSE)==TRUE) { SecureZeroMemory(&niData,sizeof(NOTIFYICONDATA)); DWORD dwMajor = 0; DWORD dwMinor = 0; GetShellVersion(&dwMajor, &dwMinor); DWORD dwVersion = PACKVERSION(dwMajor, dwMinor); if (dwVersion >= PACKVERSION(6,0)) niData.cbSize = sizeof(NOTIFYICONDATA); else if (dwVersion >= PACKVERSION(5,0)) niData.cbSize = NOTIFYICONDATA_V2_SIZE; else niData.cbSize = NOTIFYICONDATA_V1_SIZE; niData.uID = TRAY_ID; // own tray icon ID niData.hWnd = hWnd; niData.uFlags = NIF_ICON|NIF_MESSAGE; // load the icon niData.hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_TGITCACHE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); // set the message to send // note: the message value should be in the // range of WM_APP through 0xBFFF niData.uCallbackMessage = TRAY_CALLBACK; Shell_NotifyIcon(NIM_ADD,&niData); // free icon handle if(niData.hIcon && DestroyIcon(niData.hIcon)) niData.hIcon = NULL; } // Create a thread which waits for incoming pipe connections CAutoGeneralHandle hPipeThread = CreateThread( NULL, // no security attribute 0, // default stack size PipeThread, (LPVOID) &bRun, // thread parameter 0, // not suspended &dwThreadId); // returns thread ID if (!hPipeThread) { return 0; } else hPipeThread.CloseHandle(); // Create a thread which waits for incoming pipe connections CAutoGeneralHandle hCommandWaitThread = CreateThread( NULL, // no security attribute 0, // default stack size CommandWaitThread, (LPVOID) &bRun, // thread parameter 0, // not suspended &dwThreadId); // returns thread ID if (!hCommandWaitThread) { return 0; } // loop to handle window messages. while (bRun) { BOOL bLoopRet = GetMessage(&msg, NULL, 0, 0); if ((bLoopRet != -1)&&(bLoopRet != 0)) { DispatchMessage(&msg); } } bRun = false; CGitStatusCache::Destroy(); HandleRestart(); return 0; }
void HandleRequest() { char* token; short keep_processing = 1; int offset; DebugPrint("Received request %s" _C_ recv_buffer); token = FirstToken(); while (token != 0 && keep_processing) { switch (to_request(token)) { case ACTIVITY: HandleActivity(); break; case COMMAND: // COMMAND HandleCommand(); break; case EXIT: // EXIT HandleQuit(); break; case GET: // GET HandleGet(); break; case KILL: HandleKill(); break; case LISPGET: // LISPGET {STATE | GAMEINFO | MAPINFO} HandleLispGet(); break; case MAP: // Load new map if (HandleNewMap()) { LastPausedCycle = 0; keep_processing = 0; } break; case PING: // PING HandlePing(); break; case QUIT: // QUIT HandleQuit(); break; case RESTART: // RESTART / RESET HandleRestart(); LastPausedCycle = 0; keep_processing = 0; break; case SPEED: // SPEED HandleSpeed(); break; case TRANSITION: // TRANSITION HandleTransition(); keep_processing = 0; break; case VIDEO: // VIDEO HandleVideo(); break; case WRITE: HandleWrite(); break; case CYCLE: HandleGetCycle(); break; case Z: HandleRandomSeed(); break; default: SendResponseMessage("Unknown command.\n", 3); } token = NextToken(); } // Bring pending commands to the front of recv_buffer if (token != 0) { offset = token + strlen(token) - temp_buffer; temp_buffer[offset] = recv_buffer[offset]; strcpy(recv_buffer, token); } else memset(recv_buffer, 0, RECV_BUFFER_SIZE); // Clear the command buffer }