diff --git a/src/Application/Application_MassViewer.cpp b/src/Application/Application_MassViewer.cpp index 7fd1fd1..4e12f8a 100644 --- a/src/Application/Application_MassViewer.cpp +++ b/src/Application/Application_MassViewer.cpp @@ -28,7 +28,6 @@ #include "../GameData/Accessories.h" #define STYLENAMES_DEFINITION #include "../GameData/StyleNames.h" -#include "../ImportExport/Export.h" #include "Application.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d564805..28f6659 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -135,14 +135,6 @@ set(Gvas_SOURCES Gvas/PropertySerialiser.cpp ) -set(ImportExport_SOURCES - ImportExport/Import.h - ImportExport/Import.cpp - ImportExport/Export.h - ImportExport/Export.cpp - ImportExport/Keys.h -) - if(CORRADE_TARGET_WINDOWS) set(SAVETOOL_RC_FILE resource.rc) endif() @@ -222,7 +214,6 @@ add_executable(MassBuilderSaveTool ${Logger_SOURCES} ${BinaryIo_SOURCES} ${Gvas_SOURCES} - ${ImportExport_SOURCES} ${SAVETOOL_RC_FILE} ${Assets} ) diff --git a/src/ImportExport/Export.cpp b/src/ImportExport/Export.cpp deleted file mode 100644 index 30ca77a..0000000 --- a/src/ImportExport/Export.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// MassBuilderSaveTool -// Copyright (C) 2021-2024 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 . - -#include -#include - -#include "../Logger/Logger.h" -#include "../BinaryIo/Writer.h" -#include "../Configuration/Configuration.h" -#include "../Utilities/Crc32.h" - -#include "Keys.h" - -#include "Export.h" - -namespace mbst::ImportExport { - -static Containers::String last_export_error; - -Containers::StringView -lastExportError() { - return last_export_error; -} - -bool -exportStyle(Containers::StringView mass_name, mbst::GameObjects::CustomStyle& style) { - Containers::String style_type_str; - switch(style.type) { - case GameObjects::CustomStyle::Type::Unknown: - style_type_str = "Style"; - break; - case GameObjects::CustomStyle::Type::Frame: - style_type_str = "FrameStyle"; - break; - case GameObjects::CustomStyle::Type::Armour: - style_type_str = "ArmourStyle"; - break; - case GameObjects::CustomStyle::Type::Weapon: - style_type_str = "WeaponStyle"; - break; - case GameObjects::CustomStyle::Type::Global: - style_type_str = "GlobalStyle"; - break; - } - - auto filename = Utility::format("{}_{}_{}.style.mbst", mass_name, style_type_str, style.name); - for(auto& c : filename) { - if(c == ' ') { - c = '_'; - } - } - - auto path = Utility::Path::join(conf().directories().styles, filename); - BinaryIo::Writer writer{path}; - - if(!writer.open()) { - last_export_error = path + " couldn't be opened."; - return false; - } - - if(!writer.writeString("MBSTSTYLE")) { - LOG_ERROR(last_export_error = "Couldn't write magic bytes into " + filename); - return false; - } - - writer.writeValueToArray(Keys::CustomStyle::Name); - writer.writeUEStringToArray(style.name); - - writer.writeValueToArray(Keys::CustomStyle::Colour); - writer.writeValueToArray(style.colour); - writer.writeValueToArray(Keys::CustomStyle::Metallic); - writer.writeValueToArray(style.metallic); - writer.writeValueToArray(Keys::CustomStyle::Gloss); - writer.writeValueToArray(style.gloss); - writer.writeValueToArray(Keys::CustomStyle::Glow); - writer.writeValueToArray(style.glow); - - writer.writeValueToArray(Keys::CustomStyle::PatternId); - writer.writeValueToArray(style.patternId); - writer.writeValueToArray(Keys::CustomStyle::PatternOpacity); - writer.writeValueToArray(style.opacity); - writer.writeValueToArray(Keys::CustomStyle::PatternOffset); - writer.writeValueToArray(style.offset); - writer.writeValueToArray(Keys::CustomStyle::PatternRotation); - writer.writeValueToArray(style.rotation); - writer.writeValueToArray(Keys::CustomStyle::PatternScale); - writer.writeValueToArray(style.scale); - - if(!writer.writeUint64(writer.array().size())) { - LOG_ERROR(last_export_error = "Couldn't write data size into " + filename); - writer.closeFile(); - Utility::Path::remove(path); - return false; - } - - auto crc = Utilities::crc32(0, writer.array()); - if(!writer.writeUint32(crc)) { - LOG_ERROR(last_export_error = "Couldn't write CRC32 checksum into " + filename); - writer.closeFile(); - Utility::Path::remove(path); - return false; - } - - if(!writer.flushToFile()) { - LOG_ERROR(last_export_error = "Couldn't write data into " + filename); - writer.closeFile(); - Utility::Path::remove(path); - return false; - } - - return true; -} - -} diff --git a/src/ImportExport/Export.h b/src/ImportExport/Export.h deleted file mode 100644 index 40eda62..0000000 --- a/src/ImportExport/Export.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -// MassBuilderSaveTool -// Copyright (C) 2021-2024 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 . - -#include - -#include "../GameObjects/CustomStyle.h" - -using namespace Corrade; - -namespace mbst::ImportExport { - -auto lastExportError() -> Containers::StringView; - -bool exportStyle(Containers::StringView mass_name, GameObjects::CustomStyle& style); - -} diff --git a/src/ImportExport/Import.cpp b/src/ImportExport/Import.cpp deleted file mode 100644 index decdf35..0000000 --- a/src/ImportExport/Import.cpp +++ /dev/null @@ -1,186 +0,0 @@ -// MassBuilderSaveTool -// Copyright (C) 2021-2024 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 . - -#include - -#include -#include -#include -#include - -#include "../BinaryIo/Reader.h" -#include "../Configuration/Configuration.h" -#include "../Logger/Logger.h" -#include "../Utilities/Crc32.h" - -#include "Keys.h" - -#include "Import.h" - -namespace mbst::ImportExport { - -static Containers::String last_import_error; - -Containers::StringView -lastImportError() { - return last_import_error; -} - -Containers::Optional -importStyle(Containers::StringView filename) { - auto path = Utility::Path::join(conf().directories().styles, filename); - if(!Utility::Path::exists(path)) { - LOG_ERROR(last_import_error = path + " doesn't exist."); - return Containers::NullOpt; - } - - BinaryIo::Reader reader{path}; - if(!reader.open()) { - last_import_error = path + " couldn't be opened."; - return Containers::NullOpt; - } - - Containers::Array magic_bytes; - if(!reader.readArray(magic_bytes, 9)) { - LOG_ERROR(last_import_error = "Couldn't read the magic bytes."); - return Containers::NullOpt; - } - - Containers::StringView magic_bytes_view = magic_bytes; - static const auto expected_magic_bytes = "MBSTSTYLE"_s; - if(magic_bytes_view != expected_magic_bytes) { - LOG_ERROR(last_import_error = "Magic bytes are mismatched."); - return Containers::NullOpt; - } - - std::size_t data_size; - if(!reader.readUint64(data_size)) { - LOG_ERROR(last_import_error = "Couldn't read data size."); - return Containers::NullOpt; - } - - std::uint32_t crc; - if(!reader.readUint32(crc)) { - LOG_ERROR(last_import_error = "Couldn't read CRC-32 checksum."); - return Containers::NullOpt; - } - - auto position = reader.position(); - - { - Containers::Array data; - if(!reader.readArray(data, data_size)) { - LOG_ERROR(last_import_error = "Couldn't read data."); - return Containers::NullOpt; - } - - auto computed_crc = Utilities::crc32(0, data); - if(computed_crc != crc) { - LOG_ERROR(last_import_error = Utility::format("CRC-32 checksum doesn't match. " - "Expected {}, got {} instead.", - crc, computed_crc)); - return Containers::NullOpt; - } - } - - if(!reader.seek(position)) { - LOG_ERROR(last_import_error = Utility::format("Couldn't seek to position {}.", position)); - return Containers::NullOpt; - } - - GameObjects::CustomStyle style{}; - - while(!reader.eof()) { - Keys::CustomStyle key; - if(!reader.readValue(key)) { - if(reader.eof()) { - break; - } - LOG_ERROR(last_import_error = "Couldn't read key."); - return Containers::NullOpt; - } - - switch(key) { - case Keys::Name: - if(!reader.readUEString(style.name)) { - LOG_ERROR(last_import_error = "Couldn't read style name."); - return Containers::NullOpt; - } - break; - case Keys::Colour: - if(!reader.readValue(style.colour)) { - LOG_ERROR(last_import_error = "Couldn't read style colour."); - return Containers::NullOpt; - } - break; - case Keys::Metallic: - if(!reader.readFloat(style.metallic)) { - LOG_ERROR(last_import_error = "Couldn't read style metallic."); - return Containers::NullOpt; - } - break; - case Keys::Gloss: - if(!reader.readFloat(style.gloss)) { - LOG_ERROR(last_import_error = "Couldn't read style gloss."); - return Containers::NullOpt; - } - break; - case Keys::Glow: - if(!reader.readValue(style.glow)) { - LOG_ERROR(last_import_error = "Couldn't read style glow."); - return Containers::NullOpt; - } - break; - case Keys::PatternId: - if(!reader.readInt32(style.patternId)) { - LOG_ERROR(last_import_error = "Couldn't read style pattern ID."); - return Containers::NullOpt; - } - break; - case Keys::PatternOpacity: - if(!reader.readFloat(style.opacity)) { - LOG_ERROR(last_import_error = "Couldn't read style pattern opacity."); - return Containers::NullOpt; - } - break; - case Keys::PatternOffset: - if(!reader.readValue(style.offset)) { - LOG_ERROR(last_import_error = "Couldn't read style pattern offset."); - return Containers::NullOpt; - } - break; - case Keys::PatternRotation: - if(!reader.readFloat(style.rotation)) { - LOG_ERROR(last_import_error = "Couldn't read style pattern rotation."); - return Containers::NullOpt; - } - break; - case Keys::PatternScale: - if(!reader.readFloat(style.scale)) { - LOG_ERROR(last_import_error = "Couldn't read style pattern scale."); - return Containers::NullOpt; - } - break; - default: - LOG_ERROR(last_import_error = Utility::format("Unknown key {}.", key)); - return Containers::NullOpt; - } - } - - return Utility::move(style); -} - -} diff --git a/src/ImportExport/Import.h b/src/ImportExport/Import.h deleted file mode 100644 index 61d0b77..0000000 --- a/src/ImportExport/Import.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -// MassBuilderSaveTool -// Copyright (C) 2021-2024 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 . - -#include - -#include "../GameObjects/CustomStyle.h" - -using namespace Corrade; - -namespace mbst::ImportExport { - -auto lastImportError() -> Containers::StringView; - -auto importStyle(Containers::StringView filename) -> Containers::Optional; - -} diff --git a/src/ImportExport/Keys.h b/src/ImportExport/Keys.h deleted file mode 100644 index eefc2a4..0000000 --- a/src/ImportExport/Keys.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -// MassBuilderSaveTool -// Copyright (C) 2021-2024 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 . - -#include - -namespace mbst::ImportExport::Keys { - -enum CustomStyle: std::uint8_t { - Name = 0, // type: string - Colour = 1, // type: Magnum::Color4 - Metallic = 2, // type: float - Gloss = 3, // type: float - Glow = 4, // type: bool - PatternId = 5, // type: std::int32_t - PatternOpacity = 6, // type: float - PatternOffset = 7, // type: Magnum::Vector2 - PatternRotation = 8, // type: float - PatternScale = 9, // type: float -}; - -}