Skip to content

Commit 6b0a7fa

Browse files
committed
Add game and dumper info to the dump
1 parent 4f201a2 commit 6b0a7fa

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/schemareader.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#include "plugin.h"
66

7+
#include <fstream>
8+
#include <filesystem>
9+
#include <ctime>
10+
711
CSchemaSystem *SchemaReader::SchemaSystem()
812
{
913
static CSchemaSystem *s_SchemaSystem = nullptr;
@@ -54,6 +58,51 @@ std::string SchemaReader::SplitTemplatedName( CSchemaType *type ) const
5458
return name;
5559
}
5660

61+
void SchemaReader::RecordGameInfo()
62+
{
63+
std::ifstream inp( std::filesystem::path( g_SMAPI->GetBaseDir() ) / "steam.inf" );
64+
65+
if(inp.is_open())
66+
{
67+
auto game_info = GetRoot()->FindOrCreateMember( "game_info" );
68+
69+
std::string key, value;
70+
do
71+
{
72+
if(!std::getline( inp, key, '=' ))
73+
break;
74+
if(!std::getline( inp, value, '\n' ))
75+
break;
76+
77+
game_info->SetMemberString( key.c_str(), value.c_str() );
78+
} while(inp.good());
79+
}
80+
else
81+
{
82+
META_CONPRINTF( "Failed to open steam.inf, no game_info would be available in the dump file.\n" );
83+
}
84+
}
85+
86+
void SchemaReader::RecordDumperInfo()
87+
{
88+
auto dumper_info = GetRoot()->FindOrCreateMember( "dumper_info" );
89+
90+
dumper_info->SetMemberString( "version", g_ThisPlugin.GetVersion() );
91+
92+
{
93+
std::time_t time = std::time( nullptr );
94+
std::tm *gtm = std::gmtime( &time );
95+
96+
char buf[128];
97+
98+
// Formatted for ISO 8601 UTC time
99+
std::strftime( buf, sizeof( buf ), "%Y-%m-%dT%H:%M:%SZ", gtm );
100+
dumper_info->SetMemberString( "dump_date", buf );
101+
}
102+
103+
dumper_info->SetMemberInt( "dump_format_version", DUMPER_FILE_FORMAT_VERSION );
104+
}
105+
57106
void SchemaReader::RecordDumpFlags()
58107
{
59108
auto dump_flags = GetRoot()->FindOrCreateMember( "dump_flags" );
@@ -103,6 +152,9 @@ void SchemaReader::ReadSchema( uint32 flags )
103152
{
104153
META_CONPRINTF( "Reading schema...\n" );
105154

155+
RecordGameInfo();
156+
RecordDumperInfo();
157+
106158
s_Flags = flags;
107159
RecordDumpFlags();
108160

src/schemareader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <string>
1212
#include <cstring>
1313

14+
#define DUMPER_FILE_FORMAT_VERSION 1
15+
1416
template <typename T>
1517
constexpr const char *SchemaTypeToString() = delete;
1618

@@ -88,6 +90,8 @@ class SchemaReader
8890
KeyValues3 *GetDefs() { return GetRoot()->FindOrCreateMember( "defs" ); }
8991
KeyValues3 *GetAtomicDefs() { return GetRoot()->FindOrCreateMember( "atomics" ); }
9092

93+
void RecordGameInfo();
94+
void RecordDumperInfo();
9195
void RecordDumpFlags();
9296

9397
// Returns nullptr if entry already exists

0 commit comments

Comments
 (0)