本文整理汇总了C++中FArchive::Close方法的典型用法代码示例。如果您正苦于以下问题:C++ FArchive::Close方法的具体用法?C++ FArchive::Close怎么用?C++ FArchive::Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FArchive
的用法示例。
在下文中一共展示了FArchive::Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFileToString
/**
* Load a text file to an FString.
* Supports all combination of ANSI/Unicode files and platforms.
* @param Result string representation of the loaded file
* @param Filename name of the file to load
* @param VerifyFlags flags controlling the hash verification behavior ( see EHashOptions )
*/
bool FFileHelper::LoadFileToString( FString& Result, const TCHAR* Filename, uint32 VerifyFlags )
{
FArchive* Reader = IFileManager::Get().CreateFileReader( Filename );
if( !Reader )
{
return 0;
}
int32 Size = Reader->TotalSize();
uint8* Ch = (uint8*)FMemory::Malloc(Size);
Reader->Serialize( Ch, Size );
bool Success = Reader->Close();
delete Reader;
BufferToString( Result, Ch, Size );
// handle SHA verify of the file
if( (VerifyFlags & EHashOptions::EnableVerify) && ( (VerifyFlags & EHashOptions::ErrorMissingHash) || FSHA1::GetFileSHAHash(Filename, NULL) ) )
{
// kick off SHA verify task. this frees the buffer on close
FBufferReaderWithSHA Ar( Ch, Size, true, Filename, false, true );
}
else
{
// free manually since not running SHA task
FMemory::Free(Ch);
}
return Success;
}
示例2: HandleSaveCommandExecute
void SVisualLogger::HandleSaveCommandExecute()
{
TArray<TSharedPtr<class STimeline> > OutTimelines;
MainView->GetTimelines(OutTimelines, true);
if (OutTimelines.Num() == 0)
{
MainView->GetTimelines(OutTimelines);
}
if (OutTimelines.Num())
{
// Prompt the user for the filenames
TArray<FString> SaveFilenames;
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
bool bSaved = false;
if (DesktopPlatform)
{
void* ParentWindowWindowHandle = NULL;
IMainFrameModule& MainFrameModule = FModuleManager::LoadModuleChecked<IMainFrameModule>(TEXT("MainFrame"));
const TSharedPtr<SWindow>& MainFrameParentWindow = MainFrameModule.GetParentWindow();
if (MainFrameParentWindow.IsValid() && MainFrameParentWindow->GetNativeWindow().IsValid())
{
ParentWindowWindowHandle = MainFrameParentWindow->GetNativeWindow()->GetOSWindowHandle();
}
const FString DefaultBrowsePath = FString::Printf(TEXT("%slogs/"), *FPaths::GameSavedDir());
bSaved = DesktopPlatform->SaveFileDialog(
ParentWindowWindowHandle,
LOCTEXT("NewProjectBrowseTitle", "Choose a project location").ToString(),
DefaultBrowsePath,
TEXT(""),
LogVisualizer::SaveFileTypes,
EFileDialogFlags::None,
SaveFilenames
);
}
if (bSaved)
{
if (SaveFilenames.Num() > 0)
{
TArray<FVisualLogDevice::FVisualLogEntryItem> FrameCache;
for (auto CurrentItem : OutTimelines)
{
FrameCache.Append(CurrentItem->GetEntries());
}
if (FrameCache.Num())
{
FArchive* FileArchive = IFileManager::Get().CreateFileWriter(*SaveFilenames[0]);
FVisualLoggerHelpers::Serialize(*FileArchive, FrameCache);
FileArchive->Close();
delete FileArchive;
FileArchive = NULL;
}
}
}
}
}
示例3: DumpSimpleSet
bool UParticleSystemAuditCommandlet::DumpSimpleSet(TSet<FString>& InSet, const TCHAR* InShortFilename, const TCHAR* InObjectClassName)
{
if (InSet.Num() > 0)
{
check(InShortFilename != NULL);
check(InObjectClassName != NULL);
FArchive* OutputStream = GetOutputFile(InShortFilename);
if (OutputStream != NULL)
{
UE_LOG(LogParticleSystemAuditCommandlet, Log, TEXT("Dumping '%s' results..."), InShortFilename);
OutputStream->Logf(TEXT("%s,..."), InObjectClassName);
for (TSet<FString>::TIterator DumpIt(InSet); DumpIt; ++DumpIt)
{
FString ObjName = *DumpIt;
OutputStream->Logf(TEXT("%s"), *ObjName);
}
OutputStream->Close();
delete OutputStream;
}
else
{
return false;
}
}
return true;
}
示例4: SaveToFile
bool FBuildPatchAppManifest::SaveToFile(const FString& Filename, bool bUseBinary)
{
bool bSuccess = false;
FArchive* FileOut = IFileManager::Get().CreateFileWriter(*Filename);
if (FileOut)
{
if (bUseBinary)
{
Data->ManifestFileVersion = EBuildPatchAppManifestVersion::GetLatestVersion();
FManifestWriter ManifestData;
Serialize(ManifestData);
ManifestData.Finalize();
if (!ManifestData.IsError())
{
int32 DataSize = ManifestData.TotalSize();
TArray<uint8> TempCompressed;
TempCompressed.AddUninitialized(DataSize);
int32 CompressedSize = DataSize;
bool bDataIsCompressed = FCompression::CompressMemory(
static_cast<ECompressionFlags>(COMPRESS_ZLIB | COMPRESS_BiasMemory),
TempCompressed.GetData(),
CompressedSize,
ManifestData.GetBytes().GetData(),
DataSize);
TempCompressed.SetNum(CompressedSize);
TArray<uint8>& FileData = bDataIsCompressed ? TempCompressed : ManifestData.GetBytes();
FManifestFileHeader Header;
*FileOut << Header;
Header.HeaderSize = FileOut->Tell();
Header.StoredAs = bDataIsCompressed ? EManifestFileHeader::STORED_COMPRESSED : EManifestFileHeader::STORED_RAW;
Header.DataSize = DataSize;
Header.CompressedSize = bDataIsCompressed ? CompressedSize : 0;
FSHA1::HashBuffer(FileData.GetData(), FileData.Num(), Header.SHAHash.Hash);
FileOut->Seek(0);
*FileOut << Header;
FileOut->Serialize(FileData.GetData(), FileData.Num());
bSuccess = !FileOut->IsError();
}
}
else
{
Data->ManifestFileVersion = EBuildPatchAppManifestVersion::GetLatestJsonVersion();
FString JSONOutput;
SerializeToJSON(JSONOutput);
FTCHARToUTF8 JsonUTF8(*JSONOutput);
FileOut->Serialize((UTF8CHAR*)JsonUTF8.Get(), JsonUTF8.Length() * sizeof(UTF8CHAR));
}
FileOut->Close();
delete FileOut;
FileOut = nullptr;
}
return bSuccess;
}
示例5: GenerateReport
/**
* Write all the data mined from the minidump to a text file
*/
void FLinuxCrashContext::GenerateReport(const FString & DiagnosticsPath) const
{
FArchive* ReportFile = IFileManager::Get().CreateFileWriter(*DiagnosticsPath);
if (ReportFile != NULL)
{
FString Line;
WriteLine(ReportFile, "Generating report for minidump");
WriteLine(ReportFile);
Line = FString::Printf(TEXT("Application version %d.%d.%d.0" ), FEngineVersion::Current().GetMajor(), FEngineVersion::Current().GetMinor(), FEngineVersion::Current().GetPatch());
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
Line = FString::Printf(TEXT(" ... built from changelist %d"), FEngineVersion::Current().GetChangelist());
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
WriteLine(ReportFile);
utsname UnixName;
if (uname(&UnixName) == 0)
{
Line = FString::Printf(TEXT( "OS version %s %s (network name: %s)" ), ANSI_TO_TCHAR(UnixName.sysname), ANSI_TO_TCHAR(UnixName.release), ANSI_TO_TCHAR(UnixName.nodename));
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
Line = FString::Printf( TEXT( "Running %d %s processors (%d logical cores)" ), FPlatformMisc::NumberOfCores(), ANSI_TO_TCHAR(UnixName.machine), FPlatformMisc::NumberOfCoresIncludingHyperthreads());
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
}
else
{
Line = FString::Printf(TEXT("OS version could not be determined (%d, %s)"), errno, ANSI_TO_TCHAR(strerror(errno)));
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
Line = FString::Printf( TEXT( "Running %d unknown processors" ), FPlatformMisc::NumberOfCores());
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
}
Line = FString::Printf(TEXT("Exception was \"%s\""), SignalDescription);
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
WriteLine(ReportFile);
WriteLine(ReportFile, "<SOURCE START>");
WriteLine(ReportFile, "<SOURCE END>");
WriteLine(ReportFile);
WriteLine(ReportFile, "<CALLSTACK START>");
WriteLine(ReportFile, MinidumpCallstackInfo);
WriteLine(ReportFile, "<CALLSTACK END>");
WriteLine(ReportFile);
WriteLine(ReportFile, "0 loaded modules");
WriteLine(ReportFile);
Line = FString::Printf(TEXT("Report end!"));
WriteLine(ReportFile, TCHAR_TO_UTF8(*Line));
ReportFile->Close();
delete ReportFile;
}
}
示例6: HandleLoadCommandExecute
void SVisualLogger::HandleLoadCommandExecute()
{
FArchive Ar;
TArray<FVisualLogDevice::FVisualLogEntryItem> RecordedLogs;
TArray<FString> OpenFilenames;
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
bool bOpened = false;
if (DesktopPlatform)
{
void* ParentWindowWindowHandle = NULL;
IMainFrameModule& MainFrameModule = FModuleManager::LoadModuleChecked<IMainFrameModule>(TEXT("MainFrame"));
const TSharedPtr<SWindow>& MainFrameParentWindow = MainFrameModule.GetParentWindow();
if (MainFrameParentWindow.IsValid() && MainFrameParentWindow->GetNativeWindow().IsValid())
{
ParentWindowWindowHandle = MainFrameParentWindow->GetNativeWindow()->GetOSWindowHandle();
}
const FString DefaultBrowsePath = FString::Printf(TEXT("%slogs/"), *FPaths::GameSavedDir());
bOpened = DesktopPlatform->OpenFileDialog(
ParentWindowWindowHandle,
LOCTEXT("OpenProjectBrowseTitle", "Open Project").ToString(),
DefaultBrowsePath,
TEXT(""),
LogVisualizer::LoadFileTypes,
EFileDialogFlags::None,
OpenFilenames
);
}
if (bOpened && OpenFilenames.Num() > 0)
{
OnNewWorld(nullptr);
for (int FilenameIndex = 0; FilenameIndex < OpenFilenames.Num(); ++FilenameIndex)
{
FString CurrentFileName = OpenFilenames[FilenameIndex];
const bool bIsBinaryFile = CurrentFileName.Find(TEXT(".bvlog")) != INDEX_NONE;
if (bIsBinaryFile)
{
FArchive* FileAr = IFileManager::Get().CreateFileReader(*CurrentFileName);
FVisualLoggerHelpers::Serialize(*FileAr, RecordedLogs);
FileAr->Close();
delete FileAr;
FileAr = NULL;
for (FVisualLogDevice::FVisualLogEntryItem& CurrentItem : RecordedLogs)
{
OnNewLogEntry(CurrentItem);
}
}
}
}
}
示例7: WriteFile
bool UJavascriptLibrary::WriteFile(UObject* Object, FString Filename)
{
FArchive* Writer = IFileManager::Get().CreateFileWriter(*Filename);
if (!Writer)
{
return false;
}
Writer->Serialize(FArrayBufferAccessor::GetData(), FArrayBufferAccessor::GetSize());
return Writer->Close();
}
示例8: VerifyFile
uint8 FBuildPatchUtils::VerifyFile(const FString& FileToVerify, const FSHAHashData& Hash1, const FSHAHashData& Hash2, FBuildPatchFloatDelegate ProgressDelegate, FBuildPatchBoolRetDelegate ShouldPauseDelegate, double& TimeSpentPaused)
{
uint8 ReturnValue = 0;
FArchive* FileReader = IFileManager::Get().CreateFileReader(*FileToVerify);
ProgressDelegate.ExecuteIfBound(0.0f);
if (FileReader != NULL)
{
FSHA1 HashState;
FSHAHashData HashValue;
const int64 FileSize = FileReader->TotalSize();
uint8* FileReadBuffer = new uint8[FileBufferSize];
while (!FileReader->AtEnd() && !FBuildPatchInstallError::HasFatalError())
{
// Pause if necessary
const double PrePauseTime = FPlatformTime::Seconds();
double PostPauseTime = PrePauseTime;
bool bShouldPause = ShouldPauseDelegate.IsBound() && ShouldPauseDelegate.Execute();
while (bShouldPause && !FBuildPatchInstallError::HasFatalError())
{
FPlatformProcess::Sleep(0.1f);
bShouldPause = ShouldPauseDelegate.Execute();
PostPauseTime = FPlatformTime::Seconds();
}
// Count up pause time
TimeSpentPaused += PostPauseTime - PrePauseTime;
// Read file and update hash state
const int64 SizeLeft = FileSize - FileReader->Tell();
const uint32 ReadLen = FMath::Min< int64 >(FileBufferSize, SizeLeft);
FileReader->Serialize(FileReadBuffer, ReadLen);
HashState.Update(FileReadBuffer, ReadLen);
const double FileSizeTemp = FileSize;
const float Progress = 1.0f - ((SizeLeft - ReadLen) / FileSizeTemp);
ProgressDelegate.ExecuteIfBound(Progress);
}
delete[] FileReadBuffer;
HashState.Final();
HashState.GetHash(HashValue.Hash);
ReturnValue = (HashValue == Hash1) ? 1 : (HashValue == Hash2) ? 2 : 0;
if (ReturnValue == 0)
{
GLog->Logf(TEXT("BuildDataGenerator: Verify failed on %s"), *FPaths::GetCleanFilename(FileToVerify));
}
FileReader->Close();
delete FileReader;
}
else
{
GLog->Logf(TEXT("BuildDataGenerator: ERROR VerifyFile cannot open %s"), *FileToVerify);
}
ProgressDelegate.ExecuteIfBound(1.0f);
return ReturnValue;
}
示例9: GenerateMinidump
/**
* Creates (fake so far) minidump
*/
void GenerateMinidump(const FString & Path)
{
FArchive* ReportFile = IFileManager::Get().CreateFileWriter(*Path);
if (ReportFile != NULL)
{
// write BOM
static uint32 Garbage = 0xDEADBEEF;
ReportFile->Serialize(&Garbage, sizeof(Garbage));
ReportFile->Close();
delete ReportFile;
}
}
示例10: G_UnSnapshotLevel
void G_UnSnapshotLevel (bool hubLoad)
{
if (level.info->snapshot == NULL)
return;
if (level.info->isValid())
{
SaveVersion = level.info->snapshotVer;
level.info->snapshot->Reopen ();
FArchive arc (*level.info->snapshot);
if (hubLoad)
arc.SetHubTravel ();
G_SerializeLevel (arc, hubLoad);
arc.Close ();
level.FromSnapshot = true;
TThinkerIterator<APlayerPawn> it;
APlayerPawn *pawn, *next;
next = it.Next();
while ((pawn = next) != 0)
{
next = it.Next();
if (pawn->player == NULL || pawn->player->mo == NULL || !playeringame[pawn->player - players])
{
int i;
// If this isn't the unmorphed original copy of a player, destroy it, because it's extra.
for (i = 0; i < MAXPLAYERS; ++i)
{
if (playeringame[i] && players[i].morphTics && players[i].mo->tracer == pawn)
{
break;
}
}
if (i == MAXPLAYERS)
{
pawn->Destroy ();
}
}
}
}
// No reason to keep the snapshot around once the level's been entered.
level.info->ClearSnapshot();
if (hubLoad)
{
// Unlock ACS global strings that were locked when the snapshot was made.
FBehavior::StaticUnlockLevelVarStrings();
}
}
示例11: EnumerateEngineInstallations
void FDesktopPlatformLinux::EnumerateEngineInstallations(TMap<FString, FString> &OutInstallations)
{
EnumerateLauncherEngineInstallations(OutInstallations);
FString UProjectPath = FString(FPlatformProcess::ApplicationSettingsDir()) / "Unreal.uproject";
FArchive* File = IFileManager::Get().CreateFileWriter(*UProjectPath, FILEWRITE_EvenIfReadOnly);
if (File)
{
File->Close();
delete File;
}
else
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Unable to write to Settings Directory", TCHAR_TO_UTF8(*UProjectPath), NULL);
}
FConfigFile ConfigFile;
FString ConfigPath = FString(FPlatformProcess::ApplicationSettingsDir()) / FString(TEXT("UnrealEngine")) / FString(TEXT("Install.ini"));
ConfigFile.Read(ConfigPath);
FConfigSection &Section = ConfigFile.FindOrAdd(TEXT("Installations"));
// @todo: currently we can enumerate only this installation
FString EngineDir = FPaths::EngineDir();
FString EngineId;
const FName* Key = Section.FindKey(EngineDir);
if (Key)
{
EngineId = Key->ToString();
}
else
{
if (!OutInstallations.FindKey(EngineDir))
{
EngineId = FGuid::NewGuid().ToString(EGuidFormats::DigitsWithHyphens);
Section.AddUnique(*EngineId, EngineDir);
ConfigFile.Dirty = true;
}
}
if (!EngineId.IsEmpty() && !OutInstallations.Find(EngineId))
{
OutInstallations.Add(EngineId, EngineDir);
}
ConfigFile.Write(ConfigPath);
IFileManager::Get().Delete(*UProjectPath);
}
示例12: PutCachedData
bool FRuntimeAssetCacheBackend::PutCachedData(const FName Bucket, const TCHAR* CacheKey, TArray<uint8>& InData, FCacheEntryMetadata* Metadata)
{
bool bResult = false;
FArchive* Ar = CreateWriteArchive(Bucket, CacheKey);
if (!Ar)
{
return bResult;
}
*Ar << *Metadata;
Ar->Serialize(InData.GetData(), InData.Num());
bResult = Ar->Close();
delete Ar;
return bResult;
}
示例13: ReadFile
bool UJavascriptLibrary::ReadFile(UObject* Object, FString Filename)
{
FArchive* Reader = IFileManager::Get().CreateFileReader(*Filename);
if (!Reader)
{
return false;
}
int32 Size = Reader->TotalSize();
if (Size != FArrayBufferAccessor::GetSize())
{
return false;
}
Reader->Serialize(FArrayBufferAccessor::GetData(), Size);
return Reader->Close();
}
示例14:
bool FTextLocalizationManager::FLocalizationEntryTracker::ReadFromFile(const FString& FilePath)
{
FArchive* Reader = IFileManager::Get().CreateFileReader( *FilePath );
if( !Reader )
{
return false;
}
Reader->SetForceUnicode(true);
ReadFromArchive(*Reader, FilePath);
bool Success = Reader->Close();
delete Reader;
return Success;
}
示例15: LoadFileToArray
/**
* Load a binary file to a dynamic array.
*/
bool FFileHelper::LoadFileToArray( TArray<uint8>& Result, const TCHAR* Filename, uint32 Flags )
{
FArchive* Reader = IFileManager::Get().CreateFileReader( Filename, Flags );
if( !Reader )
{
if (!(Flags & FILEREAD_Silent))
{
UE_LOG(LogStreaming,Warning,TEXT("Failed to read file '%s' error."),Filename);
}
return 0;
}
Result.Reset();
Result.AddUninitialized( Reader->TotalSize() );
Reader->Serialize(Result.GetData(), Result.Num());
bool Success = Reader->Close();
delete Reader;
return Success;
}