Subversion Repositories spk

Rev

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

Rev 1 Rev 85
Line 34... Line 34...
34
}
34
}
35
 
35
 
36
 
36
 
37
void CDirIO::SetDir(CyString dir)
37
void CDirIO::SetDir(CyString dir)
38
{
38
{
39
	m_sCurrentDir = dir;
39
	m_sCurrentDir = dir.ToString();
40
	m_sCurrentDir = m_sCurrentDir.FindReplace("\\", "/");
40
	m_sCurrentDir.toFilename();
41
}
41
}
42
 
42
 
43
 
43
 
44
bool CDirIO::Exists(CyString dir)
44
bool CDirIO::Exists(CyString dir)
45
{
45
{
Line 50... Line 50...
50
 
50
 
51
	if ( ACCESS( dir.c_str(), 0 ) == 0 )
51
	if ( ACCESS( dir.c_str(), 0 ) == 0 )
52
		return true;
52
		return true;
53
 
53
 
54
	return false;
54
	return false;
-
 
55
}
-
 
56
 
-
 
57
Utils::String CDirIO::parseDir(const Utils::String &dir) const
-
 
58
{
-
 
59
	Utils::String sDir = dir.asFilename();
-
 
60
	if ( !m_sCurrentDir.empty() && !sDir.isin(":") )
-
 
61
	{
-
 
62
		if ( sDir.empty() )
-
 
63
			sDir = m_sCurrentDir;
-
 
64
		else
-
 
65
			sDir = m_sCurrentDir + "/" + sDir;
-
 
66
	}
-
 
67
 
-
 
68
	return sDir.asFilename();
55
}
69
}
56
 
70
 
57
CyString CDirIO::ParseDir(CyString dir)
71
CyString CDirIO::ParseDir(CyString dir)
58
{
72
{
59
	dir = dir.FindReplace("\\", "/");
73
	dir = dir.FindReplace("\\", "/");
60
	if ( !m_sCurrentDir.Empty() && !dir.IsIn(":") )
74
	if ( !m_sCurrentDir.empty() && !dir.IsIn(":") )
61
	{
75
	{
62
		if ( dir.Empty() )
76
		if ( dir.Empty() )
63
			dir = m_sCurrentDir;
77
			dir = m_sCurrentDir;
64
		else
78
		else
65
			dir = m_sCurrentDir + "/" + dir;
79
			dir = CyString(m_sCurrentDir) + "/" + dir;
66
	}
80
	}
67
 
81
 
68
	dir = dir.FindReplace("//", "/");
82
	dir = dir.FindReplace("//", "/");
69
	return dir;
83
	return dir;
70
}
84
}
71
 
85
 
72
bool CDirIO::IsDir(CyString dir)
86
bool CDirIO::IsDir(CyString dir)
73
{
87
{
74
	dir = ParseDir(dir);
88
	dir = ParseDir(dir);
75
	if ( ACCESS( dir.c_str(), 0 ) == 0 )
89
	if ( ACCESS( dir.c_str(), 0 ) == 0 )
76
	{
90
	{
77
		struct stat status;
91
		struct stat status;
78
		stat( dir.c_str(), &status );
92
		stat( dir.c_str(), &status );
79
 
93
 
80
		if ( status.st_mode & S_IFDIR )
94
		if ( status.st_mode & S_IFDIR )
81
			return true;
95
			return true;
Line 88... Line 102...
88
{
102
{
89
	dir = ParseDir(dir);
103
	dir = ParseDir(dir);
90
	if ( ACCESS( dir.c_str(), 0 ) == 0 )
104
	if ( ACCESS( dir.c_str(), 0 ) == 0 )
91
	{
105
	{
92
		struct stat status;
106
		struct stat status;
93
		stat( dir.c_str(), &status );
107
		stat( dir.c_str(), &status );
94
 
108
 
95
		if ( status.st_mode & S_IFDIR )
109
		if ( status.st_mode & S_IFDIR )
96
			return false;
110
			return false;
97
		else
111
		else
98
			return true;
112
			return true;
Line 158... Line 172...
158
 
172
 
159
	if ( !Exists(to) )
173
	if ( !Exists(to) )
160
	{
174
	{
161
		if ( !Create(to) )
175
		if ( !Create(to) )
162
			return false;
176
			return false;
163
	}
177
	}
164
 
178
 
165
	if ( !rename(from.c_str(), to.c_str()) )
179
	if ( !rename(from.c_str(), to.c_str()) )
166
		return true;
180
		return true;
167
 
181
 
168
	return false;
182
	return false;
Line 297... Line 311...
297
#else
311
#else
298
 
312
 
299
#endif//_WIN32
313
#endif//_WIN32
300
 
314
 
301
	return files;
315
	return files;
302
}
316
}
303
 
317
 
304
CyString CDirIO::File(CyString filename)
318
CyString CDirIO::File(CyString filename)
305
{
319
{
306
	if ( m_sCurrentDir.Empty() )
320
	if ( m_sCurrentDir.empty() )
307
		return filename;
321
		return filename;
308
 
322
 
309
	return m_sCurrentDir + "/" + filename;
323
	return CyString(m_sCurrentDir) + "/" + filename;
-
 
324
}
-
 
325
 
-
 
326
Utils::String CDirIO::dir(const Utils::String &sDir) const
-
 
327
{
-
 
328
	return parseDir(sDir);
-
 
329
}
-
 
330
 
-
 
331
const Utils::String &CDirIO::dir() const
-
 
332
{
-
 
333
	return m_sCurrentDir;
310
}
334
}
311
 
335
 
312
CyString CDirIO::Dir(CyString dir)
336
CyString CDirIO::Dir(CyString dir)
313
{
337
{
314
	return ParseDir(dir);
338
	return parseDir(dir.ToString());
315
}
339
}
316
 
340
 
317
bool CDirIO::cd(CyString dir)
341
bool CDirIO::cd(CyString dir)
318
{
342
{
-
 
343
	Utils::String sDir = dir.ToString();
-
 
344
 
319
	if ( m_sCurrentDir.Empty() )
345
	if ( m_sCurrentDir.empty() )
320
		m_sCurrentDir = dir;
346
		m_sCurrentDir = sDir;
321
	else
347
	else
322
		m_sCurrentDir = m_sCurrentDir + "/" + dir;
348
		m_sCurrentDir = m_sCurrentDir + "/" + sDir;
323
	m_sCurrentDir.FindReplace("\\", "/");
-
 
324
	m_sCurrentDir.FindReplace("//", "/");
349
	m_sCurrentDir = m_sCurrentDir.asFilename();
325
 
350
 
326
	return Exists();
351
	return Exists();
327
}
352
}
328
 
353
 
329
bool CDirIO::CreateAndChange(CyString dir)
354
bool CDirIO::CreateAndChange(CyString dir)
330
{
355
{
331
	if ( Create(dir) )
356
	if ( Create(dir) )
332
		return cd(dir);
357
		return cd(dir);
333
	return false;
358
	return false;
334
}
359
}
335
 
360
 
336
 
361
 
337
CyString CDirIO::TopDir()
362
CyString CDirIO::TopDir()
338
{
363
{
339
	if ( m_sCurrentDir.Empty() )
364
	if ( m_sCurrentDir.empty() )
340
		return NullString;
365
		return NullString;
341
 
366
 
342
	return m_sCurrentDir.GetTokenRev("/", -1);
367
	return m_sCurrentDir.token("/", -1);
343
}
368
}
344
 
369
 
345
CyString CDirIO::Back()
370
CyString CDirIO::Back()
346
{
371
{
347
	m_sCurrentDir = m_sCurrentDir.GetToken("/", 0, -1);
372
	m_sCurrentDir = m_sCurrentDir.tokens("/", 1, -2);
-
 
373
	
348
	return m_sCurrentDir;
374
	return m_sCurrentDir;
349
}
375
}