-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPath.cpp
125 lines (125 loc) · 4.92 KB
/
Path.cpp
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//---------------------------------------------------------------------------
#include "agdv.pch.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#include "Path.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
namespace System
{
String Path::m_Application;
String Path::m_Common;
String Path::m_Documents;
String Path::m_Projects;
String Path::m_ProjectName;
String Path::m_Separator;
class Path Path;
//---------------------------------------------------------------------------
__fastcall Path::Path()
{
// Can't initialise the paths here; Android API is not available during static object construction
Init();
}
//---------------------------------------------------------------------------
void __fastcall Path::Init()
{
const String appName = "AGDX Studio";
m_Separator = System::Ioutils::TPath::DirectorySeparatorChar;
m_Application = System::Ioutils::TPath::GetHomePath() + m_Separator + appName + m_Separator;
m_Common = System::Ioutils::TPath::GetSharedDocumentsPath() + m_Separator + appName + m_Separator + "Common" + m_Separator;
m_Documents = System::Ioutils::TPath::GetSharedDocumentsPath() + m_Separator;
m_Projects = System::Ioutils::TPath::GetSharedDocumentsPath() + m_Separator + appName + m_Separator + "Projects" + m_Separator;
}
//---------------------------------------------------------------------------
String __fastcall Path::GetFolder(const Location location, const String& subFolder)
{
auto folder = m_Common;
if (location == lpApplication) folder = m_Application;
else if (location == lpDocuments) folder = m_Documents;
else if (location == lpProjects) folder = m_Projects;
folder += subFolder;
return folder;
}
//---------------------------------------------------------------------------
TStringDynArray Path::GetFolders(Location location, const String& subFolder)
{
auto folder = GetFolder(location, subFolder);
if (System::Ioutils::TDirectory::Exists(folder))
{
return System::Ioutils::TDirectory::GetDirectories(folder);
}
TStringDynArray empty;
return empty;
}
//---------------------------------------------------------------------------
String __fastcall Path::GetFolderRelativeTo(const Location location, const String& path)
{
auto relPath = path;
auto folder = GetFolder(location);
if (path.Pos(folder) == 1)
{
relPath = path.SubString(folder.Length() + 1, path.Length());
}
return relPath;
}
//---------------------------------------------------------------------------
String __fastcall Path::GetActiveProjectFolder()
{
return Projects + Separator + ProjectName;
}
//---------------------------------------------------------------------------
TStringDynArray __fastcall Path::GetFiles(const String& folder, const String& filter)
{
if (System::Ioutils::TDirectory::Exists(folder))
{
return System::Ioutils::TDirectory::GetFiles(folder, filter);
}
TStringDynArray empty;
return empty;
}
//---------------------------------------------------------------------------
TStringDynArray __fastcall Path::GetFiles(Location location, const String& filter, const String& subFolder)
{
auto folder = GetFolder(location, subFolder);
return GetFiles(folder, filter);
}
//---------------------------------------------------------------------------
String __fastcall Path::Create(Location location, const String& subFolder)
{
auto folder = GetFolder(location, subFolder);
if (!Exists(location, subFolder))
{
System::Ioutils::TDirectory::CreateDirectory(folder);
}
return folder;
}
//---------------------------------------------------------------------------
bool __fastcall Path::Exists(Location location, const String& subFolder)
{
auto folder = GetFolder(location, subFolder);
return System::Ioutils::TDirectory::Exists(folder);
}
//---------------------------------------------------------------------------
void __fastcall Path::Delete(Location location, const String& subFolder)
{
if (Exists(location, subFolder))
{
auto folder = GetFolder(location, subFolder);
System::Ioutils::TDirectory::Delete(folder, true);
}
}
//---------------------------------------------------------------------------
void __fastcall Path::Rename(Location location, const String& fromSubFolder, const String& toSubFolder)
{
if (Exists(location, fromSubFolder))
{
auto fromFolder = GetFolder(location, fromSubFolder);
auto toFolder = GetFolder(location, toSubFolder);
System::Ioutils::TDirectory::Move(fromFolder, toFolder);
}
}
//---------------------------------------------------------------------------
} // File namespace
//---------------------------------------------------------------------------