View Single Post
Re: std::fstream Is not writing :(
Old
  (#6)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: std::fstream Is not writing :( - 26-02-2005

Ok so here is some simple function
- server crashed if : file does not exists, file empty or first character in file is not '1' (0x31)
- server clean if : file exists and first character in this file is '1' (0x31)

Code:
bool Crashed () {
		// acquire file name
		char tempBuffer [1024];
		GET_GAME_DIR (tempBuffer);
		std::string fileName = tempBuffer;
		// fix path, unix syntax
		replace (fileName.begin(), fileName.end(), '\\', '/');
		// our file
		fileName += "/crashstatus.bin";

		// open file
		std::ifstream file (fileName.c_str());
		if (!file.is_open()) // file does not exists, server crashed
			return true;

		char contents = 0; // important, we must initialize here
		file >> contents; // if file is empty, contents will be unchanged
		file.close();

		if (contents != '1')
			return true;
		return false; // not crashed
	}


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)
  
Reply With Quote