-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystemWin32.cpp
More file actions
55 lines (51 loc) · 1.29 KB
/
FileSystemWin32.cpp
File metadata and controls
55 lines (51 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2026 CCP ehf.
#include "StdAfx.h"
#if _WIN32
#include "FileSystem.h"
#include <shlobj.h> //for SHGetFolderPath
std::wstring GetAppdataFolder()
{
wchar_t path[MAX_PATH];
return SUCCEEDED( SHGetFolderPathW( nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, path ) ) ? path : L"";
}
bool CreateDirectoryRec(const wchar_t* dir)
{
if( CreateDirectoryW(dir, NULL) )
{
return true;
}
DWORD err = GetLastError();
if( err == ERROR_ALREADY_EXISTS )
{
return true;
}
//find the last separator
std::wstring full(dir);
std::wstring::size_type s = full.find_last_of(L"/\\");
if( s != std::wstring::npos )
{
std::wstring pre = full.substr(0, s);
if( !CreateDirectoryRec(pre.c_str()) )
{
return false;
}
return !!CreateDirectoryW(dir, NULL);
}
return false;
}
const std::wstring& GetLogsFolder()
{
static std::wstring result;
if( !result.size() )
{
wchar_t path[MAX_PATH];
HRESULT hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
if( SUCCEEDED(hr) )
{
result = std::wstring(path) + L"\\CCP\\EVE\\";
CreateDirectoryRec(result.c_str());
}
}
return result;
}
#endif