Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Flatpak) Several fixes concernig Flatpak builds. #270

Merged
merged 15 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions CHANGELOG.md

This file was deleted.

9 changes: 9 additions & 0 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ message(STATUS "SpaRcle Engine: C++ compiler is '${CMAKE_CXX_COMPILER}'")
option(SR_ENGINE_FLATPAK_BUILD "" OFF)
option(SR_ENGINE_EXTENDED_NAME "" ON)

if (SR_ENGINE_FLATPAK_BUILD)
add_compile_definitions(SR_ENGINE_FLATPAK_BUILD)
endif()

# TODO!
#add_compile_definitions(_CONTAINER_DEBUG_LEVEL=0)
#add_compile_definitions(_ITERATOR_DEBUG_LEVEL=0)
Expand Down Expand Up @@ -76,6 +80,11 @@ else()
set(executableType "latest")
endif()

if (SR_ENGINE_FLATPAK_BUILD)
install(TARGETS SREngine DESTINATION /app/bin)
install(TARGETS SREngine PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif()

if (SR_ENGINE_EXTENDED_NAME)
if (UNIX AND NOT APPLE)
set_target_properties(SREngine PROPERTIES OUTPUT_NAME "SREngine_v${SR_ENGINE_VERSION}-${executableType}_linux.${CURRENT_TARGET_ARCHITECTURE}")
Expand Down
80 changes: 51 additions & 29 deletions Engine/Core/src/Core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ namespace SR_CORE_NS {
logDir = folder;
}

InitLogger(logDir);

return InitializeResourcesFolder(argc, argv);
return InitLogger(logDir);
}

/*void Application::TryPlayStartSound() {
Expand Down Expand Up @@ -89,29 +87,27 @@ namespace SR_CORE_NS {
}*/

bool Application::FindResourcesFolder() {
m_resourcesPath = m_applicationPath.Concat("Resources");
if (m_resourcesPath.Exists(SR_UTILS_NS::Path::Type::Folder)) {
return true;
}

m_resourcesPath = m_applicationPath.Concat("../Resources");
if (m_resourcesPath.Exists(SR_UTILS_NS::Path::Type::Folder)) {
return true;
}

m_resourcesPath = m_applicationPath.Concat("../../Resources");
if (m_resourcesPath.Exists(SR_UTILS_NS::Path::Type::Folder)) {
return true;
}

m_resourcesPath = m_applicationPath.Concat("../../../Resources");
if (m_resourcesPath.Exists(SR_UTILS_NS::Path::Type::Folder)) {
return true;
}
static const std::vector<std::string> potentialPaths = {
"",
"..",
"../..",
"../../..",
"../../../.."
};

for (auto&& relativePath : potentialPaths) {
auto fullPath = m_applicationPath.Concat(relativePath);

#ifdef SR_LINUX
if (fullPath.View().size() == 1) {
return false;
}
#endif

m_resourcesPath = m_applicationPath.Concat("../../../../Resources");
if (m_resourcesPath.Exists(SR_UTILS_NS::Path::Type::Folder)) {
return true;
if (fullPath.Concat("Resources").Exists(SR_UTILS_NS::Path::Type::Folder)) {
m_resourcesPath = fullPath;
return true;
}
}

return false;
Expand All @@ -130,7 +126,6 @@ namespace SR_CORE_NS {

SR_UTILS_NS::Debug::Instance().Init(logPath, true, SR_UTILS_NS::Debug::Theme::Dark);
SR_UTILS_NS::Debug::Instance().SetLevel(SR_UTILS_NS::Debug::Level::Low);

return true;
}

Expand Down Expand Up @@ -274,20 +269,47 @@ namespace SR_CORE_NS {
}

bool Application::InitializeResourcesFolder(int argc, char** argv) {
if (auto&& folder = SR_UTILS_NS::GetCmdOption(argv, argv + argc, "-resources"); !folder.empty()) {
#ifdef SR_ENGINE_FLATPAK_BUILD
if (FindResourcesFolder()) {
return true;
}

if (SR_UTILS_NS::Path folder = SR_UTILS_NS::GetCmdOption(argv, argv + argc, "-resources"); !folder.empty()) {
m_resourcesPath = folder;

if (folder.Exists()) {
return true;
}

SR_UTILS_NS::Path defaultFlatpakPath = "/app/share/SREngine/Resources";
if (defaultFlatpakPath.Exists() && defaultFlatpakPath.Copy(folder)) {
return true;
}
}

if (!m_resourcesPath.Exists(SR_UTILS_NS::Path::Type::Folder) && !FindResourcesFolder()) {
SR_ERROR("Application::InitializeResourcesFolder() : necessary resources were not found. Please try reinstalling the application.");
return false;
#else
if (SR_UTILS_NS::Path folder = SR_UTILS_NS::GetCmdOption(argv, argv + argc, "-resources"); !folder.empty()) {
if (!folder.Exists(SR_UTILS_NS::Path::Type::Folder)) {
SR_INFO("Application::InitializeResourcesFolder() : specified resources folder does not exist!");
}
else {
m_resourcesPath = folder;
return true;
}
}
if (!FindResourcesFolder()) {
SR_LOG("Application::InitializeResourcesFolder() : failed to find resources folder!");
return false;
}

return true;
#endif
}

void Application::SwitchResourcesFolder(const SR_UTILS_NS::Path& path) {

SR_STATIC_ASSERT("Not yet implemented.");
}

void Application::Reload() {
Expand Down
17 changes: 13 additions & 4 deletions Engine/Core/src/Core/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ namespace SR_CORE_NS {
return LauncherInitStatus::Error;
}

#ifdef SR_ENGINE_FLATPAK_BUILD
if (Super::InitializeResourcesFolder(argc, argv)) {
return LauncherInitStatus::Success;
}

SR_ERROR("Launcher::InitLauncher() : failed to initialize resources folder!\n");
return LauncherInitStatus::Error;
#else
if (Super::InitializeResourcesFolder(argc, argv)) {
SR_LOG("Launcher::InitLauncher() : resources folder found.");
if (SR_UTILS_NS::HasCmdOption(argv, argv + argc, "--delete-old-app")) {
Expand All @@ -30,6 +38,7 @@ namespace SR_CORE_NS {
}

return LauncherInitStatus::Unpacking;
#endif
}

bool Launcher::UnpackAndExecute() {
Expand Down Expand Up @@ -87,20 +96,20 @@ namespace SR_CORE_NS {
bool Launcher::CloneResources() {
#ifdef SR_LINUX
auto&& git2path = GetResourcesPath().Concat("Engine/Utilities/git2");
#elif defined (SR_WIN32)
#elif defined(SR_WIN32)
auto&& git2path = GetResourcesPath().Concat("Engine/Utilities/git2.exe");
#endif

auto&& cachePath = GetResourcesPath().Concat("Cache");

if (!cachePath.Create()) {
SR_ERROR("Launcher::CloneResources() : failed to create cache directory.");
return false;
}

std::string command =
"cd " + cachePath.ToStringRef() + " && " +
git2path.ToStringRef() + " clone https://github.com/SpaRcle-Studio/SRE2R -b release/0.0.7 --depth 1";
git2path.ToStringRef() + " clone https://github.com/SpaRcle-Studio/SRE2R " +
cachePath.Concat("SRE2R").ToStringRef() +
" -b release/0.0.7 --depth 1";

SR_SYSTEM_LOG("Launcher::CloneResources() : cloning repository...\n" + command);

Expand Down
Loading