@ -3,7 +3,6 @@
//Translates a region of tiles specified by the cursor and arguments/prompts into a series of blueprint files suitable for digfort/buildingplan/quickfort
//Translates a region of tiles specified by the cursor and arguments/prompts into a series of blueprint files suitable for digfort/buildingplan/quickfort
# include <algorithm>
# include <algorithm>
# include <experimental/filesystem> // This is just <filesystem> in c++17, but we're currently compiling with c++11
# include <sstream>
# include <sstream>
# include <Console.h>
# include <Console.h>
@ -11,6 +10,7 @@
# include "LuaTools.h"
# include "LuaTools.h"
# include "modules/Buildings.h"
# include "modules/Buildings.h"
# include "modules/Filesystem.h"
# include "modules/Gui.h"
# include "modules/Gui.h"
# include "modules/MapCache.h"
# include "modules/MapCache.h"
@ -35,8 +35,6 @@ using std::pair;
using namespace DFHack ;
using namespace DFHack ;
using namespace df : : enums ;
using namespace df : : enums ;
namespace filesystem = std : : experimental : : filesystem ;
DFHACK_PLUGIN ( " blueprint " ) ;
DFHACK_PLUGIN ( " blueprint " ) ;
enum phase { DIG = 1 , BUILD = 2 , PLACE = 4 , QUERY = 8 } ;
enum phase { DIG = 1 , BUILD = 2 , PLACE = 4 , QUERY = 8 } ;
@ -562,13 +560,11 @@ string get_tile_query(df::building* b)
return " " ;
return " " ;
}
}
void init_stream ( ofstream & out , filesystem: : path basename , std : : string target )
void init_stream ( ofstream & out , std: : string basename , std : : string target )
{
{
filesystem : : path out_path ( basename ) ;
std : : ostringstream out_path ;
out_path + = " - " ;
out_path < < basename < < " - " < < target < < " .csv " ;
out_path + = target ;
out . open ( out_path . str ( ) , ofstream : : trunc ) ;
out_path + = " .csv " ;
out . open ( out_path , ofstream : : trunc ) ;
out < < " # " < < target < < endl ;
out < < " # " < < target < < endl ;
}
}
@ -576,16 +572,21 @@ command_result do_transform(DFCoord start, DFCoord end, string name, uint32_t ph
{
{
ofstream dig , build , place , query ;
ofstream dig , build , place , query ;
filesystem : : path basename = " blueprints " ;
std : : string basename = " blueprints/ " + name ;
basename / = name ;
basename . make_preferred ( ) ;
# ifdef _WIN32
// normalize to forward slashes
std : : replace ( basename . begin ( ) , basename . end ( ) , ' \\ ' , ' / ' ) ;
# endif
size_t last_slash = basename . find_last_of ( " / " ) ;
std : : string parent_path = basename . substr ( 0 , last_slash ) ;
// create output directory if it doesn't already exist
// create output directory if it doesn't already exist
std : : error_code ec ;
std : : error_code ec ;
if ( ! filesystem : : create_directories ( basename . parent_path ( ) , ec ) & & ec )
if ( ! Filesystem: : mkdir_recursive ( parent_path ) )
{
{
err < < " could not create output directory: " < < basename . parent_path ( )
err < < " could not create output directory: ' " < < parent_path < < " ' " ;
< < " ( " < < ec . message ( ) < < " ) " ;
return CR_FAILURE ;
return CR_FAILURE ;
}
}