mirror of https://github.com/OpenRCT2/OpenRCT2.git
Extract GetLastModified to Platform
This commit is contained in:
parent
4fe5b1dc79
commit
f372117939
|
@ -121,30 +121,7 @@ namespace File
|
||||||
|
|
||||||
uint64_t GetLastModified(const std::string& path)
|
uint64_t GetLastModified(const std::string& path)
|
||||||
{
|
{
|
||||||
uint64_t lastModified = 0;
|
return Platform::GetLastModified(path);
|
||||||
#ifdef _WIN32
|
|
||||||
auto pathW = String::ToWideChar(path);
|
|
||||||
auto hFile = CreateFileW(pathW.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
|
|
||||||
if (hFile != INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
FILETIME ftCreate, ftAccess, ftWrite;
|
|
||||||
if (GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
|
|
||||||
{
|
|
||||||
lastModified = (static_cast<uint64_t>(ftWrite.dwHighDateTime) << 32ULL)
|
|
||||||
| static_cast<uint64_t>(ftWrite.dwLowDateTime);
|
|
||||||
}
|
|
||||||
CloseHandle(hFile);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
struct stat statInfo
|
|
||||||
{
|
|
||||||
};
|
|
||||||
if (stat(path.c_str(), &statInfo) == 0)
|
|
||||||
{
|
|
||||||
lastModified = statInfo.st_mtime;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return lastModified;
|
|
||||||
}
|
}
|
||||||
} // namespace File
|
} // namespace File
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
# include <cstring>
|
# include <cstring>
|
||||||
# include <ctime>
|
# include <ctime>
|
||||||
# include <pwd.h>
|
# include <pwd.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
|
||||||
namespace Platform
|
namespace Platform
|
||||||
{
|
{
|
||||||
|
@ -159,6 +160,19 @@ namespace Platform
|
||||||
return -1;
|
return -1;
|
||||||
# endif // __EMSCRIPTEN__
|
# endif // __EMSCRIPTEN__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetLastModified(const std::string& path)
|
||||||
|
{
|
||||||
|
uint64_t lastModified = 0;
|
||||||
|
struct stat statInfo
|
||||||
|
{
|
||||||
|
};
|
||||||
|
if (stat(path.c_str(), &statInfo) == 0)
|
||||||
|
{
|
||||||
|
lastModified = statInfo.st_mtime;
|
||||||
|
}
|
||||||
|
return lastModified;
|
||||||
|
}
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -535,6 +535,24 @@ namespace Platform
|
||||||
log_warning("Execute() not implemented for Windows!");
|
log_warning("Execute() not implemented for Windows!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetLastModified(const std::string& path)
|
||||||
|
{
|
||||||
|
uint64_t lastModified = 0;
|
||||||
|
auto pathW = String::ToWideChar(path);
|
||||||
|
auto hFile = CreateFileW(pathW.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||||
|
if (hFile != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
FILETIME ftCreate, ftAccess, ftWrite;
|
||||||
|
if (GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
|
||||||
|
{
|
||||||
|
lastModified = (static_cast<uint64_t>(ftWrite.dwHighDateTime) << 32ULL)
|
||||||
|
| static_cast<uint64_t>(ftWrite.dwLowDateTime);
|
||||||
|
}
|
||||||
|
CloseHandle(hFile);
|
||||||
|
}
|
||||||
|
return lastModified;
|
||||||
|
}
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace Platform
|
||||||
std::string GetCurrentExecutablePath();
|
std::string GetCurrentExecutablePath();
|
||||||
std::string GetCurrentExecutableDirectory();
|
std::string GetCurrentExecutableDirectory();
|
||||||
bool FileExists(const std::string path);
|
bool FileExists(const std::string path);
|
||||||
|
uint64_t GetLastModified(const std::string& path);
|
||||||
rct2_time GetTimeLocal();
|
rct2_time GetTimeLocal();
|
||||||
rct2_date GetDateLocal();
|
rct2_date GetDateLocal();
|
||||||
bool FindApp(const std::string& app, std::string* output);
|
bool FindApp(const std::string& app, std::string* output);
|
||||||
|
|
Loading…
Reference in New Issue