Skip to content

Commit

Permalink
Replace a few more direct occurrences of boost::filesystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 15, 2017
1 parent f6be0a1 commit 67c5c7c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
19 changes: 10 additions & 9 deletions plugins/dm.gui/XData.cpp
Expand Up @@ -2,8 +2,9 @@

#include "i18n.h"
#include "itextstream.h"
#include <fstream>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/convenience.hpp>
#include "os/fs.h"
#include "os/file.h"

namespace XData
Expand All @@ -13,12 +14,12 @@ namespace XData
//->export:
FileStatus XData::xport( const std::string& filename, ExporterCommand cmd )
{
boost::filesystem::path Path(filename);
fs::path Path(filename);

boost::filesystem::path parent = Path.parent_path();
fs::path parent = Path.parent_path();

// Ensure the parent path exists
boost::filesystem::create_directories(parent);
fs::create_directories(parent);

if (os::fileOrDirExists(Path.string()))
{
Expand All @@ -27,7 +28,7 @@ FileStatus XData::xport( const std::string& filename, ExporterCommand cmd )
case Merge:
{
//Check if definition already exists and return DefinitionExists. If it does not, append the definition to the file.
boost::filesystem::fstream file(Path, std::ios_base::in | std::ios_base::out | std::ios_base::app);
std::fstream file(Path, std::ios_base::in | std::ios_base::out | std::ios_base::app);
if (!file.is_open())
return OpenFailed;
std::stringstream ss;
Expand Down Expand Up @@ -64,7 +65,7 @@ FileStatus XData::xport( const std::string& filename, ExporterCommand cmd )
{
//Find the old definition in the target file and delete it. Append the new definition.
//_definitionStart has been set in the first iteration of this method.
boost::filesystem::fstream file(Path, std::ios_base::in);
std::fstream file(Path, std::ios_base::in);
if (!file.is_open())
return OpenFailed;
std::stringstream ss;
Expand Down Expand Up @@ -92,7 +93,7 @@ FileStatus XData::xport( const std::string& filename, ExporterCommand cmd )
//Warn if the definition in the target file does not match the current definition: return DefinitionMisMatch
//else overwrite existing file.
std::string DefName;
boost::filesystem::ifstream file(Path, std::ios_base::in);
std::ifstream file(Path, std::ios_base::in);
if (!file.is_open())
return OpenFailed;
try { DefName = getDefinitionNameFromXD(file); }
Expand All @@ -116,7 +117,7 @@ FileStatus XData::xport( const std::string& filename, ExporterCommand cmd )
}

//Write the definition into the file.
boost::filesystem::ofstream file(Path, std::ios_base::out | std::ios_base::trunc);
std::ofstream file(Path, std::ios_base::out | std::ios_base::trunc);
if (!file.is_open())
return OpenFailed;
file << generateXDataDef();
Expand Down Expand Up @@ -176,7 +177,7 @@ const std::size_t XData::getDefLength(const std::string& def) const
return 0; //no appropriate bracketstructure was found.
}

const std::string XData::getDefinitionNameFromXD(boost::filesystem::ifstream& file) const
const std::string XData::getDefinitionNameFromXD(std::ifstream& file) const
{
std::string ReturnString;
parser::BasicDefTokeniser<std::istream> tok(file);
Expand Down
8 changes: 2 additions & 6 deletions plugins/dm.gui/XData.h
@@ -1,12 +1,10 @@
#ifndef XDATA_H
#define XDATA_H
#pragma once

#include <string>
#include <vector>
#include <iostream>
#include "i18n.h"
#include <memory>
#include "boost/filesystem/fstream.hpp"

#include "parser/DefTokeniser.h"

Expand Down Expand Up @@ -143,7 +141,7 @@ class XData

// Returns the definition-name found in the file or "" if multiple definitions where found.
// Used by the xport()-method in the overwrite-command for checking for a DefinitionMatch or MultipleDefinitions.
const std::string getDefinitionNameFromXD(boost::filesystem::ifstream& file) const;
const std::string getDefinitionNameFromXD(std::ifstream& file) const;

// Used to jump out of a definition. Can lead to undefined behavior on Syntax-errors.
void jumpOutOfBrackets(parser::DefTokeniser& tok, int currentDepth) const;
Expand Down Expand Up @@ -238,5 +236,3 @@ class TwoSidedXData : public XData
typedef std::shared_ptr<TwoSidedXData> TwoSidedXDataPtr;

} //namespace XData

#endif /* XDATA_H */
13 changes: 3 additions & 10 deletions radiant/map/AutoSaver.cpp
Expand Up @@ -25,10 +25,6 @@

#include <wx/frame.h>

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/exception.hpp>

namespace map
{

Expand All @@ -41,9 +37,6 @@ namespace
const char* RKEY_AUTOSAVE_SNAPSHOTS_FOLDER = "user/ui/map/snapshotFolder";
const char* RKEY_AUTOSAVE_MAX_SNAPSHOT_FOLDER_SIZE = "user/ui/map/maxSnapshotFolderSize";
const char* GKEY_MAP_EXTENSION = "/mapFormat/fileExtension";

// Filesystem path typedef
typedef boost::filesystem::path Path;
}

AutoMapSaver::AutoMapSaver() :
Expand Down Expand Up @@ -111,10 +104,10 @@ void AutoMapSaver::saveSnapshot()
}

// Construct the boost::path class out of the full map path (throws on fail)
Path fullPath = GlobalMap().getMapName();
fs::path fullPath = GlobalMap().getMapName();

// Append the the snapshot folder to the path
Path snapshotPath = fullPath;
fs::path snapshotPath = fullPath;
snapshotPath.remove_filename();
snapshotPath /= GlobalRegistry().get(RKEY_AUTOSAVE_SNAPSHOTS_FOLDER);

Expand Down Expand Up @@ -217,7 +210,7 @@ void AutoMapSaver::checkSave()
{
saveSnapshot();
}
catch (boost::filesystem::filesystem_error& f)
catch (fs::filesystem_error& f)
{
rError() << "AutoSaver::saveSnapshot: " << f.what() << std::endl;
}
Expand Down
12 changes: 3 additions & 9 deletions radiant/selection/algorithm/Primitives.cpp
Expand Up @@ -16,6 +16,7 @@
#include "brush/export/CollisionModel.h"
#include "wxutil/dialog/MessageBox.h"
#include "map/Map.h"
#include "os/fs.h"
#include "gamelib.h"
#include "ui/modelselector/ModelSelector.h"
#include "ui/texturebrowser/TextureBrowser.h"
Expand All @@ -25,9 +26,6 @@
#include "scenelib.h"
#include "selectionlib.h"

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/format.hpp>

Expand All @@ -50,9 +48,6 @@ namespace
const std::string ERRSTR_WRONG_SELECTION =
"Can't export, create and select a func_* entity\
containing the collision hull primitives.";

// Filesystem path typedef
typedef boost::filesystem::path Path;
}

void forEachSelectedFaceComponent(const std::function<void(Face&)>& functor)
Expand Down Expand Up @@ -183,8 +178,7 @@ void createCMFromSelection(const cmd::ArgumentList& args) {

try {
// create the new autosave filename by changing the extension
Path cmPath = modelPath;
cmPath.replace_extension(newExtension);
fs::path cmPath = os::replaceExtension(modelPath, newExtension);

// Open the stream to the output file
std::ofstream outfile(cmPath.string().c_str());
Expand All @@ -202,7 +196,7 @@ void createCMFromSelection(const cmd::ArgumentList& args) {
(boost::format("Couldn't save to file: %s") % cmPath.string()).str());
}
}
catch (boost::filesystem::filesystem_error f) {
catch (fs::filesystem_error f) {
rError() << "CollisionModel: " << f.what() << std::endl;
}

Expand Down

0 comments on commit 67c5c7c

Please sign in to comment.