source: trunk/gsinstaller/file.cpp@ 2013

Last change on this file since 2013 was 1541, checked in by cs025, 24 years ago

Fixes for WindowsNT. Also made File class subclass of FilePath class.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1#include <sys\stat.h>
2#include "dirent.h"
3
4#include <windows.h>
5#include <stdio.h>
6
7#include "file.h"
8
9void File::_getDetails()
10{ struct stat statData;
11
12 if (this->path.length() < 5)
13 { this->does_exist = true;
14 this->size = 0;
15 this->is_dir = true;
16 this->is_writable = true;
17 }
18 else
19 { if (stat (this->path.c_str(), &statData) == -1)
20 { this->does_exist = false;
21 this->size = 0;
22 this->is_dir = false;
23 this->is_writable = false;
24 }
25 else
26 { this->does_exist = (statData.st_mode & (S_IFDIR | S_IFREG)) != 0;
27 this->is_dir = ((statData.st_mode & S_IFDIR) != 0);
28 this->size = statData.st_size;
29 this->is_writable = ((statData.st_mode & S_IWRITE) != 0);
30 }
31 }
32}
33
34void File::getChildren()
35{ DIR * directory;
36 struct dirent * entry;
37
38 directory = opendir(this->path.c_str());
39 if (directory == NULL)
40 { return;
41 }
42
43 while ((entry = readdir(directory)) != NULL)
44 { string childName;
45
46 if (strcmp(entry->d_name, "..") == 0 ||
47 strcmp(entry->d_name, ".") == 0)
48 { continue;
49 }
50
51 childName = this->path;
52 childName.append("\\");
53 childName.append(entry->d_name);
54
55 this->children.push_back(*(new File(childName)));
56 }
57 closedir(directory);
58}
59
60File::File()
61{ this->size = 0;
62}
63
64File::File(string filename) : FilePath(filename)
65{ // this->path = filename;
66 this->_getDetails();
67 if (this->is_dir)
68 { this->getChildren();
69 }
70}
71
72/*
73File::File(string filename, unsigned long filesize)
74{ this->path = filename;
75 this->_getDetails();
76 if (this->is_dir)
77 { this->getChildren();
78 }
79}
80*/
81
82unsigned long File::getDiskSpace(DiskSpace &diskSpace)
83{ unsigned long totalSize = 0;
84
85 if (this->is_dir)
86 { vector<File>::iterator here = this->children.begin();
87 vector<File>::iterator end = this->children.end();
88
89 while (here != end)
90 { totalSize += here->getDiskSpace(diskSpace);
91 here ++;
92 }
93 }
94 totalSize += diskSpace.fileSpace(this->size);
95 return totalSize;
96}
97
98/*
99const char *File::cString()
100{ return this->path.c_str();
101}
102*/
103
104unsigned long File::getRawFileSize()
105{ return this->size;
106}
107
108unsigned long File::getFileSize()
109{ unsigned long totalSize = 0;
110
111 if (this->is_dir)
112 { vector<File>::iterator here = this->children.begin();
113 vector<File>::iterator end = this->children.end();
114
115 while (here != end)
116 { totalSize += here->getFileSize();
117 here ++;
118 }
119 }
120 totalSize += this->size;
121 return totalSize;
122}
123
124vector<File>::iterator File::childBegin()
125{ return this->children.begin();
126}
127
128vector<File>::iterator File::childEnd()
129{ return this->children.end();
130}
131
132bool File::isDirectory()
133{ return this->is_dir;
134}
135
136bool File::isWriteable()
137{ return this->is_writable;
138}
139
140bool File::exists()
141{ return this->does_exist;
142}
143
144void File::copy(char *to)
145{
146}
147
Note: See TracBrowser for help on using the repository browser.