From aac47413a034b3dbc96dabf8097b9dc109aabeb1 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Fri, 4 Aug 2023 15:57:36 +0200 Subject: [PATCH] Move `#include ` in its own file to be consistent with experimental support... Use `fs::` instead of `std::filesystem` --- CMakeLists.txt | 1 + src/include/filesystem.h | 51 ++++++++++++++++++++++++++++++++++++ src/include/iolib.h | 1 + src/include/script.h | 3 +++ src/include/util.h | 10 +------ src/network/netconnect.cpp | 10 +------ src/stratagus/iolib.cpp | 8 +++--- src/stratagus/parameters.cpp | 4 +-- src/stratagus/script.cpp | 13 ++------- 9 files changed, 66 insertions(+), 35 deletions(-) create mode 100644 src/include/filesystem.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 645fae33d..062381132 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -551,6 +551,7 @@ set(stratagus_generic_HDRS src/include/depend.h src/include/editor.h src/include/online_service.h + src/include/filesystem.h src/include/font.h src/include/fov.h src/include/fow.h diff --git a/src/include/filesystem.h b/src/include/filesystem.h new file mode 100644 index 000000000..d24554d5c --- /dev/null +++ b/src/include/filesystem.h @@ -0,0 +1,51 @@ +// _________ __ __ +// / _____// |_____________ _/ |______ ____ __ __ ______ +// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ +// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | +// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > +// \/ \/ \//_____/ \/ +// ______________________ ______________________ +// T H E W A R B E G I N S +// Stratagus - A free fantasy real time strategy game engine +// +/**@name filesystem - filesystem header selection. */ +// +// (c) Copyright 1998-2023 by Lutz Sammer, Jimmy Salmon and Joris Dauphin. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; only version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// + +#ifndef __FILESYSTEM_H__ +#define __FILESYSTEM_H__ + +//@{ + +/*---------------------------------------------------------------------------- +-- Includes +----------------------------------------------------------------------------*/ + +#if __has_include() +# include +namespace fs = std::filesystem; +#elif __has_include() +# include +namespace fs = std::experimental::filesystem; +#else +error "Missing the header." +#endif + +//@} + +#endif /* __FILESYSTEM_H__ */ diff --git a/src/include/iolib.h b/src/include/iolib.h index ce0fff3b1..de47d8e9b 100644 --- a/src/include/iolib.h +++ b/src/include/iolib.h @@ -37,6 +37,7 @@ ----------------------------------------------------------------------------*/ #include +#include "filesystem.h" #include "SDL.h" /*---------------------------------------------------------------------------- diff --git a/src/include/script.h b/src/include/script.h index 9b5e9a384..9964ddd01 100644 --- a/src/include/script.h +++ b/src/include/script.h @@ -47,6 +47,9 @@ extern "C" { } #endif +#include "filesystem.h" +#include "stratagus.h" + /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ diff --git a/src/include/util.h b/src/include/util.h index 1aa873e10..50aeeaccd 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -32,15 +32,7 @@ //@{ -#if __has_include() -#include -namespace fs = std::filesystem; -#elif __has_include() -#include -namespace fs = std::experimental::filesystem; -#else -error "Missing the header." -#endif +#include "filesystem.h" #include #include diff --git a/src/network/netconnect.cpp b/src/network/netconnect.cpp index edeacbd08..f98335d96 100644 --- a/src/network/netconnect.cpp +++ b/src/network/netconnect.cpp @@ -42,16 +42,8 @@ #include #include #include -#if __has_include() -#include -namespace fs = std::filesystem; -#elif __has_include() -#include -namespace fs = std::experimental::filesystem; -#else -error "Missing the header." -#endif +#include "filesystem.h" #include "game.h" #include "online_service.h" #include "stratagus.h" diff --git a/src/stratagus/iolib.cpp b/src/stratagus/iolib.cpp index e15a02300..211178a95 100644 --- a/src/stratagus/iolib.cpp +++ b/src/stratagus/iolib.cpp @@ -692,13 +692,13 @@ std::vector ReadDataDirectory(const fs::path& directory) { std::vector files; - for (auto it = std::filesystem::directory_iterator{directory}; - it != std::filesystem::directory_iterator{}; + for (auto it = fs::directory_iterator{directory}; + it != fs::directory_iterator{}; ++it) { - if (std::filesystem::is_directory(it->path())) { + if (fs::is_directory(it->path())) { files.emplace_back(); files.back().name = it->path().filename().string(); - } else if (std::filesystem::is_regular_file(it->path())) { + } else if (fs::is_regular_file(it->path())) { files.emplace_back(); files.back().name = it->path().filename().string(); files.back().type = 1; diff --git a/src/stratagus/parameters.cpp b/src/stratagus/parameters.cpp index 648407cf0..33895d771 100644 --- a/src/stratagus/parameters.cpp +++ b/src/stratagus/parameters.cpp @@ -31,13 +31,13 @@ #include "stratagus.h" +#include "filesystem.h" #include "parameters.h" #include #ifdef USE_WIN32 #include -#include #endif /* static */ Parameters Parameters::Instance; @@ -59,7 +59,7 @@ void Parameters::SetDefaultUserDirectory(bool noPortable) if (!noPortable) { // if launcher is in the same directory as the data, we are in a portable install fs::path executable_path = GetExecutablePath(); - if (std::filesystem::equivalent(std::filesystem::path(StratagusLibPath), executable_path.parent_path())) { + if (fs::equivalent(fs::path(StratagusLibPath), executable_path.parent_path())) { userDirectory = StratagusLibPath; return; } diff --git a/src/stratagus/script.cpp b/src/stratagus/script.cpp index 6c13935a0..bcd3250e7 100644 --- a/src/stratagus/script.cpp +++ b/src/stratagus/script.cpp @@ -33,23 +33,14 @@ -- Includes ----------------------------------------------------------------------------*/ -#if __has_include() -#include -namespace fs = std::filesystem; -#elif __has_include() -#include -namespace fs = std::experimental::filesystem; -#else -error "Missing the header." -#endif +#include "script.h" #include #include "stratagus.h" -#include "script.h" - #include "animation/animation_setplayervar.h" +#include "filesystem.h" #include "font.h" #include "game.h" #include "iolib.h"