-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuser_install_policy.cpp
More file actions
73 lines (59 loc) · 2.39 KB
/
Copy pathuser_install_policy.cpp
File metadata and controls
73 lines (59 loc) · 2.39 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "user_install_policy.hpp"
namespace acecode::desktop {
namespace {
namespace fs = std::filesystem;
fs::path normalize_absolute(const fs::path& path) {
const auto generic = path.generic_string();
if (generic.empty() || generic.front() != '/') return {};
return path.lexically_normal();
}
} // namespace
UserInstallPaths macos_user_install_paths(const fs::path& home_directory) {
UserInstallPaths paths;
paths.home = normalize_absolute(home_directory);
if (paths.home.empty()) return paths;
paths.applications = paths.home / "Applications";
paths.destination = paths.applications / "ACECode.app";
return paths;
}
SystemInstallPaths macos_system_install_paths() {
SystemInstallPaths paths;
paths.applications = fs::path("/Applications");
paths.destination = paths.applications / "ACECode.app";
return paths;
}
bool macos_user_install_destination_is_safe(
const fs::path& resolved_home,
const fs::path& resolved_applications,
const fs::path& resolved_destination) {
const fs::path home = normalize_absolute(resolved_home);
const fs::path applications = normalize_absolute(resolved_applications);
const fs::path destination = normalize_absolute(resolved_destination);
if (home.empty() || applications.empty() || destination.empty()) {
return false;
}
const UserInstallPaths expected = macos_user_install_paths(home);
return applications == expected.applications &&
destination == expected.destination;
}
MacosInstallLocation macos_self_update_install_location(
const fs::path& resolved_home,
const fs::path& resolved_applications,
const fs::path& resolved_destination) {
const fs::path applications = normalize_absolute(resolved_applications);
const fs::path destination = normalize_absolute(resolved_destination);
if (applications.empty() || destination.empty()) {
return MacosInstallLocation::unsupported;
}
const SystemInstallPaths system = macos_system_install_paths();
if (applications == system.applications &&
destination == system.destination) {
return MacosInstallLocation::system_applications;
}
if (macos_user_install_destination_is_safe(
resolved_home, applications, destination)) {
return MacosInstallLocation::user_applications;
}
return MacosInstallLocation::unsupported;
}
} // namespace acecode::desktop