Skip to content

Commit

Permalink
Remove unneeded path to string conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Apr 25, 2023
1 parent f3248df commit d5aaed0
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/lib/game/data/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace
std::optional<nlohmann::json> loadDocument (int slot)
{
const auto fileName = cSavegame::getFileName (slot);
std::ifstream file (fileName.string());
std::ifstream file (fileName);
nlohmann::json json;
if (!(file >> json))
{
Expand Down Expand Up @@ -108,7 +108,7 @@ void cSavegame::save (const cModel& model, int slot, const std::string& saveName

std::filesystem::create_directories (cSettings::getInstance().getSavesPath());
{
std::ofstream file (getFileName (slot).string());
std::ofstream file (getFileName (slot));
file << json.dump (2);
}
#if 1
Expand Down Expand Up @@ -140,7 +140,7 @@ void cSavegame::saveGuiInfo (const cNetMessageGUISaveInfo& guiInfo)

std::filesystem::create_directories (cSettings::getInstance().getSavesPath());
int loadedSlot = guiInfo.slot;
std::ofstream file (getFileName (loadedSlot).string());
std::ofstream file (getFileName (loadedSlot));
file << json->dump (2);
}

Expand Down
10 changes: 5 additions & 5 deletions src/lib/mapdownloader/mapdownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ uint32_t MapDownload::calculateCheckSum (const std::string& mapName)
{
uint32_t result = 0;
auto filename = cSettings::getInstance().getMapsPath() / mapName;
std::ifstream file (filename.string(), std::ios::in | std::ios::binary | std::ios::ate);
std::ifstream file (filename, std::ios::in | std::ios::binary | std::ios::ate);
if (!file.is_open() && !cSettings::getInstance().getUserMapsDir().empty())
{
// try to open the map from the user's maps dir
filename = cSettings::getInstance().getUserMapsDir() / mapName;
file.open (filename.string(), std::ios::in | std::ios::binary | std::ios::ate);
file.open (filename, std::ios::in | std::ios::binary | std::ios::ate);
}
if (file.is_open())
{
Expand Down Expand Up @@ -174,7 +174,7 @@ bool cMapReceiver::finished()
if (mapsFolder.empty())
mapsFolder = cSettings::getInstance().getMapsPath();
const auto filename = mapsFolder / mapName;
std::ofstream newMapFile (filename.string(), std::ios::out | std::ios::binary);
std::ofstream newMapFile (filename, std::ios::out | std::ios::binary);
if (newMapFile.bad())
return false;
newMapFile.write (readBuffer.data(), readBuffer.size());
Expand Down Expand Up @@ -238,12 +238,12 @@ bool cMapSender::getMapFileContent()
{
// read map file in memory
auto filename = cSettings::getInstance().getMapsPath() / mapName;
std::ifstream file (filename.string(), std::ios::in | std::ios::binary | std::ios::ate);
std::ifstream file (filename, std::ios::in | std::ios::binary | std::ios::ate);
if (!file.is_open() && !cSettings::getInstance().getUserMapsDir().empty())
{
// try to open the map from the user's maps dir
filename = cSettings::getInstance().getUserMapsDir() / mapName;
file.open (filename.string(), std::ios::in | std::ios::binary | std::ios::ate);
file.open (filename, std::ios::in | std::ios::binary | std::ios::ate);
}
if (!file.is_open())
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/resources/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ cKeysList::cKeysList() :
//------------------------------------------------------------------------------
void cKeysList::loadFromJsonFile (const std::filesystem::path& path)
{
std::ifstream file (path.string());
std::ifstream file (path);
nlohmann::json json;

if (!(file >> json))
Expand Down Expand Up @@ -167,7 +167,7 @@ void cKeysList::saveToFile()

serialize (archive);

std::ofstream file ((cSettings::getInstance().getMaxrHomeDir() / "keys.json").string());
std::ofstream file (cSettings::getInstance().getMaxrHomeDir() / "keys.json");
file << json.dump (0);
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/resources/loaddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static void LoadUnitData (sInitialBuildingData& buildingData, const std::filesys
const auto path = directory / "data.json";
if (!std::filesystem::exists (path)) return;

std::ifstream file (path.string());
std::ifstream file (path);
nlohmann::json json;

if (!(file >> json))
Expand All @@ -389,7 +389,7 @@ static void LoadUnitData (sInitialVehicleData& vehicleData, const std::filesyste
auto path = directory / "data.json";
if (!std::filesystem::exists (path)) return;

std::ifstream file (path.string());
std::ifstream file (path);
nlohmann::json json;

if (!(file >> json))
Expand Down Expand Up @@ -975,7 +975,7 @@ static int LoadBuildings (bool includingUiData)
return 0;
}

std::ifstream file (buildingsJsonPath.string());
std::ifstream file (buildingsJsonPath);
nlohmann::json json;

if (!(file >> json))
Expand Down Expand Up @@ -1068,7 +1068,7 @@ static int LoadVehicles (bool includingUiData)
return 0;
}

std::ifstream file (vehicleJsonPath.string());
std::ifstream file (vehicleJsonPath);
nlohmann::json json;

if (!(file >> json))
Expand Down Expand Up @@ -1147,7 +1147,7 @@ static int LoadClans()
Log.error ("File doesn't exist: " + clansPath.string());
return 0;
}
std::ifstream file (clansPath.string());
std::ifstream file (clansPath);
nlohmann::json json;
if (!(file >> json))
{
Expand Down Expand Up @@ -1177,7 +1177,7 @@ static int LoadMusic (const std::filesystem::path& directory)
Log.error ("file doesn't exist");
return 0;
}
std::ifstream file (musicPath.string());
std::ifstream file (musicPath);
nlohmann::json json;

if (!(file >> json))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void cSettings::setPaths()
//------------------------------------------------------------------------------
void cSettings::loadFromJsonFile (const std::filesystem::path& path)
{
std::ifstream file (path.string());
std::ifstream file (path);
nlohmann::json json;

if (!(file >> json))
Expand Down Expand Up @@ -254,7 +254,7 @@ void cSettings::saveInFile() const
cJsonArchiveOut out (json);
out << *this;

std::ofstream file ((homeDir / "maxr.json").string());
std::ofstream file (homeDir / "maxr.json");
file << json.dump (1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/utility/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace
void openCatalog (spiritless_po::Catalog& catalog, const std::filesystem::path& path)
{
catalog.Clear();
std::ifstream file (path.string());
std::ifstream file (path);

if (!catalog.Add (file))
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utility/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void cLog::setLogPath (const std::filesystem::path& path)
}

//create + open new log file
logfile.open (path.string(), std::fstream::out | std::fstream::trunc);
logfile.open (path, std::fstream::out | std::fstream::trunc);
if (!logfile.is_open())
{
std::cerr << "(EE): Couldn't open" + path.string() + "!\n Please check file / directory permissions\n ";
Expand Down
2 changes: 1 addition & 1 deletion src/ui/graphical/menu/dialogs/dialoglicense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void cDialogLicense::readAuthors()
cSettings::getInstance().getDataDir() / "AUTHORS";
#endif

std::ifstream authorsFile (fileName.string());
std::ifstream authorsFile (fileName);

if (authorsFile.is_open())
{
Expand Down

0 comments on commit d5aaed0

Please sign in to comment.