diff --git a/client/application.cpp b/client/application.cpp index bf7ff75f..3a740bb7 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1,7 +1,7 @@ /* * WiVRn VR streaming - * Copyright (C) 2022 Guillaume Meunier - * Copyright (C) 2022 Patrick Nicolas + * Copyright (C) 2022-2023 Guillaume Meunier + * Copyright (C) 2022-2023 Patrick Nicolas * * 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 @@ -244,6 +244,19 @@ static XrActionType guess_action_type(const std::string & name) 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( VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, @@ -710,6 +723,7 @@ application::application(application_info info) : setup_jni(); jni::object<""> act(app_info.native_app->activity->clazz); auto app = act.call>("getApplication"); + auto ctx = app.call>("getApplicationContext"); // Get the intent, to handle wivrn://uri auto intent = act.call>("getIntent"); @@ -725,6 +739,12 @@ application::application(application_info info) : server_address = data_string.substr(strlen("wivrn://")); } + auto files_dir = ctx.call>("getFilesDir"); + if (auto files_dir_path = files_dir.call("getAbsolutePath")) + { + config_path = files_dir_path; + } + app_info.native_app->userData = this; app_info.native_app->onAppCmd = [](android_app * app, int32_t cmd) { switch (cmd) @@ -766,8 +786,13 @@ application::application(application_info info) : }; initializeLoader((const XrLoaderInitInfoBaseHeaderKHR *)&loaderInitInfoAndroid); } +#else + config_path = get_config_base_dir() / "wivrn"; #endif + std::filesystem::create_directories(config_path); + spdlog::info("Config path: {}", config_path.native()); + try { initialize(); diff --git a/client/application.h b/client/application.h index fa521d92..f8cd063f 100644 --- a/client/application.h +++ b/client/application.h @@ -27,6 +27,7 @@ #include "vk/vk.h" #include "xr/xr.h" #include +#include #include #include #include @@ -117,6 +118,7 @@ class application : public singleton bool debug_extensions_found = false; std::vector xr_extensions; std::atomic exit_requested = false; + std::filesystem::path config_path; std::string server_address;