Compare commits

...

4 commits

Author SHA1 Message Date
Ralph Sennhauser
6b4ecbdc40
Create dedicated stylesheet for Atlas
Some checks are pending
checkrefs / lfscheck (push) Waiting to run
checkrefs / checkrefs (push) Waiting to run
lint / cppcheck (push) Waiting to run
lint / copyright (push) Waiting to run
lint / jenkinsfiles (push) Waiting to run
pre-commit / build (push) Waiting to run
This is meant as a central place to tweak layout per platform.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-06-15 21:27:42 +02:00
Ralph Sennhauser
149baf116b
Replace all use of POSIX truncate
Use `<filesystem>` instead of `truncate` and remove `truncate`
portability wrapper.

Add a helper function `StatusFromSystemError` to convert error_code to
`Status`.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-06-15 15:33:59 +02:00
Ralph Sennhauser
57f5b73458
Remove unused wrapper for POSIX rmdir
std::filesystem::remove can be used instead.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-06-15 15:33:59 +02:00
Ralph Sennhauser
518ed74496
Replace all use of POSIX unlink
Use `<filesystem>` instead of `unlink` and remove `unlink` portability
wrapper.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2026-06-15 15:33:59 +02:00
15 changed files with 121 additions and 104 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -38,7 +38,7 @@
#include "lib/posix/posix_aio.h" // LIO_READ, LIO_WRITE
#include "lib/posix/posix_types.h"
#include "lib/status.h"
#include "lib/sysdep/filesystem.h" // wtruncate
#include "lib/sysdep/filesystem.h"
#include "lib/sysdep/os.h"
#include "lib/sysdep/rtl.h"
#include "lib/types.h"
@ -47,7 +47,9 @@
#include <cstddef>
#include <cstdint>
#include <fcntl.h>
#include <filesystem>
#include <memory>
#include <system_error>
namespace ERR
{
@ -332,9 +334,12 @@ static inline Status Store(const OsPath& pathname, const void* data, size_t size
RETURN_STATUS_IF_ERR(io::Run(op, p, completedHook, issueHook));
file.Close(); // (required by wtruncate)
file.Close(); // (required by resize_file)
RETURN_STATUS_IF_ERR(wtruncate(pathname, size));
std::error_code ec{};
std::filesystem::resize_file(pathname.string(), size, ec);
if (ec)
return StatusFromSystemError(ec);
return INFO::OK;
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -100,6 +100,16 @@ int ErrnoFromStatus(Status status)
return EPERM;
}
Status StatusFromSystemError(std::error_code& ec)
{
if (!ec)
return INFO::OK;
std::error_condition cond = ec.default_error_condition();
if (cond.category() != std::generic_category())
return ERR::FAIL;
const StatusDefinition* def = DefinitionFromErrno(cond.value());
return def ? def->status : ERR::FAIL;
}
Status StatusFromErrno()
{

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -165,6 +165,7 @@ To summarize: +/-1SHHCC (S=subsystem, HH=header, CC=code number)
#include "lib/types.h"
#include <cstddef>
#include <system_error>
// an integral type allows defining error codes in separate headers,
// but is not as type-safe as an enum. use Lint's 'strong type' checking
@ -246,6 +247,11 @@ extern int ErrnoFromStatus(Status status);
**/
extern Status StatusFromErrno();
/**
* @return Status equivalent of error_code, or ERR::FAIL if there's no equivalent.
*/
extern Status StatusFromSystemError(std::error_code& ec);
// note: other conversion routines (e.g. to/from Win32) are implemented in
// the corresponding modules to keep this header portable.

View file

@ -56,22 +56,6 @@ extern int wopen(const OsPath& pathname, int oflag, mode_t mode);
extern int wclose(int fd);
//
// unistd.h
//
// waio requires offsets and sizes to be multiples of the sector size.
// to allow arbitrarily sized files, we truncate them after I/O.
// however, ftruncate cannot be used since it is also subject to the
// sector-alignment requirement. instead, the file must be closed and
// this function called.
int wtruncate(const OsPath& pathname, off_t length);
int wunlink(const OsPath& pathname);
int wrmdir(const OsPath& path);
//
// stdlib.h
//

View file

@ -93,22 +93,6 @@ int wclose(int fd)
return close(fd);
}
int wtruncate(const OsPath& pathname, off_t length)
{
return truncate(OsString(pathname).c_str(), length);
}
int wunlink(const OsPath& pathname)
{
return unlink(OsString(pathname).c_str());
}
int wrmdir(const OsPath& path)
{
return rmdir(OsString(path).c_str());
}
int wrename(const OsPath& pathnameOld, const OsPath& pathnameNew)
{
return rename(OsString(pathnameOld).c_str(), OsString(pathnameNew).c_str());

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -130,7 +130,7 @@ extern Status waio_close(int fd);
// @param size is rounded up to a multiple of maxSectorSize (required by
// SetEndOfFile; this could be avoided by using the undocumented
// NtSetInformationFile or SetFileInformationByHandle on Vista and later).
// use wtruncate after I/O is complete to chop off the excess padding.
// use truncate after I/O is complete to chop off the excess padding.
//
// NB: writes that extend a file (i.e. ALL WRITES when creating new files)
// are synchronous, which prevents overlapping I/O and other work.

View file

@ -131,33 +131,6 @@ int wclose(int fd)
}
int wtruncate(const OsPath& pathname, off_t length)
{
// (re-open the file to avoid the FILE_FLAG_NO_BUFFERING
// sector-alignment restriction)
HANDLE hFile = CreateFileW(OsString(pathname).c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
ENSURE(hFile != INVALID_HANDLE_VALUE);
LARGE_INTEGER ofs; ofs.QuadPart = length;
WARN_IF_FALSE(SetFilePointerEx(hFile, ofs, 0, FILE_BEGIN));
WARN_IF_FALSE(SetEndOfFile(hFile));
WARN_IF_FALSE(CloseHandle(hFile));
return 0;
}
int wunlink(const OsPath& pathname)
{
return _wunlink(OsString(pathname).c_str());
}
int wrmdir(const OsPath& path)
{
return _wrmdir(OsString(path).c_str());
}
OsPath wrealpath(const OsPath& pathname)
{
wchar_t resolved[PATH_MAX];

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -49,6 +49,7 @@
#include <boost/algorithm/string/split.hpp>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <fmt/printf.h>
#include <initializer_list>
#include <js/Array.h>
@ -56,6 +57,7 @@
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <js/Value.h>
#include <system_error>
class ScriptInterface;
@ -545,7 +547,9 @@ bool ModIo::ParseMods(const ScriptInterface& scriptInterface, std::string& err)
void ModIo::DeleteDownloadedFile()
{
if (wunlink(m_DownloadFilePath) != 0)
std::error_code ec{};
std::filesystem::remove(m_DownloadFilePath.string(), ec);
if (ec)
LOGERROR("Failed to delete temporary file.");
m_DownloadFilePath = OsPath();
}

View file

@ -51,10 +51,12 @@
#include <cstdint>
#include <ctime>
#include <filesystem>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <memory>
#include <sstream>
#include <system_error>
#include <utility>
class ScriptInterface;
@ -343,7 +345,9 @@ bool SavedGames::DeleteSavedGame(const std::wstring& name)
return false; // Error
// Delete actual file
if (wunlink(realpath) != 0)
std::error_code ec{};
std::filesystem::remove(realpath.string(), ec);
if (ec)
return false; // Error
// Successfully deleted file

View file

@ -42,6 +42,7 @@
#include <SDL_events.h>
#include <SDL_quit.h>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <js/Array.h>
@ -50,6 +51,7 @@
#include <js/Value.h>
#include <map>
#include <string>
#include <system_error>
#include <tuple>
#include <utility>
#include <vector>
@ -110,7 +112,8 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
}
LOGWARNING("The replay cache file is corrupted, it will be deleted");
wunlink(GetCacheFilePath());
std::error_code ec{};
std::filesystem::remove(GetCacheFilePath().string(), ec);
return false;
}
@ -123,7 +126,8 @@ void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::Ha
cacheStream << Script::StringifyJSON(rq, &replaysRooted);
cacheStream.close();
wunlink(GetCacheFilePath());
std::error_code ec{};
std::filesystem::remove(GetCacheFilePath().string(), ec);
if (RenameFile(GetTempCacheFilePath(), GetCacheFilePath()))
LOGERROR("Could not store the replay cache");
}

View file

@ -43,6 +43,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <fmt/format.h>
#include <js/Array.h>
#include <js/PropertyAndElement.h>
@ -53,6 +54,7 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
class ScriptInterface;
@ -288,11 +290,15 @@ bool DeleteCampaignSave(const CStrW& filePath)
OsPath realPath;
if (filePath.Left(16) != L"saves/campaigns/" || filePath.Right(12) != L".0adcampaign")
return false;
return VfsFileExists(filePath) &&
g_VFS->GetRealPath(filePath, realPath) == INFO::OK &&
g_VFS->RemoveFile(filePath) == INFO::OK &&
wunlink(realPath) == 0;
if (!VfsFileExists(filePath))
return false;
if (g_VFS->GetRealPath(filePath, realPath) != INFO::OK)
return false;
if (g_VFS->RemoveFile(filePath) != INFO::OK)
return false;
std::error_code ec;
std::filesystem::remove(realPath.string(), ec);
return !ec;
}
void RegisterScriptFunctions_ReadWriteAnywhere(const ScriptRequest& rq,

View file

@ -60,6 +60,7 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <functional>
#include <iomanip>
@ -70,6 +71,7 @@
#include <optional>
#include <set>
#include <sstream>
#include <system_error>
class CSimulation2Impl
{
@ -321,19 +323,26 @@ void CSimulation2Impl::ReportSerializationFailure(
const OsPath path = createDateIndexSubdirectory(psLogDir() / "serializationtest");
debug_printf("Writing serializationtest-data to %s\n", path.string8().c_str());
// Clean up obsolete files from previous runs
wunlink(path / "hash.before.a");
wunlink(path / "hash.before.b");
wunlink(path / "debug.before.a");
wunlink(path / "debug.before.b");
wunlink(path / "state.before.a");
wunlink(path / "state.before.b");
wunlink(path / "hash.after.a");
wunlink(path / "hash.after.b");
wunlink(path / "debug.after.a");
wunlink(path / "debug.after.b");
wunlink(path / "state.after.a");
wunlink(path / "state.after.b");
// Try to clean up obsolete files from previous runs.
constexpr auto namesToRemove{std::to_array<std::string_view>({
"hash.before.a",
"hash.before.b",
"debug.before.a",
"debug.before.b",
"state.before.a",
"state.before.b",
"hash.after.a",
"hash.after.b",
"debug.after.a",
"debug.after.b",
"state.after.a",
"state.after.b",
})};
const std::filesystem::path fspath{path.string()};
std::error_code ec{};
for (const std::string_view nameToRemove : namesToRemove)
std::filesystem::remove(fspath / nameToRemove, ec);
if (primaryStateBefore)
DumpSerializationTestState(*primaryStateBefore, path, L"before.a");

View file

@ -28,6 +28,7 @@
#include "tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.h"
#include "tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.h"
#include "tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.h"
#include "tools/atlas/AtlasUI/ScenarioEditor/StyleSheet.h"
#include <cstddef>
#include <utility>
@ -309,10 +310,10 @@ void SectionLayout::Build(ScenarioEditor& scenarioEditor)
#undef ADD_SIDEBAR
m_VertSplitter->SetDefaultSashPosition(-BOTTOMBAR_SIZE);
m_VertSplitter->SetDefaultSashPosition(-Atlas::Style::BOTTOMBAR_DEFAULT_SIZE);
m_VertSplitter->Initialize(m_Canvas);
m_HorizSplitter->SetDefaultSashPosition(SIDEBAR_SIZE);
m_HorizSplitter->SetDefaultSashPosition(Atlas::Style::SIDEBAR_DEFAULT_SIZE);
m_HorizSplitter->SplitVertically(m_SidebarBook, m_VertSplitter);
}

View file

@ -27,18 +27,6 @@ class SnapSplitterWindow;
class wxString;
class wxWindow;
// Some platform dependent sizes
#if defined(__WXGTK__)
#define SIDEBAR_SIZE 285
#define BOTTOMBAR_SIZE 200
#elif defined(__WXOSX__) || defined(__WXMAC__)
#define SIDEBAR_SIZE 285
#define BOTTOMBAR_SIZE 210
#else // __MSW__
#define SIDEBAR_SIZE 235
#define BOTTOMBAR_SIZE 180
#endif
class SectionLayout
{
public:

View file

@ -0,0 +1,39 @@
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. 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, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_ATLAS_STYLESHEET
#define INCLUDED_ATLAS_STYLESHEET
namespace Atlas::Style
{
// Platform specific values
#if defined(__WXGTK__)
constexpr int BOTTOMBAR_DEFAULT_SIZE = 200;
constexpr int SIDEBAR_DEFAULT_SIZE = 285;
#elif defined(__WXOSX__) || defined(__WXMAC__)
constexpr int BOTTOMBAR_DEFAULT_SIZE = 210;
constexpr int SIDEBAR_DEFAULT_SIZE = 285;
#else // __MSW__
constexpr int BOTTOMBAR_DEFAULT_SIZE = 180;
constexpr int SIDEBAR_DEFAULT_SIZE = 235;
#endif
} // namespace Atlas::Style
#endif // INCLUDED_ATLAS_STYLESHEET