GameList: Add played time tracker

This commit is contained in:
Connor McLaughlin
2022-10-21 21:02:19 +10:00
parent 6def728888
commit ca571f8a78
10 changed files with 439 additions and 40 deletions

View File

@ -1914,4 +1914,28 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
return false;
}
FileSystem::POSIXLock::POSIXLock(int fd)
{
if (lockf(fd, F_LOCK, 0) == 0)
{
m_fd = fd;
}
else
{
Log_ErrorPrintf("lockf() failed: %d", fd);
m_fd = -1;
}
}
FileSystem::POSIXLock::POSIXLock(std::FILE* fp)
{
POSIXLock(fileno(fp));
}
FileSystem::POSIXLock::~POSIXLock()
{
if (m_fd >= 0)
lockf(m_fd, F_ULOCK, m_fd);
}
#endif

View File

@ -108,6 +108,20 @@ enum class FileShareMode
ManagedCFilePtr OpenManagedSharedCFile(const char* filename, const char* mode, FileShareMode share_mode);
std::FILE* OpenSharedCFile(const char* filename, const char* mode, FileShareMode share_mode);
/// Abstracts a POSIX file lock.
#ifndef _WIN32
class POSIXLock
{
public:
POSIXLock(int fd);
POSIXLock(std::FILE* fp);
~POSIXLock();
private:
int m_fd;
};
#endif
std::optional<std::vector<u8>> ReadBinaryFile(const char* filename);
std::optional<std::vector<u8>> ReadBinaryFile(std::FILE* fp);
std::optional<std::string> ReadFileToString(const char* filename);