当前位置: 首页>>代码示例>>C++>>正文


C++ FileStream::close方法代码示例

本文整理汇总了C++中FileStream::close方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::close方法的具体用法?C++ FileStream::close怎么用?C++ FileStream::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileStream的用法示例。


在下文中一共展示了FileStream::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: checkSaveGame

void GameInitSettings::checkSaveGame(std::string savegame) {
    FileStream fs;

	if(fs.open(savegame.c_str(), "rb") == false) {
		throw std::runtime_error("Cannot open savegame. Make sure you have read access to this savegame!");
	}

    Uint32 magicNum;
    Uint32 savegameVersion;
    std::string duneVersion;
	try {
        magicNum = fs.readUint32();
        savegameVersion = fs.readUint32();
        duneVersion = fs.readString();
	} catch (std::exception& e) {
	    throw std::runtime_error("Cannot load this savegame,\n because it seems to be truncated!");
	}

    if(magicNum != SAVEMAGIC) {
        throw std::runtime_error("Cannot load this savegame,\n because it has a wrong magic number!");
    }

    if(savegameVersion < SAVEGAMEVERSION) {
        throw std::runtime_error("Cannot load this savegame,\n because it was created with an older version:\n" + duneVersion);
    }

    if(savegameVersion > SAVEGAMEVERSION) {
        throw std::runtime_error("Cannot load this savegame,\n because it was created with a newer version:\n" + duneVersion);
    }

	fs.close();
}
开发者ID:thebohemian,项目名称:dunelegacy-richiesbranch,代码行数:32,代码来源:GameInitSettings.cpp

示例2: dSprintf

void GFXD3D9Device::logVertexBuffers() 
{

   // NOTE: This function should be called on the destructor of this class and ONLY then
   // otherwise it'll produce the wrong output
   if( mNumAllocatedVertexBuffers == 0 )
      return;

   FileStream fs;

   fs.open( "vertexbuffer.log", Torque::FS::File::Write );

   char buff[256];

   fs.writeLine( (U8 *)avar("-- Vertex buffer memory leak report -- time = %d", Platform::getRealMilliseconds()) );
   dSprintf( (char *)&buff, sizeof( buff ), "%d un-freed vertex buffers", mNumAllocatedVertexBuffers );
   fs.writeLine( (U8 *)buff );

   GFXD3D9VertexBuffer *walk = mVBListHead;

   while( walk != NULL ) 
   {
      dSprintf( (char *)&buff, sizeof( buff ), "[Name: %s] Size: %d", walk->name, walk->mNumVerts );
      fs.writeLine( (U8 *)buff );

      walk = walk->next;
   }

   fs.writeLine( (U8 *)"-- End report --" );

   fs.close();
}
开发者ID:adhistac,项目名称:ee-client-2-0,代码行数:32,代码来源:gfxD3D9Device.cpp

示例3: init

	void init(StartGameFunc startGame, StopGameFunc stopGame)
	{
		s_startGame = startGame;
		s_stopGame  = stopGame;

		for (u32 s=0; s<SOUND_COUNT; s++)
		{
			UI_Sound& sound = s_sounds[s];
			sound.filename = c_sounds[s];

			FileStream file;
			if (file.open(sound.filename, FileStream::MODE_READ))
			{
				sound.size = file.getSize();
				sound.data = malloc(sound.size);

				file.read((u8*)sound.data, sound.size);
				file.close();
			}
			else
			{
				sound.filename = NULL;
			}
		}

		UISystem::setMouseOverSound(&s_sounds[SOUND_MOUSEOVER]);
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:27,代码来源:gameUI.cpp

示例4: logValue

/**
 * logValue() Information
 *
 * This function writes data to the log file.
 */
static void logValue(String label, Uint16 value)
{
    // open file
    dataFile.open("dataLog.txt");

    // determine label length
    int size = 0;
    String temp = label;

    for(temp = label; *temp; ++temp)
    {
        ++size;
    }

    // write label
    dataFile.write((Byte*)label, size); // to suppress compiler warning

    // convert value
    char dataString[8] = {"0x0000\n"};
    static const char toHex[] = {"0123456789ABCDEF"};

    dataString[2] = toHex[(value & 0xF000) >> 12];
    dataString[3] = toHex[(value & 0x0F00) >> 8];
    dataString[4] = toHex[(value & 0x00F0) >> 4];
    dataString[5] = toHex[(value & 0x000F)];

    // write value
    dataFile.write((Byte*)dataString, 7); // to suppress compiler warning

    // close file
    dataFile.close();
}
开发者ID:ISSCentaurus,项目名称:MGE,代码行数:37,代码来源:datalog.c

示例5: BuildCacheCRC

void BuildCacheCRC()
{
#ifdef ENABLE_DATABLOCK_CACHE
    SimDataBlockGroup* pGroup = Sim::getDataBlockGroup();
    SimDataBlock* pDataBlock = 0;
    const U32 iCount = pGroup->size();
    BitStream* stream = new InfiniteBitStream;
    U32 crc=0;
    for (U32 i = 0; i < iCount; i++)
    {
        pDataBlock = (SimDataBlock*)(*pGroup)[i];
        pDataBlock->packData(stream);
    }
    //U32 crc = CRC::calculateCRCStream(stream); //Stream CRC doesn't seem reliable.

    FileStream* datablocksOut = FileStream::createAndOpen("ServerCRC.dmp", Torque::FS::File::Write );
    if (datablocksOut==NULL)
        Con::errorf("### Datablock Cache: Unable to Build Server Datablock CRC Key File.");
    else
    {
        datablocksOut->writeBitStream(stream);
        datablocksOut->close();
        crc=Con::getFileCRC("ServerCRC.dmp");
        Con::deleteFile("ServerCRC.dmp");
    }
    Con::setVariable("$ServerDatablockCacheCRC", Con::getuIntArg(crc));
    Con::warnf("### Datablock Cache: Server Datablock CRC is %u",crc);

    delete stream;
#endif
}
开发者ID:souxiaosou,项目名称:OmniEngine.Net,代码行数:31,代码来源:mainLoop.cpp

示例6: paof

void paof() {
  FileStream stream;
  JvmPathChar file[] = {'h', 'e', 'a', 'p', '.', 't', 'x', 't', 0};
  stream.open(file);
  ObjectHeap::print_all_objects(&stream);
  stream.close();
}
开发者ID:Sektor,项目名称:phoneme-qtopia,代码行数:7,代码来源:Debug.cpp

示例7: extractFile

bool ZipArchive::extractFile(const char *pathInZip, const char *filename, bool *crcFail /* = NULL */)
{
   if(crcFail)
      *crcFail = false;

   const CentralDir *realCD = findFileInfo(pathInZip);
   if(realCD == NULL)
      return false;
   
   FileStream dest;
   if(! dest.open(filename, Torque::FS::File::Write))
      return false;

   Stream *source = openFile(pathInZip, Read);
   if(source == NULL)
   {
      dest.close();
      return false;
   }

   // [tom, 2/7/2007] CRC checking the lazy man's way
   // ZipStatFilter only fails if it doesn't have a central directory, so this is safe
   CentralDir fakeCD;
   ZipStatFilter zsf(&fakeCD);
   zsf.attachStream(source);

   bool ret = dest.copyFrom(&zsf);

   zsf.detachStream();

   if(ret && fakeCD.mCRC32 != realCD->mCRC32)
   {
      if(crcFail)
         *crcFail = true;

      if(isVerbose())
         Con::errorf("ZipArchive::extractFile - CRC failure extracting file %s", pathInZip);
      ret = false;
   }
   
   closeFile(source);
   dest.close();

   return ret;
}
开发者ID:adhistac,项目名称:ee-client-2-0,代码行数:45,代码来源:zipArchive.cpp

示例8: outputPath

bool GFXD3D9Shader::_loadCompiledOutput( const Torque::Path &filePath, 
                                         const String &target, 
                                         GenericConstBufferLayout *bufferLayoutF, 
                                         GenericConstBufferLayout *bufferLayoutI,
                                         Vector<GFXShaderConstDesc> &samplerDescriptions )
{
   Torque::Path outputPath(filePath);
   outputPath.setExtension("csf");     // "C"ompiled "S"hader "F"ile (fancy!)

   FileStream f;
   if (!f.open(outputPath, Torque::FS::File::Read))
      return false;
   U32 fileTag;
   if (!f.read(&fileTag))
      return false;
   if (fileTag != smCompiledShaderTag)
      return false;
   if (!bufferLayoutF->read(&f))
      return false;
   if (!bufferLayoutI->read(&f))
      return false;
   U32 bufferSize;
   if (!f.read(&bufferSize))
      return false;
   U32 waterMark = FrameAllocator::getWaterMark();
   DWORD* buffer = static_cast<DWORD*>(FrameAllocator::alloc(bufferSize));
   if (!f.read(bufferSize, buffer))
      return false;

   // Read sampler descriptions.

   U32 samplerCount;
   f.read( &samplerCount );   

   for ( U32 i = 0; i < samplerCount; i++ )
   {
      GFXShaderConstDesc samplerDesc;
      f.read( &(samplerDesc.name) );
      f.read( (U32*)&(samplerDesc.constType) );
      f.read( &(samplerDesc.arraySize) );

      samplerDescriptions.push_back( samplerDesc );
   }

   f.close();

   HRESULT res;
   if (target.compare("ps_", 3) == 0)      
      res = mD3D9Device->CreatePixelShader(buffer, &mPixShader );
   else
      res = mD3D9Device->CreateVertexShader(buffer, &mVertShader );
   AssertFatal(SUCCEEDED(res), "Unable to load shader!");

   FrameAllocator::setWaterMark(waterMark);
   return SUCCEEDED(res);
}
开发者ID:AlkexGas,项目名称:Torque3D,代码行数:56,代码来源:gfxD3D9Shader.cpp

示例9:

	Logged(Tab* tab, const std::string& dir) {
		assert(NULL != tab);
		this->tab = tab;
		fmain = dir + "/main";
		flog  = dir + "/log";
		FileStream file;
		if (file.xopen(fmain.c_str(), "rb")) {
			NativeDataInput<InputBuffer> dio; dio.attach(&file);
			dio >> *tab; // load the check point
			file.close();
		}
开发者ID:career-tankles,项目名称:scrawl,代码行数:11,代码来源:logged_tab.hpp

示例10: stop

	void stop()
	{
		Sound::stopMusic();
		LOCK();
			if (s_fileStream.isOpen())
			{
				ov_clear(&s_oggFile);
				s_fileStream.close();
			}
		UNLOCK();
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:11,代码来源:oggVorbis.cpp

示例11: readIni

	bool readIni(const char* filename, ReadIniCallback callback, bool liberal)
	{
		if (!callback)
		{
			return false;
		}

		bool res = false;
		FileStream file;
		if ( file.open(filename, FileStream::MODE_READ) )
		{
			size_t size = file.getSize();
			char* fileData = new char[size+1];
			if (fileData)
			{
				file.read(fileData, (u32)size);
				res = true;
			}
			file.close();

			if (res)
			{
				const char* fileEnd = &fileData[size];
				char* readPos = fileData;

				//now read the data.
				while (1)
				{
					char keyName[512], keyValue[512];

					//we are done here.
					if (!getKey(&readPos, keyName, fileEnd))
					{
						break;
					}

					if (!readValue(&readPos, keyValue, fileEnd, liberal))
					{
						break;
					}

					//remove preceding or trailing spaces, remove exterior quotation marks.
					fixupString(keyName);
					fixupString(keyValue);

					res &= callback(keyName, keyValue);
				};
			}

			delete [] fileData;
		}

		return res;
	}
开发者ID:Mailaender,项目名称:XL-Engine,代码行数:54,代码来源:iniReader.cpp

示例12: vnmalloc

Variable_array * VariableScript::parse(const FilePath &file) {
    FileStream *fs = FileManager::instance().open(file);
    if (!fs) {
        _makeErrorMsg("open file \"%u:/%s\" failed!", file.fsId, file.fileName.c_str());
        return 0;
    }
    fs->seek(0, DataStream::kEnd);
    size_t size = (size_t)fs->tell();
    fs->seek(0);
    c8 *ptr = vnmalloc(c8, size);
    if (fs->read(ptr, size) != size) {
        _makeErrorMsg("read file \"%u:/%s\" failed!", file.fsId, file.fileName.c_str());
        fs->close();
        vnfree(ptr);
        return 0;
    }
    fs->close();
    
    c8 *txt = ptr;
    // utf8 bom
    if (strncmp(txt, "\xEF\xBB\xBF", 3) == 0) {
        txt += 3;
        size -= 3;
    }
    
    Token::File *tf = vnnew Token::File();
    c8 buf[512];
    int len = sprintf(buf, "%u:/%s", file.fsId, file.fileName.c_str());
    tf->name.assign(buf, len);
    
    Variable_array *ret = parse(txt, size, tf);
    
    vnfree(ptr);
    tf->drop();
    
    return ret;
}
开发者ID:signorinotang,项目名称:tools,代码行数:37,代码来源:vnVariableScript.cpp

示例13: addFile

bool ZipArchive::addFile(const char *filename, const char *pathInZip, bool replace /* = true */)
{
   FileStream f;
   if (!f.open(filename, Torque::FS::File::Read))
      return false;

   const CentralDir *cd = findFileInfo(pathInZip);
   if(! replace && cd && (cd->mInternalFlags & CDFileDeleted) == 0)
      return false;

   Stream *dest = openFile(pathInZip, Write);
   if(dest == NULL)
   {
      f.close();
      return false;
   }

   bool ret = dest->copyFrom(&f);

   closeFile(dest);
   f.close();

   return ret;
}
开发者ID:adhistac,项目名称:ee-client-2-0,代码行数:24,代码来源:zipArchive.cpp

示例14: save

/**
 *
 * Saves connection settings given an array of settings. This also destroys
 * their pointers if destroy is true
 *
 * @param settings An array of connection settings
 * @param format The file format to use
 * @param filename The filename to save to
 * @return void
 */
void ConnectionSettings::save(
        std::vector<ConnectionSettings *> &settings, FileFormat format,
        std::string filename)
{
    VariantVector connections;
    FileStream *stream;

    for (auto it = settings.cbegin(); it != settings.cend(); ++it) {

        auto connection = (*it);

        if (connection->getParent() == nullptr) {

            // Add to collection
            connections.push_back(connection->toVariantMap());
        }
    }

    switch (format) {
        case FileFormat::BINARY:

            stream = new BinaryFileStream();
            break;
        case FileFormat::JSON:

            stream = new JsonFileStream();
    }

    // Open stream
    stream->open(filename, std::ios::out);

    // Save connections
    *stream << connections;

    // Close stream
    stream->close();

    // Free memory
    delete stream;
}
开发者ID:RabidSQL,项目名称:backend,代码行数:50,代码来源:ConnectionSettings.cpp

示例15: saveFile

// -----------------------------------------------------------------------------
// Get true if file saves successfully.
// -----------------------------------------------------------------------------
S32 SimXMLDocument::saveFile(const char* rFileName)
{
   char buffer[1024];
   Con::expandPath(buffer, sizeof(buffer), rFileName);

   if(*buffer == 0)
      return false;

   FileStream strm;
   if(!ResourceManager->openFileForWrite(strm, buffer, FileStream::Write))
   {
      Con::errorf(ConsoleLogEntry::General, "Unable to open file '%s for writing.", buffer);
      return false;
   }

   bool retVal = m_qDocument->SaveFile(strm);//m_qDocument->SaveFile( buffer );

   // close the stream
   strm.close();

   return retVal;
}
开发者ID:greenfire27,项目名称:Torque2D,代码行数:25,代码来源:SimXMLDocument.cpp


注:本文中的FileStream::close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。