MassBuilderSaveTool/src/Gvas/File.h

99 lines
2.9 KiB
C++

#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2023 Guillaume Jacquemin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Reference.h>
#include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
#include "Types/UnrealPropertyBase.h"
#include "PropertySerialiser.h"
using namespace Corrade;
namespace Gvas {
class File {
public:
explicit File(Containers::String filepath);
bool valid() const;
auto lastError() const -> Containers::StringView;
bool reloadData();
auto saveType() -> Containers::StringView;
template<typename T>
std::enable_if_t<std::is_base_of<Types::UnrealPropertyBase, T>::value, T*>
at(Containers::StringView name) {
for(auto& prop : _properties) {
if(prop->name == name) {
return static_cast<T*>(prop.get());
}
}
return nullptr;
}
void appendProperty(Types::UnrealPropertyBase::ptr prop);
auto props() -> Containers::ArrayView<Types::UnrealPropertyBase::ptr>;
bool saveToFile();
private:
void loadData();
bool _valid{false};
Containers::String _lastError;
Containers::String _filepath;
bool _noReloadAfterSave = false;
Containers::StaticArray<4, char> _magicBytes{'G', 'V', 'A', 'S'};
std::uint32_t _saveVersion = 0;
std::uint32_t _packageVersion = 0;
struct {
std::uint16_t major = 0;
std::uint16_t minor = 0;
std::uint16_t patch = 0;
std::uint32_t build = 0;
Containers::String buildId;
} _engineVersion;
std::uint32_t _customFormatVersion = 0;
struct CustomFormatDataEntry {
Containers::StaticArray<16, char> id;
std::int32_t value = 0;
};
Containers::Array<CustomFormatDataEntry> _customFormatData;
Containers::String _saveType;
Containers::Array<Types::UnrealPropertyBase::ptr> _properties;
Containers::Reference<PropertySerialiser> _propSerialiser;
};
}