From 2f1f780d3127393d0f8d961afce6acb2f48e4bb6 Mon Sep 17 00:00:00 2001 From: GbotHQ <56745325+GbotHQ@users.noreply.github.com> Date: Sun, 22 Sep 2024 01:43:31 +0200 Subject: [PATCH 1/2] Statically link shaders, update cmake version, c++ version and add CPM for cmake package managment --- CMakeLists.txt | 12 +++++-- cmake/modules/get_cpm.cmake | 24 +++++++++++++ src/core/CMakeLists.txt | 16 +++++++++ src/core/DestinationTexturizer.cpp | 13 ++++---- src/core/LayerNode.cpp | 2 +- src/core/MeshTransformer.cpp | 4 +-- src/core/MeshTransformer.h | 2 +- src/core/MeshTransformerResource.cpp | 7 ++-- src/core/MeshTransformerResource.h | 2 +- src/core/ShaderHolder.cpp | 50 +++++++++++++++------------- src/ctrl/CMakeLists.txt | 7 ++++ src/ctrl/FFDEditor.cpp | 9 ++--- src/ctrl/ffd/ffd_TaskResource.cpp | 22 ++++++------ src/ctrl/ffd/ffd_TaskResource.h | 4 +-- src/gui/MainMenuBar.cpp | 2 +- 15 files changed, 114 insertions(+), 62 deletions(-) create mode 100644 cmake/modules/get_cpm.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e452fe95..ce014756 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,19 @@ -cmake_minimum_required(VERSION 3.16) -project(AnimeEffects VERSION 1.5.0 LANGUAGES C CXX) +cmake_minimum_required(VERSION 3.21) +project(AnimeEffects C CXX) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) +set(CMAKE_CXX_STANDARD 20) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") +include(get_cpm) + +CPMAddPackage("gh:batterycenter/embed#v1.2.19") + include(GNUInstallDirs) # You need to add the Qt directory to your path if you're on Windows, otherwise you'll have a very bad time find_package(Qt6 REQUIRED COMPONENTS Core5Compat Core Gui OpenGL OpenGLWidgets Xml Concurrent Widgets Multimedia) diff --git a/cmake/modules/get_cpm.cmake b/cmake/modules/get_cpm.cmake new file mode 100644 index 00000000..baf2d8c3 --- /dev/null +++ b/cmake/modules/get_cpm.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.40.2) +set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 385f847e..0cc96127 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -70,6 +70,21 @@ add_library(${PROJECT_NAME} TimeLine.cpp TimeLine.h TimeLineEvent.cpp TimeLineEvent.h ) + +set(SHADERS_DIR ../../data/shader) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/ClipperWritingFrag.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/ClipperWritingVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/GridDrawingFrag.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/GridDrawingVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/HSVAdjustFrag.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/HSVAdjustVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/LayerDrawingFrag.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/LayerDrawingVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/MeshTransformVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/PartialScreenCopyingFrag.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/PartialScreenCopyingVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/TestBlurVert.glsl) + target_include_directories(${PROJECT_NAME} PUBLIC .. ) @@ -83,6 +98,7 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC AE_PROJECT_FORMAT_OLDEST_MAJOR_VERSION=0 AE_PROJECT_FORMAT_OLDEST_MINOR_VERSION=4 USE_GL_CORE_PROFILE + SHADERS_DIR="${SHADERS_DIR}" ) target_link_libraries(${PROJECT_NAME} PUBLIC diff --git a/src/core/DestinationTexturizer.cpp b/src/core/DestinationTexturizer.cpp index f722a2ca..952ad1f6 100644 --- a/src/core/DestinationTexturizer.cpp +++ b/src/core/DestinationTexturizer.cpp @@ -1,6 +1,7 @@ #include "gl/Global.h" #include "gl/Util.h" #include "core/DestinationTexturizer.h" +#include "battery/embed.hpp" namespace { static const int kAttachmentId = 0; @@ -104,13 +105,13 @@ void DestinationTexturizer::createShader() { auto shader = &mShader; gl::ExtendShader source; - if (!source.openFromFileVert("./data/shader/PartialScreenCopyingVert.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open vertex shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/PartialScreenCopyingVert.glsl">(); + source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size())); } - if (!source.openFromFileFrag("./data/shader/PartialScreenCopyingFrag.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open fragment shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/PartialScreenCopyingFrag.glsl">(); + source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size())); } if (!source.resolveVariation()) { diff --git a/src/core/LayerNode.cpp b/src/core/LayerNode.cpp index 9a5e6371..aa51b01b 100644 --- a/src/core/LayerNode.cpp +++ b/src/core/LayerNode.cpp @@ -29,7 +29,7 @@ LayerNode::LayerNode(const QString& aName, ShaderHolder& aShaderHolder): mTimeLine(), mShaderHolder(aShaderHolder), mIsClipped(), - mMeshTransformer("./data/shader/MeshTransformVert.glsl"), + mMeshTransformer(), mCurrentMesh(), mClippees() {} diff --git a/src/core/MeshTransformer.cpp b/src/core/MeshTransformer.cpp index 05c2f179..3460e621 100644 --- a/src/core/MeshTransformer.cpp +++ b/src/core/MeshTransformer.cpp @@ -7,9 +7,9 @@ namespace core { //------------------------------------------------------------------------------------------------- -MeshTransformer::MeshTransformer(const QString& aShaderPath): +MeshTransformer::MeshTransformer(): mResource(*(new MeshTransformerResource())), mResourceOwns(true), mOutPositions(), mOutXArrows(), mOutYArrows() { - mResource.setup(aShaderPath); + mResource.setup(); } MeshTransformer::MeshTransformer(MeshTransformerResource& aResource): diff --git a/src/core/MeshTransformer.h b/src/core/MeshTransformer.h index c83a8828..12c57b00 100644 --- a/src/core/MeshTransformer.h +++ b/src/core/MeshTransformer.h @@ -16,7 +16,7 @@ namespace core { class MeshTransformer: private util::NonCopyable { public: - MeshTransformer(const QString& aShaderPath); + MeshTransformer(); MeshTransformer(MeshTransformerResource& aResource); ~MeshTransformer(); diff --git a/src/core/MeshTransformerResource.cpp b/src/core/MeshTransformerResource.cpp index 4c2dc374..445d37f1 100644 --- a/src/core/MeshTransformerResource.cpp +++ b/src/core/MeshTransformerResource.cpp @@ -2,15 +2,16 @@ #include "gl/Global.h" #include "gl/ExtendShader.h" #include "core/MeshTransformerResource.h" +#include "battery/embed.hpp" namespace core { //------------------------------------------------------------------------------------------------- MeshTransformerResource::MeshTransformerResource() {} -void MeshTransformerResource::setup(const QString& aShaderPath) { - QString code; - loadFile(aShaderPath, code); +void MeshTransformerResource::setup() { + auto tmp = b::embed<"../../data/shader/MeshTransformVert.glsl">(); + auto code = QString::fromUtf8(tmp.data(), tmp.size()); buildShader(mProgram[0], code, false, false); buildShader(mProgram[1], code, true, false); diff --git a/src/core/MeshTransformerResource.h b/src/core/MeshTransformerResource.h index 06af789a..d614629a 100644 --- a/src/core/MeshTransformerResource.h +++ b/src/core/MeshTransformerResource.h @@ -8,7 +8,7 @@ namespace core { class MeshTransformerResource { public: MeshTransformerResource(); - void setup(const QString& aShaderPath); + void setup(); gl::EasyShaderProgram& program(bool aUseSkinning, bool aUseDualQuaternion); const gl::EasyShaderProgram& program(bool aUseSkinning, bool aUseDualQuaternion) const; diff --git a/src/core/ShaderHolder.cpp b/src/core/ShaderHolder.cpp index 1938ac6a..55cf2e84 100644 --- a/src/core/ShaderHolder.cpp +++ b/src/core/ShaderHolder.cpp @@ -1,6 +1,7 @@ #include "gl/ExtendShader.h" #include "gl/Global.h" #include "core/ShaderHolder.h" +#include "battery/embed.hpp" namespace core { @@ -37,13 +38,13 @@ gl::EasyShaderProgram& ShaderHolder::reserveShader(img::BlendMode aBlendMode, bo auto shader = mShaders[index]; gl::ExtendShader source; - if (!source.openFromFileVert("./data/shader/LayerDrawingVert.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open vertex shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/LayerDrawingVert.glsl">(); + source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size())); } - if (!source.openFromFileFrag("./data/shader/LayerDrawingFrag.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open fragment shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/LayerDrawingFrag.glsl">(); + source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size())); } auto blendFunc = QString("Blend") + img::getBlendFuncNameFromBlendMode(aBlendMode); @@ -90,13 +91,14 @@ gl::EasyShaderProgram& ShaderHolder::reserveHSVShader() { auto shader = mHSVShaders[index]; gl::ExtendShader source; - if (!source.openFromFileVert("./data/shader/HSVAdjustVert.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open vertex shader file.", source.log()); + + { + auto tmp = b::embed<"../../data/shader/HSVAdjustVert.glsl">(); + source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size())); } - if (!source.openFromFileFrag("./data/shader/HSVAdjustFrag.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open fragment shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/HSVAdjustFrag.glsl">(); + source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size())); } if (!source.resolveVariation()) { @@ -134,13 +136,13 @@ gl::EasyShaderProgram& ShaderHolder::reserveGridShader() { auto shader = mGridShaders[0]; gl::ExtendShader source; - if (!source.openFromFileVert("./data/shader/GridDrawingVert.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open vertex shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/GridDrawingVert.glsl">(); + source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size())); } - if (!source.openFromFileFrag("./data/shader/GridDrawingFrag.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open fragment shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/GridDrawingFrag.glsl">(); + source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size())); } if (!source.resolveVariation()) { @@ -175,13 +177,13 @@ gl::EasyShaderProgram& ShaderHolder::reserveClipperShader(bool aIsClippee) { auto shader = mClipperShaders[aIsClippee]; gl::ExtendShader source; - if (!source.openFromFileVert("./data/shader/ClipperWritingVert.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open vertex shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/ClipperWritingVert.glsl">(); + source.openFromTextVert(QString::fromUtf8(tmp.data(), tmp.size())); } - if (!source.openFromFileFrag("./data/shader/ClipperWritingFrag.glsl")) { - XC_FATAL_ERROR("FileIO Error", "Current location: " + QDir::currentPath() + - "Failed to open fragment shader file.", source.log()); + { + auto tmp = b::embed<"../../data/shader/ClipperWritingFrag.glsl">(); + source.openFromTextFrag(QString::fromUtf8(tmp.data(), tmp.size())); } source.setVariationValue("IS_CLIPPEE", aIsClippee ? "1" : "0"); diff --git a/src/ctrl/CMakeLists.txt b/src/ctrl/CMakeLists.txt index b8573d47..7fdfb234 100644 --- a/src/ctrl/CMakeLists.txt +++ b/src/ctrl/CMakeLists.txt @@ -100,6 +100,13 @@ add_library(${PROJECT_NAME} time/time_Scaler.cpp time/time_Scaler.h ExportParams.h ) + +set(SHADERS_DIR ../../data/shader) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FFDBlurVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FFDEraseVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FFDFocusVertexVert.glsl) +b_embed(${PROJECT_NAME} ${SHADERS_DIR}/FreeFormDeformVert.glsl) + target_include_directories(${PROJECT_NAME} PUBLIC .. ) diff --git a/src/ctrl/FFDEditor.cpp b/src/ctrl/FFDEditor.cpp index 5768d753..cca94107 100644 --- a/src/ctrl/FFDEditor.cpp +++ b/src/ctrl/FFDEditor.cpp @@ -23,17 +23,12 @@ FFDEditor::FFDEditor(Project& aProject, DriverResources& aDriverResources, UILog if (!mDriverResources.meshTransformerResource()) { gl::Global::makeCurrent(); mDriverResources.grabMeshTransformerResoure(new core::MeshTransformerResource()); - mDriverResources.meshTransformerResource()->setup("./data/shader/MeshTransformVert.glsl"); + mDriverResources.meshTransformerResource()->setup(); } if (!mDriverResources.ffdTaskResource()) { gl::Global::makeCurrent(); mDriverResources.grabFFDTaskResource(new ffd::TaskResource()); - mDriverResources.ffdTaskResource()->setup( - "./data/shader/FreeFormDeformVert.glsl", - "./data/shader/FFDEraseVert.glsl", - "./data/shader/FFDFocusVertexVert.glsl", - "./data/shader/FFDBlurVert.glsl" - ); + mDriverResources.ffdTaskResource()->setup(); } #if 0 diff --git a/src/ctrl/ffd/ffd_TaskResource.cpp b/src/ctrl/ffd/ffd_TaskResource.cpp index a9daf7a5..b7cd00ae 100644 --- a/src/ctrl/ffd/ffd_TaskResource.cpp +++ b/src/ctrl/ffd/ffd_TaskResource.cpp @@ -2,6 +2,7 @@ #include "gl/Global.h" #include "gl/ExtendShader.h" #include "ctrl/ffd/ffd_TaskResource.h" +#include "battery/embed.hpp" namespace ctrl { namespace ffd { @@ -9,13 +10,11 @@ namespace ffd { //------------------------------------------------------------------------------------------------- TaskResource::TaskResource() {} - void TaskResource::setup( - const QString& aBrushPath, const QString& aEraserPath, const QString& aFocuserPath, const QString& aBlurPath - ) { + void TaskResource::setup() { // load brush shader { - QString code; - loadFile(aBrushPath, code); + auto tmp = b::embed<"../../data/shader/FreeFormDeformVert.glsl">(); + auto code = QString::fromUtf8(tmp.data(), tmp.size()); for (int hard = 0; hard < kHardness; ++hard) { buildShader(mProgram[kTypeDeformer * kHardness + hard], code, kTypeDeformer, hard); @@ -24,8 +23,8 @@ namespace ffd { // load eraser shader { - QString code; - loadFile(aEraserPath, code); + auto tmp = b::embed<"../../data/shader/FFDEraseVert.glsl">(); + auto code = QString::fromUtf8(tmp.data(), tmp.size()); for (int hard = 0; hard < kHardness; ++hard) { buildShader(mProgram[kTypeEraser * kHardness + hard], code, kTypeEraser, hard); @@ -34,16 +33,17 @@ namespace ffd { // load focuser shader { - QString code; - loadFile(aFocuserPath, code); + auto tmp = b::embed<"../../data/shader/FFDFocusVertexVert.glsl">(); + auto code = QString::fromUtf8(tmp.data(), tmp.size()); buildShader(mProgram[kTypeFocuser * kHardness], code, kTypeFocuser, 0); } // load blur path { - QString code; - loadFile(aBlurPath, code); + auto tmp = b::embed<"../../data/shader/FFDBlurVert.glsl">(); + auto code = QString::fromUtf8(tmp.data(), tmp.size()); + buildBlurShader(mBlurProgram, code); } } diff --git a/src/ctrl/ffd/ffd_TaskResource.h b/src/ctrl/ffd/ffd_TaskResource.h index 03924388..d5cc07d5 100644 --- a/src/ctrl/ffd/ffd_TaskResource.h +++ b/src/ctrl/ffd/ffd_TaskResource.h @@ -13,9 +13,7 @@ namespace ffd { TaskResource(); - void setup( - const QString& aBrushPath, const QString& aEraserPath, const QString& aFocuserPath, const QString& aBlurPath - ); + void setup(); gl::EasyShaderProgram& program(int aType, int aHard); const gl::EasyShaderProgram& program(int aType, int aHard) const; diff --git a/src/gui/MainMenuBar.cpp b/src/gui/MainMenuBar.cpp index f615dd10..e74e8d23 100644 --- a/src/gui/MainMenuBar.cpp +++ b/src/gui/MainMenuBar.cpp @@ -20,7 +20,7 @@ namespace gui { //------------------------------------------------------------------------------------------------- QDomDocument getVideoExportDocument() { - QFile file("./data/encode/VideoEncode.txt"); + auto file = QFile("./data/encode/VideoEncode.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << file.errorString(); From a03dd7b21b427929edbfb88ff714a49ff059e1d4 Mon Sep 17 00:00:00 2001 From: GbotHQ <56745325+GbotHQ@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:30:25 +0200 Subject: [PATCH 2/2] Statically link localization and replace ffmpeg test file with a filter --- CMakeLists.txt | 4 +++ src/gui/CMakeLists.txt | 8 +++++ src/gui/GeneralSettingDialog.cpp | 8 ++--- src/gui/LocaleDecider.cpp | 51 +++++++++++++++++++++----------- src/gui/MainMenuBar.cpp | 15 ++++------ 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce014756..0f016e4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,10 @@ set(CMAKE_CXX_STANDARD 20) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") include(get_cpm) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") +else() + set(B_PRODUCTION_MODE ON) +endif() CPMAddPackage("gh:batterycenter/embed#v1.2.19") include(GNUInstallDirs) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index f42f45a9..545a76fb 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -99,6 +99,14 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE AudioPlaybackWidget.cpp AudioPlaybackWidget.h ) + +b_embed(${PROJECT_NAME} ../../data/encode/VideoEncode.txt) +b_embed(${PROJECT_NAME} ../../data/locale/translation_ja.qm) +b_embed(${PROJECT_NAME} ../../data/locale/translation_zh.qm) +b_embed(${PROJECT_NAME} ../../data/locale/preference.txt) +b_embed(${PROJECT_NAME} ../../data/locale/preference_ja.txt) +b_embed(${PROJECT_NAME} ../../data/locale/preference_zh.txt) + target_include_directories(${PROJECT_NAME} PRIVATE .. ) diff --git a/src/gui/GeneralSettingDialog.cpp b/src/gui/GeneralSettingDialog.cpp index 04168824..2c26e52d 100644 --- a/src/gui/GeneralSettingDialog.cpp +++ b/src/gui/GeneralSettingDialog.cpp @@ -421,12 +421,10 @@ GeneralSettingDialog::GeneralSettingDialog(GUIResources& aGUIResources, QWidget* ffmpegNotif.exec(); return; } - // Test file - QString testFile = QFileInfo("./data/themes/classic/icon/filew.png").absoluteFilePath(); - // Sample gif test QProcess gif; - gif.start(ffmpeg, {"-i", testFile, "gif.gif"}, QProcess::ReadWrite); + const QStringList testInput = {"-f", "lavfi", "-i", "testsrc=duration=1:size=24x20:rate=2"}; + gif.start(ffmpeg, testInput + QStringList{"gif.gif"}, QProcess::ReadWrite); gif.waitForFinished(); bool exportSuccess = gif.exitStatus() == 0 && QFileInfo::exists("gif.gif"); qDebug() << "Gif exists: " << QFileInfo::exists("gif.gif") @@ -443,7 +441,7 @@ GeneralSettingDialog::GeneralSettingDialog(GUIResources& aGUIResources, QWidget* // Palettegen test QProcess palettegen; - palettegen.start(ffmpeg, {"-i", testFile, "-vf", "palettegen", "palette.png"}, QProcess::ReadWrite); + palettegen.start(ffmpeg, testInput + QStringList{"-vf", "palettegen", "palette.png"}, QProcess::ReadWrite); palettegen.waitForFinished(); bool pGenSuccess = palettegen.exitStatus() == 0 && QFileInfo::exists("palette.png"); if (!pGenSuccess) { diff --git a/src/gui/LocaleDecider.cpp b/src/gui/LocaleDecider.cpp index 4b7a1ec9..e01c36ef 100644 --- a/src/gui/LocaleDecider.cpp +++ b/src/gui/LocaleDecider.cpp @@ -2,7 +2,9 @@ #include #include #include +#include #include "gui/LocaleDecider.h" +#include "battery/embed.hpp" namespace gui { @@ -31,8 +33,16 @@ LocaleDecider::LocaleDecider(): mLocaleParam(), mTranslator(), mHasTranslator() } if (!locAbb.isEmpty()) { - if (mTranslator.load("translation_" + locAbb, "data/locale")) { - mHasTranslator = true; + if (locAbb == "ja") { + auto locale = b::embed<"../../data/locale/translation_ja.qm">(); + if (mTranslator.load(reinterpret_cast(locale.data()), locale.length(), "data/locale")) { + mHasTranslator = true; + } + } else if (locAbb == "zh") { + auto locale = b::embed<"../../data/locale/translation_zh.qm">(); + if (mTranslator.load(reinterpret_cast(locale.data()), locale.length(), "data/locale")) { + mHasTranslator = true; + } } } @@ -45,23 +55,30 @@ LocaleDecider::LocaleDecider(): mLocaleParam(), mTranslator(), mHasTranslator() const QString opt = ""; #endif - const QString preference = locAbb.isEmpty() ? "preference" : "preference_" + locAbb; + QString preference; + if (locAbb == "ja") { + auto tmp = b::embed<"../../data/locale/preference_ja.txt">(); + preference = QString::fromUtf8(tmp.data(), tmp.size()); + } else if (locAbb == "zh") { + auto tmp = b::embed<"../../data/locale/preference_zh.txt">(); + preference = QString::fromUtf8(tmp.data(), tmp.size()); + } else { + auto tmp = b::embed<"../../data/locale/preference.txt">(); + preference = QString::fromUtf8(tmp.data(), tmp.size()); + } - QFile file("./data/locale/" + preference + ".txt"); - if (file.open(QIODevice::ReadOnly)) { - QTextStream in(&file); - while (!in.atEnd()) { - auto kv = in.readLine().split('='); - if (kv.count() != 2) - continue; - auto key = kv[0].trimmed(); - auto value = kv[1].trimmed(); + for (const auto line : preference.split('\n')) { + auto kv = line.split('='); + if (kv.count() != 2) + continue; + + auto key = kv[0].trimmed(); + auto value = kv[1].trimmed(); - if (key == "font_family" + opt) { - mLocaleParam.fontFamily = value; - } else if (key == "font_size" + opt) { - mLocaleParam.fontSize = value; - } + if (key == "font_family" + opt) { + mLocaleParam.fontFamily = value; + } else if (key == "font_size" + opt) { + mLocaleParam.fontSize = value; } } } diff --git a/src/gui/MainMenuBar.cpp b/src/gui/MainMenuBar.cpp index e74e8d23..c0d4c5ba 100644 --- a/src/gui/MainMenuBar.cpp +++ b/src/gui/MainMenuBar.cpp @@ -2,7 +2,6 @@ #include #include #include -#include "qprocess.h" #include "util/TextUtil.h" #include "cmnd/BasicCommands.h" #include "cmnd/ScopedMacro.h" @@ -16,27 +15,23 @@ #include "gui/GeneralSettingDialog.h" #include "gui/MouseSettingDialog.h" #include "util/NetworkUtil.h" +#include "battery/embed.hpp" namespace gui { //------------------------------------------------------------------------------------------------- QDomDocument getVideoExportDocument() { - auto file = QFile("./data/encode/VideoEncode.txt"); - - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << file.errorString(); - return {}; - } + auto tmp = b::embed<"../../data/encode/VideoEncode.txt">(); + auto code = QString::fromUtf8(tmp.data(), tmp.size()); QDomDocument prop; QString errorMessage; int errorLine = 0; int errorColumn = 0; - if (!prop.setContent(&file, false, &errorMessage, &errorLine, &errorColumn)) { - qDebug() << "invalid xml file. " << file.fileName() << errorMessage << ", line = " << errorLine + if (!prop.setContent(code, false, &errorMessage, &errorLine, &errorColumn)) { + qDebug() << "Internal error: invalid xml file. Error: " << errorMessage << ", line = " << errorLine << ", column = " << errorColumn; return {}; } - file.close(); return prop; }