bool UFlareSaveGameSystem::SaveGame(const FString SaveName, UFlareSaveGame* SaveData) { bool ret = false; SaveLock.Lock(); FLOGV("UFlareSaveGameSystem::SaveGame SaveName=%s", *SaveName); UFlareSaveWriter* SaveWriter = NewObject<UFlareSaveWriter>(this, UFlareSaveWriter::StaticClass()); TSharedRef<FJsonObject> JsonObject = SaveWriter->SaveGame(SaveData); // Save the json object FString FileContents; //TSharedRef< TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> > JsonWriter = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>>::Create(&FileContents); TSharedRef< TJsonWriter<> > JsonWriter = TJsonWriterFactory<>::Create(&FileContents); if (FJsonSerializer::Serialize(JsonObject, JsonWriter)) { JsonWriter->Close(); ret = FFileHelper::SaveStringToFile(FileContents, *GetSaveGamePath(SaveName)); FLOG("UFlareSaveGameSystem::SaveGame : Save done"); } else { FLOGV("Fail to serialize save %s", *SaveName); ret = false; } SaveLock.Unlock(); return ret; }
bool UFlareSaveGameSystem::SaveGame(const FString SaveName, UFlareSaveGame* SaveData) { bool ret = false; SaveLock.Lock(); FLOGV("UFlareSaveGameSystem::SaveGame SaveName=%s", *SaveName); UFlareSaveWriter* SaveWriter = NewObject<UFlareSaveWriter>(this, UFlareSaveWriter::StaticClass()); TSharedRef<FJsonObject> JsonObject = SaveWriter->SaveGame(SaveData); // Save the json object FString FileContents; //TSharedRef< TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> > JsonWriter = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>>::Create(&FileContents); TSharedRef< TJsonWriter<> > JsonWriter = TJsonWriterFactory<>::Create(&FileContents); if (FJsonSerializer::Serialize(JsonObject, JsonWriter)) { JsonWriter->Close(); bool Compress = true; if(Compress) { uint32 StrLength = FCStringAnsi::Strlen(TCHAR_TO_UTF8(*FileContents)); uint8* CompressedDataRaw = new uint8[StrLength]; int32 CompressedSize = StrLength; const bool bResult = FCompression::CompressMemory((ECompressionFlags)(COMPRESS_GZIP), CompressedDataRaw, CompressedSize, TCHAR_TO_UTF8(*FileContents), StrLength); if (bResult) { ret = FFileHelper::SaveArrayToFile(TArrayView<const uint8>(CompressedDataRaw, CompressedSize), *GetSaveGamePath(SaveName, true)); } delete[] CompressedDataRaw; } else { ret = FFileHelper::SaveStringToFile(FileContents, *GetSaveGamePath(SaveName, false)); } FLOG("UFlareSaveGameSystem::SaveGame : Save done"); } else { FLOGV("Fail to serialize save %s", *SaveName); ret = false; } SaveLock.Unlock(); SaveListLock.Lock(); SaveList.Remove(SaveData); SaveListLock.Unlock(); return ret; }