From 35fe214588589151c861777489efc817dd4e5097 Mon Sep 17 00:00:00 2001 From: Project579 Date: Sat, 11 Jun 2022 23:38:09 +0200 Subject: [PATCH] Updated components/misc/timeconvert.hpp to fix the Android build. --- apps/mwiniimporter/importer.cpp | 3 ++- apps/mwiniimporter/main.cpp | 4 ++-- apps/opencs/view/doc/filedialog.hpp | 4 ++-- apps/opencs/view/doc/newgame.hpp | 4 ++-- apps/opencs/view/tools/merge.hpp | 2 -- apps/openmw/mwgui/savegamedialog.cpp | 3 ++- apps/openmw/mwstate/character.cpp | 7 +++---- apps/openmw/mwstate/character.hpp | 2 +- components/config/gamesettings.cpp | 2 +- components/files/configurationmanager.cpp | 2 +- components/files/windowspath.cpp | 6 +++--- components/misc/timeconvert.hpp | 15 ++++++++------- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/apps/mwiniimporter/importer.cpp b/apps/mwiniimporter/importer.cpp index c4377fc0ac..305587162b 100644 --- a/apps/mwiniimporter/importer.cpp +++ b/apps/mwiniimporter/importer.cpp @@ -7,6 +7,7 @@ #include #include #include +#include @@ -990,7 +991,7 @@ std::time_t MwIniImporter::lastWriteTime(const std::filesystem::path& filename, if (std::filesystem::exists(filename)) { std::filesystem::path resolved = std::filesystem::canonical(filename); - writeTime = std::chrono::system_clock::to_time_t (Misc::clockCast (std::filesystem::last_write_time (resolved)));; + writeTime = Misc::to_time_t(std::filesystem::last_write_time (resolved)); // print timestamp const int size=1024; diff --git a/apps/mwiniimporter/main.cpp b/apps/mwiniimporter/main.cpp index 1d4b6b588e..d6afecb1ef 100644 --- a/apps/mwiniimporter/main.cpp +++ b/apps/mwiniimporter/main.cpp @@ -47,13 +47,13 @@ private: OpenMW application stack assumes UTF-8 encoding, therefore this conversion. - For std::filesystem::path::imbue see components/files/windowspath.cpp + For boost::filesystem::path::imbue see components/files/windowspath.cpp */ int wmain(int argc, wchar_t *wargv[]) { utf8argv converter(argc, wargv); char **argv = converter.get(); // TODO(Project579): Temporarly disabled until a good solution is found (no solution might actually be needed) - //std::filesystem::path::imbue(boost::locale::generator().generate("")); + //boost::filesystem::path::imbue(boost::locale::generator().generate("")); #endif try diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 4e4113a178..154efc14ea 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -8,8 +8,8 @@ #include "adjusterwidget.hpp" -#ifndef CS_QT_BOOST_FILESYSTEM_PATH_DECLARED -#define CS_QT_BOOST_FILESYSTEM_PATH_DECLARED +#ifndef CS_QT_STD_FILESYSTEM_PATH_DECLARED +#define CS_QT_STD_FILESYSTEM_PATH_DECLARED Q_DECLARE_METATYPE (std::filesystem::path) #endif diff --git a/apps/opencs/view/doc/newgame.hpp b/apps/opencs/view/doc/newgame.hpp index 12b2f3eefe..f5eace0671 100644 --- a/apps/opencs/view/doc/newgame.hpp +++ b/apps/opencs/view/doc/newgame.hpp @@ -6,8 +6,8 @@ #include -#ifndef CS_QT_BOOST_FILESYSTEM_PATH_DECLARED -#define CS_QT_BOOST_FILESYSTEM_PATH_DECLARED +#ifndef CS_QT_STD_FILESYSTEM_PATH_DECLARED +#define CS_QT_STD_FILESYSTEM_PATH_DECLARED Q_DECLARE_METATYPE (std::filesystem::path) #endif diff --git a/apps/opencs/view/tools/merge.hpp b/apps/opencs/view/tools/merge.hpp index 39dea6fbb0..51633c5bb4 100644 --- a/apps/opencs/view/tools/merge.hpp +++ b/apps/opencs/view/tools/merge.hpp @@ -3,9 +3,7 @@ #include -#ifndef Q_MOC_RUN #include -#endif class QPushButton; class QListWidget; diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index e39cf16198..413e677917 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -20,6 +20,7 @@ #include #include +#include #include @@ -403,7 +404,7 @@ namespace MWGui throw std::runtime_error("Can't find selected slot"); std::stringstream text; - time_t time = mCurrentSlot->mTimeStamp; + time_t time = Misc::to_time_t(mCurrentSlot->mTimeStamp); struct tm* timeinfo; timeinfo = localtime(&time); diff --git a/apps/openmw/mwstate/character.cpp b/apps/openmw/mwstate/character.cpp index c43229f588..0d90ab121a 100644 --- a/apps/openmw/mwstate/character.cpp +++ b/apps/openmw/mwstate/character.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include @@ -31,7 +30,7 @@ void MWState::Character::addSlot (const std::filesystem::path& path, const std:: { Slot slot; slot.mPath = path; - slot.mTimeStamp = std::chrono::system_clock::to_time_t (Misc::clockCast (std::filesystem::last_write_time (path))); + slot.mTimeStamp = std::filesystem::last_write_time (path); ESM::ESMReader reader; reader.open (slot.mPath.string()); @@ -78,7 +77,7 @@ void MWState::Character::addSlot (const ESM::SavedGame& profile) } slot.mProfile = profile; - slot.mTimeStamp = std::time (nullptr); + slot.mTimeStamp = std::filesystem::file_time_type (); mSlots.push_back (slot); } @@ -156,7 +155,7 @@ const MWState::Slot *MWState::Character::updateSlot (const Slot *slot, const ESM Slot newSlot = *slot; newSlot.mProfile = profile; - newSlot.mTimeStamp = std::time (nullptr); + newSlot.mTimeStamp = std::filesystem::file_time_type (); mSlots.erase (mSlots.begin()+index); diff --git a/apps/openmw/mwstate/character.hpp b/apps/openmw/mwstate/character.hpp index 31dbde5830..9883eb253c 100644 --- a/apps/openmw/mwstate/character.hpp +++ b/apps/openmw/mwstate/character.hpp @@ -11,7 +11,7 @@ namespace MWState { std::filesystem::path mPath; ESM::SavedGame mProfile; - std::time_t mTimeStamp; + std::filesystem::file_time_type mTimeStamp; }; bool operator< (const Slot& left, const Slot& right); diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index d15cb4bb97..aa63c3191e 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -173,7 +173,7 @@ bool Config::GameSettings::writeFile(QTextStream &stream) while (i.hasPrevious()) { i.previous(); - // path lines (e.g. 'data=...') need quotes and ampersands escaping to match how std::filesystem::path uses boost::io::quoted + // path lines (e.g. 'data=...') need quotes and ampersands escaping to match how boost::filesystem::path uses boost::io::quoted if (i.key() == QLatin1String("data") || i.key() == QLatin1String("data-local") || i.key() == QLatin1String("resources") diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 37eca2c460..900c341edc 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -427,7 +427,7 @@ void parseConfig(std::istream& stream, bpo::variables_map& variables, const bpo: std::istream& operator>> (std::istream& istream, MaybeQuotedPath& MaybeQuotedPath) { - // If the stream starts with a double quote, read from stream using std::filesystem::path rules, then discard anything remaining. + // If the stream starts with a double quote, read from stream using boost::filesystem::path rules, then discard anything remaining. // This prevents boost::program_options getting upset that we've not consumed the whole stream. // If it doesn't start with a double quote, read the whole thing verbatim if (istream.peek() == '"') diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 1222c2e5cb..da26e773f6 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -38,10 +38,10 @@ WindowsPath::WindowsPath(const std::string& application_name) with UTF-8 encoding (generated for empty name from boost::locale) to handle Unicode in platform-agnostic way using std::string. - See std::filesystem and boost::locale reference for details. + See boost::filesystem and boost::locale reference for details. */ // TODO(Project579): Temporarly disabled until a good solution is found (no solution might actually be needed) - //std::filesystem::path::imbue(boost::locale::generator().generate("")); + //boost::filesystem::path::imbue(boost::locale::generator().generate("")); std::filesystem::path localPath = getLocalPath(); if (!SetCurrentDirectoryA(localPath.string().c_str())) @@ -111,7 +111,7 @@ std::filesystem::path WindowsPath::getCachePath() const std::filesystem::path WindowsPath::getInstallPath() const { - std::filesystem::path installPath(""); + std::filesystem::path installPath(); HKEY hKey; diff --git a/components/misc/timeconvert.hpp b/components/misc/timeconvert.hpp index dd6f542a44..26073025a3 100644 --- a/components/misc/timeconvert.hpp +++ b/components/misc/timeconvert.hpp @@ -1,16 +1,17 @@ #ifndef OPENMW_COMPONENTS_MISC_TIMECONVERT_H #define OPENMW_COMPONENTS_MISC_TIMECONVERT_H +#include +#include + namespace Misc { -// Very ugly hack to go from std::chrono::file_clock to any other clock, can be replaced with better solution in C++20 -// https://stackoverflow.com/questions/35282308/convert-between-c11-clocks -template -inline DstTimePointT clockCast (const SrcTimePointT tp) +template +inline std::time_t to_time_t(TP tp) { - const auto src_now = SrcClockT::now(); - const auto dst_now = DstClockT::now(); - return dst_now + (tp - src_now); + using namespace std::chrono; + auto sctp = time_point_cast(tp - TP::clock::now() + system_clock::now()); + return system_clock::to_time_t(sctp); } } // namespace Misc