blob: e0b45a93a390833bb8ceb1f98af50125751c4e37 (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/*
filesystem/filesystem.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
// project headers
#include "filesystem/filesystem.h"
#include "filesystem/diskfile.h"
#include "filesystem/file.h"
#include "sys/sys.h"
namespace filesystem
{
std::string datadir = "";
std::string homedir = "";
std::string basedir = "";
std::string moddir = "";
std::string writedir = "";
void init()
{
con_print << "Initializing filesystem..." << std::endl;
// initialize game data locations
// FIXME datadir should by set by ./configure and read from config.h
datadir = "./data/";
// FIXME a local or remote game module must be able to set these
basedir = "base/";
moddir = "";
#ifndef _WIN32
homedir = getenv("HOME");
homedir = homedir + "/.osirion/";
#else
// FIXME win32
homedir = "./home/";
#endif
sys::mkdir(homedir);
sys::mkdir(homedir+basedir);
writedir = homedir;
if (moddir.size()) {
writedir.append(moddir);
} else
writedir.append(basedir);
sys::mkdir(writedir);
con_print << " files are created in " << writedir << std::endl;
}
void shutdown()
{
con_print << "Shutting down filesystem..." << std::endl;
}
File *open(const char *filename)
{
// for now, File is always a DiskFile
DiskFile *f = new DiskFile();
if (!f->open(filename)) {
delete f;
f = 0;
return 0;
}
return f;
}
void close(File *file)
{
if (!file)
return;
file->close();
delete file;
}
}
|