stockpiles: fix loading crash

develop
Casey Link 2014-12-04 14:28:43 +01:00
parent 7e6066daf2
commit 346f397bca
1 changed files with 9 additions and 10 deletions

@ -288,11 +288,15 @@ static command_result loadstock ( color_ostream &out, vector <string> & paramete
file = o; file = o;
} }
} }
if ( file.empty() ) {
if ( !is_dfstockfile ( file ) ) file += ".dfstock"; out.printerr ( "ERROR: missing .dfstock file parameter\n");
if ( file.empty() || !Filesystem::exists ( file ) ) return DFHack::CR_WRONG_USAGE;
}
if ( !is_dfstockfile ( file ) )
file += ".dfstock";
if ( !Filesystem::exists ( file ) )
{ {
out.printerr ( "loadstock: a .dfstock file is required to import\n" ); out.printerr ( "ERROR: the .dfstock file doesn't exist: %s\n", file.c_str());
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
} }
@ -495,7 +499,7 @@ static int stockpiles_list_settings ( lua_State *L )
auto path = luaL_checkstring ( L, 1 ); auto path = luaL_checkstring ( L, 1 );
if ( !Filesystem::exists ( path ) ) if ( !Filesystem::exists ( path ) )
{ {
lua_pushfstring ( L, "stocksettings path invalid: %s", path ); lua_pushfstring ( L, "stocksettings folder doesn't exist: %s", path );
lua_error ( L ); lua_error ( L );
return 0; return 0;
} }
@ -514,11 +518,6 @@ static int stockpiles_list_settings ( lua_State *L )
static void stockpiles_load ( color_ostream &out, std::string filename ) static void stockpiles_load ( color_ostream &out, std::string filename )
{ {
out << "stockpiles_load " << filename << " "; out << "stockpiles_load " << filename << " ";
if ( !Filesystem::exists ( filename ) )
{
out.printerr ( "invalid file: %s\n", filename.c_str() );
return;
}
std::vector<std::string> params; std::vector<std::string> params;
params.push_back ( filename ); params.push_back ( filename );
command_result r = loadstock ( out, params ); command_result r = loadstock ( out, params );