• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ParadoxGameConverters / commonItems / 12846535547

18 Jan 2025 06:41PM UTC coverage: 75.846% (-1.7%) from 77.556%
12846535547

Pull #274

github

web-flow
Merge 8b9494010 into b007cb890
Pull Request #274: Eliminate warnings

279 of 358 new or added lines in 13 files covered. (77.93%)

38 existing lines in 2 files now uncovered.

1837 of 2422 relevant lines covered (75.85%)

240.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.61
/ModLoader/ModParser.cpp
1
#include "ModParser.h"
2

3
#include <external/json/single_include/nlohmann/json.hpp>
4
#include <external/json/single_include/nlohmann/json_fwd.hpp>
5
#include <fstream>
6

7
#include "../CommonFunctions.h"
8
#include "../CommonRegexes.h"
9
#include "../ParserHelpers.h"
10
#include "../StringUtils.h"
11

12

13

14
using std::filesystem::path;
15
using std::filesystem::u8path;
16

17

18

19
void commonItems::ModParser::parseMod(std::istream& theStream)
11✔
20
{
21
        registerKeys();
11✔
22
        parseStream(theStream);
11✔
23
        clearRegisteredKeywords();
11✔
24

25
        if (!path_.empty())
11✔
26
        {
27
                const auto ending = path_.extension();
8✔
28
                compressed_ = ending == ".zip" || ending == ".bin";
8✔
29
        }
8✔
30
}
11✔
31

32
void commonItems::ModParser::parseMod(const path& fileName)
82✔
33
{
34
        registerKeys();
82✔
35
        parseFile(fileName);
82✔
36
        clearRegisteredKeywords();
82✔
37

38
        if (!path_.empty())
82✔
39
        {
40
                const auto ending = path_.extension();
60✔
41
                compressed_ = ending == ".zip" || ending == ".bin";
60✔
42
        }
60✔
43
}
82✔
44

45

46
void commonItems::ModParser::parseMod(const std::string& fileName)
11✔
47
{
48
#pragma warning(push)
49
#pragma warning(disable : 4996)
50
        parseMod(u8path(fileName));
11✔
51
#pragma warning(pop)
52
}
11✔
53

54

55
void commonItems::ModParser::registerKeys()
93✔
56
{
57
        registerSetter("name", name_);
93✔
58
        registerRegex("path|archive", [this]([[maybe_unused]] const std::string& unused, std::istream& theStream) {
93✔
59
                path_ = getString(theStream);
68✔
60
        });
68✔
61
        registerKeyword("dependencies", [this](std::istream& theStream) {
93✔
62
                const auto theDependencies = getStrings(theStream);
28✔
63
                dependencies_.insert(theDependencies.begin(), theDependencies.end());
28✔
64
        });
28✔
65
        registerKeyword("replace_path", [this](std::istream& theStream) {
93✔
66
                replacedPaths_.emplace(path(getString(theStream)).make_preferred());
504✔
67
        });
504✔
68
        registerRegex(catchallRegex, ignoreItem);
93✔
69
}
93✔
70

71

72
void commonItems::ModParser::parseMetadata(std::istream& theStream)
41✔
73
{
74
        nlohmann::json data = nlohmann::json::parse(theStream);
41✔
75
        name_ = commonItems::remQuotes(data.value("name", ""));
41✔
76

77
        if (const auto game_custom_data = data.find("game_custom_data"); game_custom_data != data.end())
41✔
78
        {
79
                if (const auto replace_paths = game_custom_data->find("replace_paths"); replace_paths != game_custom_data->end())
30✔
80
                {
81
                        for (const auto& replace_path: *replace_paths)
90✔
82
                        {
83
                                replacedPaths_.emplace(path(std::string(replace_path)).make_preferred());
60✔
84
                        }
85
                }
86
        }
87
}
41✔
88

89

90
void commonItems::ModParser::parseMetadata(const path& metadata_path)
40✔
91
{
92
        path fs_path(metadata_path);
40✔
93
        fs_path = fs_path.parent_path(); // remove metadata.json
40✔
94
        fs_path = fs_path.parent_path(); // remove /.metadata
40✔
95

96
        // path_ should be the final two path components
97
        path last;
40✔
98
        path second_to_last;
40✔
99
        for (const auto component: fs_path)
159✔
100
        {
101
                second_to_last = last;
119✔
102
                last = component;
119✔
103
        }
119✔
104
        path_ = second_to_last / last;
40✔
105
        path_.make_preferred();
40✔
106

107
        std::ifstream file_stream(metadata_path);
40✔
108
        if (file_stream.is_open())
40✔
109
        {
110
                parseMetadata(file_stream);
39✔
111
                file_stream.close();
39✔
112
        }
113
}
40✔
114

115

116
void commonItems::ModParser::parseMetadata(const std::string& fileName)
6✔
117
{
118
#pragma warning(push)
119
#pragma warning(disable : 4996)
120
        parseMetadata(u8path(fileName));
6✔
121
#pragma warning(pop)
122
}
6✔
123

124

125
const std::set<std::string> commonItems::ModParser::getReplacedPaths() const
8✔
126
{
127
        std::set<std::string> replaced_paths;
8✔
128
        for (const path& path: replacedPaths_)
16✔
129
        {
130
                replaced_paths.emplace(path.string());
8✔
131
        }
132

133
        return replaced_paths;
8✔
NEW
134
}
×
135

136

137
void commonItems::ModParser::setPath(const std::string& path)
1✔
138
{
139
#pragma warning(push)
140
#pragma warning(disable : 4996)
141
        path_ = u8path(path).make_preferred();
1✔
142
#pragma warning(pop)
143
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc