Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ SET(BIN "${OPENC2E_BINARY_DIR}")
SET(GEN "${BIN}/generated")
EXECUTE_PROCESS(COMMAND mkdir -p "${GEN}")

SET(CMAKE_CXX_FLAGS "-fpermissive")

SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS 1)
SET(CMAKE_MODULE_PATH "${SRC}/cmake")

Expand Down
26 changes: 13 additions & 13 deletions src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void Engine::loadGameData() {
if (fs::exists(palpath) && !fs::is_directory(palpath)) {
palette = new unsigned char[768];

std::ifstream f(palpath.native_directory_string().c_str(), std::ios::binary);
std::ifstream f(palpath.string().c_str(), std::ios::binary);
f >> std::noskipws;
f.read((char *)palette, 768);

Expand Down Expand Up @@ -624,7 +624,7 @@ bool Engine::parseCommandLine(int argc, char *argv[]) {

// add all the data directories to the list
for (std::vector<std::string>::iterator i = data_vec.begin(); i != data_vec.end(); i++) {
fs::path datadir(*i, fs::native);
fs::path datadir(*i);
if (!fs::exists(datadir)) {
throw creaturesException("data path '" + *i + "' doesn't exist");
}
Expand Down Expand Up @@ -746,11 +746,11 @@ bool Engine::initialSetup() {
// inform the user of the port used, and store it in the relevant file
std::cout << "Listening for connections on port " << listenport << "." << std::endl;
#ifndef _WIN32
fs::path p = fs::path(homeDirectory().native_directory_string() + "/.creaturesengine", fs::native);
fs::path p = fs::path(homeDirectory().string() + "/.creaturesengine");
if (!fs::exists(p))
fs::create_directory(p);
if (fs::is_directory(p)) {
std::ofstream f((p.native_directory_string() + "/port").c_str(), std::ios::trunc);
std::ofstream f((p.string() + "/port").c_str(), std::ios::trunc);
f << boost::str(boost::format("%d") % listenport);
}
#endif
Expand All @@ -776,7 +776,7 @@ bool Engine::initialSetup() {
throw creaturesException("multiple bootstrap files provided in C1/C2 mode");

for (std::vector< std::string >::iterator bsi = cmdline_bootstrap.begin(); bsi != cmdline_bootstrap.end(); bsi++) {
fs::path scriptdir(*bsi, fs::native);
fs::path scriptdir(*bsi);
if (engine.version > 2 || fs::extension(scriptdir) == ".cos") {
// pass it to the world to execute (it handles both files and directories)

Expand All @@ -792,7 +792,7 @@ bool Engine::initialSetup() {
throw creaturesException("non-existant bootstrap file provided in C1/C2 mode");
// TODO: the default SFCFile loading code is in World, maybe this should be too..
SFCFile sfc;
std::ifstream f(scriptdir.native_directory_string().c_str(), std::ios::binary);
std::ifstream f(scriptdir.string().c_str(), std::ios::binary);
f >> std::noskipws;
sfc.read(&f);
sfc.copyToWorld();
Expand Down Expand Up @@ -832,12 +832,12 @@ fs::path Engine::homeDirectory() {
#ifndef _WIN32
char *envhome = getenv("HOME");
if (envhome)
p = fs::path(envhome, fs::native);
p = fs::path(envhome);
if ((!envhome) || (!fs::is_directory(p)))
p = fs::path(getpwuid(getuid())->pw_dir, fs::native);
p = fs::path(getpwuid(getuid())->pw_dir);
if (!fs::is_directory(p)) {
std::cerr << "Can't work out what your home directory is, giving up and using /tmp for now." << std::endl;
p = fs::path("/tmp", fs::native); // sigh
p = fs::path("/tmp"); // sigh
}
#else
TCHAR szPath[_MAX_PATH];
Expand All @@ -863,18 +863,18 @@ fs::path Engine::storageDirectory() {
#endif

// main storage dir
fs::path p = fs::path(homeDirectory().native_directory_string() + dirname, fs::native);
fs::path p = fs::path(homeDirectory().string() + dirname);
if (!fs::exists(p))
fs::create_directory(p);
else if (!fs::is_directory(p))
throw creaturesException("Your openc2e data directory " + p.native_directory_string() + " is a file, not a directory. That's bad.");
throw creaturesException("Your openc2e data directory " + p.string() + " is a file, not a directory. That's bad.");

// game-specific storage dir
p = fs::path(p.native_directory_string() + std::string("/" + gamename), fs::native);
p = fs::path(p.string() + std::string("/" + gamename));
if (!fs::exists(p))
fs::create_directory(p);
else if (!fs::is_directory(p))
throw creaturesException("Your openc2e game data directory " + p.native_directory_string() + " is a file, not a directory. That's bad.");
throw creaturesException("Your openc2e game data directory " + p.string() + " is a file, not a directory. That's bad.");

return p;
}
Expand Down
12 changes: 6 additions & 6 deletions src/PathResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ static string toLowerCase(string in) {
}

static path lcpath(path &orig) {
return path(toLowerCase(orig.string()), native);
return path(toLowerCase(orig.string()));
}

static path lcleaf(path &orig) {
path br, leaf;
br = orig.branch_path();
leaf = path(toLowerCase(orig.leaf()), native);
leaf = path(toLowerCase(orig.leaf().string()));
return br / leaf;
}

Expand All @@ -68,21 +68,21 @@ bool resolveFile(path &p) {
if (!resolveFile(s))
return false;
}
p = path(s, native);
p = path(s);
return true;
#else
return exists(p);
#endif
}

bool resolveFile_(string &srcPath) {
path orig(srcPath, native);
path orig(srcPath);
if (exists(orig))
return true;

orig.normalize();
path dir = orig.branch_path();
path leaf = path(orig.leaf(), native);
path leaf = path(orig.leaf());

if (!checkDirCache(dir))
return false;
Expand Down Expand Up @@ -180,7 +180,7 @@ std::vector<std::string> findByWildcard(std::string dir, std::string wild) {

wild = toLowerCase(wild);

path dirp(dir, native);
path dirp(dir);
dirp.normalize();
if (!resolveFile(dirp))
return std::vector<std::string>();
Expand Down
12 changes: 6 additions & 6 deletions src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ void World::executeInitScript(fs::path p) {
assert(fs::exists(p));
assert(!fs::is_directory(p));

std::string x = p.native_file_string();
std::string x = p.string();
std::ifstream s(x.c_str());
assert(s.is_open());
//std::cout << "executing script " << x << "...\n";
Expand Down Expand Up @@ -564,7 +564,7 @@ void World::executeBootstrap(bool switcher) {
fs::path edenpath(data_directories[0] / "/Eden.sfc");
if (fs::exists(edenpath) && !fs::is_directory(edenpath)) {
SFCFile sfc;
std::ifstream f(edenpath.native_directory_string().c_str(), std::ios::binary);
std::ifstream f(edenpath.string().c_str(), std::ios::binary);
f >> std::noskipws;
sfc.read(&f);
sfc.copyToWorld();
Expand All @@ -585,7 +585,7 @@ void World::executeBootstrap(bool switcher) {
// iterate through each bootstrap directory
for (fs::directory_iterator d(b); d != fsend; ++d) {
if (fs::exists(*d) && fs::is_directory(*d)) {
std::string s = d->path().leaf();
std::string s = d->path().leaf().string();
// TODO: cvillage has switcher code in 'Startup', so i included it here too
if (s == "000 Switcher" || s == "Startup") {
if (!switcher) continue;
Expand Down Expand Up @@ -620,7 +620,7 @@ std::string World::findFile(std::string name) {
// Go backwards, so we find files in more 'modern' directories first..
for (int i = data_directories.size() - 1; i != -1; i--) {
fs::path p = data_directories[i];
std::string r = (p / fs::path(name, fs::native)).native_directory_string();
std::string r = (p / fs::path(name)).string();
if (resolveFile(r))
return r;
}
Expand All @@ -634,7 +634,7 @@ std::vector<std::string> World::findFiles(std::string dir, std::string wild) {
// Go backwards, so we find files in more 'modern' directories first..
for (int i = data_directories.size() - 1; i != -1; i--) {
fs::path p = data_directories[i];
std::string r = (p / fs::path(dir, fs::native)).native_directory_string();
std::string r = (p / fs::path(dir)).string();
std::vector<std::string> results = findByWildcard(r, wild);
possibles.insert(possibles.end(), results.begin(), results.end()); // merge results
}
Expand All @@ -643,7 +643,7 @@ std::vector<std::string> World::findFiles(std::string dir, std::string wild) {
}

std::string World::getUserDataDir() {
return (data_directories.end() - 1)->native_directory_string();
return (data_directories.end() - 1)->string();
}

void World::selectCreature(boost::shared_ptr<Agent> a) {
Expand Down
12 changes: 6 additions & 6 deletions src/backends/qtgui/AgentInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void AgentInjector::readAgents() {
std::transform(cobext.begin(), cobext.end(), cobext.begin(), (int(*)(int))tolower); // downcase
if (cobext != ".cob") continue;

std::string cob = itr->path().native_file_string();
std::string cob = itr->path().string();

if (engine.version == 1) {
std::ifstream cobstream(cob.c_str(), std::ios::binary);
Expand Down Expand Up @@ -166,8 +166,8 @@ void AgentInjector::onInject() {
std::string directory = world.praymanager.getResourceDir(praytype);
caos_assert(!directory.empty());

fs::path possiblefile = fs::path(directory, fs::native) / fs::path(name, fs::native);
if (!world.findFile(possiblefile.native_directory_string()).empty()) continue; // TODO: update file if necessary?
fs::path possiblefile = fs::path(directory) / fs::path(name);
if (!world.findFile(possiblefile.string()).empty()) continue; // TODO: update file if necessary?

std::vector<cobBlock *>::iterator j;

Expand All @@ -179,15 +179,15 @@ void AgentInjector::onInject() {
cobFileBlock *a = new cobFileBlock(*j);
if (a->filetype == type && a->filename == name) {
// Found dependency!
fs::path dir = fs::path(world.getUserDataDir(), fs::native) / fs::path(directory, fs::native);
fs::path dir = fs::path(world.getUserDataDir()) / fs::path(directory);
if (!fs::exists(dir))
fs::create_directory(dir);
assert(fs::exists(dir) && fs::is_directory(dir)); // TODO: error handling

fs::path outputfile = dir / fs::path(name, fs::native);
fs::path outputfile = dir / fs::path(name);
assert(!fs::exists(outputfile));

std::ofstream output(outputfile.native_directory_string().c_str(), std::ios::binary);
std::ofstream output(outputfile.string().c_str(), std::ios::binary);
output.write((char *)a->getFileContents(), a->filesize);

a->getParent()->free();
Expand Down
2 changes: 1 addition & 1 deletion src/caos/caosVM_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void caosVM::v_OC2E_DDIR() {

for (std::vector<boost::filesystem::path>::iterator i = world.data_directories.begin(); i != world.data_directories.end(); i++) {
boost::filesystem::path &p = *i;
d = d + boost::filesystem::system_complete(p).native_file_string() + "\n";
d = d + boost::filesystem::system_complete(p).string() + "\n";
}

result.setString(d);
Expand Down
2 changes: 1 addition & 1 deletion src/caos/caosVM_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string calculateJournalFilename(int directory, std::string filename, bool w
default: throw caosException("unknown Journal directory");
}

fs::path dir = fs::path(fullfilename, fs::native);
fs::path dir = fs::path(fullfilename);
if (!fs::exists(dir))
fs::create_directory(dir);
caos_assert(fs::exists(dir) && fs::is_directory(dir));
Expand Down
10 changes: 5 additions & 5 deletions src/caos/caosVM_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ bool prayInstall(std::string name, unsigned int type, bool actually_install) {
std::string directory = world.praymanager.getResourceDir(type);
caos_assert(!directory.empty());

fs::path dir = fs::path(world.getUserDataDir(), fs::native) / fs::path(directory, fs::native);
fs::path dir = fs::path(world.getUserDataDir()) / fs::path(directory);
if (!fs::exists(dir))
fs::create_directory(dir);
caos_assert(fs::exists(dir) && fs::is_directory(dir));

fs::path outputfile = dir / fs::path(name, fs::native);
fs::path outputfile = dir / fs::path(name);
if (fs::exists(outputfile)) {
// TODO: update file if necessary? check it's not a directory :P
return true;
}

fs::path possiblefile = fs::path(directory, fs::native) / fs::path(name, fs::native);
if (!world.findFile(possiblefile.native_directory_string()).empty()) {
fs::path possiblefile = fs::path(directory) / fs::path(name);
if (!world.findFile(possiblefile.string()).empty()) {
// TODO: we need to return 'okay' if the file exists anywhere, but someone needs to work out update behaviour (see other comment above, also)
return true;
}
Expand All @@ -65,7 +65,7 @@ bool prayInstall(std::string name, unsigned int type, bool actually_install) {
}

p->load();
std::ofstream output(outputfile.native_directory_string().c_str(), std::ios::binary);
std::ofstream output(outputfile.string().c_str(), std::ios::binary);
output.write((char *)p->getBuffer(), p->getSize());
// p->unload();

Expand Down
6 changes: 3 additions & 3 deletions src/cobFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@

cobFile::cobFile(fs::path filepath) {
path = filepath;
file.open(path.native_directory_string().c_str(), std::ios::binary);
file.open(path.string().c_str(), std::ios::binary);

if (!file.is_open())
throw creaturesException(std::string("couldn't open COB file \"") + path.native_directory_string() + "\"");
throw creaturesException(std::string("couldn't open COB file \"") + path.string() + "\"");

// TODO: c1 cob support
char majic[4];
file.read(majic, 4);
if (strncmp(majic, "cob2", 4) != 0)
throw creaturesException(std::string("bad magic of C2 COB file \"") + path.native_directory_string() + "\"");
throw creaturesException(std::string("bad magic of C2 COB file \"") + path.string() + "\"");

while (!file.eof()) {
// TODO: catch exceptions, and free all blocks before passing it up the stack
Expand Down
24 changes: 12 additions & 12 deletions src/imageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ bool tryOpen(mmapifstream *in, shared_ptr<creaturesImage> &img, std::string fnam
std::string cachename;
if (fname.size() < 5) return false; // not enough chars for an extension and filename..

realfile = path(world.findFile(fname), native);
realfile = path(world.findFile(fname));
// if it doesn't exist, too bad, give up.
if (!exists(realfile)) return false;

std::string basename = realfile.leaf(); basename.erase(basename.end() - 4, basename.end());
std::string basename = realfile.leaf().string(); basename.erase(basename.end() - 4, basename.end());

// work out where the cached file should be
cachename = engine.storageDirectory().native_directory_string() + "/" + fname;
cachename = engine.storageDirectory().string() + "/" + fname;
if (ft == c16) { // TODO: we should really stop the caller from appending .s16/.c16
cachename.erase(cachename.end() - 4, cachename.end());
cachename.append(".s16");
Expand All @@ -62,47 +62,47 @@ bool tryOpen(mmapifstream *in, shared_ptr<creaturesImage> &img, std::string fnam
if (ft != spr)
cachename = cachename + ".big";
#endif
cachefile = path(cachename, native);
cachefile = path(cachename);

if (resolveFile(cachefile)) {
// TODO: check for up-to-date-ness
in->clear();
in->mmapopen(cachefile.native_file_string());
in->mmapopen(cachefile.string());
if (ft == c16) ft = s16;
goto done;
}
//std::cout << "couldn't find cached version: " << cachefile.native_file_string() << std::endl;
//std::cout << "couldn't find cached version: " << cachefile.string() << std::endl;

in->clear();
in->mmapopen(realfile.native_file_string());
in->mmapopen(realfile.string());
#if OC2E_BIG_ENDIAN
if (in->is_open() && (ft != spr)) {
path p = cachefile.branch_path();
if (!exists(p))
create_directory(p);
if (!is_directory(p))
throw creaturesException("imageManager couldn't create cache directory '" + p.native_directory_string() + "'");
throw creaturesException("imageManager couldn't create cache directory '" + p.string() + "'");

fileSwapper f;
switch (ft) {
case blk:
f.convertblk(realfile.native_file_string(), cachefile.native_file_string());
f.convertblk(realfile.string(), cachefile.string());
break;
case s16:
f.converts16(realfile.native_file_string(), cachefile.native_file_string());
f.converts16(realfile.string(), cachefile.string());
break;
case c16:
//cachefile = change_extension(cachefile, "");
//cachefile = change_extension(cachefile, ".s16.big");
f.convertc16(realfile.native_file_string(), cachefile.native_file_string());
f.convertc16(realfile.string(), cachefile.string());
ft = s16;
break;
default:
return true; // TODO: exception?
}
in->close(); // TODO: close the mmap too! how?
if (!exists(cachefile)) return false; // TODO: exception?
in->mmapopen(cachefile.native_file_string());
in->mmapopen(cachefile.string());
}
#endif
done:
Expand Down
Loading