forked from TypesettingTools/Aegisub
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathpath_win.cpp
More file actions
57 lines (45 loc) · 1.91 KB
/
Copy pathpath_win.cpp
File metadata and controls
57 lines (45 loc) · 1.91 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
56
57
// Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// Aegisub Project http://www.aegisub.org/
/// @file path.cpp
/// @brief Windows-specific path code
/// @ingroup libaegisub windows
#include <libaegisub/path.h>
#include <libaegisub/exception.h>
#include <libaegisub/make_unique.h>
#include <boost/filesystem.hpp>
#include <Shlobj.h>
#include <Shellapi.h>
namespace {
agi::fs::path WinGetFolderPath(int folder) {
wchar_t path[MAX_PATH+1] = {0};
if (FAILED(SHGetFolderPathW(0, folder, 0, 0, path)))
throw agi::EnvironmentError("SHGetFolderPath failed. This should not happen.");
return path;
}
}
namespace agi {
void Path::FillPlatformSpecificPaths() {
SetToken("?temp", boost::filesystem::temp_directory_path());
SetToken("?user", WinGetFolderPath(CSIDL_APPDATA)/"Aegisub");
SetToken("?local", WinGetFolderPath(CSIDL_LOCAL_APPDATA)/"Aegisub");
SetToken("?state", WinGetFolderPath(CSIDL_APPDATA)/"Aegisub");
std::wstring filename(MAX_PATH + 1, L'\0');
while (static_cast<DWORD>(filename.size()) == GetModuleFileNameW(nullptr, &filename[0], filename.size()))
filename.resize(filename.size() * 2);
SetToken("?data", filename);
SetToken("?dictionary", Decode("?data/dictionaries"));
}
}