Get the configuration directory path during initialization

This commit is contained in:
Guillaume Meunier
2024-01-28 11:33:30 +01:00
parent 6d808eac94
commit 891ff81c4f
2 changed files with 29 additions and 2 deletions
+27 -2
View File
@@ -1,7 +1,7 @@
/* /*
* WiVRn VR streaming * WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net> * Copyright (C) 2022-2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net> * Copyright (C) 2022-2023 Patrick Nicolas <patricknicolas@laposte.net>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -244,6 +244,19 @@ static XrActionType guess_action_type(const std::string & name)
return XR_ACTION_TYPE_FLOAT_INPUT; return XR_ACTION_TYPE_FLOAT_INPUT;
} }
#ifndef XR_USE_PLATFORM_ANDROID
static std::filesystem::path get_config_base_dir()
{
const char * xdg_config_home = std::getenv("XDG_CONFIG_HOME");
if (xdg_config_home)
return xdg_config_home;
const char * home = std::getenv("HOME");
if (home)
return std::filesystem::path(home) / ".config";
return ".";
}
#endif
VkBool32 application::vulkan_debug_report_callback( VkBool32 application::vulkan_debug_report_callback(
VkDebugReportFlagsEXT flags, VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objectType, VkDebugReportObjectTypeEXT objectType,
@@ -710,6 +723,7 @@ application::application(application_info info) :
setup_jni(); setup_jni();
jni::object<""> act(app_info.native_app->activity->clazz); jni::object<""> act(app_info.native_app->activity->clazz);
auto app = act.call<jni::object<"android/app/Application">>("getApplication"); auto app = act.call<jni::object<"android/app/Application">>("getApplication");
auto ctx = app.call<jni::object<"android/content/Context">>("getApplicationContext");
// Get the intent, to handle wivrn://uri // Get the intent, to handle wivrn://uri
auto intent = act.call<jni::object<"android/content/Intent">>("getIntent"); auto intent = act.call<jni::object<"android/content/Intent">>("getIntent");
@@ -725,6 +739,12 @@ application::application(application_info info) :
server_address = data_string.substr(strlen("wivrn://")); server_address = data_string.substr(strlen("wivrn://"));
} }
auto files_dir = ctx.call<jni::object<"java/io/File">>("getFilesDir");
if (auto files_dir_path = files_dir.call<jni::string>("getAbsolutePath"))
{
config_path = files_dir_path;
}
app_info.native_app->userData = this; app_info.native_app->userData = this;
app_info.native_app->onAppCmd = [](android_app * app, int32_t cmd) { app_info.native_app->onAppCmd = [](android_app * app, int32_t cmd) {
switch (cmd) switch (cmd)
@@ -766,8 +786,13 @@ application::application(application_info info) :
}; };
initializeLoader((const XrLoaderInitInfoBaseHeaderKHR *)&loaderInitInfoAndroid); initializeLoader((const XrLoaderInitInfoBaseHeaderKHR *)&loaderInitInfoAndroid);
} }
#else
config_path = get_config_base_dir() / "wivrn";
#endif #endif
std::filesystem::create_directories(config_path);
spdlog::info("Config path: {}", config_path.native());
try try
{ {
initialize(); initialize();
+2
View File
@@ -27,6 +27,7 @@
#include "vk/vk.h" #include "vk/vk.h"
#include "xr/xr.h" #include "xr/xr.h"
#include <array> #include <array>
#include <filesystem>
#include <mutex> #include <mutex>
#include <unordered_set> #include <unordered_set>
#include <vulkan/vulkan_raii.hpp> #include <vulkan/vulkan_raii.hpp>
@@ -117,6 +118,7 @@ class application : public singleton<application>
bool debug_extensions_found = false; bool debug_extensions_found = false;
std::vector<std::string> xr_extensions; std::vector<std::string> xr_extensions;
std::atomic<bool> exit_requested = false; std::atomic<bool> exit_requested = false;
std::filesystem::path config_path;
std::string server_address; std::string server_address;