-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiskMonitorFileInfo.cpp
153 lines (144 loc) · 4.46 KB
/
DiskMonitorFileInfo.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DiskMonitorFileInfo.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TMonitorFileInfo::TMonitorFileInfo(AnsiString Path, AnsiString Name)
: TObject()
{
Pathname = new AnsiString();
Filename = new AnsiString();
SetPathname(Path);
*Filename = Name;
Construct();
}
//---------------------------------------------------------------------------
__fastcall TMonitorFileInfo::TMonitorFileInfo(AnsiString FullPathname)
{
Pathname = new AnsiString();
Filename = new AnsiString();
SetPathname(FullPathname);
Construct();
}
//---------------------------------------------------------------------------
void __fastcall TMonitorFileInfo::Construct()
{
Attributes = 0;
FileSize = -1;
LastWrite = 0;
FileExists = false;
LoadInfo();
}
//---------------------------------------------------------------------------
__fastcall TMonitorFileInfo::~TMonitorFileInfo()
{
delete Pathname;
delete Filename;
}
//---------------------------------------------------------------------------
void __fastcall TMonitorFileInfo::LoadInfo()
{
TSearchRec sr;
if (!Filename->IsEmpty()) {
if (FindFirst(*Pathname + "\\" + *Filename, faAnyFile, sr) == 0) {
FileExists = true;
Attributes = sr.Attr;
FileSize = sr.Size;
LastWrite = LastWrite.FileDateToDateTime(sr.Time);
} else
FileExists = false;
FindClose(sr);
}
}
//---------------------------------------------------------------------------
void __fastcall TMonitorFileInfo::ReloadInfo()
{
LoadInfo();
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::Exists()
{
ReloadInfo();
return FileExists;
}
//---------------------------------------------------------------------------
void __fastcall TMonitorFileInfo::SetPathname(AnsiString Path)
{
if (Path.SubString(Path.Length(), 1) == "\\")
*Pathname = Path.SubString(1, Path.Length() - 1);
else
*Pathname = Path;
if (!DirExists(*Pathname)) {
*Filename = ExtractFileName(*Pathname);
*Pathname = ExtractFilePath(*Pathname);
} else
*Filename = "";
}
//---------------------------------------------------------------------------
AnsiString __fastcall TMonitorFileInfo::GetPathname()
{
return *Pathname;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TMonitorFileInfo::GetFilename()
{
return *Filename;
}
//---------------------------------------------------------------------------
int __fastcall TMonitorFileInfo::GetAttributes()
{
return Attributes;
}
//---------------------------------------------------------------------------
long __fastcall TMonitorFileInfo::GetFileSize()
{
return FileSize;
}
//---------------------------------------------------------------------------
TDateTime __fastcall TMonitorFileInfo::GetLastWrite()
{
return LastWrite;
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::IsReadOnly()
{
return ((Attributes & faReadOnly) == faReadOnly);
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::IsHidden()
{
return ((Attributes & faHidden) == faHidden);
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::IsSystem()
{
return ((Attributes & faSysFile) == faSysFile);
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::IsVolumeID()
{
return ((Attributes & faVolumeID) == faVolumeID);
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::IsDirectory()
{
return ((Attributes & faDirectory) == faDirectory);
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::IsArchive()
{
return ((Attributes & faArchive) == faArchive);
}
//---------------------------------------------------------------------------
bool __fastcall TMonitorFileInfo::DirExists(AnsiString dir)
{
bool rc;
AnsiString *d = new AnsiString();
*d = GetCurrentDir();
rc = SetCurrentDir(dir);
SetCurrentDir(*d);
return rc;
}
//---------------------------------------------------------------------------