-
Notifications
You must be signed in to change notification settings - Fork 519
/
PathUtils.android.cc
68 lines (54 loc) · 1.11 KB
/
PathUtils.android.cc
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
// Copyright 2013 Viewfinder. All rights reserved.
// Author: Marc Berhault.
#import "FileUtils.h"
#import "Format.h"
#import "Logging.h"
#import "PathUtils.h"
#import "StringUtils.h"
namespace {
string TmpPath() {
return "tmp";
}
class AppDir : public string {
public:
AppDir(const string& dir) {
DirCreate(dir);
DirCreate(JoinPath(dir, LibraryPath()));
DirCreate(JoinPath(dir, TmpPath()));
assign(dir);
}
};
AppDir* kAppDir = NULL;
} // namespace
void InitApplicationPath(const string& dir) {
if (kAppDir == NULL) {
kAppDir = new AppDir(dir);
}
}
string JoinPath(const Slice& a, const Slice& b) {
if (b.empty()) {
return a.ToString();
}
if (!a.ends_with("/")) {
return Format("%s/%s", a, b);
}
return Format("%s%s", a, b);
}
string HomeDir() {
return *kAppDir;
}
string LibraryPath() {
return "Library";
}
string LibraryDir() {
return JoinPath(*kAppDir, LibraryPath());
}
string LoggingDir() {
return JoinPath(LibraryDir(), "Logs");
}
string LoggingQueueDir() {
return JoinPath(LoggingDir(), "Queue");
}
string TmpDir() {
return JoinPath(*kAppDir, TmpPath());
}