BOOL CHashDatabase::GetTiger(DWORD nIndex, CTigerTree* pTree) { pTree->Clear(); CSingleLock pLock( &m_pSection, TRUE ); if ( m_bOpen == FALSE ) return FALSE; HASHDB_INDEX* pIndex = Lookup( nIndex, HASH_TIGERTREE ); if ( pIndex == NULL ) return FALSE; try { m_pFile.Seek( pIndex->nOffset, 0 ); CArchive ar( &m_pFile, CArchive::load, 32768 ); // 32 KB buffer try { Serialize( ar, pTree ); ar.Close(); } catch ( CException* pException ) { ar.Abort(); m_pFile.Abort(); pException->Delete(); return FALSE; } } catch ( CException* pException ) { m_pFile.Abort(); pException->Delete(); return FALSE; } return TRUE; }
CString CGXGridCellData::GetMultiCaptionBlobDataChange ( ) { CString strProperty; ASSERT_VALID(this); // if ( !m_bSingleMode ) // DeleteContents(); CMemFile memFile; CArchive arMem(&memFile, CArchive::store ); Serialize ( arMem ); arMem.Flush(); DWORD dwDataLen = memFile.GetLength(); if ( dwDataLen > 0 ) { BYTE *pTemp = new BYTE [dwDataLen+1]; memFile.Seek(0, CFile::begin); memFile.Read(pTemp, dwDataLen ); DWORD dwTotLen = dwDataLen + sizeof(DWORD); BYTE *pvData = new BYTE[dwTotLen]; *(DWORD*)pvData = dwTotLen; memcpy ( pvData + sizeof(DWORD), pTemp, dwDataLen ); if ( pTemp ) delete[] pTemp; // Property Save CString strProperty = BinaryToStringEx ( pvData, dwTotLen ); if ( pvData ) delete[] pvData; } return strProperty; }
char *Json_Array_Delete(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) { char *str; int n; PJVAL jvp; PJAR arp; PGLOBAL g = (PGLOBAL)initid->ptr; PlugSubSet(g, g->Sarea, g->Sarea_Size); jvp = MakeValue(g, args, 0); if (jvp->GetValType() != TYPE_JAR) { push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, "First argument is not an array"); str = args->args[0]; } else if (args->arg_type[1] != INT_RESULT) { push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, "Second argument is not an integer"); str = args->args[0]; } else { n = *(int*)args->args[1]; arp = jvp->GetArray(); arp->DeleteValue(n - 1); arp->InitArray(g); if (!(str = Serialize(g, arp, NULL, 0))) { str = strcpy(result, g->Message); push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, str); } // endif str } // endif's *res_length = strlen(str); return str; } // end of Json_Array_Delete
void SaveGame(const std::string& filename, const ServerSaveGameData& server_save_game_data, const std::vector<PlayerSaveGameData>& player_save_game_data, const Universe& universe, const EmpireManager& empire_manager, const SpeciesManager& species_manager, const CombatLogManager& combat_log_manager) { GetUniverse().EncodingEmpire() = ALL_EMPIRES; std::map<int, SaveGameEmpireData> empire_save_game_data = CompileSaveGameEmpireData(empire_manager); try { #ifdef FREEORION_WIN32 // convert UTF-8 file name to UTF-16 fs::path::string_type file_name_native; utf8::utf8to16(filename.begin(), filename.end(), std::back_inserter(file_name_native)); fs::path path = fs::path(file_name_native); #else fs::path path = fs::path(filename); #endif fs::ofstream ofs(path, std::ios_base::binary); if (!ofs) throw std::runtime_error(UNABLE_TO_OPEN_FILE); FREEORION_OARCHIVE_TYPE oa(ofs); oa << BOOST_SERIALIZATION_NVP(server_save_game_data); oa << BOOST_SERIALIZATION_NVP(player_save_game_data); oa << BOOST_SERIALIZATION_NVP(empire_save_game_data); oa << BOOST_SERIALIZATION_NVP(empire_manager); oa << BOOST_SERIALIZATION_NVP(species_manager); oa << BOOST_SERIALIZATION_NVP(combat_log_manager); Serialize(oa, universe); } catch (const std::exception& e) { Logger().errorStream() << UserString("UNABLE_TO_WRITE_SAVE_FILE") << " SaveGame exception: " << ": " << e.what(); throw e; } }
void CaIeaDataForLoadSave::LoadData (CaIEAInfo* pIEAData, CString& strFile) { try { CFile f((LPCTSTR)strFile, CFile::shareDenyNone|CFile::modeRead); CArchive ar(&f, CArchive::load); Serialize (ar); ar.Flush(); ar.Close(); f.Close(); } catch (CFileException* e) { throw e; } catch (CArchiveException* e) { throw e; } catch(...) { AfxMessageBox (_T("Serialization error. \nCause: Unknown."), MB_OK|MB_ICONEXCLAMATION); } }
BOOL CDownloadGroups::Save(BOOL bForce) { CSingleLock pLock( &m_pSection, TRUE ); if ( ! bForce && m_nBaseCookie == m_nSaveCookie ) return FALSE; m_nSaveCookie = m_nBaseCookie; CString strPath = Settings.General.UserPath + _T("\\Data\\DownloadGroups.dat"); DeleteFile( strPath + _T(".tmp") ); CFile pFile; if ( ! pFile.Open( strPath + _T(".tmp"), CFile::modeWrite | CFile::modeCreate ) ) return FALSE; BYTE* pBuffer = new BYTE[ 4096 ]; try { CArchive ar( &pFile, CArchive::store, 4096, pBuffer ); Serialize( ar ); } catch ( CException* pException ) { delete [] pBuffer; pException->Delete(); return FALSE; } delete [] pBuffer; pFile.Close(); DeleteFile( strPath ); MoveFile( strPath + _T(".tmp"), strPath ); return TRUE; }
QByteArray IMessage::ToJSON(bool *ok) { if (ok != 0) *ok = false; if (!IsValid(true)) { LogError("IMessage::ToJSON: Message is not in a valid state."); return QByteArray(); } // Request the implementation to update the data member. Serialize(); QVariantMap msg; msg["type"] = MessageTypeName(); msg["data"] = data; QVariantMap out; out["channel"] = ChannelTypeName(); out["message"] = msg; return TundraJson::Serialize(out, TundraJson::IndentNone, ok); }
void DTerrain::Load( void* Buffer, dword Size ) { DMemoryReader Loader( Buffer, Size ); Loader.SetBinary(); Serialize( Loader ); //hjk DTerrainSector *pSector = NULL; int nMaxNum = m_aSectors.Num(); for( int i = 0; i < nMaxNum; i++) { pSector = &m_aSectors[i]; if( pSector->m_aSectorLayers.Num() == 0 ) continue; pSector->InitLOD(s_fDistOfNearPlane, s_fDistOfFarPlane, s_fFOV, m_vScale); } //hjk end // Size Confirm // Size = TileSize * TileNum * SectorNum m_vDrawSize.X = m_vScale.X * TC_SectorResolution * m_iSectorsX; m_vDrawSize.Y = m_vScale.Y * TC_SectorResolution * m_iSectorsY; m_vDrawSize.Z = 0.0f; m_fDrawRadius = m_vDrawSize.X*m_vDrawSize.X + m_vDrawSize.Y*m_vDrawSize.Y; }
BOOL CDocument::OnSaveDocument( LPCTSTR lpszPathName ) /****************************************************/ { CFileException ex; CFile *pFile = GetFile( lpszPathName, CFile::modeCreate | CFile::modeWrite, &ex ); if( pFile == NULL ) { ReportSaveLoadException( lpszPathName, &ex, TRUE, AFX_IDP_FAILED_TO_SAVE_DOC ); return( FALSE ); } try { CArchive ar( pFile, CArchive::store ); Serialize( ar ); ar.Close(); SetPathName( lpszPathName ); SetTitle( pFile->GetFileTitle() ); ReleaseFile( pFile, FALSE ); } catch( CException *pEx ) { ReportSaveLoadException( lpszPathName, pEx, TRUE, AFX_IDP_FAILED_TO_SAVE_DOC ); ReleaseFile( pFile, TRUE ); return( FALSE ); } SetModifiedFlag( FALSE ); return( TRUE ); }
/******************************************************************************* Function: FlashWriteStatusRegister( ST_uint8 ucStatusRegister) Arguments: ucStatusRegister, an 8-bit new value to be written to the Status Register Return Value: Flash_Success Description: This function modifies the Status Register by sending an SPI_FLASH_INS_WRSR Instruction. The Write Status Register (WRSR) Instruction has no effect on b6, b5, b1(WEL) and b0(WIP) of the Status Register.b6 and b5 are always read as 0. Pseudo Code: Step 1: Disable Write protection Step 2: Initialize the data (i.e. Instruction & value) packet to be sent serially Step 3: Send the packet serially Step 4: Wait until the operation completes or a timeout occurs. *******************************************************************************/ ReturnType FlashWriteStatusRegister( ST_uint8 ucStatusRegister) { CharStream char_stream_send; ST_uint8 pIns_Val[2]; // Step 1: Disable Write protection FlashWriteEnable(); // Step 2: Initialize the data (i.e. Instruction & value) packet to be sent serially char_stream_send.length = 2; char_stream_send.pChar = pIns_Val; pIns_Val[0] = SPI_FLASH_INS_WRSR; pIns_Val[1] = ucStatusRegister; // Step 3: Send the packet serially Serialize(&char_stream_send, ptrNull, enumEnableTransOnly_SelectSlave, enumDisableTransOnly_DeSelectSlave ); // Step 4: Wait until the operation completes or a timeout occurs. WAIT_TILL_Instruction_EXECUTION_COMPLETE(1) return Flash_Success; }
bool COleDBConnectionProp::LoadFromFile(LPCTSTR FileName) { LPCTSTR iniFileName = FileName; try { CFile file(iniFileName,CFile::modeRead); CArchive ar(&file,CArchive::load); Serialize(ar); } catch(CFileException *ex) { ex->Delete(); return false; } catch(CArchiveException *exAr) { exAr->Delete(); return false; } return true; }
/** * Write the FString to a file. * Supports all combination of ANSI/Unicode files and platforms. */ bool FFileHelper::SaveStringToFile( const FString& String, const TCHAR* Filename, EEncodingOptions::Type EncodingOptions, IFileManager* FileManager /*= &IFileManager::Get()*/ ) { // max size of the string is a UCS2CHAR for each character and some UNICODE magic auto Ar = TUniquePtr<FArchive>( FileManager->CreateFileWriter( Filename, 0 ) ); if( !Ar ) return false; if( String.IsEmpty() ) return true; const TCHAR* StrPtr = *String; bool SaveAsUnicode = EncodingOptions == EEncodingOptions::ForceUnicode || ( EncodingOptions == EEncodingOptions::AutoDetect && !FCString::IsPureAnsi(StrPtr) ); if( EncodingOptions == EEncodingOptions::ForceUTF8 ) { UTF8CHAR UTF8BOM[] = { 0xEF, 0xBB, 0xBF }; Ar->Serialize( &UTF8BOM, ARRAY_COUNT(UTF8BOM) * sizeof(UTF8CHAR) ); FTCHARToUTF8 UTF8String(StrPtr); Ar->Serialize( (UTF8CHAR*)UTF8String.Get(), UTF8String.Length() * sizeof(UTF8CHAR) ); } else if ( EncodingOptions == EEncodingOptions::ForceUTF8WithoutBOM ) { FTCHARToUTF8 UTF8String(StrPtr); Ar->Serialize((UTF8CHAR*)UTF8String.Get(), UTF8String.Length() * sizeof(UTF8CHAR)); } else if (SaveAsUnicode) { UCS2CHAR BOM = UNICODE_BOM; Ar->Serialize( &BOM, sizeof(UCS2CHAR) ); auto Src = StringCast<UCS2CHAR>(StrPtr, String.Len()); Ar->Serialize( (UCS2CHAR*)Src.Get(), Src.Length() * sizeof(UCS2CHAR) ); } else { auto Src = StringCast<ANSICHAR>(StrPtr, String.Len()); Ar->Serialize( (ANSICHAR*)Src.Get(), Src.Length() * sizeof(ANSICHAR) ); } return true; }
void Serializer::Serialize (const string &name, uint64 data) { SerializeString (name); Serialize (data); }
void Serializer::Serialize (const string &name, const char *data) { Serialize (name, string (data)); }
void Serializer::Serialize (const string &name, int32 data) { SerializeString (name); Serialize ((uint32) data); }
void Serializer::Serialize (const string &name, bool data) { SerializeString (name); byte d = data ? 1 : 0; Serialize (d); }
void Serializer::Serialize (const string &name, byte data) { SerializeString (name); Serialize (data); }
AgreementPool::AgreementPool(CivArchive &archive) : ObjPool(k_BIT_GAME_OBJ_TYPE_AGREEMENT) { Serialize(archive) ; }
void Serializer::Serialize (const string &name, const wchar_t *data) { Serialize (name, wstring (data)); }
void SETTINGS::Save(std::string sfile) { CONFIGFILE c; c.Load(sfile); version = SET_VER; Serialize(true, c); c.Write(); }
bool sDocumentBase::Load() { sReader s(Filename); Serialize(s); return s.Finish(); }
void Serializer::SerializeWString (const wstring &data) { uint64 size = (data.size() + 1) * sizeof (wchar_t); Serialize (size); DataStream->Write (ConstBufferPtr ((byte *) (data.data() ? data.data() : data.c_str()), (size_t) size)); }
void Serializer::SerializeString (const string &data) { Serialize ((uint64) data.size() + 1); DataStream->Write (ConstBufferPtr ((byte *) (data.data() ? data.data() : data.c_str()), data.size() + 1)); }
CityList::CityList(BSet<CityAgent> *city_set, CivArchive &archive) { Serialize(city_set, archive); }
void SaveGame(const std::string& filename, const ServerSaveGameData& server_save_game_data, const std::vector<PlayerSaveGameData>& player_save_game_data, const Universe& universe, const EmpireManager& empire_manager, const SpeciesManager& species_manager, const CombatLogManager& combat_log_manager, const GalaxySetupData& galaxy_setup_data, bool multiplayer) { ScopedTimer timer("SaveGame: " + filename, true); bool use_binary = GetOptionsDB().Get<bool>("binary-serialization"); DebugLogger() << "SaveGame(" << (use_binary ? "binary" : "zlib-xml") << ") filename: " << filename; GetUniverse().EncodingEmpire() = ALL_EMPIRES; DebugLogger() << "Compiling save empire and preview data"; std::map<int, SaveGameEmpireData> empire_save_game_data = CompileSaveGameEmpireData(empire_manager); SaveGamePreviewData save_preview_data; CompileSaveGamePreviewData(server_save_game_data, player_save_game_data, empire_save_game_data, save_preview_data); // reinterpret save game data as header data for uncompressed header std::vector<PlayerSaveHeaderData> player_save_header_data; for (std::vector<PlayerSaveGameData>::const_iterator it = player_save_game_data.begin(); it != player_save_game_data.end(); ++it) { player_save_header_data.push_back(*it); } try { fs::path path = FilenameToPath(filename); // A relative path should be relative to the save directory. if (path.is_relative()) { path = GetSaveDir()/path; DebugLogger() << "Made save path relative to save dir. Is now: " << path; } if (multiplayer) { // Make sure the path points into our save directory if (!IsInside(path, GetSaveDir())) { path = GetSaveDir() / path.filename(); } } // set up output archive / stream for saving fs::ofstream ofs(path, std::ios_base::binary); if (!ofs) throw std::runtime_error(UNABLE_TO_OPEN_FILE); if (use_binary) { DebugLogger() << "Creating binary oarchive"; freeorion_bin_oarchive boa(ofs); boa << BOOST_SERIALIZATION_NVP(save_preview_data); boa << BOOST_SERIALIZATION_NVP(galaxy_setup_data); boa << BOOST_SERIALIZATION_NVP(server_save_game_data); boa << BOOST_SERIALIZATION_NVP(player_save_header_data); boa << BOOST_SERIALIZATION_NVP(empire_save_game_data); boa << BOOST_SERIALIZATION_NVP(player_save_game_data); boa << BOOST_SERIALIZATION_NVP(empire_manager); boa << BOOST_SERIALIZATION_NVP(species_manager); boa << BOOST_SERIALIZATION_NVP(combat_log_manager); Serialize(boa, universe); DebugLogger() << "Done serializing"; } else { // Two-tier serialization: // main archive is uncompressed serialized header data first // then contains a string for compressed second archive // that contains the main gamestate info // allocate buffers for serialized gamestate DebugLogger() << "Allocating buffers for XML serialization..."; std::string serial_str, compressed_str; try { serial_str.reserve( std::pow(2.0, 29.0)); compressed_str.reserve(std::pow(2.0, 26.0)); } catch (...) { DebugLogger() << "Unable to preallocate full serialization buffers. Attempting serialization with dynamic buffer allocation."; } // wrap buffer string in iostream::stream to receive serialized data typedef boost::iostreams::back_insert_device<std::string> InsertDevice; InsertDevice serial_inserter(serial_str); boost::iostreams::stream<InsertDevice> s_sink(serial_inserter); // create archive with (preallocated) buffer... freeorion_xml_oarchive xoa(s_sink); // serialize main gamestate info xoa << BOOST_SERIALIZATION_NVP(player_save_game_data); xoa << BOOST_SERIALIZATION_NVP(empire_manager); xoa << BOOST_SERIALIZATION_NVP(species_manager); xoa << BOOST_SERIALIZATION_NVP(combat_log_manager); Serialize(xoa, universe); s_sink.flush(); // wrap gamestate string in iostream::stream to extract serialized data typedef boost::iostreams::basic_array_source<char> SourceDevice; SourceDevice source(serial_str.data(), serial_str.size()); boost::iostreams::stream<SourceDevice> s_source(source); // wrap compresed buffer string in iostream::streams to receive compressed string InsertDevice compressed_inserter(compressed_str); boost::iostreams::stream<InsertDevice> c_sink(compressed_inserter); // compression-filter gamestate into compressed string boost::iostreams::filtering_ostreambuf o; o.push(boost::iostreams::zlib_compressor()); o.push(c_sink); boost::iostreams::copy(s_source, o); c_sink.flush(); // write to save file: uncompressed header serialized data, with compressed main archive string at end... freeorion_xml_oarchive xoa2(ofs); // serialize uncompressed save header info xoa2 << BOOST_SERIALIZATION_NVP(save_preview_data); xoa2 << BOOST_SERIALIZATION_NVP(galaxy_setup_data); xoa2 << BOOST_SERIALIZATION_NVP(server_save_game_data); xoa2 << BOOST_SERIALIZATION_NVP(player_save_header_data); xoa2 << BOOST_SERIALIZATION_NVP(empire_save_game_data); // append compressed gamestate info xoa2 << BOOST_SERIALIZATION_NVP(compressed_str); } } catch (const std::exception& e) { ErrorLogger() << UserString("UNABLE_TO_WRITE_SAVE_FILE") << " SaveGame exception: " << ": " << e.what(); throw e; } DebugLogger() << "SaveGame : Successfully wrote save file"; }
C3String::C3String(CivArchive &archive) { Serialize(archive); }
bool sDocumentBase::Save() { sWriter s(Filename); Serialize(s); return s.Finish(); }
bool FShader::SerializeBase(FArchive& Ar, bool bShadersInline) { Serialize(Ar); Ar << OutputHash; Ar << MaterialShaderMapHash; Ar << VFType; Ar << VFSourceHash; Ar << Type; Ar << SourceHash; Ar << Target; if (Ar.IsLoading()) { int32 NumUniformParameters; Ar << NumUniformParameters; for (int32 ParameterIndex = 0; ParameterIndex < NumUniformParameters; ParameterIndex++) { FString StructName; Ar << StructName; FUniformBufferStruct* Struct = FindUniformBufferStructByName(*StructName); FShaderUniformBufferParameter* Parameter = Struct ? Struct->ConstructTypedParameter() : new FShaderUniformBufferParameter(); Ar << *Parameter; UniformBufferParameterStructs.Add(Struct); UniformBufferParameters.Add(Parameter); } // The shader has been serialized in, so this shader is now initialized. check(Canary != ShaderMagic_CleaningUp); Canary = ShaderMagic_Initialized; } else { int32 NumUniformParameters = UniformBufferParameters.Num(); Ar << NumUniformParameters; for (int32 StructIndex = 0; StructIndex < UniformBufferParameters.Num(); StructIndex++) { FString StructName(UniformBufferParameterStructs[StructIndex]->GetStructTypeName()); Ar << StructName; Ar << *UniformBufferParameters[StructIndex]; } } if (bShadersInline) { // Save the shader resource if we are inlining shaders if (Ar.IsSaving()) { Resource->Serialize(Ar); } if (Ar.IsLoading()) { // Load the inlined shader resource FShaderResource* ShaderResource = new FShaderResource(); ShaderResource->Serialize(Ar); TRefCountPtr<FShaderResource> ExistingResource = FShaderResource::FindShaderResourceById(ShaderResource->GetId()); // Reuse an existing shader resource if a matching one already exists in memory if (ExistingResource) { delete ShaderResource; ShaderResource = ExistingResource; } else { // Register the newly loaded shader resource so it can be reused by other shaders ShaderResource->Register(); } SetResource(ShaderResource); } } else { // if saving, there's nothing to, the required data is already saved above to look it up at load time if (Ar.IsLoading()) { // generate a resource id FShaderResourceId ResourceId; ResourceId.Target = Target; ResourceId.OutputHash = OutputHash; ResourceId.SpecificShaderTypeName = Type->LimitShaderResourceToThisType() ? Type->GetName() : NULL; // use it to look up in the registered resource map TRefCountPtr<FShaderResource> ExistingResource = FShaderResource::FindShaderResourceById(ResourceId); SetResource(ExistingResource); } } return false; }
void SETTINGS::Load(std::string sfile) { CONFIGFILE c; c.Load(sfile); Serialize(false, c); }
TradeRouteData::TradeRouteData(CivArchive &archive) : GameObj(0) { m_astarPath = new Path; m_dontAdjustPointsWhenKilled = FALSE; Serialize(archive); }