summaryrefslogtreecommitdiff
path: root/library/Core.cpp
diff options
context:
space:
mode:
authorClayton Hughes2012-03-12 00:33:59 -0700
committerClayton Hughes2012-03-12 00:33:59 -0700
commit4cb8995a0558d0ccf316584ca81f304ad976da37 (patch)
tree1c6fcc52e8c974e7b33e2b43d66c56d2ecf73154 /library/Core.cpp
parentd7f7437ca1a7b056795cd98e92194604e2c17937 (diff)
downloaddfhack-4cb8995a0558d0ccf316584ca81f304ad976da37.tar.gz
dfhack-4cb8995a0558d0ccf316584ca81f304ad976da37.tar.bz2
dfhack-4cb8995a0558d0ccf316584ca81f304ad976da37.tar.xz
Fixed script loading improperly checking for errors.
Also closed the file for good measure. I couldn't find any documentation that said that ~ifstream() did this.
Diffstat (limited to 'library/Core.cpp')
-rw-r--r--library/Core.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/library/Core.cpp b/library/Core.cpp
index 1b8d5388..82c8c793 100644
--- a/library/Core.cpp
+++ b/library/Core.cpp
@@ -500,19 +500,22 @@ static void loadScriptFile(Core *core, PluginManager *plug_mgr, string fname)
{
core->con << "Loading script at " << fname << std::endl;
ifstream script(fname);
- if (script.bad())
+ if (script.good())
{
- core->con.printerr("Error loading script\n");
- return;
+ int tmp = 0;
+ string command;
+ while (getline(script, command))
+ {
+ if (!command.empty())
+ runInteractiveCommand(core, plug_mgr, tmp, command);
+ }
}
-
- int tmp = 0;
- string command;
- while (getline(script, command))
+ else
{
- if (!command.empty())
- runInteractiveCommand(core, plug_mgr, tmp, command);
+ core->con.printerr("Error loading script\n");
}
+
+ script.close();
}
// A thread function... for the interactive console.