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; }
/** ** The main program: initialise, parse options and arguments. ** ** @param argc Number of arguments. ** @param argv Vector of arguments. */ int stratagusMain(int argc, char **argv) { #ifdef REDIRECT_OUTPUT RedirectOutput(); #endif #ifdef USE_BEOS // Parse arguments for BeOS beos_init(argc, argv); #endif // Setup some defaults. #ifndef MAC_BUNDLE StratagusLibPath = "."; #else freopen("/tmp/stdout.txt", "w", stdout); freopen("/tmp/stderr.txt", "w", stderr); // Look for the specified data set inside the application bundle // This should be a subdir of the Resources directory CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL); CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); Assert(pathPtr); StratagusLibPath = pathPtr; #endif Parameters ¶meters = Parameters::Instance; parameters.SetDefaultValues(); parameters.SetLocalPlayerNameFromEnv(); if (argc > 0) { parameters.applicationName = argv[0]; } // FIXME: Parse options before or after scripts? ParseCommandLine(argc, argv, parameters); // Init the random number generator. InitSyncRand(); makedir(parameters.GetUserDirectory().c_str(), 0777); // Init Lua and register lua functions! InitLua(); LuaRegisterModules(); // Initialise AI module InitAiModule(); LoadCcl(parameters.luaStartFilename); PrintHeader(); PrintLicense(); // Setup video display InitVideo(); // Setup sound card if (!InitSound()) { InitMusic(); } #ifndef DEBUG // For debug it's better not to have: srand(time(NULL)); // Random counter = random each start #endif // Show title screens. SetDefaultTextColors(FontYellow, FontWhite); LoadFonts(); SetClipping(0, 0, Video.Width - 1, Video.Height - 1); Video.ClearScreen(); ShowTitleScreens(); // Init player data ThisPlayer = NULL; //Don't clear the Players strucure as it would erase the allowed units. // memset(Players, 0, sizeof(Players)); NumPlayers = 0; UnitManager.Init(); // Units memory management PreMenuSetup(); // Load everything needed for menus MenuLoop(); Exit(0); return 0; }