Skip to content

Commit

Permalink
Move #include <filesystem> in its own file to be consistent with ex…
Browse files Browse the repository at this point in the history
…perimental support...

Use `fs::` instead of `std::filesystem`
  • Loading branch information
Jarod42 committed Aug 4, 2023
1 parent 994e926 commit b93c6ca
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 35 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions src/include/filesystem.h
Original file line number Diff line number Diff line change
@@ -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(<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

//@}

#endif /* __FILESYSTEM_H__ */
1 change: 1 addition & 0 deletions src/include/iolib.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
----------------------------------------------------------------------------*/

#include <vector>
#include "filesystem.h"
#include "SDL.h"

/*----------------------------------------------------------------------------
Expand Down
10 changes: 1 addition & 9 deletions src/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@

//@{

#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 "filesystem.h"

#include <cstdlib>
#include <cstdint>
Expand Down
10 changes: 1 addition & 9 deletions src/network/netconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@
#include <array>
#include <utility>
#include <random>
#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 "filesystem.h"
#include "game.h"
#include "online_service.h"
#include "stratagus.h"
Expand Down
8 changes: 4 additions & 4 deletions src/stratagus/iolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,13 @@ std::vector<FileList> ReadDataDirectory(const fs::path& directory)
{
std::vector<FileList> 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;
Expand Down
4 changes: 2 additions & 2 deletions src/stratagus/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

#include "stratagus.h"

#include "filesystem.h"
#include "parameters.h"

#include <stdlib.h>

#ifdef USE_WIN32
#include <Shlobj.h>
#include <filesystem>
#endif

/* static */ Parameters Parameters::Instance;
Expand All @@ -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;
}
Expand Down
13 changes: 2 additions & 11 deletions src/stratagus/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,14 @@
-- Includes
----------------------------------------------------------------------------*/

#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 "script.h"

#include <signal.h>

#include "stratagus.h"

#include "script.h"

#include "animation/animation_setplayervar.h"
#include "filesystem.h"
#include "font.h"
#include "game.h"
#include "iolib.h"
Expand Down

0 comments on commit b93c6ca

Please sign in to comment.