@@ -25,16 +25,14 @@ namespace p2c::infra::util
2525
2626 FolderResolver::FolderResolver (std::wstring appPathSubdir, std::wstring docPathSubdir, bool createSubdirectories)
2727 {
28- if (!appPathSubdir.empty ())
29- {
28+ if (!appPathSubdir.empty ()) {
3029 wchar_t * pPath = nullptr ;
31- if (auto hr = SHGetKnownFolderPath (FOLDERID_LocalAppData, 0 , nullptr , &pPath); FAILED (hr))
32- {
30+ if (auto hr = SHGetKnownFolderPath (FOLDERID_LocalAppData, 0 , nullptr , &pPath); FAILED (hr)) {
3331 CoTaskMemFree (pPath);
3432 pPath = nullptr ;
3533 pmlog_error (" Failed getting local app data path" );
3634 throw Except<Exception>();
37- }
35+ }
3836 const auto dir = std::format (L" {}\\ {}" , pPath, appPathSubdir);
3937 try {
4038 std::filesystem::create_directories (dir);
@@ -46,26 +44,22 @@ namespace p2c::infra::util
4644 pmlog_error (" Failed creating directory: " + str::ToNarrow (dir));
4745 throw Except<Exception>();
4846 }
49- if (pPath)
50- {
47+ if (pPath) {
5148 CoTaskMemFree (pPath);
5249 }
5350 }
54- else
55- {
51+ else {
5652 appPath = std::filesystem::current_path ().wstring ();
5753 }
5854
59- if (!docPathSubdir.empty ())
60- {
55+ if (!docPathSubdir.empty ()) {
6156 wchar_t * pPath = nullptr ;
62- if (auto hr = SHGetKnownFolderPath (FOLDERID_Documents, 0 , nullptr , &pPath); FAILED (hr))
63- {
57+ if (auto hr = SHGetKnownFolderPath (FOLDERID_Documents, 0 , nullptr , &pPath); FAILED (hr)) {
6458 CoTaskMemFree (pPath);
6559 pPath = nullptr ;
6660 pmlog_error (" Failed getting user documents path" );
6761 throw Except<Exception>();
68- }
62+ }
6963 const auto dir = std::format (L" {}\\ {}" , pPath, docPathSubdir);
7064 try {
7165 std::filesystem::create_directories (dir);
@@ -77,13 +71,11 @@ namespace p2c::infra::util
7771 pmlog_error (" Failed creating directory: " + str::ToNarrow (dir));
7872 throw Except<Exception>();
7973 }
80- if (pPath)
81- {
74+ if (pPath) {
8275 CoTaskMemFree (pPath);
8376 }
8477 }
85- else
86- {
78+ else {
8779 docPath = std::filesystem::current_path ().wstring ();
8880 }
8981
@@ -97,50 +89,39 @@ namespace p2c::infra::util
9789
9890 std::wstring FolderResolver::Resolve (Folder f, std::wstring path) const
9991 {
100- switch (f)
101- {
92+ switch (f) {
10293 case Folder::App:
103- if (appPath.empty ())
104- {
94+ if (appPath.empty ()) {
10595 pmlog_error (" Failed to resolve app path: not initialized" );
10696 throw Except<Exception>();
10797 }
108- if (path.empty ())
109- {
98+ if (path.empty ()) {
11099 return appPath;
111100 }
112- else
113- {
101+ else {
114102 return std::format (L" {}\\ {}" , appPath, path);
115103 }
116- case Folder::Documents:
117- {
118- if (docPath.empty ())
119- {
104+ case Folder::Documents: {
105+ if (docPath.empty ()) {
120106 pmlog_error (" Failed to resolve documents path: not initialized" );
121107 throw Except<Exception>();
122108 }
123- if (path.empty ())
124- {
109+ if (path.empty ()) {
125110 return docPath;
126111 }
127- else
128- {
112+ else {
129113 return std::format (L" {}\\ {}" , docPath, path);
130114 }
131115 }
132- case Folder::Temp:
133- {
116+ case Folder::Temp: {
134117 wchar_t tempPath[MAX_PATH + 1 ];
135- if (!GetTempPathW (MAX_PATH, tempPath))
136- {
118+ if (!GetTempPathW (MAX_PATH, tempPath)) {
137119 pmlog_error (" failed resolving temp dir" ).hr ();
138120 throw Except<Exception>();
139121 }
140122 return std::format (L" {}{}" , tempPath, path);
141123 }
142- case Folder::Install:
143- {
124+ case Folder::Install: {
144125 wchar_t modulePath[MAX_PATH];
145126 ::GetModuleFileNameW (nullptr , modulePath, (DWORD)std::size(modulePath));
146127 const auto dir = std::filesystem::path{ modulePath }.remove_filename ().wstring ();
0 commit comments