Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 53c72d8b07de5cdc2a60aa5c1133cb3805f9f8f7 (plain)
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
/*
   filesystem/ifilestream.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include "filesystem/filesystem.h"
#include "filesystem/filestream.h"

namespace filesystem
{

IFileStream::IFileStream(const char *name) : std::ifstream()
{
	if (name)
		fstream_name.assign(name);

	open(name);
}

IFileStream::IFileStream(const std::string &name) : std::ifstream(), fstream_name(name)
{
	open(fstream_name);
}

void IFileStream::open(const char *name)
{
	if (!name) {
		if (is_open()) {
			close();
		}
		fstream_name.clear();
		fstream_filename.clear();
		return;
	}

	fstream_name.assign(name);

	for (SearchPath::iterator path = searchpath().begin(); path != searchpath().end(); path++) {
		fstream_filename.assign((*path));
		fstream_filename.append(fstream_name);
		/*
		#ifdef _WIN32
				for (size_t i = 0; i < fstream_filename.size(); i++)
					if (fstream_filename[i] == '/') fstream_filename[i] = '\\';
		#endif
		*/

		if (sys::file_exists(fstream_filename)) {
			std::ifstream::open(fstream_filename.c_str());
			if (good())
				return;
		}
	}

	fstream_filename.clear();
}

void IFileStream::open(const std::string &name)
{
	open(name.c_str());
}

}