4#include "Stroika/Foundation/StroikaPreComp.h"
6#if qStroika_Foundation_Common_Platform_Windows
13#include "Stroika/Foundation/Execution/Throw.h"
14#if qStroika_Foundation_Common_Platform_Windows
15#include "Stroika/Foundation/Execution/Platform/Windows/Exception.h"
24using namespace Stroika::Foundation::IO;
35filesystem::path FileSystem::WellKnownLocations::GetMyDocuments (
bool createIfNotPresent)
37#if qStroika_Foundation_Common_Platform_POSIX
43 static const filesystem::path kCachedResult_ = [] () -> filesystem::path {
45 const char* pPath = ::getenv (
"HOME");
46 if (pPath !=
nullptr) {
49 return filesystem::path{};
51 return kCachedResult_;
52#elif qStroika_Foundation_Common_Platform_Windows
55 wchar_t fileBuf[MAX_PATH]{};
58 filesystem::path result = fileBuf;
60 if (result.empty ()) {
61 result = path{
"c:"sv};
63 Ensure (not createIfNotPresent or filesystem::is_directory (result));
67 return filesystem::path ();
78#if qStroika_Foundation_Common_Platform_POSIX
79 static const filesystem::path kVarSpool_{
"/var/spool/"sv};
81#elif qStroika_Foundation_Common_Platform_Windows
83 SDKChar fileBuf[MAX_PATH]{};
84 Verify (::SHGetSpecialFolderPath (
nullptr, fileBuf, CSIDL_COMMON_APPDATA,
false));
85 filesystem::path result = fileBuf;
87 if (result.empty ()) {
88 result = filesystem::path (
"c:");
90 if (filesystem::is_directory (filesystem::path (result))) {
91 return filesystem::path (result);
94 return filesystem::path{};
109#if qStroika_Foundation_Common_Platform_POSIX
111 static const filesystem::path kVarLib_{
"/var/opt/"};
113#elif qStroika_Foundation_Common_Platform_Windows
114 SDKChar fileBuf[MAX_PATH]{};
115 Verify (::SHGetSpecialFolderPath (
nullptr, fileBuf, CSIDL_COMMON_APPDATA, createIfNotPresent));
116 filesystem::path result = fileBuf;
118 if (result.empty ()) {
119 result = filesystem::path{
"c:"};
121 Ensure (not createIfNotPresent or filesystem::is_directory (result));
136#if qStroika_Foundation_Common_Platform_POSIX
137 static const filesystem::path kResult_{
"/var/run/"sv};
139#elif qStroika_Foundation_Common_Platform_Windows
147#if qStroika_Foundation_Common_Platform_Windows
153filesystem::path FileSystem::WellKnownLocations::GetWinSxS ()
155 wchar_t fileBuf[MAX_PATH]{};
156 Verify (::SHGetSpecialFolderPathW (
nullptr, fileBuf, CSIDL_WINDOWS,
false));
157 filesystem::path result = fileBuf;
159 if (result.empty ()) {
163 if (not filesystem::is_directory (result)) {
166 Ensure (result.empty () or filesystem::is_directory (result));
177 SDKString AssureDirectoryPathSlashTerminated_ (
const SDKString& dirPath)
179 if (dirPath.empty ()) {
183 SDKChar tmp = filesystem::path::preferred_separator;
184 return SDKString (&tmp, &tmp + 1);
187 SDKChar lastChar = dirPath[dirPath.size () - 1];
188 if (lastChar == filesystem::path::preferred_separator) {
192 result += filesystem::path::preferred_separator;
198#if qStroika_Foundation_Common_Platform_POSIX
200 const char* pPath = ::getenv (
"TMPDIR");
201 if (pPath !=
nullptr) {
202 return AssureDirectoryPathSlashTerminated_ (pPath);
205#elif qStroika_Foundation_Common_Platform_Windows
208 if (::GetTempPath (
static_cast<DWORD
> (Memory::NEltsOf (buf)), buf) == 0) {
209 return SDKSTR (
"c:\\Temp\\");
212 return AssureDirectoryPathSlashTerminated_ (buf);
216 return SDKSTR (L
"/tmp/");
226 static const filesystem::path kCachedResult_ = [] () -> filesystem::path {
227#if qStroika_Foundation_Common_Platform_POSIX
229 const char* pPath = ::getenv (
"TMPDIR");
230 if (pPath !=
nullptr) {
231 return AssureDirectoryPathSlashTerminated_ (pPath);
234#elif qStroika_Foundation_Common_Platform_Windows
236 SDKChar buf[4 * 1024];
237 if (::GetTempPath (
static_cast<DWORD
> (Memory::NEltsOf (buf)), buf) == 0) {
238 return SDKSTR (
"c:\\Temp\\");
245 return SDKSTR (L
"/tmp/");
248 return kCachedResult_;
#define AssertNotImplemented()
#define AssertNotReached()
String is like std::u32string, except it is much easier to use, often much more space efficient,...
conditional_t< qTargetPlatformSDKUseswchar_t, wchar_t, char > SDKChar
basic_string< SDKChar > SDKString
filesystem::path GetTemporary()
filesystem::path GetSpoolDirectory()
filesystem::path GetApplicationData(bool createIfNotPresent=true)
filesystem::path GetRuntimeVariableData()