Skip to content

Commit

Permalink
Eliminate warnings (#274)
Browse files Browse the repository at this point in the history
* Turn on more warnings.

* Exclude externals from warnings.

* Fix warnings in modParser

* Fix warnings in commons

* More mod parser fixes

* More fixes in OS layer

* Fixes for localization db

* Parser helper fixes

* Parser fixes

* Converter version updates

* ModLoader updates

* ConverterVersion updates

* GameVersion updates

* Update a few 'find path' functions

* Deprecate some more functions.

* Add missing file to cmake, fix compile errors.

* Add another function duplicate

* Sort some headers

* using statements

* Another override

* path -> u8path in overrides.

* Review comment.

* Include path fix.

* Formatting.

* Apply warnings stuff to MSVC project

* Make zip external

* Fix borken tests.

* Linux updates

* Disable warning on linux

* More formatting.

* Revert "Disable warning on linux"

This reverts commit 93dcb52.

* Disable a linux warning.

* Fix last commit

* Formatting

* Try again.

* Try again

* Turn off unknown pragmas

* Restore function.

* Undo bad formatting.

* Fix some tests on linux.

* Fix another test.

* UTF16ToUTF8() on linux

* Reference instead of copy

* Only set up coverage if this is a top-level project
  • Loading branch information
Idhrendur authored Jan 26, 2025
1 parent b007cb8 commit 8876106
Show file tree
Hide file tree
Showing 51 changed files with 1,619 additions and 478 deletions.
20 changes: 12 additions & 8 deletions BulkParser.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
#include "BulkParser.h"
#include "CommonFunctions.h"

void commonItems::bulkParser::ParseGameFile(const std::string& relative_path, const ModFilesystem& mod_fs)


using std::filesystem::path;



void commonItems::bulkParser::ParseGameFile(const path& relative_path, const ModFilesystem& mod_fs)
{
if (const auto file_path = mod_fs.GetActualFileLocation(relative_path); file_path)
parseFile(*file_path);
}

void commonItems::bulkParser::ParseGameFolder(const std::string& relative_path,
const ModFilesystem& mod_fs,
const std::set<std::string>& extensions,
bool recursive)

void commonItems::bulkParser::ParseGameFolder(const path& relative_path, const ModFilesystem& mod_fs, const std::set<path>& extensions, bool recursive)
{
std::set<std::string> all_files;
std::set<path> all_files;
if (recursive)
all_files = mod_fs.GetAllFilesInFolderRecursive(relative_path);
else
all_files = mod_fs.GetAllFilesInFolder(relative_path);

for (const auto& file: all_files)
if (extensions.contains(getExtension(file)))
if (extensions.contains(file.extension()))
parseFile(file);
}
}
7 changes: 5 additions & 2 deletions BulkParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ class bulkParser: public parser
// Parses a game file in either vanilla game or mods directory.
// For example:
// relativePath may be "map_data/areas.txt"
void ParseGameFile(const std::string& relative_path, const ModFilesystem& mod_fs);
void ParseGameFile(const std::filesystem::path& relative_path, const ModFilesystem& mod_fs);

// Parses a game folder in both vanilla game and mods directory.
// For example:
// relativePath may be "common/governments"
// extensions may be "txt", "text"
void ParseGameFolder(const std::string& relative_path, const ModFilesystem& mod_fs, const std::set<std::string>& extensions, bool recursive);
void ParseGameFolder(const std::filesystem::path& relative_path,
const ModFilesystem& mod_fs,
const std::set<std::filesystem::path>& extensions,
bool recursive);
};
} // namespace commonItems
#endif // BULK_PARSER_H
58 changes: 28 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ set(CMAKE_CXX_STANDARD 23)
set (UNICODE_DEFAULT OFF)

if (PLATFORM STREQUAL "Windows")
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
ADD_DEFINITIONS(-DUNICODE -D_UNICODE -DWINDOWS)
elseif (PLATFORM STREQUAL "Linux")
#set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*)
if (COVERAGE STREQUAL true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage -Wno-deprecated-declarations -Wno-unknown-pragmas")
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
else (COVERAGE STREQUAL true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -Wno-deprecated-declarations -Wno-unknown-pragmas")
endif (COVERAGE STREQUAL true)
endif (PLATFORM STREQUAL "Windows")

Expand All @@ -35,53 +35,44 @@ add_subdirectory("external/googletest" "googletest")
################################################################################
# Source groups
################################################################################
set(COMMON_SOURCES ${COMMON_SOURCES} "BulkParser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Color.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Color.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "CommonFunctions.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "CommonFunctions.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "CommonRegexes.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConvenientParser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConvenientParser.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConverterVersion.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ConverterVersion.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Date.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Date.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "GameVersion.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "GameVersion.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "iconvlite.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "iconvlite.h")
if (PLATFORM STREQUAL "Windows")
set(COMMON_SOURCES ${COMMON_SOURCES} "WinUtils.cpp")
elseif (PLATFORM STREQUAL "Linux")
set(COMMON_SOURCES ${COMMON_SOURCES} "LinuxUtils.cpp")
endif (PLATFORM STREQUAL "Windows")
set(COMMON_SOURCES ${COMMON_SOURCES} "Log.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Log.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "OSCommonLayer.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Parser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ParserHelpers.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "StringUtils.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationBlock.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationBlock.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationDatabase.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationDatabase.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationLambdas.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/Mod.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModFilesystem.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModFilesystem.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModLoader.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModLoader.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModParser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModParser.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "OSCommonLayer.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "OSCompatibilityLayer.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "Parser.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "Parser.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "ParserHelpers.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "ParserHelpers.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "StringUtils.cpp")
set(COMMON_SOURCES ${COMMON_SOURCES} "StringUtils.h")
set(COMMON_SOURCES ${COMMON_SOURCES} "external/zip/src/zip.c")
add_library(commonLib
${COMMON_SOURCES}
)

add_subdirectory(external/zip SYSTEM PRIVATE EXCLUDE_FROM_ALL)
get_target_property(lib_include_dirs zip INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(commonLib SYSTEM PRIVATE ${lib_include_dirs})
target_link_libraries(commonLib PRIVATE zip)

if (PLATFORM STREQUAL "Windows")
target_compile_options(commonLib PRIVATE /permissive /W4 /w14242 /w14254 /w14263 /w14265 /w14287 /we4289 /w14296 /w14311 /w14545 /w14546
/w14547 /w14549 /w14555 /w14619 /w14640 /w14826 /w14905 /w14906 /w14928 /external:anglebrackets /external:W0 /WX)
elseif (PLATFORM STREQUAL "Linux")
endif (PLATFORM STREQUAL "Windows")

set(tests
"tests/test_main.cpp"
"tests/ColorTests.cpp"
Expand All @@ -92,8 +83,6 @@ set(tests
"tests/DateTests.cpp"
"tests/GameVersionTests.cpp"
"tests/iconvliteTests.cpp"
"tests/Localization/LocalizationBlockTests.cpp"
"tests/Localization/LocalizationDatabaseTests.cpp"
"tests/LogTests.cpp"
"tests/ModFilesystemTests.cpp"
"tests/ModLoaderTests.cpp"
Expand All @@ -102,6 +91,8 @@ set(tests
"tests/ParserHelperTests.cpp"
"tests/ParserTests.cpp"
"tests/StringUtilsTests.cpp"
"tests/Localization/LocalizationBlockTests.cpp"
"tests/Localization/LocalizationDatabaseTests.cpp"
)
source_group("tests" FILES ${tests})

Expand All @@ -111,6 +102,11 @@ source_group("tests" FILES ${tests})
################################################################################
add_executable(${PROJECT_NAME} ${tests})
target_link_libraries(${PROJECT_NAME} commonLib)
if (PLATFORM STREQUAL "Windows")
target_compile_options(${PROJECT_NAME} PRIVATE /permissive /W4 /w14242 /w14254 /w14263 /w14265 /w14287 /we4289 /w14296 /w14311 /w14545 /w14546
/w14547 /w14549 /w14555 /w14619 /w14640 /w14826 /w14905 /w14906 /w14928 /external:anglebrackets /external:W0 /WX)
elseif (PLATFORM STREQUAL "Linux")
endif (PLATFORM STREQUAL "Windows")

################################################################################
# Test Files
Expand All @@ -121,6 +117,7 @@ file(COPY "tests/TestFiles/" DESTINATION "./")
################################
# Coverage
################################
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
if (COVERAGE STREQUAL true)
add_custom_target(lcov
COMMAND mkdir -p lcoverage
Expand Down Expand Up @@ -158,6 +155,7 @@ if (COVERAGE STREQUAL true)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif (COVERAGE STREQUAL true)
endif (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)

################################
# Unit Tests
Expand Down
9 changes: 9 additions & 0 deletions CommonFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ std::string trimPath(const std::string& fileName)

std::string getPath(const std::string& fileName)
{
#pragma warning(push)
#pragma warning(disable : 4996)
const auto rawFile = trimPath(fileName);
#pragma warning(pop)
const auto filePos = fileName.find(rawFile);
return fileName.substr(0, filePos);
}

std::string trimExtension(const std::string& fileName)
{
#pragma warning(push)
#pragma warning(disable : 4996)
const auto rawFile = trimPath(fileName);
#pragma warning(pop)
const auto dotPos = rawFile.find_last_of('.');
if (dotPos == std::string::npos)
{
Expand All @@ -35,7 +41,10 @@ std::string trimExtension(const std::string& fileName)

std::string getExtension(const std::string& fileName)
{
#pragma warning(push)
#pragma warning(disable : 4996)
const auto rawFile = trimPath(fileName);
#pragma warning(pop)
const auto dotPos = rawFile.find_last_of('.');
if (dotPos == std::string::npos)
{
Expand Down
13 changes: 7 additions & 6 deletions CommonFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ constexpr auto utf8BOM = "\xEF\xBB\xBF";


// Given a file with path included (such as '/this/is/a/path.txt' or 'c:\this\is\a\path.txt'), returns the part that's just the filename ('path.txt')
std::string trimPath(const std::string& fileName);
[[deprecated("Use std::filesystem::path::filename()")]] std::string trimPath(const std::string& fileName);


// Given a file with path included (such as '/this/is/a/path.txt' or 'c:\this\is\a\path.txt'), returns the part that's just the path ('/this/is/a/' or
// 'c:\this\is\a\')
std::string getPath(const std::string& fileName);
[[deprecated("Use std::filesystem::path::parent_path()")]] std::string getPath(const std::string& fileName);


// Given a filename with an extension (such as 'file.extension' or 'file.name.with.extension'), returns the extension ('extension')
std::string trimExtension(const std::string& fileName);
// Given a filename with an extension (such as 'file.extension' or 'file.name.with.extension'), returns the filename ('file' or 'file.name.with')
[[deprecated("Use std::filesystem::path::stem()")]] std::string trimExtension(const std::string& fileName);


// Given a filename with an extension (such as 'file.extension' or 'file.name.with.extension'), returns the filename ('file' or 'file.name.with')
std::string getExtension(const std::string& fileName);
// Given a filename with an extension (such as 'file.extension' or 'file.name.with.extension'), returns the extension ('extension')
[[deprecated("Use std::filesystem::path::extension(). Note that the recommended function includes the dot.")]] std::string getExtension(
const std::string& fileName);


// Given a string (such as 'a file name.eu4'), replaces all instances of the specified character (such as ' ') with underscores (resulting in 'a_file_name.eu4')
Expand Down
13 changes: 10 additions & 3 deletions CommonItems/CommonItems.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<ClCompile Include="..\ConvenientParser.cpp" />
<ClCompile Include="..\ConverterVersion.cpp" />
<ClCompile Include="..\Date.cpp" />
<ClCompile Include="..\external\zip\src\zip.c" />
<ClCompile Include="..\GameVersion.cpp" />
<ClCompile Include="..\iconvlite.cpp" />
<ClCompile Include="..\LinuxUtils.cpp">
Expand Down Expand Up @@ -45,8 +44,6 @@
<ClInclude Include="..\ConvenientParser.h" />
<ClInclude Include="..\ConverterVersion.h" />
<ClInclude Include="..\Date.h" />
<ClInclude Include="..\external\zip\src\miniz.h" />
<ClInclude Include="..\external\zip\src\zip.h" />
<ClInclude Include="..\GameVersion.h" />
<ClInclude Include="..\iconvlite.h" />
<ClInclude Include="..\Localization\LocalizationBlock.h" />
Expand Down Expand Up @@ -109,6 +106,12 @@
<LanguageStandard>stdcpplatest</LanguageStandard>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<TreatAngleIncludeAsExternal>true</TreatAngleIncludeAsExternal>
<ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel>
<TreatSpecificWarningsAsErrors>4242;4254;4263;4265;4287;4289;4296;4311;4545;4546;4547;4549;4555;4619;4640;4826;4905;4906;4928</TreatSpecificWarningsAsErrors>
<WarningLevel>Level4</WarningLevel>
</ClCompile>
<Link>
<SubSystem>
Expand All @@ -126,6 +129,10 @@
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
<TreatAngleIncludeAsExternal>true</TreatAngleIncludeAsExternal>
<ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>
Expand Down
15 changes: 0 additions & 15 deletions CommonItems/CommonItems.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
<Filter Include="commonItems">
<UniqueIdentifier>{569e5cb7-b294-4ea8-991d-ba24d2e9c236}</UniqueIdentifier>
</Filter>
<Filter Include="external">
<UniqueIdentifier>{c32ded5e-5cf5-4c96-9d9d-0a332b595382}</UniqueIdentifier>
</Filter>
<Filter Include="external\zip">
<UniqueIdentifier>{cdb3317d-89c8-469e-994a-ccea14e50e98}</UniqueIdentifier>
</Filter>
<Filter Include="commonItems\Localization">
<UniqueIdentifier>{5e9fa605-7e0b-42ab-9583-fce44952fd6f}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -66,9 +60,6 @@
<ClCompile Include="..\WinUtils.cpp">
<Filter>commonItems</Filter>
</ClCompile>
<ClCompile Include="..\external\zip\src\zip.c">
<Filter>external\zip</Filter>
</ClCompile>
<ClCompile Include="..\Localization\LocalizationBlock.cpp">
<Filter>commonItems\Localization</Filter>
</ClCompile>
Expand Down Expand Up @@ -131,12 +122,6 @@
<ClInclude Include="..\targa.h">
<Filter>commonItems</Filter>
</ClInclude>
<ClInclude Include="..\external\zip\src\miniz.h">
<Filter>external\zip</Filter>
</ClInclude>
<ClInclude Include="..\external\zip\src\zip.h">
<Filter>external\zip</Filter>
</ClInclude>
<ClInclude Include="..\Localization\LocalizationBlock.h">
<Filter>commonItems\Localization</Filter>
</ClInclude>
Expand Down
23 changes: 21 additions & 2 deletions ConverterVersion.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
#include "ConverterVersion.h"

#include <fstream>

#include "CommonRegexes.h"
#include "ParserHelpers.h"
#include <fstream>

void commonItems::ConverterVersion::loadVersion(const std::string& filename)


using std::filesystem::path;
using std::filesystem::u8path;



void commonItems::ConverterVersion::loadVersion(const path& filename)
{
registerKeys();
parseFile(filename);
clearRegisteredKeywords();
}


void commonItems::ConverterVersion::loadVersion(const std::string& filename)
{
#pragma warning(push)
#pragma warning(disable : 4996)
loadVersion(u8path(filename));
#pragma warning(pop)
}


void commonItems::ConverterVersion::loadVersion(std::istream& theStream)
{
registerKeys();
Expand Down
3 changes: 2 additions & 1 deletion ConverterVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class ConverterVersion: convenientParser
{
public:
ConverterVersion() = default;
void loadVersion(const std::string& filename);
void loadVersion(const std::filesystem::path& filename);
[[deprecated("Use std::filesystem::path version")]] void loadVersion(const std::string& filename);
void loadVersion(std::istream& theStream);

[[nodiscard]] const auto& getName() const { return name; }
Expand Down
Loading

0 comments on commit 8876106

Please sign in to comment.