From 3adf066ea3e0d302f3caf5f7b8d9cb96ba9f1cd7 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 11 Oct 2014 17:59:49 +0100 Subject: [PATCH] Fixed false successes for db creation. * If not on Windows, a local data path must be supplied. * The supplied paths must be valid directories. * Added general exception catching. --- src/api/api.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 14266ad6..f891d6e9 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -248,18 +248,30 @@ LOOT_API unsigned int loot_create_db(loot_db * const db, boost::filesystem::path game_local_path = ""; if (gameLocalPath != nullptr) game_local_path = gameLocalPath; +#ifndef _WIN32 + else + return c_error(loot_error_invalid_args, "A local data path must be supplied on non-Windows platforms."); +#endif - loot_db retVal = {0}; try { - retVal = new _loot_db_int(clientGame, game_path, game_local_path); - } + // Check for valid paths. + if (gamePath != nullptr && !boost::filesystem::is_directory(gamePath)) + return c_error(loot_error_invalid_args, "Given game path \"" + std::string(gamePath) + "\" is not a valid directory."); + + if (gameLocalPath != nullptr && !boost::filesystem::is_directory(gameLocalPath)) + return c_error(loot_error_invalid_args, "Given local data path \"" + std::string(gameLocalPath) + "\" is not a valid directory."); + + *db = new _loot_db_int(clientGame, game_path, game_local_path); +} catch (loot::error& e) { return c_error(e); } catch (std::bad_alloc& e) { return c_error(loot_error_no_mem, e.what()); } - *db = retVal; + catch (std::exception& e) { + return c_error(loot_error_invalid_args, e.what()); + } return loot_ok; }