From f38cc4a95997fd2bd9c8bda2d64a4686a5910da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 5 Sep 2024 20:52:12 +0200 Subject: [PATCH] Add some prototype UI for overwriting saves --- Common/File/FileUtil.cpp | 19 +++++++++++++++++++ Common/File/FileUtil.h | 2 ++ Core/Util/GameManager.cpp | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Common/File/FileUtil.cpp b/Common/File/FileUtil.cpp index fe6a94dde0..79d5e46dad 100644 --- a/Common/File/FileUtil.cpp +++ b/Common/File/FileUtil.cpp @@ -37,6 +37,9 @@ #include #include +#include +#include + #include "Common/Log.h" #include "Common/LogReporting.h" #include "Common/File/AndroidContentURI.h" @@ -1240,4 +1243,20 @@ bool WriteDataToFile(bool text_file, const void* data, size_t size, const Path & return true; } +void ChangeMTime(const Path &path, time_t mtime) { + if (path.Type() == PathType::CONTENT_URI) { + // No clue what to do here. + return; + } + + _utimbuf buf{}; + buf.actime = mtime; + buf.modtime = mtime; +#ifdef _WIN32 + _utime(path.c_str(), &buf); +#else + utime(path.c_str(), &buf); +#endif +} + } // namespace File diff --git a/Common/File/FileUtil.h b/Common/File/FileUtil.h index 872ba6e4bc..9a3af34bb0 100644 --- a/Common/File/FileUtil.h +++ b/Common/File/FileUtil.h @@ -83,6 +83,8 @@ uint64_t ComputeRecursiveDirectorySize(const Path &path); // Returns true if successful, or path already exists. bool CreateDir(const Path &filename); +void ChangeMTime(const Path &path, time_t mtime); + // Creates the full path of fullPath returns true on success bool CreateFullPath(const Path &fullPath); diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index e77ba91442..1e00d7cf12 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -24,13 +24,15 @@ #include #include #include - +#include +#include #ifdef SHARED_LIBZIP #include #else #include "ext/libzip/zip.h" #endif #ifdef _WIN32 + #include "Common/CommonWindows.h" #endif #include "Common/Data/Encoding/Utf8.h" @@ -652,8 +654,14 @@ bool GameManager::ExtractFile(struct zip *z, int file_index, const Path &outFile *bytesCopied += readSize; installProgress_ = (float)*bytesCopied / (float)allBytes; } + zip_fclose(zf); fclose(f); + + // Copy the mtime, too. May not be possible on Android? + if (zstat.mtime) { + File::ChangeMTime(outFilename, zstat.mtime); + } delete[] buffer; return true; } else {