My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
#ifndef MAP_BG__FILE_UTILS_H
#define MAP_BG__FILE_UTILS_H

#include <Core/Core.h>
using namespace Upp;

inline bool IsValidPath(const String& fp)
{
return fp.Left(1) != "." && fp.Left(2) != "..";
}

inline bool IsFolder(const String& fp)
{
return fp.GetCount() ? fp[fp.GetCount() - 1] == '/' : false;
}

static Vector<String> GetDirectoryFiles(const String& dir, const String& search = "*",
String prefix = String())
{
FindFile ff(AppendFileName(dir, search));
Vector<String> r;

while (ff)
{
if (ff.IsFolder())
{
prefix.IsEmpty()
? r.Append( GetDirectoryFiles(AppendFileName(dir, ff.GetName()), ff.GetName()) )
: r.Append( GetDirectoryFiles(AppendFileName(dir, ff.GetName()),
AppendFileName(prefix, ff.GetName())) );
}
if (ff.IsFile())
{
prefix.IsEmpty()
? r.Add(ff.GetName())
: r.Add(AppendFileName(prefix, ff.GetName()));
}
ff.Next();
}

return r;
}

static Vector<String> GetSubDirectories(const String& dir, String prefix = String())
{
FindFile ff(AppendFileName(dir, "*"));
Vector<String> r;

while (ff)
{
if (ff.IsFolder())
{
Vector<String> files = GetSubDirectories(AppendFileName(dir, ff.GetName()),
ff.GetName());

if (files.GetCount())
r.Append(files);

prefix.IsEmpty()
? r.Add(ff.GetName())
: r.Add(AppendFileName(prefix, ff.GetName()));
}
ff.Next();
}

return r;
}

static bool RemoveDirectory(const String& dir)
{
if (!DirectoryExists(dir))
return true;

Vector<String> files = GetDirectoryFiles(dir);
bool done = true;

for (int i = files.GetCount() - 1; i >= 0; --i)
{
done &= FileDelete( AppendFileName(dir, files[i]) );
}

Vector<String> folders = GetSubDirectories(dir);
for (int i = 0; i < folders.GetCount(); ++i)
{
done &= DirectoryDelete( AppendFileName(dir, folders[i]) );
}

return done &= DirectoryDelete(dir);
}

#endif

Change log

r4180 by Sc0rch on Nov 17, 2011   Diff
MapRender: First release
(FormEditorCommon, FormEditorProperties,
Map, MapBG, MapCommon, MapEditor,
MapRenderTest.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1938 bytes, 91 lines
Powered by Google Project Hosting