Subversion Repositories spk

Rev

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

Rev 125 Rev 129
Line 142... Line 142...
142
	return false;
142
	return false;
143
}
143
}
144
 
144
 
145
bool CDirIO::Create(CyString sDir)
145
bool CDirIO::Create(CyString sDir)
146
{
146
{
-
 
147
	return create(sDir.ToString());
-
 
148
}
-
 
149
bool CDirIO::create() const
-
 
150
{
-
 
151
	return create(Utils::String::Null());
-
 
152
}
-
 
153
bool CDirIO::create(const Utils::String &sDir) const
-
 
154
{
147
	Utils::String dir = sDir.ToString();
155
	Utils::String dir = sDir;
148
	if ( dir.empty() )
156
	if ( dir.empty() )
149
		dir = m_sCurrentDir;
157
		dir = m_sCurrentDir;
150
	dir = _parseDir(dir);
158
	dir = _parseDir(dir);
151
 
159
 
152
	// split up directorys
160
	// split up directorys
Line 157... Line 165...
157
	int start = 1;
165
	int start = 1;
158
	Utils::String curDir;
166
	Utils::String curDir;
159
	
167
	
160
	if ( dirs && max )
168
	if ( dirs && max )
161
		curDir = dirs[0];
169
		curDir = dirs[0];
162
 
170
 
163
	if ( !curDir.isin(":") )
171
	if ( !curDir.isin(":") )
164
	{
172
	{
165
		curDir = m_sCurrentDir;
173
		curDir = m_sCurrentDir;
166
		start = 0;
174
		start = 0;
167
	}
175
	}
Line 182... Line 190...
182
			if ( mkdir(curDir.c_str(), 0755) )
190
			if ( mkdir(curDir.c_str(), 0755) )
183
#endif
191
#endif
184
			{
192
			{
185
				CLEANSPLIT(dirs, max);
193
				CLEANSPLIT(dirs, max);
186
				return false;
194
				return false;
187
			}
195
			}
188
		}
196
		}
189
	}
197
	}
190
 
198
 
191
	CLEANSPLIT(dirs, max);
199
	CLEANSPLIT(dirs, max);
192
 
200
 
193
	return true;
201
	return true;
194
}
202
}
195
 
203
 
196
bool CDirIO::move(const Utils::String &sTo)
204
bool CDirIO::move(const Utils::String &sTo)
Line 201... Line 209...
201
		return false;
209
		return false;
202
 
210
 
203
	if (!rename(m_sCurrentDir.c_str(), to.c_str()))
211
	if (!rename(m_sCurrentDir.c_str(), to.c_str()))
204
	{
212
	{
205
		m_sCurrentDir = to;
213
		m_sCurrentDir = to;
206
		return true;
214
		return true;
207
	}
215
	}
208
 
216
 
209
	return false;
217
	return false;
210
}
218
}
211
 
219
 
212
 
220
 
213
bool CDirIO::Move(CyString sFrom, CyString sTo)
221
bool CDirIO::Move(CyString sFrom, CyString sTo)
214
{
222
{
215
	Utils::String from = _parseDir(sFrom.ToString());
223
	Utils::String from = _parseDir(sFrom.ToString());
Line 220... Line 228...
220
		if ( !Create(to) )
228
		if ( !Create(to) )
221
			return false;
229
			return false;
222
	}
230
	}
223
 
231
 
224
	if ( !rename(from.c_str(), to.c_str()) )
232
	if ( !rename(from.c_str(), to.c_str()) )
225
		return true;
233
		return true;
226
 
234
 
227
	return false;
235
	return false;
228
}
236
}
229
 
237
 
230
bool CDirIO::CheckEmptyDir(CyStringList *dirList)
238
bool CDirIO::CheckEmptyDir(CyStringList *dirList)
231
{
239
{
232
	// no pointer, most likly empty
240
	// no pointer, most likly empty
233
	if ( !dirList )
241
	if ( !dirList )
Line 252... Line 260...
252
 
260
 
253
bool CDirIO::RemoveDir(CyString dir, bool doFiles, bool recursive, CyStringList *errors)
261
bool CDirIO::RemoveDir(CyString dir, bool doFiles, bool recursive, CyStringList *errors)
254
{
262
{
255
	// check if the dir is empty
263
	// check if the dir is empty
256
	CyStringList *dirList = DirList(dir);
264
	CyStringList *dirList = DirList(dir);
257
	if ( CheckEmptyDir(dirList) )
265
	if ( CheckEmptyDir(dirList) )
258
	{
266
	{
259
		CyString remDir = _parseDir(dir.ToString());
267
		CyString remDir = _parseDir(dir.ToString());
260
		#ifdef _WIN32
268
		#ifdef _WIN32
261
		if ( _rmdir(remDir.c_str()) == 0 )
269
		if ( _rmdir(remDir.c_str()) == 0 )
262
		#else
270
		#else
263
		if ( rmdir(remDir.c_str()) == 0 )
271
		if ( rmdir(remDir.c_str()) == 0 )
264
		#endif
272
		#endif
265
		{
273
		{
266
			if ( errors )
274
			if ( errors )
267
				errors->PushBack(remDir);
275
				errors->PushBack(remDir);
268
		}
276
		}
269
		return true;
277
		return true;
270
	}
278
	}
271
 
279
 
Line 337... Line 345...
337
	}
345
	}
338
	dir = dir.findReplace("//", "/");
346
	dir = dir.findReplace("//", "/");
339
 
347
 
340
#ifdef _WIN32
348
#ifdef _WIN32
341
	dir = dir.findReplace("/", "\\");
349
	dir = dir.findReplace("/", "\\");
342
 
350
 
343
	WIN32_FIND_DATA data;
351
	WIN32_FIND_DATA data;
344
	TCHAR buf[5000];
352
	TCHAR buf[5000];
345
	wsprintf(buf, L"%hs", dir.c_str());
353
	wsprintf(buf, L"%hs", dir.c_str());
346
 
354
 
347
	HANDLE h = FindFirstFile(buf, &data);
355
	HANDLE h = FindFirstFile(buf, &data);
348
	if ( h != INVALID_HANDLE_VALUE)
356
	if ( h != INVALID_HANDLE_VALUE)
349
	{
357
	{
350
		std::wstring ws(data.cFileName);
358
		std::wstring ws(data.cFileName);
351
		std::string s(ws.begin(), ws.end());
359
		std::string s(ws.begin(), ws.end());
352
 
360
 
353
		Utils::String checkFile(s);
361
		Utils::String checkFile(s);
354
		if ( !checkFile.Compare(".") && !checkFile.Compare("..") )
362
		if ( !checkFile.Compare(".") && !checkFile.Compare("..") )
355
			files.pushBack(checkFile);
363
			files.pushBack(checkFile);
356
 
364
 
357
		while ( FindNextFile(h, &data) )
365
		while ( FindNextFile(h, &data) )
358
		{
366
		{
359
			std::wstring ws(data.cFileName);
367
			std::wstring ws(data.cFileName);
360
			std::string s(ws.begin(), ws.end());
368
			std::string s(ws.begin(), ws.end());
361
 
369
 
362
			Utils::String checkFile(s);
370
			Utils::String checkFile(s);
363
			if ( checkFile != "." && checkFile != ".." )
371
			if ( checkFile != "." && checkFile != ".." )
364
				files.pushBack(checkFile);
372
				files.pushBack(checkFile);
365
		}
373
		}
366
 
374
 
Line 378... Line 386...
378
				files.pushBack(checkFile);
386
				files.pushBack(checkFile);
379
		}
387
		}
380
		closedir(dir);
388
		closedir(dir);
381
	}
389
	}
382
	return true;
390
	return true;
383
#endif//_WIN32
391
#endif//_WIN32
384
 
392
 
385
}
393
}
386
 
394
 
387
CyStringList *CDirIO::DirList(CyString dir, CyString filepattern)
395
CyStringList *CDirIO::DirList(CyString dir, CyString filepattern)
388
{
396
{
389
	dir = _parseDir(dir.ToString());
397
	dir = _parseDir(dir.ToString());
390
	if ( dir.Empty() )
398
	if ( dir.Empty() )
Line 458... Line 466...
458
CyString CDirIO::Dir(CyString dir)
466
CyString CDirIO::Dir(CyString dir)
459
{
467
{
460
	return _parseDir(dir.ToString());
468
	return _parseDir(dir.ToString());
461
}
469
}
462
 
470
 
463
bool CDirIO::cd(CyString dir)
471
bool CDirIO::cd(const Utils::String &sDir)
464
{
472
{
465
	Utils::String sDir = dir.ToString();
-
 
466
 
-
 
467
	if ( m_sCurrentDir.empty() )
473
	if ( m_sCurrentDir.empty() )
468
		m_sCurrentDir = sDir;
474
		m_sCurrentDir = sDir;
469
	else
475
	else
470
		m_sCurrentDir = m_sCurrentDir + "/" + sDir;
476
		m_sCurrentDir = m_sCurrentDir + "/" + sDir;
471
	m_sCurrentDir = m_sCurrentDir.asFilename();
477
	m_sCurrentDir = m_sCurrentDir.asFilename();
Line 474... Line 480...
474
}
480
}
475
 
481
 
476
bool CDirIO::CreateAndChange(CyString dir)
482
bool CDirIO::CreateAndChange(CyString dir)
477
{
483
{
478
	if ( Create(dir) )
484
	if ( Create(dir) )
479
		return cd(dir);
485
		return cd(dir.ToString());
480
	return false;
486
	return false;
481
}
487
}
482
 
488
 
483
 
489
 
484
Utils::String CDirIO::topDir() const
490
Utils::String CDirIO::topDir() const