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

ParadoxGameConverters / Vic3ToHoI4 / 13090188366

26 Jan 2025 07:59AM UTC coverage: 95.116% (-0.03%) from 95.146%
13090188366

push

github

web-flow
Eliminate warnings (#701)

* Externals in angle brackets.

* Commons from lib

* Update to preview versions of externals.

* Update fronter

* Switch to std::filesystem::path

* Unused variables

* Type conversion stuff.

* constness

* Missing headers

* Prefix increment, not postfix

* Check optional

* Remove a stray extern

* explicit

* Return an error case.

* Default value

* Enforce warnings.

* Disable some unfixable warnings.

* Update commons

* Formatting

* Fix a test

* Use fixed common

* Fix tests.

* Formatting

* Update to merged versions

* Make codefactor happier.

965 of 1008 new or added lines in 120 files covered. (95.73%)

2 existing lines in 2 files now uncovered.

20428 of 21477 relevant lines covered (95.12%)

61689.32 hits per line

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

81.82
/src/out_hoi4/out_mod.cpp
1
#include "out_mod.h"
2

3
#include <external/commonItems/Log.h>
4
#include <external/commonItems/OSCompatibilityLayer.h>
5
#include <external/fmt/include/fmt/format.h>
6
#include <external/fmt/include/fmt/ostream.h>
7

8
#include <fstream>
9
#include <string>
10

11

12

13
using std::filesystem::copy_options;
14
using std::filesystem::create_directories;
15
using std::filesystem::path;
16

17

18

19
namespace out
20
{
21

22
namespace
23
{
24

25
void CreateSubfolder(const path& output_name, std::string_view subfolder)
45✔
26
{
27
   if (const path path = "output" / output_name / subfolder;
45✔
28
       !commonItems::DoesFolderExist(path) && !create_directories(path))
45✔
29
   {
NEW
30
      throw std::runtime_error(fmt::format("Could not create {}", path.string()));
×
31
   }
45✔
32
}
45✔
33

34

35
void CreateOutputFolder(const path& output_name)
5✔
36
{
37
   Log(LogLevel::Info) << "\tCopying blank mod";
5✔
38
   if (!commonItems::DoesFolderExist(path("output")))
5✔
39
   {
NEW
40
      if (!create_directories("output"))
×
41
      {
NEW
42
         throw std::runtime_error("Could not create output folder");
×
43
      }
44
   }
45
   try
46
   {
47
      copy(path("blank_mod"), "output" / output_name, copy_options::recursive);
5✔
48
   }
NEW
49
   catch (...)
×
50
   {
NEW
51
      throw std::runtime_error("Could not copy blank_mod");
×
UNCOV
52
   }
×
53

54
   CreateSubfolder(output_name, "common");
5✔
55
   CreateSubfolder(output_name, "common/countries");
5✔
56
   CreateSubfolder(output_name, "common/country_tags");
5✔
57
   CreateSubfolder(output_name, "history");
5✔
58
   CreateSubfolder(output_name, "history/countries");
5✔
59
   CreateSubfolder(output_name, "history/states");
5✔
60
   CreateSubfolder(output_name, "history/units");
5✔
61
   CreateSubfolder(output_name, "map");
5✔
62
   CreateSubfolder(output_name, "map/strategicregions");
5✔
63
}
5✔
64

65

66
void CreateModFiles(std::string_view output_name, const GameVersion& game_version)
5✔
67
{
68
   Log(LogLevel::Info) << "\tCreating .mod files";
5✔
69

70
   std::ofstream mod_file(path("output") / fmt::format("{}.mod", output_name));
5✔
71
   if (!mod_file.is_open())
5✔
72
   {
73
      throw std::runtime_error("Could not create .mod file");
×
74
   }
75
   fmt::print(mod_file,
5✔
76
       "name = \"Converted - {}\"\n"
77
       "path = \"mod/{}/\"\n"
78
       "user_dir = \"{}_user_dir\"\n"
79
       "replace_path=\"common/countries\"\n"
80
       "replace_path=\"common/national_focus\"\n"
81
       "replace_path=\"common/peace_conference/ai_peace\"\n"
82
       "replace_path=\"common/peace_conference/cost_modifiers\"\n"
83
       "replace_path=\"events\"\n"
84
       "replace_path=\"history/countries\"\n"
85
       "replace_path=\"history/states\"\n"
86
       "replace_path=\"history/units\"\n"
87
       "replace_path=\"map/supplyareas\"\n"
88
       "replace_path=\"map/strategicregions\"\n"
89
       "supported_version=\"{}\"",
90
       output_name,
91
       output_name,
92
       output_name,
93
       game_version.toWildCard());
10✔
94
   mod_file.close();
5✔
95

96
   std::ofstream descriptor_file("output" / path(output_name) / "descriptor.mod");
5✔
97
   if (!descriptor_file.is_open())
5✔
98
   {
99
      throw std::runtime_error("Could not create descriptor.mod");
×
100
   }
101
   fmt::print(descriptor_file,
5✔
102
       "name = \"Converted - {}\"\n"
103
       "replace_path=\"common/countries\"\n"
104
       "replace_path=\"common/national_focus\"\n"
105
       "replace_path=\"common/peace_conference/ai_peace\"\n"
106
       "replace_path=\"common/peace_conference/cost_modifiers\"\n"
107
       "replace_path=\"events\"\n"
108
       "replace_path=\"history/countries\"\n"
109
       "replace_path=\"history/states\"\n"
110
       "replace_path=\"history/units\"\n"
111
       "replace_path=\"map/supplyareas\"\n"
112
       "replace_path=\"map/strategicregions\"\n"
113
       "supported_version=\"{}\"",
114
       output_name,
115
       game_version.toWildCard());
10✔
116
   descriptor_file.close();
5✔
117
}
5✔
118

119
}  // namespace
120

121

122
void ClearOutputFolder(const path& output_name)
7✔
123
{
124
   const path output_folder = "output" / output_name;
7✔
125
   if (commonItems::DoesFolderExist(output_folder))
7✔
126
   {
127
      Log(LogLevel::Info) << "Removing pre-existing copy of " << output_name.string();
1✔
128
      if (remove_all(output_folder) == static_cast<std::uintmax_t>(-1))
1✔
129
      {
NEW
130
         throw std::runtime_error("Could not remove pre-existing output folder " + output_folder.string() +
×
NEW
131
                                  ". Please delete folder and try converting again.");
×
132
      }
133
   }
134
}
7✔
135

136

137
void OutputMod(std::string_view output_name, const GameVersion& game_version)
5✔
138
{
139
   Log(LogLevel::Progress) << "80%";
5✔
140
   Log(LogLevel::Info) << "Outputting mod";
5✔
141

142
   CreateOutputFolder(output_name);
5✔
143
   CreateModFiles(output_name, game_version);
5✔
144
   Log(LogLevel::Progress) << "85%";
5✔
145
}
5✔
146

147
}  // namespace out
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

© 2026 Coveralls, Inc