|
4 | 4 |
|
5 | 5 | #include "plugin.h" |
6 | 6 |
|
| 7 | +#include <fstream> |
| 8 | +#include <filesystem> |
| 9 | +#include <ctime> |
| 10 | + |
7 | 11 | CSchemaSystem *SchemaReader::SchemaSystem() |
8 | 12 | { |
9 | 13 | static CSchemaSystem *s_SchemaSystem = nullptr; |
@@ -54,6 +58,51 @@ std::string SchemaReader::SplitTemplatedName( CSchemaType *type ) const |
54 | 58 | return name; |
55 | 59 | } |
56 | 60 |
|
| 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 | + |
57 | 106 | void SchemaReader::RecordDumpFlags() |
58 | 107 | { |
59 | 108 | auto dump_flags = GetRoot()->FindOrCreateMember( "dump_flags" ); |
@@ -103,6 +152,9 @@ void SchemaReader::ReadSchema( uint32 flags ) |
103 | 152 | { |
104 | 153 | META_CONPRINTF( "Reading schema...\n" ); |
105 | 154 |
|
| 155 | + RecordGameInfo(); |
| 156 | + RecordDumperInfo(); |
| 157 | + |
106 | 158 | s_Flags = flags; |
107 | 159 | RecordDumpFlags(); |
108 | 160 |
|
|
0 commit comments