blob: cfd4ae7955ffd9fb86f466395dfd125dff7e3907 (
plain)
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
|
// ExtractingFilePath.cpp
#include "StdAfx.h"
#include "ExtractingFilePath.h"
static UString ReplaceIncorrectChars(const UString &s)
{
UString res;
for (int i = 0; i < s.Length(); i++)
{
wchar_t c = s[i];
#ifdef _WIN32
if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>' || c == '|' || c == ':' || c == '"')
c = '_';
#endif
res += c;
}
return res;
}
static void ReplaceDisk(UString &s)
{
int i;
for (i = 0; i < s.Length(); i++)
if (s[i] != ' ')
break;
if (s.Length() > i + 1)
{
if (s[i + 1] == L':')
{
s.Delete(i + 1);
// s.Insert(i + 1, L'_');
}
}
}
UString GetCorrectFileName(const UString &path)
{
UString result = path;
{
UString test = path;
test.Trim();
if (test == L"..")
result.Replace(L"..", L"");
}
ReplaceDisk(result);
return result;
}
UString GetCorrectPath(const UString &path)
{
UString result = path;
int first;
for (first = 0; first < result.Length(); first++)
if (result[first] != ' ')
break;
while(result.Length() > first)
{
if (
#ifdef _WIN32
result[first] == L'\\' ||
#endif
result[first] == L'/')
{
result.Delete(first);
continue;
}
break;
}
#ifdef _WIN32
result.Replace(L"..\\", L"");
#endif
result.Replace(L"../", L"");
ReplaceDisk(result);
return ReplaceIncorrectChars(result);
}
void MakeCorrectPath(UStringVector &pathParts)
{
for (int i = 0; i < pathParts.Size();)
{
UString &s = pathParts[i];
s = GetCorrectFileName(s);
if (s.IsEmpty())
pathParts.Delete(i);
else
i++;
}
}
|