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


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

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


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

示例1: ReadOnly

// ReadOnly
//------------------------------------------------------------------------------
void TestFileIO::ReadOnly() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// should not be read only
	TEST_ASSERT( FileIO::GetReadOnly( path ) == false );

	// set readonly
	TEST_ASSERT( FileIO::SetReadOnly( path.Get(), true ) == true );

	// should be read only
	TEST_ASSERT( FileIO::GetReadOnly( path ) == true );

	// delete should fail
	TEST_ASSERT( FileIO::FileDelete( path.Get() ) == false );

	// clean up
	TEST_ASSERT( FileIO::SetReadOnly( path.Get(), false ) == true );
    TEST_ASSERT( FileIO::GetReadOnly( path ) == false );
	TEST_ASSERT( FileIO::FileDelete( path.Get() ) == true );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:30,代码来源:TestFileIO.cpp

示例2: Load

void Settings::Load()
{
    Directory appDataDir = GetAppDataDir();
    if (appDataDir.Exists())
    {
        File config;
        config.SetLocation(appDataDir.Location().OriginalString() + "/config.txt");
        FileStream fs;
        if (config.Exists())
        {
            AutoPointerArray<UInt8> buf(new UInt8[config.Size()], config.Size());
            if (fs.Open(config.Location(), FileAccessMode::Read, FileAccessPriority::ReadThroughput))
            {
                fs.Read(buf.Get(), 0, buf.Size());
                fs.Close();
                for (Size i = 0, s = 0; i < buf.Size(); ++i)
                    if (buf[i] == '\n')
                    {
                        String line = String(reinterpret_cast<const char*>(&buf[s]), i - s);
                        AutoPointerArray<String> keyValue = line.Split(String("="));
                        if (keyValue.Count() == 2)
                        {
                            const char* key = StringCache::Find(keyValue[0]);
                            if (key == 0)
                                key = keyValue[0].c_str();
                            m_PImpl->m_Data[key] = keyValue[1];
                        }
                        s = i+1;
                    }
            }
        }
    }
}
开发者ID:wangscript,项目名称:RadonFramework,代码行数:33,代码来源:Settings.cpp

示例3: FileCopy

// FileCopy
//------------------------------------------------------------------------------
void TestFileIO::FileCopy() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// generate copy file name
	AStackString<> pathCopy( path );
	pathCopy += ".copy";

	// make sure nothing is left from previous runs
	FileIO::FileDelete( path.Get() );
	FileIO::FileDelete( pathCopy.Get() );
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == false );
	TEST_ASSERT( FileIO::FileExists( pathCopy.Get() ) == false );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// copy it
	TEST_ASSERT( FileIO::FileCopy( path.Get(), pathCopy.Get() ) );
	TEST_ASSERT( FileIO::FileExists( pathCopy.Get() ) == true );

	// copy without overwrite allowed should fail
	const bool allowOverwrite = false;
	TEST_ASSERT( FileIO::FileCopy( path.Get(), pathCopy.Get(), allowOverwrite ) == false );

	// cleanup
	VERIFY( FileIO::FileDelete( path.Get() ) );
	VERIFY( FileIO::FileDelete( pathCopy.Get() ) );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:35,代码来源:TestFileIO.cpp

示例4: while

    /*static*/ void FileIO::WorkAroundForWindowsFilePermissionProblem( const AString & fileName )
    {
        // Sometimes after closing a file, subsequent operations on that file will
        // fail.  For example, trying to set the file time, or even another process
        // opening the file.
        //
        // This seems to be a known issue in windows, with multiple potential causes
        // like Virus scanners and possibly the behaviour of the kernel itself.
        //
        // A work-around for this problem is to attempt to open a file we just closed.
        // This will sometimes fail, but if we retry until it succeeds, we avoid the
        // problem on the subsequent operation.
        FileStream f;
        Timer timer;
        while ( f.Open( fileName.Get() ) == false )
        {
            Thread::Sleep( 1 );

            // timeout so we don't get stuck in here forever
            if ( timer.GetElapsed() > 1.0f )
            {
                ASSERT( false && "WorkAroundForWindowsFilePermissionProblem Failed!" );
                return;
            }
        }
        f.Close();
    }
开发者ID:JeremieA,项目名称:fastbuild,代码行数:27,代码来源:FileIO.cpp

示例5: FileExists

REGISTER_TESTS_END

// FileExists
//------------------------------------------------------------------------------
void TestFileIO::FileExists() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// ensure doesn't exist
	FileIO::FileDelete( path.Get() ); // delete in case left over from previous test run
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == false );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// ensure exists
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == true );

	// clean up
	TEST_ASSERT( FileIO::FileDelete( path.Get() ) == true );
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == false );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:26,代码来源:TestFileIO.cpp

示例6: Main

void Test::Main(){
	String* path = new String("MyTest.txt");
	if (File::Exists(path)){
		File::Delete(path);
	}
	FileStream* fs = File::Create(path);
	Test::AddText(fs, new String("This is some text"));
	Test::AddText(fs, new String("This is some more text,"));
	Test::AddText(fs, new String("\r\nand this is on a new line"));
	Test::AddText(fs, new String("\r\n\r\nThe following is a subset of characters:\r\n"));
	for (int i = 100; i < 220; i += 1) {
		Test::AddText(fs, new String(Convert::ToChar(i)));
		if (i % 10 == 0) {
			Test::AddText(fs, new String("\r\n"));
		}
	}
	fs->Close();
	fs = File::OpenRead(path);
	Array<char>* b = new Array<char>(1024);
	UTF8Encoding* temp = new UTF8Encoding();
	while (fs->Read(b, 0, b->Length) > 0) {
		String* s = temp->GetString(b);
		Console::WriteLine(s);
	}
}
开发者ID:AlexAlbala,项目名称:AlterNative-Tests,代码行数:25,代码来源:Test.cpp

示例7: net_send_file

int DERPEditor::net_send_file(lua_State *L)
{
    if (lua_gettop(L) == 1)
    {
        const char* path = lua_tostring(L, 1);
        FileStream s;

        if (!s.OpenReadBinary(path))
        {
            char msg[4096];
            //Format(msg, "Could not open file to send (send_file): '%s'", path);
            lua_pushstring(L, msg);
            lua_error(L);
            return 0;
        }

        unsigned fsize = s.GetSize();
        char* data = new char[fsize];
        s.Read(data, fsize);
        unsigned long hash = Hash(data, fsize);
        s.Close();

        Packet* packet = LuaApp::GetInstance()->m_net->CreateEmptyPacket("res", 1 /* datacache */);

        // hash, filename, datalen, data
        packet->PushInt(hash);
        const char* filename = PathFileName(path);
        packet->PushString(filename, strlen(filename)+1);
        packet->PushInt(fsize);
        packet->PushString(data, fsize);

        Util::Array<Network::Client*>& Clients = LuaApp::GetInstance()->m_net->GetClients();
        Util::Array<Network::Client*>::iterator iter = Clients.begin();

        while (iter != Clients.end())
        {
            printf("Sending to client %d.\n", (*iter)->Ident);
            (*iter)->SendPacket(packet);
            iter++;
        }

        delete packet;
        delete data;

        char ret[256];
        //Format(ret, "%X_%s", hash, filename);

        lua_pushstring(L, ret);

        return 1;
    }
    else
    {
        lua_pushstring(L, "Invalid arguments passed to send_file function!");
        lua_error(L);
    }

    return 0;
}
开发者ID:pxf,项目名称:pxf-tech2,代码行数:59,代码来源:AppNetLib.cpp

示例8: DoesFileExist

bool DoesFileExist( const char* pBuff, long& lSize ){
	FileStream file;
	if ( file.Open( pBuff, "r" ) ) {
		lSize += file.GetLength();
		file.Close();
		return true;
	}
	return false;
}
开发者ID:GSIO01,项目名称:GtkRadiant,代码行数:9,代码来源:qe3.cpp

示例9: Map_SaveFile

/*
   ===========
   Map_SaveFile
   \todo FIXME remove the use_region, this is broken .. work with a global flag to set region mode or not
   ===========
 */
void Map_SaveFile( const char *filename, qboolean use_region ){
	clock_t start, finish;
	double elapsed_time;
	start = clock();
	Sys_Printf( "Saving map to %s\n",filename );

	Pointfile_Clear();

	if ( !use_region ) {
		char backup[1024];

		// rename current to .bak
		strcpy( backup, filename );
		StripExtension( backup );
		strcat( backup, ".bak" );
		unlink( backup );
		rename( filename, backup );
	}

	Sys_Printf( "Map_SaveFile: %s\n", filename );

	// build the out data stream
	FileStream file;
	if ( !file.Open( filename,"w" ) ) {
		Sys_FPrintf( SYS_ERR, "ERROR: couldn't open %s for write\n", filename );
		return;
	}

	// extract filetype
	Map_Export( &file, filename_get_extension( filename ), use_region );

	file.Close();

	finish = clock();
	elapsed_time = (double)( finish - start ) / CLOCKS_PER_SEC;

	Sys_Printf( "Saved in %-.2f second(s).\n",elapsed_time );
	modified = false;

	if ( !strstr( filename, "autosave" ) ) {
		Sys_SetTitle( filename );
	}

	if ( !use_region ) {
		time_t timer;

		time( &timer );

		Sys_Beep();

		Sys_Status( "Saved.", 0 );
	}
}
开发者ID:haapanen,项目名称:GtkRadiant,代码行数:59,代码来源:map.cpp

示例10: LoadShaderSource

/*!***********************************************************************
 @Function		LoadShader
 @Access		public 
 @Param			const char * c_pszName
 @Returns		bool
 @Description	
*************************************************************************/
bool ResourceManager::LoadShaderSource(const char* c_pszFilename, Uint32 uiType, Uint32& uiHandleOUT)
{
	FileStream* pFile = RESMAN->OpenFile(c_pszFilename);
	if(!pFile)
	{
		DebugLog("Failed to load shader: %s", c_pszFilename);
		return false;
	}

	Uint32 uiDataSize = pFile->GetFileSize();
	if(uiDataSize == 0)
	{
		DebugLog("Shader '%s' appears empty!", c_pszFilename);
		delete pFile;
		return false;
	}

	// Load the data file to memory.
	char* pszShaderSource = (char*)malloc(uiDataSize + 1);		// + 1 for NULL terminate.
	pFile->Read(pszShaderSource, uiDataSize, 1);
	pFile->Close();

	pszShaderSource[uiDataSize] = 0;

	// Create and compile the shader object
	uiHandleOUT = glCreateShader((GLenum)uiType);
	glShaderSource(uiHandleOUT, 1, (const char**)&pszShaderSource, NULL);

	DebugLog("------------ COMPILING: %s", c_pszFilename);
	glCompileShader(uiHandleOUT);

	// Test if compilation succeeded
	GLint ShaderCompiled;
	glGetShaderiv(uiHandleOUT, GL_COMPILE_STATUS, &ShaderCompiled);
	if (!ShaderCompiled)
	{
		int i32InfoLogLength, i32CharsWritten;
		glGetShaderiv(uiHandleOUT, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
		char* pszInfoLog = new char[i32InfoLogLength];
		glGetShaderInfoLog(uiHandleOUT, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
		
		DebugLog("Failed to compile shader: %s", pszInfoLog);
		
		delete [] pszInfoLog;
		glDeleteShader(uiHandleOUT);
	}

	free(pszShaderSource);
	
	delete pFile;
	
	return ShaderCompiled;
}
开发者ID:arron-h,项目名称:gravity-wars-redux,代码行数:60,代码来源:Resource.cpp

示例11: GetCacheFileName

// Publish
//------------------------------------------------------------------------------
/*virtual*/ bool Cache::Publish( const AString & cacheId, const void * data, size_t dataSize )
{
    AStackString<> cacheFileName;
    GetCacheFileName( cacheId, cacheFileName );

    // make sure the cache output path exists
    char * lastSlash = cacheFileName.FindLast( NATIVE_SLASH );
    *lastSlash = 0;
    if ( !FileIO::EnsurePathExists( cacheFileName ) )
    {
        return false;
    }
    *lastSlash = NATIVE_SLASH;

    // open output cache (tmp) file
    AStackString<> cacheFileTmpName( cacheFileName );
    cacheFileTmpName += ".tmp";
    FileStream cacheTmpFile;
    if( !cacheTmpFile.Open( cacheFileTmpName.Get(), FileStream::WRITE_ONLY ) )
    {
        return false;
    }

    // write data
    bool cacheTmpWriteOk = ( cacheTmpFile.Write( data, dataSize ) == dataSize );
    cacheTmpFile.Close();

    if ( !cacheTmpWriteOk )
    {
        // failed to write to cache tmp file
        FileIO::FileDelete( cacheFileTmpName.Get() ); // try to cleanup failure
        return false;
    }

    // rename tmp file to real file
    if ( FileIO::FileMove( cacheFileTmpName, cacheFileName ) == false )
    {
        // try to delete (possibly) existing file
        FileIO::FileDelete( cacheFileName.Get() );

        // try rename again
        if ( FileIO::FileMove( cacheFileTmpName, cacheFileName ) == false )
        {
            // problem renaming file
            FileIO::FileDelete( cacheFileTmpName.Get() ); // try to cleanup tmp file
            return false;
        }
    }

    return true;
}
开发者ID:dontnod,项目名称:fastbuild,代码行数:53,代码来源:Cache.cpp

示例12: FileTime

// FileTime
//------------------------------------------------------------------------------
void TestFileIO::FileTime() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// get last write time
	const uint64_t oldTime = FileIO::GetFileLastWriteTime( path );
	TEST_ASSERT( oldTime != 0 );

	// wait for some time that is bigger than filesystem time granularity
    #if defined( __OSX__ )
        // HFS+ has surprisingly poor time resolution (1 second)
        Thread::Sleep( 1100 );
    #else
        Thread::Sleep( 500 );
    #endif
    
	// modify file
	FileStream f2;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Write( (uint32_t)0 );
	f.Close();

	// get new last write time
	const uint64_t newTime = FileIO::GetFileLastWriteTime( path );
	TEST_ASSERT( newTime > oldTime );

	// manually set time back
	TEST_ASSERT( FileIO::SetFileLastWriteTime( path, oldTime ) == true );
	uint64_t timeNow = FileIO::GetFileLastWriteTime( path );
    TEST_ASSERT( timeNow == oldTime );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:40,代码来源:TestFileIO.cpp

示例13:

bool
	FileStream::TestClass()
{
	char buffer[65535];
	int i;
	Time total;
	Time s; 

	Check_Object(FileStreamManager::Instance);
	FileStream Testit;

	memset(buffer,'A',65535);

	SPEW((GROUP_STUFF_TEST, "Starting FileStream test..."));
	s = gos_GetHiResTime();
 	for(i=0; i < 1024; i++)
	{
		Testit.Open("filetest.tst",WriteOnly);
		Testit.WriteBytes(buffer,65535);
		Testit.Close();
		Testit.Open("filetest.tst",ReadOnly);
		Testit.ReadBytes(buffer,65535);
		Testit.Close();
	}
	total = gos_GetHiResTime() - s;
	for(i=0; i < 65535; i++) Verify(buffer[i] == 'A');
	SPEW((GROUP_STUFF_TEST, "Opening, writing, closing, opening, reading, and closing"));
	SPEW((
		GROUP_STUFF_TEST,
		"  64K file 1024 times, averaging out to %f ticks apiece...",
		total / 1024.0f
	));
	SPEW((GROUP_STUFF_TEST, "File data checks out, as well..."));
	SPEW((GROUP_STUFF_TEST, "Leaving FileStream test..."));

	return true;
};
开发者ID:Ariemeth,项目名称:MechCommander2HD,代码行数:37,代码来源:filestream_test.cpp

示例14: FileDelete

// FileDelete
//------------------------------------------------------------------------------
void TestFileIO::FileDelete() const
{
	// generate a process unique file path
	AStackString<> path;
	GenerateTempFileName( path );

	// create it
	FileStream f;
	TEST_ASSERT( f.Open( path.Get(), FileStream::WRITE_ONLY ) == true );
	f.Close();

	// ensure exists
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == true );

	// delete
	TEST_ASSERT( FileIO::FileDelete( path.Get() ) == true );
	TEST_ASSERT( FileIO::FileExists( path.Get() ) == false );
}
开发者ID:scott-nelson,项目名称:fastbuild,代码行数:20,代码来源:TestFileIO.cpp

示例15: Map_SaveSelected

//
//===========
//Map_SaveSelected
//===========
//
// Saves selected world brushes and whole entities with partial/full selections
//
void Map_SaveSelected( const char* filename ){
	FileStream file;

	Sys_Printf( "Saving selection to %s\n",filename );

	const char* type = strrchr( filename,'.' );
	if ( type != NULL ) {
		type++;
	}
	if ( file.Open( filename, "w" ) ) {
		Map_Export( &file, type, false, true );
	}
	else{
		Sys_FPrintf( SYS_ERR, "ERROR: failed to open %s for write\n", filename );
	}

	file.Close();

}
开发者ID:haapanen,项目名称:GtkRadiant,代码行数:26,代码来源:map.cpp


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