Add code to find luprex root directory
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
@@ -91,10 +92,10 @@ static std::vector<std::string> parse_control_lst(std::string_view ctrl) {
|
||||
|
||||
// Read a source file into a string.
|
||||
//
|
||||
static std::string read_file(const char *fn, std::string &err) {
|
||||
static std::string read_file(const std::filesystem::path &fn, std::string &err) {
|
||||
std::ifstream t(fn);
|
||||
if (t.fail()) {
|
||||
err = std::string("Could not open ") + fn;
|
||||
err = std::string("Could not open ") + std::string(fn);
|
||||
return "";
|
||||
}
|
||||
t.seekg(0, std::ios::end);
|
||||
@@ -103,7 +104,7 @@ static std::string read_file(const char *fn, std::string &err) {
|
||||
t.seekg(0);
|
||||
t.read(&result[0], size);
|
||||
if ((t.fail()) || (size_t(t.tellg()) != size)) {
|
||||
err = std::string("Could not read ") + fn;
|
||||
err = std::string("Could not read ") + std::string(fn);
|
||||
return "";
|
||||
}
|
||||
err = "";
|
||||
@@ -132,7 +133,7 @@ static void sbwrite_string(std::ostream *s, std::string_view sv) {
|
||||
|
||||
// This encoding can be read by StreamBuffer::read_string.
|
||||
//
|
||||
static bool sbwrite_file(std::ostream *s, const char *fn) {
|
||||
static bool sbwrite_file(std::ostream *s, const std::filesystem::path &fn) {
|
||||
s->put(0xFF);
|
||||
uint64_t pos1 = s->tellp();
|
||||
sbwrite_uint64(s, 0);
|
||||
@@ -152,10 +153,10 @@ static bool sbwrite_file(std::ostream *s, const char *fn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string package_lua_source(const std::string &base, std::ostream *s) {
|
||||
std::string package_lua_source(const std::filesystem::path &base, std::ostream *s) {
|
||||
std::string err;
|
||||
std::string cfn = base + "/../../lua/control.lst";
|
||||
std::string ctrl = read_file(cfn.c_str(), err);
|
||||
std::filesystem::path cfn = base / "lua/control.lst";
|
||||
std::string ctrl = read_file(cfn, err);
|
||||
if (!err.empty()) {
|
||||
return err;
|
||||
}
|
||||
@@ -166,9 +167,9 @@ std::string package_lua_source(const std::string &base, std::ostream *s) {
|
||||
sbwrite_string(s, names[i]);
|
||||
}
|
||||
for (int i = 0; i < int(names.size()); i++) {
|
||||
std::string lfn = base + "/../../lua/" + names[i];
|
||||
if (!sbwrite_file(s, lfn.c_str())) {
|
||||
return std::string("Cannot read source file: ") + lfn;
|
||||
std::filesystem::path lfn = base / "lua" / names[i];
|
||||
if (!sbwrite_file(s, lfn)) {
|
||||
return std::string("Cannot read source file: ") + std::string(lfn);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user