Merge pull request #354 from Wargus/topic/fix-compilations
fix filesystem use on older gcc and clang versions
This commit is contained in:
commit
cf563a3e0d
4 changed files with 45 additions and 37 deletions
gameheaders
src
|
@ -276,8 +276,8 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
char* extraction_files[] = { EXTRACTION_FILES, NULL };
|
||||
char* efile = extraction_files[0];
|
||||
for (int i = 0; efile != NULL; i++) {
|
||||
std::filesystem::path efile_path = std::filesystem::path(destination) / efile;
|
||||
if (!std::filesystem::exists(efile_path)) {
|
||||
fs::path efile_path = fs::path(destination) / efile;
|
||||
if (!fs::exists(efile_path)) {
|
||||
// file to extract not found
|
||||
canJustReextract = 0;
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
int patterncount = 0;
|
||||
while (filepatterns[patterncount++] != NULL);
|
||||
#endif
|
||||
std::filesystem::path srcfolder;
|
||||
fs::path srcfolder;
|
||||
if (!canJustReextract) {
|
||||
const char* datafileCstr = tinyfd_openFileDialog(GAME_CD " location", "",
|
||||
patterncount - 1, filepatterns, NULL, 0);
|
||||
|
@ -322,9 +322,9 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
char moduleFileName[BUFF_SIZE];
|
||||
memset(moduleFileName, 0, sizeof(moduleFileName));
|
||||
GetModuleFileName(NULL, moduleFileName, sizeof(moduleFileName)-1);
|
||||
std::filesystem::path innoextractPath = std::filesystem::path(moduleFileName).parent_path() / "innoextract.exe";
|
||||
fs::path innoextractPath = fs::path(moduleFileName).parent_path() / "innoextract.exe";
|
||||
std::wstring file = innoextractPath.wstring();
|
||||
std::vector<std::wstring> argv = {L"-i", std::filesystem::path(datafile).wstring()};
|
||||
std::vector<std::wstring> argv = {L"-i", fs::path(datafile).wstring()};
|
||||
#else
|
||||
const char *file = "innoextract";
|
||||
char *argv[] = {"-i", (char*)datafile.c_str(), NULL};
|
||||
|
@ -332,8 +332,8 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
if (runCommand(file, argv) == 0) {
|
||||
// innoextract exists and this exe file is an innosetup file
|
||||
bool success = false;
|
||||
std::filesystem::path tmpp = std::filesystem::temp_directory_path() / GAME;
|
||||
std::filesystem::create_directories(tmpp);
|
||||
fs::path tmpp = fs::temp_directory_path() / GAME;
|
||||
fs::create_directories(tmpp);
|
||||
#ifdef WIN32
|
||||
wchar_t *curdir = _wgetcwd(NULL, 0);
|
||||
#else
|
||||
|
@ -381,13 +381,13 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
"to check if its a single-file installer. If it is, please extract/install "
|
||||
"manually first and then run " GAME " again.", "ok", "question", 1);
|
||||
}
|
||||
srcfolder = std::filesystem::path(datafile).parent_path();
|
||||
srcfolder = fs::path(datafile).parent_path();
|
||||
}
|
||||
} else {
|
||||
srcfolder = std::filesystem::path(datafile).parent_path();
|
||||
srcfolder = fs::path(datafile).parent_path();
|
||||
}
|
||||
} else {
|
||||
srcfolder = std::filesystem::path(destination);
|
||||
srcfolder = fs::path(destination);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -404,21 +404,21 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
char* sourcepath = strdup(scripts_path);
|
||||
#endif
|
||||
|
||||
std::filesystem::create_directories(std::filesystem::path(destination));
|
||||
fs::create_directories(fs::path(destination));
|
||||
|
||||
if (!std::filesystem::exists(sourcepath)) {
|
||||
if (!fs::exists(sourcepath)) {
|
||||
// deployment time path not found, try compile time path
|
||||
strcpy(sourcepath, std::filesystem::path(SRC_PATH()).parent_path().string().c_str());
|
||||
strcpy(sourcepath, fs::path(SRC_PATH()).parent_path().string().c_str());
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
if (!std::filesystem::exists(sourcepath)) {
|
||||
if (!fs::exists(sourcepath)) {
|
||||
// deployment time path might be same as extractor
|
||||
strcpy(sourcepath, std::filesystem::path(extractor_tool).parent_path().string().c_str());
|
||||
strcpy(sourcepath, fs::path(extractor_tool).parent_path().string().c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!std::filesystem::exists(sourcepath)) {
|
||||
if (!fs::exists(sourcepath)) {
|
||||
// scripts not found, abort!
|
||||
std::string msg("There was an error copying the data, could not discover scripts path: ");
|
||||
msg += sourcepath;
|
||||
|
@ -427,8 +427,8 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
}
|
||||
|
||||
if (force != 2) {
|
||||
std::filesystem::path contrib_src_path;
|
||||
std::filesystem::path contrib_dest_path(destination);
|
||||
fs::path contrib_src_path;
|
||||
fs::path contrib_dest_path(destination);
|
||||
int i = 0;
|
||||
int optional = 0;
|
||||
char* contrib_directories[] = CONTRIB_DIRECTORIES;
|
||||
|
@ -439,13 +439,13 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
} else {
|
||||
if (contrib_directories[i][0] != '/') {
|
||||
// absolute Unix paths are not appended to the source path
|
||||
contrib_src_path = std::filesystem::path(sourcepath);
|
||||
contrib_src_path = fs::path(sourcepath);
|
||||
contrib_src_path /= contrib_directories[i];
|
||||
} else {
|
||||
contrib_src_path = std::filesystem::path(contrib_directories[i]);
|
||||
contrib_src_path = fs::path(contrib_directories[i]);
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists(contrib_src_path)) {
|
||||
if (!fs::exists(contrib_src_path)) {
|
||||
// contrib dir not found, abort!
|
||||
if (!optional) {
|
||||
std::string msg("There was an error copying the data, could not discover contributed directory path: ");
|
||||
|
@ -468,7 +468,7 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
std::wstring file;
|
||||
std::vector<std::wstring> args;
|
||||
|
||||
file = std::filesystem::path(extractor_tool).wstring();
|
||||
file = fs::path(extractor_tool).wstring();
|
||||
for (int i = 0; ; i++) {
|
||||
const char *earg = extractor_args[i];
|
||||
if (earg == NULL) {
|
||||
|
@ -481,7 +481,7 @@ static void ExtractData(char* extractor_tool, char *const extractor_args[], char
|
|||
}
|
||||
}
|
||||
args.push_back(srcfolder.wstring());
|
||||
args.push_back(std::filesystem::path(destination).wstring());
|
||||
args.push_back(fs::path(destination).wstring());
|
||||
std::wstring combinedCommandline;
|
||||
exitcode = runCommand(file, args, true, &combinedCommandline);
|
||||
#else
|
||||
|
|
|
@ -100,7 +100,15 @@ void copy_dir(const char* source_folder, const char* target_folder);
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <istream>
|
||||
#include <filesystem>
|
||||
#if __has_include(<filesystem>)
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#elif __has_include(<experimental/filesystem>)
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#else
|
||||
error "Missing the <filesystem> header."
|
||||
#endif
|
||||
|
||||
#include "stratagus-tinyfiledialogs.h"
|
||||
|
||||
|
@ -116,22 +124,22 @@ void error(const char* title, const char* text) {
|
|||
}
|
||||
|
||||
void mkdir_p(const char* path) {
|
||||
std::filesystem::create_directories(path);
|
||||
fs::create_directories(path);
|
||||
}
|
||||
|
||||
void copy_dir(std::filesystem::path source_folder, std::filesystem::path target_folder) {
|
||||
if (std::filesystem::exists(target_folder)) {
|
||||
if (std::filesystem::equivalent(source_folder, target_folder)) {
|
||||
void copy_dir(fs::path source_folder, fs::path target_folder) {
|
||||
if (fs::exists(target_folder)) {
|
||||
if (fs::equivalent(source_folder, target_folder)) {
|
||||
return;
|
||||
}
|
||||
// first delete the target_folder, if it exists, to ensure clean slate
|
||||
std::filesystem::remove_all(target_folder);
|
||||
fs::remove_all(target_folder);
|
||||
} else {
|
||||
// make the parentdir of the target folder
|
||||
std::filesystem::create_directories(target_folder.parent_path());
|
||||
fs::create_directories(target_folder.parent_path());
|
||||
}
|
||||
// now copy the new folder in its place
|
||||
std::filesystem::copy(source_folder, target_folder, std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing);
|
||||
fs::copy(source_folder, target_folder, fs::copy_options::recursive | fs::copy_options::overwrite_existing);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -308,4 +316,4 @@ int runCommand(const char *file, char *const argv[], bool echo = false, std::str
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -827,7 +827,7 @@ public:
|
|||
msg.serialize32NativeByteOrder((uint32_t) extendedInfoNames.size());
|
||||
extendedInfoNames.push_back(username);
|
||||
msg.serialize(username.c_str());
|
||||
for (const auto key : defaultUserKeys) {
|
||||
for (const auto& key : defaultUserKeys) {
|
||||
msg.serialize(key.c_str());
|
||||
}
|
||||
msg.flush(getTCPSocket());
|
||||
|
@ -1062,7 +1062,7 @@ public:
|
|||
void setCurrentChannel(std::string name) {
|
||||
this->currentChannel = name;
|
||||
bool unlisted = true;
|
||||
for (const auto c : channelList) {
|
||||
for (const auto& c : channelList) {
|
||||
if (c == name) {
|
||||
unlisted = false;
|
||||
break;
|
||||
|
@ -1207,7 +1207,7 @@ public:
|
|||
this->channelList = channels;
|
||||
if (SetChannels != NULL) {
|
||||
SetChannels->pushPreamble();
|
||||
for (const auto value : channels) {
|
||||
for (const auto& value : channels) {
|
||||
SetChannels->pushString(value);
|
||||
}
|
||||
SetChannels->run();
|
||||
|
|
|
@ -107,7 +107,7 @@ void LuaCallback::pushString(const std::string &s)
|
|||
*/
|
||||
void LuaCallback::pushTable(std::initializer_list<std::pair<std::string, std::variant<std::string, int>>> list) {
|
||||
lua_createtable(Lua, 0, list.size());
|
||||
for (const auto entry : list) {
|
||||
for (const auto& entry : list) {
|
||||
if (std::holds_alternative<std::string>(entry.second)) {
|
||||
lua_pushstring(Lua, std::get<std::string>(entry.second).c_str());
|
||||
} else {
|
||||
|
@ -123,7 +123,7 @@ void LuaCallback::pushTable(std::initializer_list<std::pair<std::string, std::va
|
|||
*/
|
||||
void LuaCallback::pushTable(std::map<std::string, std::variant<std::string, int>> map) {
|
||||
lua_createtable(Lua, 0, map.size());
|
||||
for (const auto entry : map) {
|
||||
for (const auto& entry : map) {
|
||||
if (std::holds_alternative<std::string>(entry.second)) {
|
||||
lua_pushstring(Lua, std::get<std::string>(entry.second).c_str());
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue