Cleanup use of boost::filesystem

Suppressing boost warnings is already covered by how we include
libraries if there are actually still any of them relevant.

Then the v2 vs v3 stuff is obsolete as boost ships with filesystem v4
this days.

Lastly injecting a namespace alias via pch header is questionable, so
just don't.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2025-06-17 14:04:24 +02:00
parent fd847c2a23
commit 657be906fe
No known key found for this signature in database
9 changed files with 21 additions and 124 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2024 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -792,11 +792,11 @@ public:
*/
CTextureConverter::Settings GetConverterSettings(const CTexturePtr& texture)
{
fs::wpath srcPath = texture->m_Properties.m_Path.string();
boost::filesystem::path srcPath = texture->m_Properties.m_Path.string();
std::vector<CTextureConverter::SettingsFile*> files;
VfsPath p;
for (fs::wpath::iterator it = srcPath.begin(); it != srcPath.end(); ++it)
for (boost::filesystem::path::iterator it = srcPath.begin(); it != srcPath.end(); ++it)
{
VfsPath settingsPath = p / "textures.xml";
m_HotloadFiles[settingsPath].insert(texture);

View file

@ -1,43 +0,0 @@
/* Copyright (C) 2025 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// rationale: boost is only included from the PCH, but warnings are still
// raised when templates are instantiated (e.g. vfs_lookup.cpp),
// so include this header from such source files as well.
#include "lib/sysdep/compiler.h" // MSC_VERSION
#include "lib/sysdep/arch.h" // ARCH_IA32
#if MSC_VERSION
# pragma warning(disable:4710) // function not inlined
# pragma warning(disable:4626) // assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted
# pragma warning(disable:4625) // copy constructor was implicitly defined as deleted
# pragma warning(disable:4668) // 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
# pragma warning(disable:5027) // 'type': move assignment operator was implicitly defined as deleted
# pragma warning(disable:4365) // signed/unsigned mismatch
# pragma warning(disable:4619) // there is no warning for 'warning'
# pragma warning(disable:5031) // #pragma warning(pop): likely mismatch, popping warning state pushed in different file
# pragma warning(disable:5026) // 'type': move constructor was implicitly defined as deleted
# pragma warning(disable:4820) // incorrect padding
# pragma warning(disable:4514) // unreferenced inlined function has been removed
# pragma warning(disable:4571) // Informational: catch(...) semantics changed since Visual C++ 7.1; structured exceptions (SEH) are no longer caught
#endif

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2024 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -210,9 +210,9 @@ Status RenameFile(const OsPath& path, const OsPath& newPath)
try
{
fs::rename(fs::path(path.string()), fs::path(newPath.string()));
boost::filesystem::rename(boost::filesystem::path(path.string()), boost::filesystem::path(newPath.string()));
}
catch (fs::filesystem_error& err)
catch (boost::filesystem::filesystem_error& err)
{
debug_printf("RenameFile: failed to rename %s to %s.\n%s\n", path.string8().c_str(), path.string8().c_str(), err.what());
return ERR::EXCEPTION;
@ -231,14 +231,14 @@ Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exis
{
if(override_if_exists)
#if BOOST_VERSION >=107400
fs::copy_file(fs::path(path.string()), fs::path(newPath.string()), boost::filesystem::copy_options::overwrite_existing);
boost::filesystem::copy_file(boost::filesystem::path(path.string()), boost::filesystem::path(newPath.string()), boost::filesystem::copy_options::overwrite_existing);
#else
fs::copy_file(fs::path(path.string()), fs::path(newPath.string()), boost::filesystem::copy_option::overwrite_if_exists);
boost::filesystem::copy_file(boost::filesystem::path(path.string()), boost::filesystem::path(newPath.string()), boost::filesystem::copy_option::overwrite_if_exists);
#endif
else
fs::copy_file(fs::path(path.string()), fs::path(newPath.string()));
boost::filesystem::copy_file(boost::filesystem::path(path.string()), boost::filesystem::path(newPath.string()));
}
catch(fs::filesystem_error& err)
catch(boost::filesystem::filesystem_error& err)
{
debug_printf("CopyFile: failed to copy %s to %s.\n%s\n", path.string8().c_str(), path.string8().c_str(), err.what());
return ERR::EXCEPTION;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -25,10 +25,8 @@
*/
#include "precompiled.h"
#include "lib/file/vfs/vfs_lookup.h"
#include "lib/external_libraries/suppress_boost_warnings.h"
#include "lib/sysdep/filesystem.h"
#include "lib/file/file.h"
#include "lib/file/vfs/vfs.h" // error codes

View file

@ -1,58 +0,0 @@
/* Copyright (C) 2022 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef INCLUDED_PCH_BOOST
#define INCLUDED_PCH_BOOST
#include "lib/external_libraries/suppress_boost_warnings.h"
#if MSC_VERSION
# define BOOST_HAS_STDINT_H
#endif
// don't compile get_system_category() etc, since we don't use them and they
// sometimes cause problems when linking.
// But Filesystem <= 1.43 requires boost::system::posix, so only disable if newer
#include <boost/version.hpp>
#if BOOST_VERSION >= 104400
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
// the following boost libraries have been included in TR1 and are
// thus deemed usable:
#if BOOST_VERSION >= 104400
// Filesystem v3 is included since Boost 1.44
// v2 is deprecated since 1.46 and removed entirely in 1.50
# define BOOST_FILESYSTEM_VERSION 3
#else
# define BOOST_FILESYSTEM_VERSION 2
#endif
namespace boost{
namespace filesystem {
class path;
typedef path wpath;
};
}
namespace fs = boost::filesystem;
#endif // #ifndef INCLUDED_PCH_BOOST

View file

@ -69,8 +69,6 @@
#include "lib/lib.h"
#include "lib/secure_crt.h"
#include "lib/pch/pch_boost.h"
#include <array>
#include <memory>

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -97,7 +97,7 @@ Status ReloadChangedFiles()
return INFO::OK;
}
std::wstring GetWstringFromWpath(const fs::wpath& path)
std::wstring GetWstringFromWpath(const boost::filesystem::path& path)
{
#if BOOST_FILESYSTEM_VERSION == 3
return path.wstring();

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -24,6 +24,8 @@
#include "ps/CStrForward.h"
#include "ps/Errors.h"
#include <boost/filesystem.hpp>
extern PIVFS g_VFS;
extern bool VfsFileExists(const VfsPath& pathname);
@ -57,7 +59,7 @@ extern Status ReloadChangedFiles();
/**
* Helper function to handle API differences between Boost Filesystem v2 and v3
*/
std::wstring GetWstringFromWpath(const fs::wpath& path);
std::wstring GetWstringFromWpath(const boost::filesystem::path& path);
ERROR_GROUP(CVFSFile);
ERROR_TYPE(CVFSFile, LoadFailed);

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2023 Wildfire Games.
/* Copyright (C) 2025 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -60,8 +60,8 @@ public:
ScriptRequest rq(self->m_ScriptInterface);
// Extract the 3rd component of the path (i.e. the directory after simulation/ai/)
fs::wpath components = pathname.string();
fs::wpath::iterator it = components.begin();
boost::filesystem::path components = pathname.string();
boost::filesystem::path::iterator it = components.begin();
std::advance(it, 2);
std::wstring dirname = GetWstringFromWpath(*it);