本文整理汇总了C++中FArchive::Seek方法的典型用法代码示例。如果您正苦于以下问题:C++ FArchive::Seek方法的具体用法?C++ FArchive::Seek怎么用?C++ FArchive::Seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FArchive
的用法示例。
在下文中一共展示了FArchive::Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: SkipLazyArray
void SkipLazyArray(FArchive &Ar)
{
guard(SkipLazyArray);
assert(Ar.IsLoading);
int pos;
Ar << pos;
assert(Ar.Tell() < pos);
Ar.Seek(pos);
unguard;
}
示例3: appFindGameFile
static byte *FindBioTexture(const UTexture *Tex)
{
int needSize = Tex->CachedBulkDataSize & 0xFFFFFFFF;
#if DEBUG_BIO_BULK
appPrintf("Search for ... %s (size=%X)\n", Tex->Name, needSize);
#endif
BioReadBulkCatalog();
for (int i = 0; i < bioCatalog.Num(); i++)
{
BioBulkCatalog &Cat = bioCatalog[i];
for (int j = 0; j < Cat.Files.Num(); j++)
{
const BioBulkCatalogFile &File = Cat.Files[j];
for (int k = 0; k < File.Items.Num(); k++)
{
const BioBulkCatalogItem &Item = File.Items[k];
if (!strcmp(Tex->Name, Item.ObjectName))
{
if (abs(needSize - Item.DataSize) > 0x4000) // differs in 16k
{
#if DEBUG_BIO_BULK
appPrintf("... Found %s in %s with wrong BulkDataSize %X (need %X)\n", Tex->Name, *File.Filename, Item.DataSize, needSize);
#endif
continue;
}
#if DEBUG_BIO_BULK
appPrintf("... Found %s in %s at %X size %X (%dx%d fmt=%d bpp=%g strip:%d mips:%d)\n", Tex->Name, *File.Filename, Item.DataOffset, Item.DataSize,
Tex->USize, Tex->VSize, Tex->Format, (float)Item.DataSize / (Tex->USize * Tex->VSize),
Tex->HasBeenStripped, Tex->StrippedNumMips);
#endif
// found
const CGameFileInfo *bulkFile = appFindGameFile(File.Filename);
if (!bulkFile)
{
// no bulk file
appPrintf("Decompressing %s: %s is missing\n", Tex->Name, *File.Filename);
return NULL;
}
appPrintf("Reading %s mip level %d (%dx%d) from %s\n", Tex->Name, 0, Tex->USize, Tex->VSize, bulkFile->RelativeName);
FArchive *Reader = appCreateFileReader(bulkFile);
Reader->Seek(Item.DataOffset);
byte *buf = (byte*)appMalloc(max(Item.DataSize, needSize));
Reader->Serialize(buf, Item.DataSize);
delete Reader;
return buf;
}
}
}
}
#if DEBUG_BIO_BULK
appPrintf("... Bulk for %s was not found\n", Tex->Name);
#endif
return NULL;
}
示例4: Save
void FShaderCache::Save(FArchive& Ar, const map<FGuid, FShader*>& InShaders)
{
Ar << m_nPlatform;
// serialize the global shader crc
UINT NumShaderBuilderCRC = m_mapShaderBuilderCRC.size();
Ar << NumShaderBuilderCRC;
map<FShaderBuilder*, DWORD>::iterator it;
for( it = m_mapShaderBuilderCRC.begin(); it != m_mapShaderBuilderCRC.end(); ++it )
{
FShaderBuilder* ShaderBuilder = it->first;
Ar << ShaderBuilder;
Ar << it->second;
}
// serialize the global shaders
UINT NumShaders = InShaders.size();
Ar << NumShaders;
for( map<FGuid, FShader*>::const_iterator it = InShaders.begin(); it != InShaders.end(); ++it )
{
FShader* Shader = it->second;
// shader builder的序列化,在加载时可用于检测此类型的shader是否仍存在
FShaderBuilder* ShaderBuilder = Shader->GetShaderBuilder();
FGuid ShaderId = Shader->GetId();
Ar << ShaderBuilder << ShaderId;
// 占个位先。。。应该记录序列化此shader的结束位置
INT SkipOffset = Ar.Tell();
Ar << SkipOffset;
Shader->Serialize(Ar);
INT EndOffset = Ar.Tell();
Ar.Seek(SkipOffset); // 定位回之前位置
Ar << EndOffset; // 记录此shader的结束位置
Ar.Seek(EndOffset); // 定位结束位置,继续下一个shader的序列化
}
}
示例5: UncompressCopyFile
bool UncompressCopyFile(FArchive& Dest, FArchive& Source, const FPakEntry& Entry, uint8*& PersistentBuffer, int64& BufferSize)
{
if (Entry.UncompressedSize == 0)
{
return false;
}
int64 WorkingSize = Entry.CompressionBlockSize;
int32 MaxCompressionBlockSize = FCompression::CompressMemoryBound((ECompressionFlags)Entry.CompressionMethod, WorkingSize);
WorkingSize += MaxCompressionBlockSize;
if (BufferSize < WorkingSize)
{
PersistentBuffer = (uint8*)FMemory::Realloc(PersistentBuffer, WorkingSize);
BufferSize = WorkingSize;
}
uint8* UncompressedBuffer = PersistentBuffer+MaxCompressionBlockSize;
for (uint32 BlockIndex=0, BlockIndexNum=Entry.CompressionBlocks.Num(); BlockIndex < BlockIndexNum; ++BlockIndex)
{
uint32 CompressedBlockSize = Entry.CompressionBlocks[BlockIndex].CompressedEnd - Entry.CompressionBlocks[BlockIndex].CompressedStart;
uint32 UncompressedBlockSize = (uint32)FMath::Min<int64>(Entry.UncompressedSize - Entry.CompressionBlockSize*BlockIndex, Entry.CompressionBlockSize);
Source.Seek(Entry.CompressionBlocks[BlockIndex].CompressedStart);
uint32 SizeToRead = Entry.bEncrypted ? Align(CompressedBlockSize, FAES::AESBlockSize) : CompressedBlockSize;
Source.Serialize(PersistentBuffer, SizeToRead);
if (Entry.bEncrypted)
{
FAES::DecryptData(PersistentBuffer, SizeToRead);
}
if(!FCompression::UncompressMemory((ECompressionFlags)Entry.CompressionMethod,UncompressedBuffer,UncompressedBlockSize,PersistentBuffer,CompressedBlockSize))
{
return false;
}
Dest.Serialize(UncompressedBuffer,UncompressedBlockSize);
}
return true;
}
示例6: ReadTimeArray
static void ReadTimeArray(FArchive &Ar, int NumKeys, TArray<float> &Times, int NumFrames)
{
guard(ReadTimeArray);
Times.Empty(NumKeys);
if (NumKeys <= 1) return;
// appPrintf(" pos=%4X keys (max=%X)[ ", Ar.Tell(), NumFrames);
if (NumFrames < 256)
{
for (int k = 0; k < NumKeys; k++)
{
uint8 v;
Ar << v;
Times.Add(v);
// if (k < 4 || k > NumKeys - 5) appPrintf(" %02X ", v);
// else if (k == 4) appPrintf("...");
}
}
else
{
for (int k = 0; k < NumKeys; k++)
{
uint16 v;
Ar << v;
Times.Add(v);
// if (k < 4 || k > NumKeys - 5) appPrintf(" %04X ", v);
// else if (k == 4) appPrintf("...");
}
}
// appPrintf(" ]\n");
// align to 4 bytes
Ar.Seek(Align(Ar.Tell(), 4));
unguard;
}
示例7: LoadStructWithScript
//------------------------------------------------------------------------------
bool FStructScriptLoader::LoadStructWithScript(UStruct* DestScriptContainer, FArchive& Ar, bool bAllowDeferredSerialization)
{
if (!Ar.IsLoading() || !IsPrimed() || GIsDuplicatingClassForReinstancing)
{
return false;
}
bool const bIsLinkerLoader = Ar.IsPersistent() && (Ar.GetLinker() != nullptr);
int32 const ScriptEndOffset = ScriptSerializationOffset + SerializedScriptSize;
// to help us move development forward (and not have to support ancient
// script code), we define a minimum script version
bool bSkipScriptSerialization = (Ar.UE4Ver() < VER_MIN_SCRIPTVM_UE4) || (Ar.LicenseeUE4Ver() < VER_MIN_SCRIPTVM_LICENSEEUE4);
#if WITH_EDITOR
static const FBoolConfigValueHelper SkipByteCodeHelper(TEXT("StructSerialization"), TEXT("SkipByteCodeSerialization"));
// in editor builds, we're going to regenerate the bytecode anyways, so it
// is a waste of cycles to try and serialize it in
bSkipScriptSerialization |= (bool)SkipByteCodeHelper;
#endif // WITH_EDITOR
bSkipScriptSerialization &= bIsLinkerLoader; // to keep consistent with old UStruct::Serialize() functionality
if (bSkipScriptSerialization)
{
int32 TrackedBufferSize = BytecodeBufferSize;
BytecodeBufferSize = 0; // temporarily clear so that ClearScriptCode() doesn't leave Class->Script with anything allocated
ClearScriptCode(DestScriptContainer);
BytecodeBufferSize = TrackedBufferSize;
// we have to at least move the archiver forward, so it is positioned
// where it expects to be (as if we read in the script)
Ar.Seek(ScriptEndOffset);
return false;
}
bAllowDeferredSerialization &= bIsLinkerLoader;
if (bAllowDeferredSerialization && ShouldDeferScriptSerialization(Ar))
{
ULinkerLoad* Linker = CastChecked<ULinkerLoad>(Ar.GetLinker());
FDeferredScriptTracker::Get().AddDeferredScriptObject(Linker, DestScriptContainer, *this);
// we have to at least move the archiver forward, so it is positioned
// where it expects to be (as if we read in the script)
Ar.Seek(ScriptEndOffset);
return false;
}
Ar.Seek(ScriptSerializationOffset);
if (bIsLinkerLoader)
{
ULinkerLoad* LinkerLoad = CastChecked<ULinkerLoad>(Ar.GetLinker());
TArray<uint8> ShaScriptBuffer;
ShaScriptBuffer.AddUninitialized(SerializedScriptSize);
Ar.Serialize(ShaScriptBuffer.GetData(), SerializedScriptSize);
ensure(ScriptEndOffset == Ar.Tell());
LinkerLoad->UpdateScriptSHAKey(ShaScriptBuffer);
Ar.Seek(ScriptSerializationOffset);
}
DestScriptContainer->Script.Empty(BytecodeBufferSize);
DestScriptContainer->Script.AddUninitialized(BytecodeBufferSize);
int32 BytecodeIndex = 0;
while (BytecodeIndex < BytecodeBufferSize)
{
DestScriptContainer->SerializeExpr(BytecodeIndex, Ar);
}
ensure(ScriptEndOffset == Ar.Tell());
checkf(BytecodeIndex == BytecodeBufferSize, TEXT("'%s' script expression-count mismatch; Expected: %i, Got: %i"), *DestScriptContainer->GetName(), BytecodeBufferSize, BytecodeIndex);
if (!GUObjectArray.IsDisregardForGC(DestScriptContainer))
{
DestScriptContainer->ScriptObjectReferences.Empty();
FArchiveScriptReferenceCollector ObjRefCollector(DestScriptContainer->ScriptObjectReferences);
BytecodeIndex = 0;
while (BytecodeIndex < BytecodeBufferSize)
{
DestScriptContainer->SerializeExpr(BytecodeIndex, ObjRefCollector);
}
}
// success! (we filled the target with serialized script code)
return true;
}
示例8: Serialize
void UTexture::Serialize(FArchive &Ar)
{
guard(UTexture::Serialize);
Super::Serialize(Ar);
#if BIOSHOCK
TRIBES_HDR(Ar, 0x2E);
if (Ar.Game == GAME_Bioshock && t3_hdrSV >= 1)
Ar << CachedBulkDataSize;
if (Ar.Game == GAME_Bioshock && Format == 12) // remap format; note: Bioshock used 3DC name, but real format is DXT5N
Format = TEXF_DXT5N;
#endif // BIOSHOCK
#if SWRC
if (Ar.Game == GAME_RepCommando)
{
if (Format == 14) Format = TEXF_CxV8U8; //?? not verified
}
#endif // SWRC
#if VANGUARD
if (Ar.Game == GAME_Vanguard && Ar.ArVer >= 128 && Ar.ArLicenseeVer >= 25)
{
// has some table for fast mipmap lookups
Ar.Seek(Ar.Tell() + 142); // skip that table
// serialize mips using AR_INDEX count (this game uses int for array counts in all other places)
int Count;
Ar << AR_INDEX(Count);
Mips.AddDefaulted(Count);
for (int i = 0; i < Count; i++)
Ar << Mips[i];
return;
}
#endif // VANGUARD
#if AA2
if (Ar.Game == GAME_AA2 && Ar.ArLicenseeVer >= 8)
{
int unk; // always 10619
Ar << unk;
}
#endif // AA2
Ar << Mips;
if (Ar.Engine() == GAME_UE1)
{
// UE1
bMasked = false; // ignored by UE1, used surface.PolyFlags instead (but UE2 ignores PolyFlags ...)
if (bHasComp) // skip compressed mipmaps
{
TArray<FMipmap> CompMips;
Ar << CompMips;
}
}
#if XIII
if (Ar.Game == GAME_XIII)
{
if (Ar.ArLicenseeVer >= 42)
{
// serialize palette
if (Format == TEXF_P8 || Format == 13) // 13 == TEXF_P4
{
assert(!Palette);
Palette = new UPalette;
Ar << Palette->Colors;
}
}
if (Ar.ArLicenseeVer >= 55)
Ar.Seek(Ar.Tell() + 3);
}
#endif // XIII
#if EXTEEL
if (Ar.Game == GAME_Exteel)
{
// note: this property is serialized as UObject's property too
byte MaterialType; // enum GFMaterialType
Ar << MaterialType;
}
#endif // EXTEEL
unguard;
}
示例9: ReadXprFile
static bool ReadXprFile(const CGameFileInfo *file)
{
guard(ReadXprFile);
FArchive *Ar = appCreateFileReader(file);
int Tag, FileLen, DataStart, DataCount;
*Ar << Tag << FileLen << DataStart << DataCount;
//?? "XPR0" - xpr variant with a single object (texture) inside
if (Tag != BYTES4('X','P','R','1'))
{
#if XPR_DEBUG
appPrintf("Unknown XPR tag in %s\n", file->RelativeName);
#endif
delete Ar;
return true;
}
#if XPR_DEBUG
appPrintf("Scanning %s ...\n", file->RelativeName);
#endif
XprInfo *Info = new(xprFiles) XprInfo;
Info->File = file;
Info->DataStart = DataStart;
// read filelist
int i;
for (i = 0; i < DataCount; i++)
{
int NameOffset, DataOffset;
*Ar << NameOffset << DataOffset;
int savePos = Ar->Tell();
Ar->Seek(NameOffset + 12);
// read name
char c, buf[256];
int n = 0;
while (true)
{
*Ar << c;
if (n < ARRAY_COUNT(buf))
buf[n++] = c;
if (!c) break;
}
buf[ARRAY_COUNT(buf)-1] = 0; // just in case
// create item
XprEntry *Entry = new(Info->Items) XprEntry;
appStrncpyz(Entry->Name, buf, ARRAY_COUNT(Entry->Name));
Entry->DataOffset = DataOffset + 12;
assert(Entry->DataOffset < DataStart);
// seek back
Ar->Seek(savePos);
// setup size of previous item
if (i >= 1)
{
XprEntry *PrevEntry = &Info->Items[i - 1];
PrevEntry->DataSize = Entry->DataOffset - PrevEntry->DataOffset;
}
// setup size of the last item
if (i == DataCount - 1)
Entry->DataSize = DataStart - Entry->DataOffset;
}
// scan data
// data block is either embedded in this block or followed after DataStart position
for (i = 0; i < DataCount; i++)
{
XprEntry *Entry = &Info->Items[i];
#if XPR_DEBUG
// appPrintf(" %08X [%08X] %s\n", Entry->DataOffset, Entry->DataSize, Entry->Name);
#endif
Ar->Seek(Entry->DataOffset);
int id;
*Ar << id;
switch (id)
{
case 0x80020001:
// header is 4 dwords + immediately followed data
Entry->DataOffset += 4 * 4;
Entry->DataSize -= 4 * 4;
break;
case 0x00040001:
// header is 5 dwords + external data
{
int pos;
*Ar << pos;
Entry->DataOffset = DataStart + pos;
}
break;
case 0x00020001:
// header is 4 dwords + external data
{
int d1, d2, pos;
*Ar << d1 << d2 << pos;
Entry->DataOffset = DataStart + pos;
}
break;
default:
// header is 2 dwords - offset and size + external data
{
//.........这里部分代码省略.........
示例10: Serialize
//.........这里部分代码省略.........
Ar << BulkDataSizeOnDisk;
Ar << BulkDataOffsetInFile;
// fix up the file offset
if (Owner != NULL && Owner->GetLinker())
{
BulkDataOffsetInFile += Owner->GetLinker()->Summary.BulkDataStartOffset;
}
// determine whether the payload is stored inline or at the end of the file
bool bPayloadInline = !(BulkDataFlags&BULKDATA_PayloadAtEndOfFile);
// check( (bPayloadInline && BulkDataOffsetInFile == Ar.Tell()) ||
// (!bPayloadInline && BulkDataOffsetInFile > Ar.Tell()));
// We're allowing defered serialization.
if( Ar.IsAllowingLazyLoading() && Owner != NULL)
{
Linker = Owner->GetLinker();
#if WITH_EDITOR
check(Linker);
Ar.AttachBulkData( Owner, this );
AttachedAr = &Ar;
#else
check(Linker.IsValid());
Filename = Linker->Filename;
#endif // WITH_EDITOR
// only skip over payload, if it's stored inline
if (bPayloadInline)
{
Ar.Seek( Ar.Tell() + BulkDataSizeOnDisk );
}
}
// Serialize the bulk data right away.
else
{
// memory for bulk data can come from preallocated GPU-accessible resource memory or default to system memory
BulkData = GetBulkDataResourceMemory(Owner,Idx);
if( !BulkData )
{
BulkData = FMemory::Realloc( BulkData, GetBulkDataSize() );
}
if (bPayloadInline)
{
// if the payload is stored inline, just serialize it
SerializeBulkData( Ar, BulkData );
}
else
{
// if the payload is NOT stored inline ...
// store the current file offset
int64 CurOffset = Ar.Tell();
// seek to the location in the file where the payload is stored
Ar.Seek(BulkDataOffsetInFile);
// serialize the payload
SerializeBulkData( Ar, BulkData );
// seek to the location we came from
Ar.Seek(CurOffset);
}
}
}
示例11: Serialize
void Serialize(int64 DesiredPosition, void* V, int64 Length)
{
const int32 CompressionBlockSize = PakEntry.CompressionBlockSize;
uint32 CompressionBlockIndex = DesiredPosition / CompressionBlockSize;
uint8* WorkingBuffers[2];
int64 DirectCopyStart = DesiredPosition % PakEntry.CompressionBlockSize;
FAsyncTask<FPakUncompressTask> UncompressTask;
FCompressionScratchBuffers& ScratchSpace = FCompressionScratchBuffers::Get();
bool bStartedUncompress = false;
int64 WorkingBufferRequiredSize = FCompression::CompressMemoryBound((ECompressionFlags)PakEntry.CompressionMethod,CompressionBlockSize);
WorkingBufferRequiredSize = EncryptionPolicy::AlignReadRequest(WorkingBufferRequiredSize);
ScratchSpace.EnsureBufferSpace(CompressionBlockSize, WorkingBufferRequiredSize*2);
WorkingBuffers[0] = ScratchSpace.ScratchBuffer;
WorkingBuffers[1] = ScratchSpace.ScratchBuffer + WorkingBufferRequiredSize;
while (Length > 0)
{
const FPakCompressedBlock& Block = PakEntry.CompressionBlocks[CompressionBlockIndex];
int64 Pos = CompressionBlockIndex * CompressionBlockSize;
int64 CompressedBlockSize = Block.CompressedEnd-Block.CompressedStart;
int64 UncompressedBlockSize = FMath::Min<int64>(PakEntry.UncompressedSize-Pos, PakEntry.CompressionBlockSize);
int64 ReadSize = EncryptionPolicy::AlignReadRequest(CompressedBlockSize);
int64 WriteSize = FMath::Min<int64>(UncompressedBlockSize - DirectCopyStart, Length);
PakReader->Seek(Block.CompressedStart);
PakReader->Serialize(WorkingBuffers[CompressionBlockIndex & 1],ReadSize);
if (bStartedUncompress)
{
UncompressTask.EnsureCompletion();
bStartedUncompress = false;
}
FPakUncompressTask& TaskDetails = UncompressTask.GetTask();
if (DirectCopyStart == 0 && Length >= CompressionBlockSize)
{
// Block can be decompressed directly into output buffer
TaskDetails.Flags = (ECompressionFlags)PakEntry.CompressionMethod;
TaskDetails.UncompressedBuffer = (uint8*)V;
TaskDetails.UncompressedSize = UncompressedBlockSize;
TaskDetails.CompressedBuffer = WorkingBuffers[CompressionBlockIndex & 1];
TaskDetails.CompressedSize = CompressedBlockSize;
TaskDetails.CopyOut = nullptr;
}
else
{
// Block needs to be copied from a working buffer
TaskDetails.Flags = (ECompressionFlags)PakEntry.CompressionMethod;
TaskDetails.UncompressedBuffer = (uint8*)ScratchSpace.TempBuffer;
TaskDetails.UncompressedSize = UncompressedBlockSize;
TaskDetails.CompressedBuffer = WorkingBuffers[CompressionBlockIndex & 1];
TaskDetails.CompressedSize = CompressedBlockSize;
TaskDetails.CopyOut = V;
TaskDetails.CopyOffset = DirectCopyStart;
TaskDetails.CopyLength = WriteSize;
}
if (Length == WriteSize)
{
UncompressTask.StartSynchronousTask();
}
else
{
UncompressTask.StartBackgroundTask();
}
bStartedUncompress = true;
V = (void*)((uint8*)V + WriteSize);
Length -= WriteSize;
DirectCopyStart = 0;
++CompressionBlockIndex;
}
if(bStartedUncompress)
{
UncompressTask.EnsureCompletion();
}
}
示例12: ProcessCopy
//.........这里部分代码省略.........
LocalizedFileError( TEXT("FailedClosingDest"), TEXT("AdviseBadDest"), *ThisDest );
delete DestAr;
unguard;
// Patch SrcAr + DeltaFile -> DestAr.
if( Info.Ref!=TEXT("") )
{
guard(PatchFile);
BYTE Buffer[4096];
// Open files.
FString ThisSrc = FullPatch;
FArchive* SrcAr = GFileManager->CreateFileReader( *ThisSrc );
if( !SrcAr )
LocalizedFileError( TEXT("FailedOpenSource"), Patch ? TEXT("AdviseBadDownload") : TEXT("AdviseBadMedia"), *ThisSrc );
INT Size = SrcAr->TotalSize();
FArchive* DestAr = GFileManager->CreateFileWriter(*FullDest,FILEWRITE_EvenIfReadOnly);
if( !DestAr )
LocalizedFileError( TEXT("FailedOpenDest"), TEXT("AdviseBadDest"), *FullDest );
// Load delta file.
TArray<BYTE> Delta;
FString DeltaName = Info.Src;
if( !appLoadFileToArray( Delta, *DeltaName ) )
LocalizedFileError( TEXT("FailedLoadingUpdate"), TEXT("AdviseBadDownload"), *Info.Src );
debugf( TEXT("Patching %s to %s with %s"), *ThisSrc, *FullDest, *DeltaName );
// Decompress variables.
INT PrevSpot=0, CountSize=0, CRC=0;
INT Magic=0, OldSize=0, OldCRC=0, NewSize=0, NewCRC;
FBufferReader Reader( Delta );
Reader << Magic << OldSize << OldCRC << NewSize << NewCRC;
// Validate.
if( Magic!=0x92f92912 )
appErrorf( LineFormat(LocalizeError("PatchCorrupt")), *DeltaName, LocalizeError("AdviseBadDownload") );
if( OldSize!=Size || OldCRC!=CalcOldCRC )
appErrorf( LocalizeError("CdFileMismatch"), *Info.Ref, *LocalProduct );
// Delta decode it.
INT OldCountSize=0;
while( !Reader.AtEnd() )
{
INT Index;
Reader << AR_INDEX(Index);
if( Index<0 )
{
CRC = appMemCrc( &Delta(Reader.Tell()), -Index, CRC );
DestAr->Serialize( &Delta(Reader.Tell()), -Index );
if( DestAr->IsError() )
LocalizedFileError( TEXT("FailedWritingDest"), TEXT("AdviseBadDest"), *FullDest );
Reader.Seek( Reader.Tell() - Index );
CountSize -= Index;
}
else
{
INT CopyPos;
Reader << AR_INDEX(CopyPos);
CopyPos += PrevSpot;
check(CopyPos>=0);
check(CopyPos+Index<=Size);
SrcAr->Seek( CopyPos );
for( INT Base=Index; Base>0; Base-=sizeof(Buffer) )
{
INT Move = Min(Base,(INT)sizeof(Buffer));
SrcAr->Serialize( Buffer, Move );
if( SrcAr->IsError() )
LocalizedFileError( TEXT("FailedReadingSource"), Patch ? TEXT("AdviseBadDownload") : TEXT("AdviseBadDownload"), *ThisSrc );
CRC = appMemCrc( Buffer, Move, CRC );
DestAr->Serialize( Buffer, Move );
if( DestAr->IsError() )
LocalizedFileError( TEXT("FailedWritingDest"), TEXT("AdviseBadDest"), *FullDest );
}
CountSize += Index;
PrevSpot = CopyPos + Index;
}
if( ((CountSize^OldCountSize)&~(sizeof(Buffer)-1)) || Reader.AtEnd() )
{
if( !Poll->Poll(*FullDest,CountSize,Info.Size,RunningBytes+=(CountSize-OldCountSize),TotalBytes) )
{
delete SrcAr;
delete DestAr;
DidCancel();
}
OldCountSize = CountSize;
}
}
if( NewSize!=CountSize || NewCRC!=CRC )
appErrorf( LineFormat(LocalizeError("PatchCorrupt")), *DeltaName, LocalizeError("AdviseBadDownload") );
delete SrcAr;
if( !DestAr->Close() )
LocalizedFileError( TEXT("FailedClosingDest"), TEXT("AdviseBadDest"), *FullDest );
delete DestAr;
GFileManager->Delete( *ThisSrc );
unguard;
}
}
}
unguard;
}
示例13: Load
void FShaderCache::Load(FArchive& Ar)
{
Ar << m_nPlatform;
UINT NumShaderBuilderCRC = 0;
Ar << NumShaderBuilderCRC;
for(UINT IndexBuilder = 0; IndexBuilder < NumShaderBuilderCRC; ++IndexBuilder)
{
FShaderBuilder* ShaderBuilder = NULL;
Ar << ShaderBuilder;
DWORD CRC = 0;
Ar << CRC;
if( ShaderBuilder )
{
m_mapShaderBuilderCRC[ShaderBuilder] = CRC;
}
}
// serialize the global shaders
UINT NumShaders = 0;
UINT NumDesertedShaders = 0;
UINT NumRedundantShaders = 0;
vector<FString> OutdatedShaderBuilders;
Ar << NumShaders;
for(UINT IndexShader = 0; IndexShader < NumShaders; ++IndexShader)
{
FShaderBuilder* ShaderBuilder = NULL;
FGuid ShaderId;
Ar << ShaderBuilder << ShaderId;
INT SkipOffset = 0;
Ar << SkipOffset;
if( !ShaderBuilder )
{
++NumDesertedShaders;
Ar.Seek(SkipOffset); // this shader builder doesn't exist any more, skip the shader
}
else
{
DWORD CurrentCRC = 0;
DWORD SavedCRC = 0;
// 比较当前与之前版本的CRC,检测是否有改动
CurrentCRC = ShaderBuilder->GetSourceCRC();
map<FShaderBuilder*, DWORD>::const_iterator it = m_mapShaderBuilderCRC.find(ShaderBuilder);
if( it != m_mapShaderBuilderCRC.end() )
{
SavedCRC = it->second;
}
FShader* Shader = ShaderBuilder->FindShaderById(ShaderId);
if( Shader )
{
++NumRedundantShaders;
Ar.Seek(SkipOffset); // has already exist, skip it
}
else if( SavedCRC != CurrentCRC )
{
++NumDesertedShaders;
Ar.Seek(SkipOffset);
if( SavedCRC != 0 ) // denote SHADER BUILDER exists, but it has changed
{
OutdatedShaderBuilders.push_back(ShaderBuilder->GetShaderName());
}
}
else
{
// the shader is compatiable, create it
Shader = ShaderBuilder->ConstructSerialization();
UBOOL bShaderHasOutdatedParameters = Shader->Serialize(Ar);
if( bShaderHasOutdatedParameters )
{
ShaderBuilder->UnregisterShader(Shader);
delete Shader;
}
check(Ar.Tell() == SkipOffset);
}
}
}
if( OutdatedShaderBuilders.size() > 0 )
{
debugf(TEXT("Skip %d outdated FShaderBuilder"), OutdatedShaderBuilders.size());
for(UINT IndexBuilder = 0; IndexBuilder < OutdatedShaderBuilders.size(); ++IndexBuilder)
{
debugf(TEXT(" %s"), OutdatedShaderBuilders.at(IndexBuilder).c_str());
}
}
if( NumShaders > 0 )
{
debugf(TEXT("Loaded %d shaders (%d deserted, %d redundant)"), NumShaders, NumDesertedShaders, NumRedundantShaders);
}
}
示例14: LoadCapture
void FProfilerClientManager::LoadCapture( const FString& DataFilepath, const FGuid& ProfileId )
{
#if STATS
// start an async load
LoadConnection = &Connections.FindOrAdd(ProfileId);
LoadConnection->InstanceId = ProfileId;
LoadConnection->MetaData.CriticalSection = &LoadConnection->CriticalSection;
LoadConnection->MetaData.SecondsPerCycle = FPlatformTime::GetSecondsPerCycle(); // fix this by adding a message which specifies this
const int64 Size = IFileManager::Get().FileSize( *DataFilepath );
if( Size < 4 )
{
UE_LOG( LogProfile, Error, TEXT( "Could not open: %s" ), *DataFilepath );
return;
}
#if PROFILER_THREADED_LOAD
FArchive* FileReader = IFileManager::Get().CreateFileReader(*DataFilepath);
#else
FileReader = IFileManager::Get().CreateFileReader( *DataFilepath );
#endif
if( !FileReader )
{
UE_LOG( LogProfile, Error, TEXT( "Could not open: %s" ), *DataFilepath );
return;
}
if( !LoadConnection->Stream.ReadHeader( *FileReader ) )
{
UE_LOG( LogProfile, Error, TEXT( "Could not open, bad magic: %s" ), *DataFilepath );
delete FileReader;
return;
}
// This shouldn't happen.
if( LoadConnection->Stream.Header.bRawStatsFile )
{
delete FileReader;
return;
}
const bool bIsFinalized = LoadConnection->Stream.Header.IsFinalized();
if( bIsFinalized )
{
// Read metadata.
TArray<FStatMessage> MetadataMessages;
LoadConnection->Stream.ReadFNamesAndMetadataMessages( *FileReader, MetadataMessages );
LoadConnection->CurrentThreadState.ProcessMetaDataOnly( MetadataMessages );
// Read frames offsets.
LoadConnection->Stream.ReadFramesOffsets( *FileReader );
FileReader->Seek( LoadConnection->Stream.FramesInfo[0].FrameFileOffset );
}
if( LoadConnection->Stream.Header.HasCompressedData() )
{
UE_CLOG( !bIsFinalized, LogProfile, Fatal, TEXT( "Compressed stats file has to be finalized" ) );
}
#if PROFILER_THREADED_LOAD
LoadTask = new FAsyncTask<FAsyncReadWorker>(LoadConnection, FileReader);
LoadTask->StartBackgroundTask();
#endif
RetryTime = 0.05f;
TickDelegateHandle = FTicker::GetCoreTicker().AddTicker(TickDelegate, RetryTime);
ProfilerLoadStartedDelegate.Broadcast(ProfileId);
#endif
}
示例15: Serialize
void UNavCollision::Serialize(FArchive& Ar)
{
Super::Serialize(Ar);
const int32 VerInitial = 1;
const int32 VerAreaClass = 2;
const int32 VerConvexTransforms = 3;
const int32 VerLatest = VerConvexTransforms;
// use magic number to determine if serialized stream has version :/
const int32 MagicNum = 0xA237F237;
int64 StreamStartPos = Ar.Tell();
int32 Version = VerLatest;
int32 MyMagicNum = MagicNum;
Ar << MyMagicNum;
if (MyMagicNum != MagicNum)
{
Version = VerInitial;
Ar.Seek(StreamStartPos);
}
else
{
Ar << Version;
}
// loading a dummy GUID to have serialization not break on
// packages serialized before switching over UNavCollision to
// use BodySetup's guid rather than its own one
// motivation: not creating a new engine version
// @NOTE could be addressed during next engine version bump
FGuid Guid;
Ar << Guid;
bool bCooked = Ar.IsCooking();
Ar << bCooked;
if (FPlatformProperties::RequiresCookedData() && !bCooked && Ar.IsLoading())
{
UE_LOG(LogNavigation, Fatal, TEXT("This platform requires cooked packages, and NavCollision data was not cooked into %s."), *GetFullName());
}
if (bCooked && ShouldUseConvexCollision())
{
if (Ar.IsCooking())
{
FName Format = NAVCOLLISION_FORMAT;
GetCookedData(Format); // Get the data from the DDC or build it
TArray<FName> ActualFormatsToSave;
ActualFormatsToSave.Add(Format);
CookedFormatData.Serialize(Ar, this, &ActualFormatsToSave);
}
else
{
CookedFormatData.Serialize(Ar, this);
}
}
if (Version >= VerAreaClass)
{
Ar << AreaClass;
}
if (Version < VerConvexTransforms && Ar.IsLoading() && GIsEditor)
{
bForceGeometryRebuild = true;
}
}