From 346f397bca65b0f5915d32abc7e0d9e20a028c84 Mon Sep 17 00:00:00 2001 From: Casey Link Date: Thu, 4 Dec 2014 14:28:43 +0100 Subject: [PATCH] stockpiles: fix loading crash --- plugins/stockpiles/stockpiles.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/stockpiles/stockpiles.cpp b/plugins/stockpiles/stockpiles.cpp index f9aee708c..ac9de5f57 100644 --- a/plugins/stockpiles/stockpiles.cpp +++ b/plugins/stockpiles/stockpiles.cpp @@ -288,11 +288,15 @@ static command_result loadstock ( color_ostream &out, vector & paramete file = o; } } - - if ( !is_dfstockfile ( file ) ) file += ".dfstock"; - if ( file.empty() || !Filesystem::exists ( file ) ) + if ( file.empty() ) { + out.printerr ( "ERROR: missing .dfstock file parameter\n"); + 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; } @@ -495,7 +499,7 @@ static int stockpiles_list_settings ( lua_State *L ) auto path = luaL_checkstring ( L, 1 ); 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 ); return 0; } @@ -514,11 +518,6 @@ static int stockpiles_list_settings ( lua_State *L ) static void stockpiles_load ( color_ostream &out, std::string filename ) { out << "stockpiles_load " << filename << " "; - if ( !Filesystem::exists ( filename ) ) - { - out.printerr ( "invalid file: %s\n", filename.c_str() ); - return; - } std::vector params; params.push_back ( filename ); command_result r = loadstock ( out, params );