-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFilePath.cpp
More file actions
110 lines (80 loc) · 2.13 KB
/
FilePath.cpp
File metadata and controls
110 lines (80 loc) · 2.13 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "FilePath.h"
#include "shlwapi.h"
#include <algorithm>
#include "Globals.h"
const string currentOblivionPath = GetOblivionDirectory ();
const vector<string> supportedExtensions = {".mp3", ".wav", ".wma"};
bool exists (const string &path) {
return PathFileExists (path.c_str ()) != 0;
}
bool isDirectory (const string &path) {
return PathIsDirectory (path.c_str ()) != 0;
}
bool isExtensionSupported (const string &path) {
return endsWithAny (path, supportedExtensions);
}
string getFileName (const string &path) {
size_t pos = path.find_last_of ('\\');
if (pos != string::npos) {
return path.substr (pos);
} else {
return path;
}
}
string getFolderPath (const string &path) {
size_t pos = path.find_last_of ('\\');
if (pos != string::npos) {
return path.substr (0, pos + 1);
} else {
return path;
}
}
string cleanPath (const string &path, bool relativize) {
string pathC = trim (path);
replace (pathC.begin (), pathC.end (), '/', '\\');
if (relativize && PathIsRelative (pathC.c_str ()) != 0) {
pathC = currentOblivionPath + pathC;
}
return pathC;
}
string trim (const string &str) {
size_t first = str.find_first_not_of (" \t\n\r");
if (first == string::npos)
return "";
size_t last = str.find_last_not_of (" \t\n\r");
return str.substr (first, (last - first + 1));
}
bool endsWith (const string &str, const string &ending) {
int strLen = str.length ();
int endLen = ending.length ();
if (strLen >= endLen) {
return str.compare (strLen - endLen, endLen, ending) == 0;
} else {
return false;
}
}
bool endsWithAny (const string &str, const vector<string> &endings) {
for (const string &ending : endings) {
if (endsWith (str, ending)) {
return true;
}
}
return false;
}
bool endsNotWith (const string &str, const string &ending) {
int strLen = str.length ();
int endLen = ending.length ();
if (strLen >= endLen) {
return str.compare (strLen - endLen, endLen, ending) != 0;
} else {
return true;
}
}
bool endsNotWithAll (const string &str, const vector<string> &endings) {
for (const string &ending : endings){
if (endsWith (str, ending)) {
return false;
}
}
return true;
}