Subversion Repositories spk

Rev

Rev 211 | Rev 302 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 211 Rev 227
Line 8... Line 8...
8
 
8
 
9
#ifdef _WIN32
9
#ifdef _WIN32
10
#include <windows.h>
10
#include <windows.h>
11
#include <io.h>
11
#include <io.h>
12
#include <direct.h>
12
#include <direct.h>
13
#define ACCESS _access
13
#define ACCESS _waccess
14
#else
14
#else
15
#include <dirent.h>
15
#include <dirent.h>
16
#define ACCESS access
16
#define ACCESS waccess
17
#endif
17
#endif
18
 
18
 
19
#pragma warning(disable:4244)
19
#pragma warning(disable:4244)
20
std::string TOSTRING(const std::wstring& s) { return std::string(s.begin(), s.end()); }
20
std::string TOSTRING(const std::wstring& s) { return std::string(s.begin(), s.end()); }
21
#pragma warning(default:4244)
21
#pragma warning(default:4244)
Line 83... Line 83...
83
	Utils::WString dir = m_sCurrentDir;
83
	Utils::WString dir = m_sCurrentDir;
84
 
84
 
85
	if (dir.empty())
85
	if (dir.empty())
86
		return false;
86
		return false;
87
 
87
 
-
 
88
	//std::wifstream f(dir.c_str());
-
 
89
	//if (f.good())
-
 
90
		//return true;
-
 
91
 
88
	if (ACCESS(TOSTRING(dir).c_str(), 0) == 0)
92
	if (ACCESS(dir.c_str(), 0) == 0)
89
		return true;
93
		return true;
90
 
94
 
91
	return false;
95
	return false;
92
}
96
}
93
 
97
 
94
bool CDirIO::exists(const Utils::WString &dir) const
98
bool CDirIO::exists(const Utils::WString &dir) const
95
{
99
{
96
	Utils::WString d = _parseDir(dir);
100
	Utils::WString d = _parseDir(dir);
97
 
101
 
98
	if (d.empty())
102
	if (d.empty())
99
		return false;
103
		return false;
100
 
104
 
-
 
105
	//std::wifstream f(d.c_str());
-
 
106
	//if (f.good())
-
 
107
		//return true;
-
 
108
 
101
	if (ACCESS(TOSTRING(d).c_str(), 0) == 0)
109
	if (ACCESS(d.c_str(), 0) == 0)
102
		return true;
110
		return true;
103
 
111
 
104
	return false;
112
	return false;
105
}
113
}
106
 
114
 
107
Utils::WString CDirIO::_parseDir(const Utils::WString &dir) const
115
Utils::WString CDirIO::_parseDir(const Utils::WString &dir) const
108
{
116
{
109
	Utils::WString sDir = dir.asFilename();
117
	Utils::WString sDir = dir.asFilename();
110
	if ( !m_sCurrentDir.empty() && !sDir.contains(L":") )
118
	if ( !m_sCurrentDir.empty() && !sDir.contains(L":") )
111
	{
119
	{
Line 117... Line 125...
117
 
125
 
118
	return sDir.asFilename();
126
	return sDir.asFilename();
119
}
127
}
120
 
128
 
121
bool CDirIO::isDir(const Utils::WString &sDir) const
129
bool CDirIO::isDir(const Utils::WString &sDir) const
122
{
130
{
123
	Utils::WString dir = _parseDir(sDir);
131
	Utils::WString dir = _parseDir(sDir);
124
	if (ACCESS(TOSTRING(dir).c_str(), 0) != -1)
132
	if (ACCESS(dir.c_str(), 0) != -1)
125
	{
133
	{
-
 
134
#ifdef _WIN32
-
 
135
		struct _stat64i32 status;
-
 
136
		_wstat(dir.c_str(), &status);
-
 
137
 
-
 
138
		if (status.st_mode & S_IFDIR)
-
 
139
			return true;
-
 
140
#else
126
		struct stat status;
141
		struct stat status;
127
		stat(TOSTRING(dir).c_str(), &status);
142
		stat(TOSTRING(dir).c_str(), &status);
128
 
143
 
129
		if (status.st_mode & S_IFDIR)
144
		if (status.st_mode & S_IFDIR)
130
			return true;
145
			return true;
-
 
146
#endif
131
	}
147
	}
132
	else {
148
	else {
133
		return !dir.token(L"/", -1).contains(L".");
149
		return !dir.token(L"/", -1).contains(L".");
134
	}
150
	}
135
 
151
 
Line 146... Line 162...
146
	return isFile(m_sCurrentDir);
162
	return isFile(m_sCurrentDir);
147
}
163
}
148
bool CDirIO::isFile(const Utils::WString &sDir) const
164
bool CDirIO::isFile(const Utils::WString &sDir) const
149
{
165
{
150
	Utils::WString dir = _parseDir(sDir);
166
	Utils::WString dir = _parseDir(sDir);
151
	if (ACCESS(TOSTRING(dir).c_str(), 0) != -1)
167
	if (ACCESS(dir.c_str(), 0) != -1)
152
	{
168
	{
-
 
169
#ifdef _WIN32
-
 
170
		struct _stat64i32 status;
-
 
171
		_wstat(dir.c_str(), &status);
-
 
172
 
-
 
173
		if (status.st_mode & S_IFDIR)
-
 
174
			return false;
-
 
175
#else
153
		struct stat status;
176
		struct stat status;
154
		stat(TOSTRING(dir).c_str(), &status);
177
		stat(TOSTRING(dir).c_str(), &status);
155
 
178
 
156
		if (status.st_mode & S_IFDIR)
179
		if (status.st_mode & S_IFDIR)
157
			return false;
180
			return false;
158
		else
181
#endif
159
			return true;
182
		return true;
160
	}
183
	}
161
	else {
184
	else {
162
		return dir.token(L"/", -1).contains(L".");
185
		return dir.token(L"/", -1).contains(L".");
163
	}
186
	}
164
 
187
 
Line 200... Line 223...
200
 
223
 
201
			// check if the directory exists
224
			// check if the directory exists
202
			if (!exists(curDir))
225
			if (!exists(curDir))
203
			{
226
			{
204
#ifdef _WIN32
227
#ifdef _WIN32
-
 
228
				std::string str = TOSTRING(curDir);
205
				if (_mkdir(TOSTRING(curDir).c_str()))
229
				if (_wmkdir(curDir.c_str()))
206
#else
230
#else
207
				if (mkdir(TOSTRING(curDir).c_str(), 0755))
231
				if (mkdir(TOSTRING(curDir).c_str(), 0755))
208
#endif
232
#endif
209
					return false;
233
					return false;
210
			}
234
			}
Line 240... Line 264...
240
	{
264
	{
241
		if ( !create(to) )
265
		if ( !create(to) )
242
			return false;
266
			return false;
243
	}
267
	}
244
 
268
 
245
	if ( !rename(TOSTRING(from).c_str(), TOSTRING(to).c_str()) )
269
	if(CFileIO::Rename(from, to))
246
		return true;
270
		return true;
247
 
271
 
248
	return false;
272
	return false;
249
}
273
}
250
 
274
 
Line 276... Line 300...
276
	{
300
	{
277
		if (CDirIO::IsEmptyDir(list))
301
		if (CDirIO::IsEmptyDir(list))
278
		{
302
		{
279
			Utils::WString remDir = _parseDir(dir);
303
			Utils::WString remDir = _parseDir(dir);
280
#ifdef _WIN32
304
#ifdef _WIN32
281
			if (_rmdir(TOSTRING(remDir).c_str()) == 0)
305
			if (_wrmdir(remDir.c_str()) == 0)
282
#else
306
#else
283
			if (rmdir(TOSTRING(remDir).c_str()) == 0)
307
			if (rmdir(TOSTRING(remDir).c_str()) == 0)
284
#endif
308
#endif
285
			{
309
			{
286
				if (errors)
310
				if (errors)
Line 320... Line 344...
320
	{
344
	{
321
		if (CDirIO::IsEmptyDir(list))
345
		if (CDirIO::IsEmptyDir(list))
322
		{
346
		{
323
			Utils::WString remDir = _parseDir(dir);
347
			Utils::WString remDir = _parseDir(dir);
324
#ifdef _WIN32
348
#ifdef _WIN32
325
			if (_rmdir(TOSTRING(remDir).c_str()) == 0)
349
			if (_wrmdir(remDir.c_str()) == 0)
326
#else
350
#else
327
			if (rmdir(TOSTRING(remDir).c_str()) == 0)
351
			if (rmdir(TOSTRING(remDir).c_str()) == 0)
328
#endif
352
#endif
329
			{
353
			{
330
				if (errors)
354
				if (errors)