Atlas Game Manager
A game manager for f95 and dlsite written in c++
Loading...
Searching...
No Matches
Version.hpp
Go to the documentation of this file.
1//
2// Created by kj16609 on 1/15/23.
3//
4
5#pragma once
6#ifndef ATLAS_GAMEMETADATA_HPP
7#define ATLAS_GAMEMETADATA_HPP
8
9#include <QString>
10
11#include <filesystem>
12
13#include "core/Types.hpp"
15
16namespace atlas::records
17{
18 class Game;
19 struct GameData;
20
22 {
24 QString m_version {};
25 std::filesystem::path m_game_path {};
26 std::filesystem::path m_exec_path {};
27 std::uint64_t m_last_played { 0 };
28 std::uint64_t m_total_playtime { 0 };
29 std::uint64_t m_folder_size { 0 };
30 std::uint64_t m_date_added { 0 };
31
32 VersionData() = delete;
33 VersionData( const RecordID id, const QString& name );
34 VersionData( const VersionData& other ) = delete;
35 VersionData( VersionData&& other ) = delete;
36 };
37
39 class Version
40 {
42 QString m_version;
43
44 std::shared_ptr< VersionData > data_ptr;
45
46 public:
47
48 const VersionData* operator->() const
49 {
50 if ( data_ptr == nullptr ) throw AtlasException( "Version: Pointer was nullptr!" );
51 return data_ptr.get();
52 }
53
54 //Setters
56 void addPlaytime( const std::uint32_t playtime );
57
58 template < class Rep, class Period >
59 void addPlaytime( const std::chrono::duration< Rep, Period > time_diff )
60 {
61 addPlaytime( static_cast< std::uint32_t >( std::chrono::duration_cast< std::chrono::seconds >( time_diff )
62 .count() ) );
63 }
64
66 void setLastPlayed( const std::uint64_t last_played );
68 void playGame();
69
70 void setVersionName( const QString str );
71 void setRelativeExecPath( const std::filesystem::path& path );
72
73 //Getters
74 QString getVersionName() const;
76 bool isInPlace() const;
77 std::uint32_t getPlaytime() const;
78 std::uint64_t getLastPlayed() const;
79 std::filesystem::path getPath() const;
80 std::filesystem::path getRelativeExecPath() const;
81 std::filesystem::path getExecPath() const;
82 std::uint64_t getFolderSize() const;
83 RecordID getParentID() const;
84 std::uint64_t getImportTime() const;
85
86 Version() = delete;
87
88 bool operator==( const Version& other ) const
89 {
90 return m_version == other.m_version && m_parent_id == other.m_parent_id;
91 }
92
93 Version( const RecordID, const QString& name );
94 ~Version();
95
96 Version( const Version& other ) noexcept :
97 m_parent_id( other.m_parent_id ),
98 m_version( other.m_version ),
99 data_ptr( other.data_ptr )
100 {}
101
102 Version( Version&& other ) noexcept :
103 m_parent_id( other.m_parent_id ),
104 m_version( std::move( other.m_version ) ),
105 data_ptr( other.data_ptr )
106 {}
107
108 Game parent() const;
109
111 Version& operator=( const Version& other ) noexcept
112 {
113 std::construct_at( this, other );
114 return *this;
115 }
116 };
117
118 struct MetadataException : public std::runtime_error
119 {
120 MetadataException( const std::string& msg ) : std::runtime_error( msg ) {}
121 };
122
124 {
126 const QString m_metadata;
127
128 MetadataAlreadyExists( const RecordID id, const Version& metadata ) :
129 MetadataException( "Tried to insert duplicate metadata" ),
130 m_id( id ),
131 m_metadata( metadata.getVersionName() )
132 {}
133 };
134} // namespace atlas::records
135#endif //ATLAS_GAMEMETADATA_HPP
constexpr RecordID INVALID_RECORD_ID
Definition Types.hpp:15
std::uint32_t RecordID
Definition Types.hpp:11
Definition Game.hpp:34
Representation of a game version.
Definition Version.hpp:40
QString getVersionName() const
Definition Version.cpp:16
bool operator==(const Version &other) const
Definition Version.hpp:88
Version(Version &&other) noexcept
Definition Version.hpp:102
std::uint32_t getPlaytime() const
Definition Version.cpp:33
std::filesystem::path getPath() const
Definition Version.cpp:59
std::uint64_t getLastPlayed() const
Definition Version.cpp:46
RecordID getParentID() const
Definition Version.cpp:150
bool isInPlace() const
If true then the game is not located in config::paths::games::get()
Definition Version.cpp:21
void addPlaytime(const std::uint32_t playtime)
Adds playtime to this and it's parent record.
Definition Version.cpp:119
const VersionData * operator->() const
Definition Version.hpp:48
void setVersionName(const QString str)
Definition Version.cpp:155
QString m_version
Definition Version.hpp:42
Game parent() const
Definition Version.cpp:184
std::uint64_t getImportTime() const
Definition Version.cpp:172
void setRelativeExecPath(const std::filesystem::path &path)
Definition Version.cpp:164
std::filesystem::path getRelativeExecPath() const
Definition Version.cpp:74
std::filesystem::path getExecPath() const
Definition Version.cpp:85
void setLastPlayed(const std::uint64_t last_played)
Sets the last played timestamp for this and it's parent record.
Definition Version.cpp:129
Version(const Version &other) noexcept
Definition Version.hpp:96
RecordID m_parent_id
Definition Version.hpp:41
Version & operator=(const Version &other) noexcept
Required to make std::vector happy.
Definition Version.hpp:111
void playGame()
Executes the game for this record.
Definition Version.cpp:91
void addPlaytime(const std::chrono::duration< Rep, Period > time_diff)
Definition Version.hpp:59
~Version()
Definition Version.cpp:254
std::shared_ptr< VersionData > data_ptr
Definition Version.hpp:44
std::uint64_t getFolderSize() const
Definition Version.cpp:139
Definition banners.cpp:15
Definition exceptions.hpp:17
MetadataAlreadyExists(const RecordID id, const Version &metadata)
Definition Version.hpp:128
const QString m_metadata
Definition Version.hpp:126
const RecordID m_id
Definition Version.hpp:125
MetadataException(const std::string &msg)
Definition Version.hpp:120
Definition Version.hpp:22
RecordID m_parent_id
Definition Version.hpp:23
VersionData(const VersionData &other)=delete
std::uint64_t m_date_added
Definition Version.hpp:30
std::uint64_t m_folder_size
Definition Version.hpp:29
std::filesystem::path m_game_path
Definition Version.hpp:25
std::filesystem::path m_exec_path
Definition Version.hpp:26
QString m_version
Definition Version.hpp:24
VersionData(VersionData &&other)=delete
std::uint64_t m_total_playtime
Definition Version.hpp:28
std::uint64_t m_last_played
Definition Version.hpp:27