Files
source/Utils/INIReader.h
T
1d6ff6be3c let CIniReader take its strings as pointers to const
STR8 is char*, so const STR8 is char* const: a const pointer to a mutable
string, which is not what any of these sixty parameters wanted. What they
wanted is const CHAR8*, a pointer to a string they will not write to, and
that is what all of them do.

Under the MSVC compatibility rules clang-cl applies, a string literal still
converts to char*, so most calls survive this mistake untouched. An expression
of type const char* does not, and Intro.cpp has thirteen of them:

    inireader.ReadString("INTRO_BEGINNING", "INTRO_REBEL_CRDT",
                         no_defaults ? "" : "INTRO\\Rebel_cr");

The conditional is a const char*, not a literal, so it has nowhere to bind and
the call does not compile. The other two arguments are literals and are
accepted, which is why only the third one was ever reported.

The invariant: in these two files, every parameter spelled const STR8 becomes
const CHAR8*, and nothing else changes. No body assigns to one of them, so
none needed rewriting; STR8 input_buffer in the five-argument ReadString is
genuinely an output and keeps its type. Three commented-out lines still say
const STR8 and were left as they are.

Verification:

    grep -n 'const[ \t]*STR8' Utils/INIReader.h Utils/INIReader.cpp
        # three hits, all on lines beginning with //

    git show HEAD -U0 | grep '^[+-][^+-]' |
      sed -E 's/const[ \t]+(STR8|CHAR8\*)/const/g; s/^[+-]//' |
      sort | uniq -c | awk '$1 % 2'          # no output

    ninja -C build parse         # ReadString class gone: 45 -> 32 sites
    ninja -C build -k 0          # Release, four applications, green
    ninja -C build-debug -k 0    # Debug, four applications, green

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-23 19:29:55 -03:00

70 lines
3.1 KiB
C++

#ifndef INIREADER_H
#define INIREADER_H
#define NOMINMAX
#include <algorithm>
#include <windows.h>
#include <types.h>
#include <stack>
#include <string>
#include <vfs/Tools/vfs_property_container.h>
// Kaiden: This will read any value out of
// an INI file as long as the correct type is specified.
// Methods should be fairly self explainatory
//
// Note: readers without valid range parameters will be removed to "encourage" developers to specify
// valid ranges. Consider carefully what those values should be.
//
// Queue of error messages. They are queued because screen is not ready for I/O yet.
extern std::stack<std::string> iniErrorMessages;
class CIniReader
{
public:
CIniReader(const CHAR8* szFileName);
CIniReader(const CHAR8* szFileName, BOOLEAN Force_Custom_Data_Path); // force path for nonexisting INI files
// Warning: the following function will be removed
int ReadInteger(const CHAR8* szSection, const CHAR8* szKey, int iDefaultValue);
int ReadInteger(const CHAR8* szSection, const CHAR8* szKey, int defaultValue, int minValue, int maxValue);
//UINT32 CIniReader::testReadUINT32(void);//various limit tests of UINT and double/float handling
//front end functions that control type interpretation and range control, each calls internal ReadUINT
UINT32 ReadUINT32(const CHAR8* szSection, const CHAR8* szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue);
UINT16 ReadUINT16(const CHAR8* szSection, const CHAR8* szKey, UINT16 defaultValue, UINT16 minValue, UINT16 maxValue);
UINT8 ReadUINT8 (const CHAR8* szSection, const CHAR8* szKey, UINT8 defaultValue, UINT8 minValue, UINT8 maxValue);
// Warning: the following function will be removed
//double ReadDouble(const STR8 szSection, const STR8 szKey, double fltDefaultValue);
// Read_reals
DOUBLE ReadDouble(const CHAR8* szSection, const CHAR8* szKey, DOUBLE defaultValue, DOUBLE minValue, DOUBLE maxValue);
FLOAT ReadFloat (const CHAR8* szSection, const CHAR8* szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue);
void ReadFloatArray(const CHAR8* szSection, const CHAR8* szKey, std::vector<FLOAT>& vec);
void ReadINT32Array(const CHAR8* szSection, const CHAR8* szKey, std::vector<INT32>& vec);
BOOLEAN ReadBoolean(const CHAR8* szSection, const CHAR8* szKey, bool bolDefaultValue, bool bolDisplayError = true);
void ReadString(const CHAR8* szSection, const CHAR8* szKey, const CHAR8* szDefaultValue, STR8 input_buffer, size_t buffer_size);
// WANNE - MP: Old version, currently used by Multiplayer
STR8 ReadString(const CHAR8* szSection, const CHAR8* szKey, const CHAR8* szDefaultValue);
BOOLEAN Is_CIniReader_File_Found(void) {return (CIniReader_File_Found);}
void Clear();
static void RegisterFileForMerging(vfs::Path const& filename);
private:
vfs::PropertyContainer m_oProps;
char m_szFileName[MAX_PATH];
BOOLEAN CIniReader_File_Found;
UINT32 ReadUINT(const CHAR8* szSection, const CHAR8* szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue);
static std::set<vfs::Path, vfs::Path::Less> m_merge_files;
};
#endif//INIREADER_H