/* Ensures that there exists an app data folder for this program. */ void initializeAppDataFolder() { #if PLATFORM == PLATFORM_WINDOWS /* Just run a command to create the directory. */ _mkdir(getAppDataFolder().c_str()); _mkdir((getAppDataFolder() + "client\\").c_str()); _mkdir((getAppDataFolder() + "server\\").c_str()); _mkdir((getAppDataFolder() + "server\\users\\").c_str()); #else #endif }
void createCrashReport(EXCEPTION_POINTERS* exceptionPointers) { _bstr_t directory; if (!getAppDataFolder(directory)) return; if (::SHCreateDirectoryEx(0, directory, 0) != ERROR_SUCCESS && ::GetLastError() != ERROR_FILE_EXISTS && ::GetLastError() != ERROR_ALREADY_EXISTS) return; std::wstring fileName = directory + L"\\CrashReport.dmp"; HANDLE miniDumpFile = ::CreateFile(fileName.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (miniDumpFile && miniDumpFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION mdei; mdei.ThreadId = ::GetCurrentThreadId(); mdei.ExceptionPointers = exceptionPointers; mdei.ClientPointers = 0; #ifdef _DEBUG MINIDUMP_TYPE dumpType = MiniDumpWithFullMemory; #else MINIDUMP_TYPE dumpType = MiniDumpNormal; #endif ::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), miniDumpFile, dumpType, &mdei, 0, 0); ::CloseHandle(miniDumpFile); processCrashReport(fileName.c_str()); } }
static std::string getLogFolderPath(bool folder_timestamp) { std::string logfolder = folder_timestamp ? Utils::to_string(Utils::now()) : ""; std::string fullPath = combine(getAppDataFolder(), logfolder); ensureFolder(fullPath); return fullPath; }
static bool setCacheFolder() { IWebCachePtr webCache = gWinLauncher->webCache(); if (!webCache) return false; _bstr_t appDataFolder; if (!getAppDataFolder(appDataFolder)) return false; appDataFolder += L"\\cache"; webCache->setCacheFolder(appDataFolder); return true; }
static std::string getLogFileNamePath(std::string prefix, std::string suffix, std::string extension, bool add_timestamp) { std::string logfolder = Utils::to_string(Utils::now(), "%Y-%m-%d"); std::string fullPath = combine(getAppDataFolder(), logfolder); std::string timestamp = add_timestamp ? Utils::to_string(Utils::now()) : ""; //TODO: because this bug we are using alternative code with stringstream //https://answers.unrealengine.com/questions/664905/unreal-crashes-on-two-lines-of-extremely-simple-st.html std::string filename; filename.append(ensureFolder(fullPath)) .push_back(kPathSeparator); filename.append(prefix) .append(suffix) .append(timestamp) .append(extension); return filename; //std::stringstream filename_ss; //filename_ss << ensureFolder(fullPath) << kPathSeparator << prefix << suffix << timestamp << extension; //return filename_ss.str(); }
Client::Client(Socket &_socket, HWND _wnd, HINSTANCE _instance, unsigned int _screenWidth, unsigned int _screenHeight, bool _isWindowed) : sock(_socket), normalFont(512, 256, 32, 32, 32), currentState(nullptr), time(0), wnd(_wnd), screenWidth(_screenWidth), screenHeight(_screenHeight), isWindowed(_isWindowed), isRunning(true), textureManager(nullptr), directInput(nullptr), direct3D(nullptr), xAudio(nullptr), tabClickSFX(-1), errorSFX(-1), acceptedSFX(-1), backImgID(-1), splash(false), timer(0), splashScreen(-1), splashMusicID(-1) { //Seed Rand srand((unsigned int)::time(0)); /* Acquire the lame SGD singleton instances. */ textureManager = CSGD_TextureManager::GetInstance(); directInput = CSGD_DirectInput::GetInstance(); direct3D = CSGD_Direct3D::GetInstance(); xAudio = CSGD_XAudio2::GetInstance(); /* Initialize the SGD wrappers. */ direct3D->InitDirect3D(wnd, screenWidth, screenHeight, isWindowed, false); textureManager->InitTextureManager(direct3D->GetDirect3DDevice(), direct3D->GetSprite()); directInput->InitDirectInput(wnd, _instance, DI_KEYBOARD | DI_MOUSE | DI_JOYSTICKS); xAudio->InitXAudio2(); /* Read in user options. */ std::ifstream opts((getAppDataFolder() + "client\\options").c_str(), std::ios_base::binary | std::ios_base::in); if(opts.is_open()) { float volumes[2] = { 0.0f, 0.0f }; bool fullscreen = false; /* Read in the volumes and close the file. */ opts.read((char*)volumes, sizeof(volumes)); opts.read((char*)&fullscreen, sizeof(fullscreen)); opts.close(); /* Set the volumes. */ xAudio->MusicSetMasterVolume(volumes[0]); xAudio->SFXSetMasterVolume(volumes[1]); /* Set the fullscreen settings. */ setIsWindowed(!fullscreen); } /* Set the localhost address. */ localhost.setAddress("127.0.0.1"); localhost.setPort(CLIENT_PORT); /* Set the server address. */ server.setPort(SERVER_PORT); /* Disable both the Direct3D and the Windows cursor in our window. */ direct3D->GetDirect3DDevice()->ShowCursor(false); ShowCursor(true); //When the Client start it goes straight to the Main Menu State MainMenuState* mainMenu = new MainMenuState(*this); PushState(mainMenu); /* Load the normal font. */ normalFont.loadTexture(_T("resources/fonts/test2.png")); /* Load the hud image and potions. */ gameplayImgID = textureManager->LoadTexture(_T("resources/hud/HUD_assets.png")); /* Load the menu image. */ menuImgID = textureManager->LoadTexture(_T("resources/menus/menu&HUD.png")); //Load the styalized background image backImgID = textureManager->LoadTexture(_T("resources/world/graphics/World_map1.png")); /* The Loading of the world tile image is handled in worldMap. */ worldImgID = -1; server.setPort(SERVER_PORT); //Load the Sound Effects buttonClickSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/menu/buttonClick.wav")); tabClickSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/menu/tabClick.wav")); errorSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/menu/warningBeep.wav")); acceptedSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/menu/acceptedBeep.wav")); //Load Spell Sound Effects fireballSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/fireball.wav")); healSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/heal.wav")); iceballSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/iceball.wav")); aoeFireballSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/aoeFireball.wav")); diabloSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/diablo.wav")); frostbiteSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/frostbite.wav")); glacialSpikeSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/glacialSpike.wav")); lightningBoltSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/lightningBolt.wav")); lightningStrikeSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/lightningStrike.wav")); phoenixSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/phoenix.wav")); valkyrieSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/spells/valkyrie.wav")); //load music backgroundMusicID = xAudio->MusicLoadSong(_T("resources/audio/DayGloomy.xwm")); splashMusicID = xAudio->MusicLoadSong(_T("resources/audio/Intro.xwm")); //Play music xAudio->MusicPlaySong(splashMusicID, false); //Display Splash Screen splash = true; timer = 5.0f; //Load Splash Screen splashScreen = textureManager->LoadTexture(_T("resources/hud/darkRedemptionLogo.png")); inventorySelectionSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/menu/inventorySelection.wav")); potionSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/world/potion.wav")); deathSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/character/death1.wav")); goldSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/world/gold.wav")); gemSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/world/gem.wav")); pickUpSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/character/pickup.wav")); getHitSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/character/gethit.wav")); enemyGetHitSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/enemies/gethit1.wav")); enemyGrowlerHitSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/enemies/gethit3.wav")); levelUpSFX = xAudio->SFXLoadSound(_T("resources/audio/sfx/character/levelup.wav")); #if PLATFORM_ARCADE setIsWindowed(false); #endif }