HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
path_location_win32_impl.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
8
9#include "path_location_intf.hpp"
10#include "../metadata/metadata.hpp"
11#include "../telemetry/telemetry.hpp"
12#include "../utility/utility.hpp"
13#include "../char_maps/char_maps.hpp" // XXX #616
14#include "../macros.hpp"
15#include <filesystem>
16#include <string>
17#include <coroutine>
18
19hi_export_module(hikogui.path.path_location : impl);
20
21hi_export namespace hi::inline v1 {
22
30hi_export [[nodiscard]] hi_inline std::filesystem::path get_path_by_id(const KNOWNFOLDERID& folder_id) noexcept
31{
32 PWSTR wpath = nullptr;
33 if (SHGetKnownFolderPath(folder_id, 0, nullptr, &wpath) != S_OK) {
34 hi_log_fatal("Could not get known folder path.");
35 }
36 auto const d = defer{[&] {
38 }};
39
40 return std::filesystem::path{wpath} / "";
41}
42
43hi_export [[nodiscard]] hi_inline std::filesystem::path executable_file() noexcept
44{
45 if (auto path = win32_GetModuleFileName()) {
46 return *path;
47 } else {
48 hi_log_fatal("Could not get executable-file. {}", make_error_code(path.error()).message());
49 }
50}
51
52hi_export [[nodiscard]] hi_inline std::filesystem::path data_dir() noexcept
53{
54 // "%LOCALAPPDATA%<Application Vendor><Application Name>\"
55 // FOLDERID_LocalAppData has the default path: %LOCALAPPDATA% (%USERPROFILE%\AppData\Local)
57 return local_app_data / get_application_vendor() / get_application_name() / "";
58}
59
60hi_export [[nodiscard]] hi_inline std::filesystem::path log_dir() noexcept
61{
62 // "%LOCALAPPDATA%<Application Vendor><Application Name>\Log\"
63 return data_dir() / "Log" / "";
64}
65
66hi_export [[nodiscard]] hi_inline std::filesystem::path preferences_file() noexcept
67{
68 // "%LOCALAPPDATA%<Application Vendor><Application Name>\preferences.json"
69 return data_dir() / "preferences.json";
70}
71
73{
74 if (auto source_path = source_dir()) {
75 // Fallback when the application is executed from its build directory.
76 co_yield executable_dir() / "resources" / "";
77 co_yield *source_path / "resources" / "";
78
79 if (auto install_path = library_install_dir()) {
80 co_yield *install_path / "resources" / "";
81
82 } else {
83 // Fallback when HikoGUI is also still in its build directory.
84 co_yield library_source_dir() / "resources" / "";
85 co_yield library_build_dir() / "resources" / "";
86 }
87 } else {
88 co_yield executable_dir() / "resources" / "";
89 co_yield data_dir() / "resources" / "";
90 }
91}
92
94{
96}
97
98hi_export [[nodiscard]] hi_inline generator<std::filesystem::path> font_dirs() noexcept
99{
100 for (auto const& path : resource_dirs()) {
101 co_yield path;
102 }
103 for (auto const& path : system_font_dirs()) {
104 co_yield path;
105 }
106}
107
108hi_export [[nodiscard]] hi_inline generator<std::filesystem::path> theme_dirs() noexcept
109{
110 for (auto const& path : resource_dirs()) {
111 co_yield path;
112 }
113}
114
115} // namespace hi::inline v1
Rules for working with win32 headers.
std::filesystem::path executable_file() noexcept
Get the full path to this executable.
std::filesystem::path log_dir() noexcept
Get the full path to the directory where the application should store its log files.
std::filesystem::path data_dir() noexcept
Get the full path to the directory where the application should store its data.
std::filesystem::path preferences_file() noexcept
Get the full path to application preferences file.
hi_inline std::filesystem::path executable_dir() noexcept
Get the full path to the directory when this executable is located.
Definition path_location_intf.hpp:67
hi_inline generator< std::filesystem::path > resource_dirs() noexcept
The directories to search for resource files.
hi_inline std::optional< std::filesystem::path > source_dir() noexcept
Get the full path to source code of this executable.
Definition path_location_intf.hpp:150
hi_inline std::optional< std::filesystem::path > library_install_dir() noexcept
The full path where HikoGUI is installed during compilation of the application.
Definition path_location_intf.hpp:171
hi_inline generator< std::filesystem::path > system_font_dirs() noexcept
The directories to search for system font files.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
hi_export hi_inline std::filesystem::path get_path_by_id(const KNOWNFOLDERID &folder_id) noexcept
Convenience function for SHGetKnownFolderPath().
Definition path_location_win32_impl.hpp:30
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
T message(T... args)