diff --git a/src/api/api.cpp b/src/api/api.cpp index 89284aed..c531e932 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -44,53 +44,53 @@ #include #include -const unsigned int loot_ok = loot::error::ok; -const unsigned int loot_error_liblo_error = loot::error::liblo_error; -const unsigned int loot_error_file_write_fail = loot::error::path_write_fail; -const unsigned int loot_error_parse_fail = loot::error::path_read_fail; -const unsigned int loot_error_condition_eval_fail = loot::error::condition_eval_fail; -const unsigned int loot_error_regex_eval_fail = loot::error::regex_eval_fail; -const unsigned int loot_error_no_mem = loot::error::no_mem; -const unsigned int loot_error_invalid_args = loot::error::invalid_args; -const unsigned int loot_error_no_tag_map = loot::error::no_tag_map; -const unsigned int loot_error_path_not_found = loot::error::path_not_found; -const unsigned int loot_error_no_game_detected = loot::error::no_game_detected; -const unsigned int loot_error_windows_error = loot::error::windows_error; -const unsigned int loot_error_sorting_error = loot::error::sorting_error; -const unsigned int loot_return_max = loot_error_sorting_error; +const unsigned int loot_ok = loot::error::ok; +const unsigned int loot_error_liblo_error = loot::error::liblo_error; +const unsigned int loot_error_file_write_fail = loot::error::path_write_fail; +const unsigned int loot_error_parse_fail = loot::error::path_read_fail; +const unsigned int loot_error_condition_eval_fail = loot::error::condition_eval_fail; +const unsigned int loot_error_regex_eval_fail = loot::error::regex_eval_fail; +const unsigned int loot_error_no_mem = loot::error::no_mem; +const unsigned int loot_error_invalid_args = loot::error::invalid_args; +const unsigned int loot_error_no_tag_map = loot::error::no_tag_map; +const unsigned int loot_error_path_not_found = loot::error::path_not_found; +const unsigned int loot_error_no_game_detected = loot::error::no_game_detected; +const unsigned int loot_error_windows_error = loot::error::windows_error; +const unsigned int loot_error_sorting_error = loot::error::sorting_error; +const unsigned int loot_return_max = loot_error_sorting_error; // The following are the games identifiers used by the API. -const unsigned int loot_game_tes4 = loot::Game::tes4; -const unsigned int loot_game_tes5 = loot::Game::tes5; -const unsigned int loot_game_fo3 = loot::Game::fo3; -const unsigned int loot_game_fonv = loot::Game::fonv; +const unsigned int loot_game_tes4 = loot::Game::tes4; +const unsigned int loot_game_tes5 = loot::Game::tes5; +const unsigned int loot_game_fo3 = loot::Game::fo3; +const unsigned int loot_game_fonv = loot::Game::fonv; // LOOT message types. -const unsigned int loot_message_say = loot::Message::say; -const unsigned int loot_message_warn = loot::Message::warn; -const unsigned int loot_message_error = loot::Message::error; -const unsigned int loot_message_tag = loot::Message::tag; +const unsigned int loot_message_say = loot::Message::say; +const unsigned int loot_message_warn = loot::Message::warn; +const unsigned int loot_message_error = loot::Message::error; +const unsigned int loot_message_tag = loot::Message::tag; // LOOT message languages. -const unsigned int loot_lang_any = loot::Language::any; -const unsigned int loot_lang_english = loot::Language::english; -const unsigned int loot_lang_spanish = loot::Language::spanish; -const unsigned int loot_lang_russian = loot::Language::russian; -const unsigned int loot_lang_french = loot::Language::french; -const unsigned int loot_lang_chinese = loot::Language::chinese; -const unsigned int loot_lang_polish = loot::Language::polish; -const unsigned int loot_lang_brazilian_portuguese = loot::Language::brazilian_portuguese; -const unsigned int loot_lang_finnish = loot::Language::finnish; -const unsigned int loot_lang_german = loot::Language::german; -const unsigned int loot_lang_danish = loot::Language::danish; +const unsigned int loot_lang_any = loot::Language::any; +const unsigned int loot_lang_english = loot::Language::english; +const unsigned int loot_lang_spanish = loot::Language::spanish; +const unsigned int loot_lang_russian = loot::Language::russian; +const unsigned int loot_lang_french = loot::Language::french; +const unsigned int loot_lang_chinese = loot::Language::chinese; +const unsigned int loot_lang_polish = loot::Language::polish; +const unsigned int loot_lang_brazilian_portuguese = loot::Language::brazilian_portuguese; +const unsigned int loot_lang_finnish = loot::Language::finnish; +const unsigned int loot_lang_german = loot::Language::german; +const unsigned int loot_lang_danish = loot::Language::danish; // LOOT cleanliness codes. -const unsigned int loot_needs_cleaning_no = 0; -const unsigned int loot_needs_cleaning_yes = 1; -const unsigned int loot_needs_cleaning_unknown = 2; +const unsigned int loot_needs_cleaning_no = 0; +const unsigned int loot_needs_cleaning_yes = 1; +const unsigned int loot_needs_cleaning_unknown = 2; struct _loot_db_int : public loot::Game { - _loot_db_int(const unsigned int clientGame, const std::string gamePath) + _loot_db_int(const unsigned int clientGame, const std::string& gamePath) : Game(clientGame), extTagMap(nullptr), extAddedTagIds(nullptr), @@ -105,13 +105,13 @@ struct _loot_db_int : public loot::Game { delete[] extRemovedTagIds; if (extTagMap != nullptr) { - for (size_t i=0; i < bashTagMap.size(); i++) + for (size_t i = 0; i < bashTagMap.size(); i++) delete[] extTagMap[i]; //Gotta clear those allocated strings. delete[] extTagMap; } if (extMessageArray != nullptr) { - for (size_t i=0; i < extMessageArraySize; i++) + for (size_t i = 0; i < extMessageArraySize; i++) delete[] extMessageArray[i].message; //Gotta clear those allocated strings. delete[] extMessageArray; } @@ -243,7 +243,7 @@ LOOT_API unsigned int loot_create_db(loot_db * const db, const unsigned int clie if (gamePath != nullptr) game_path = gamePath; - loot_db retVal ={ 0 }; + loot_db retVal = {0}; try { retVal = new _loot_db_int(clientGame, game_path); } @@ -306,13 +306,13 @@ LOOT_API unsigned int loot_load_lists(loot_db db, const char * const masterlistP delete[] db->extRemovedTagIds; if (db->extTagMap != nullptr) { - for (size_t i=0; i < db->bashTagMap.size(); i++) + for (size_t i = 0; i < db->bashTagMap.size(); i++) delete[] db->extTagMap[i]; //Gotta clear those allocated strings. delete[] db->extTagMap; } if (db->extMessageArray != nullptr) { - for (size_t i=0; i < db->extMessageArraySize; i++) + for (size_t i = 0; i < db->extMessageArraySize; i++) delete[] db->extMessageArray[i].message; //Gotta clear those allocated strings. delete[] db->extMessageArray; } @@ -374,7 +374,7 @@ LOOT_API unsigned int loot_get_tag_map(loot_db db, char *** const tagMap, size_t //Clear existing array allocation. if (db->extTagMap != nullptr) { - for (size_t i=0, max=db->bashTagMap.size(); i < max; ++i) { + for (size_t i = 0, max = db->bashTagMap.size(); i < max; ++i) { delete[] db->extTagMap[i]; } delete[] db->extTagMap; @@ -410,8 +410,8 @@ LOOT_API unsigned int loot_get_tag_map(loot_db db, char *** const tagMap, size_t return c_error(loot_error_no_mem, e.what()); } - unsigned int UID = 0; try { + unsigned int UID = 0; for (const auto &tag : allTags) { db->bashTagMap.emplace(tag, UID); //Also allocate memory. @@ -502,12 +502,12 @@ LOOT_API unsigned int loot_get_plugin_tags(loot_db db, const char * const plugin try { if (numAdded != 0) { db->extAddedTagIds = new uint32_t[numAdded]; - for (size_t i=0; i < numAdded; i++) + for (size_t i = 0; i < numAdded; i++) db->extAddedTagIds[i] = tagsAddedIDs[i]; } if (numRemoved != 0) { db->extRemovedTagIds = new uint32_t[numRemoved]; - for (size_t i=0; i < numRemoved; i++) + for (size_t i = 0; i < numRemoved; i++) db->extRemovedTagIds[i] = tagsRemovedIDs[i]; } } @@ -535,7 +535,7 @@ LOOT_API unsigned int loot_get_plugin_messages(loot_db db, const char * const pl //Clear existing array allocation. if (db->extMessageArray != nullptr) { - for (size_t i=0; i < db->extMessageArraySize; ++i) { + for (size_t i = 0; i < db->extMessageArraySize; ++i) { delete[] db->extMessageArray[i].message; } delete[] db->extMessageArray; diff --git a/src/backend/error.h b/src/backend/error.h index 5aba022f..658f9954 100644 --- a/src/backend/error.h +++ b/src/backend/error.h @@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License along with LOOT. If not, see . -*/ + */ #ifndef __LOOT_ERROR__ #define __LOOT_ERROR__ @@ -29,7 +29,6 @@ #include namespace loot { - class error : public std::exception { public: error(const unsigned int code_arg, const std::string& what_arg) : _code(code_arg), _what(what_arg) {} @@ -39,26 +38,25 @@ namespace loot { const char * what() const throw() { return _what.c_str(); } /* These must not be changed for API stability. */ - static const unsigned int ok = 0; - static const unsigned int liblo_error = 1; - static const unsigned int path_write_fail = 2; - static const unsigned int path_read_fail = 3; - static const unsigned int condition_eval_fail = 4; - static const unsigned int regex_eval_fail = 5; - static const unsigned int no_mem = 6; - static const unsigned int invalid_args = 7; - static const unsigned int no_tag_map = 8; - static const unsigned int path_not_found = 9; - static const unsigned int no_game_detected = 10; + static const unsigned int ok = 0; + static const unsigned int liblo_error = 1; + static const unsigned int path_write_fail = 2; + static const unsigned int path_read_fail = 3; + static const unsigned int condition_eval_fail = 4; + static const unsigned int regex_eval_fail = 5; + static const unsigned int no_mem = 6; + static const unsigned int invalid_args = 7; + static const unsigned int no_tag_map = 8; + static const unsigned int path_not_found = 9; + static const unsigned int no_game_detected = 10; //11 was subversion_error, and was removed along with svn support. - static const unsigned int git_error = 12; - static const unsigned int windows_error = 13; - static const unsigned int sorting_error = 14; + static const unsigned int git_error = 12; + static const unsigned int windows_error = 13; + static const unsigned int sorting_error = 14; private: - std::string _what; unsigned int _code; + std::string _what; }; - } #endif diff --git a/src/backend/game.cpp b/src/backend/game.cpp index d66ad6d7..9ad392cd 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -262,7 +262,7 @@ namespace loot { } catch (...) {} } - throw e; + throw; } } @@ -478,6 +478,8 @@ namespace loot { ret = lo_create_handle(&gh, LIBLO_GAME_FO3, gamePath.string().c_str()); else if (Id() == Game::fonv) ret = lo_create_handle(&gh, LIBLO_GAME_FNV, gamePath.string().c_str()); + else + ret = LIBLO_ERROR_INVALID_ARGS; if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) { const char * e = nullptr; @@ -559,6 +561,8 @@ namespace loot { ret = lo_create_handle(&gh, LIBLO_GAME_FO3, gamePath.string().c_str()); else if (Id() == Game::fonv) ret = lo_create_handle(&gh, LIBLO_GAME_FNV, gamePath.string().c_str()); + else + ret = LIBLO_ERROR_INVALID_ARGS; if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) { const char * e = nullptr; @@ -635,6 +639,8 @@ namespace loot { ret = lo_create_handle(&gh, LIBLO_GAME_FO3, gamePath.string().c_str()); else if (Id() == Game::fonv) ret = lo_create_handle(&gh, LIBLO_GAME_FNV, gamePath.string().c_str()); + else + ret = LIBLO_ERROR_INVALID_ARGS; if (ret != LIBLO_OK && ret != LIBLO_WARN_LO_MISMATCH) { const char * e = nullptr; diff --git a/src/backend/git.cpp b/src/backend/git.cpp index 3eb298b0..78fc898b 100644 --- a/src/backend/git.cpp +++ b/src/backend/git.cpp @@ -227,7 +227,6 @@ namespace loot { // Clone the remote repository. BOOST_LOG_TRIVIAL(info) << "Repository doesn't exist, cloning the remote repository."; - bool wasEmpty = true; fs::path temp_path = repo_path.string() + ".temp"; if (!fs::is_empty(repo_path)) { // Clear any read-only flags first. @@ -247,7 +246,6 @@ namespace loot { fs::rename(repo_path, temp_path); // Recreate the game folder so that we don't inadvertently cause any other errors (everything past LOOT init assumes it exists). fs::create_directory(repo_path); - wasEmpty = false; } //First set up clone options. diff --git a/src/backend/helpers.cpp b/src/backend/helpers.cpp index a4ce86e6..a0249c07 100644 --- a/src/backend/helpers.cpp +++ b/src/backend/helpers.cpp @@ -133,12 +133,12 @@ namespace loot { //Calculate the CRC of the given file for comparison purposes. uint32_t GetCrc32(const fs::path& filename) { uint32_t chksum = 0; - static const size_t buffer_size = 8192; - char buffer[buffer_size]; loot::ifstream ifile(filename, ios::binary); BOOST_LOG_TRIVIAL(trace) << "Calculating CRC for: " << filename.string(); boost::crc_32_type result; if (ifile) { + static const size_t buffer_size = 8192; + char buffer[buffer_size]; do { ifile.read(buffer, buffer_size); result.process_bytes(buffer, ifile.gcount()); @@ -347,7 +347,6 @@ namespace loot { LPBYTE point = new BYTE[size]; UINT uLen; VS_FIXEDFILEINFO *info; - string ver; GetFileVersionInfo(ToWinWide(file.string()).c_str(), 0, size, point); @@ -382,15 +381,13 @@ namespace loot { #endif } - Version::Version(const Plugin& plugin) { - verString = plugin.Version(); - } + Version::Version(const Plugin& plugin) : verString(plugin.Version()) {} string Version::AsString() const { return verString; } - bool Version::operator < (Version ver) { + bool Version::operator < (const Version& ver) const { //Version string could have a wide variety of formats. Use regex to choose specific comparison types. regex reg1("(\\d+\\.?)+"); //a.b.c.d.e.f.... where the letters are all integers, and 'a' is the shortest possible match. @@ -430,23 +427,23 @@ namespace loot { } } - bool Version::operator > (Version ver) { + bool Version::operator > (const Version& ver) const { return (*this != ver && !(*this < ver)); } - bool Version::operator >= (Version ver) { + bool Version::operator >= (const Version& ver) const { return (*this == ver || *this > ver); } - bool Version::operator <= (Version ver) { + bool Version::operator <= (const Version& ver) const { return (*this == ver || *this < ver); } - bool Version::operator == (Version ver) { + bool Version::operator == (const Version& ver) const { return (verString == ver.AsString()); } - bool Version::operator != (Version ver) { + bool Version::operator != (const Version& ver) const { return !(*this == ver); } } diff --git a/src/backend/helpers.h b/src/backend/helpers.h index 370f0b40..6c7130ee 100644 --- a/src/backend/helpers.h +++ b/src/backend/helpers.h @@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License along with LOOT. If not, see . -*/ + */ #ifndef __LOOT_HELPERS__ #define __LOOT_HELPERS__ @@ -33,7 +33,6 @@ #include namespace loot { - /// Array used to try each of the expressions defined using /// an iteration for each of them. extern const std::regex version_checks[7]; @@ -125,12 +124,12 @@ namespace loot { std::string AsString() const; - bool operator > (Version); - bool operator < (Version); - bool operator >= (Version); - bool operator <= (Version); - bool operator == (Version); - bool operator != (Version); + bool operator > (const Version&) const; + bool operator < (const Version&) const; + bool operator >= (const Version&) const; + bool operator <= (const Version&) const; + bool operator == (const Version&) const; + bool operator != (const Version&) const; }; } diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index 4a69789d..b41d2c4a 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -206,7 +206,7 @@ namespace loot { return (_language == rhs.Language() && boost::iequals(_str, rhs.Str())); } - Message::Message() {} + Message::Message() : _type(Message::say) {} Message::Message(const unsigned int type, const std::string& content, const std::string& condition) : _type(type), ConditionStruct(condition) { @@ -330,8 +330,8 @@ namespace loot { return _name; } - Plugin::Plugin() : enabled(true), priority(0), isMaster(false), crc(0), numOverrideRecords(0), _isPriorityExplicit(false) {} - Plugin::Plugin(const std::string& n) : name(n), enabled(true), priority(0), isMaster(false), crc(0), numOverrideRecords(0), _isPriorityExplicit(false) { + Plugin::Plugin() : enabled(true), _isPriorityExplicit(false), priority(0), isMaster(false), crc(0), numOverrideRecords(0) {} + Plugin::Plugin(const std::string& n) : name(n), enabled(true), _isPriorityExplicit(false), priority(0), isMaster(false), crc(0), numOverrideRecords(0) { //If the name passed ends in '.ghost', that should be trimmed. if (boost::iends_with(name, ".ghost")) name = name.substr(0, name.length() - 6); diff --git a/src/backend/metadata.h b/src/backend/metadata.h index 03efa274..95de1d7f 100644 --- a/src/backend/metadata.h +++ b/src/backend/metadata.h @@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License along with LOOT. If not, see . -*/ + */ #ifndef __LOOT_METADATA__ #define __LOOT_METADATA__ @@ -35,7 +35,6 @@ #include namespace loot { - const unsigned int max_priority = 1000000; class Game; @@ -123,10 +122,9 @@ namespace loot { std::vector Content() const; MessageContent ChooseContent(const unsigned int language) const; - static const unsigned int say = 0; - static const unsigned int warn = 1; + static const unsigned int say = 0; + static const unsigned int warn = 1; static const unsigned int error = 2; - static const unsigned int tag = 3; private: unsigned int _type; std::vector _content; @@ -136,7 +134,7 @@ namespace loot { public: File(); File(const std::string& name, const std::string& display = "", - const std::string& condition = ""); + const std::string& condition = ""); bool operator < (const File& rhs) const; bool operator == (const File& rhs) const; diff --git a/src/gui/app.cpp b/src/gui/app.cpp index b88a69c4..744e9f09 100644 --- a/src/gui/app.cpp +++ b/src/gui/app.cpp @@ -122,7 +122,7 @@ namespace loot { // LootState member functions //--------------------------- - LootState::LootState() : _currentGame(0), isMidSort(false) {} + LootState::LootState() : isMidSort(false), _currentGame(0) {} void LootState::Init(const std::string& cmdLineGame) { // Do some preliminary locale / UTF-8 support setup here, in case the settings file reading requires it. diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index 21ab6d6e..de229831 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -776,7 +776,7 @@ namespace loot { wasChanged = true; } else - throw e; + throw; } // Now regenerate the JS-side masterlist data if the masterlist was changed. diff --git a/src/gui/handler.h b/src/gui/handler.h index 9c47c0c6..29cce50c 100644 --- a/src/gui/handler.h +++ b/src/gui/handler.h @@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License along with LOOT. If not, see . -*/ + */ #ifndef __LOOT_GUI_HANDLER__ #define __LOOT_GUI_HANDLER__ @@ -36,18 +36,17 @@ #include namespace loot { - class Handler : public CefMessageRouterBrowserSide::Handler { public: Handler(); // Called due to cefQuery execution in binding.html. virtual bool OnQuery(CefRefPtr browser, - CefRefPtr frame, - int64 query_id, - const CefString& request, - bool persistent, - CefRefPtr callback) OVERRIDE; + CefRefPtr frame, + int64 query_id, + const CefString& request, + bool persistent, + CefRefPtr callback) OVERRIDE; private: void OpenReadme(); void OpenLogLocation(); @@ -63,7 +62,7 @@ namespace loot { // Handle queries with input arguments. bool HandleComplexQuery(CefRefPtr browser, - CefRefPtr frame, + CefRefPtr frame, YAML::Node& request, CefRefPtr callback); @@ -74,8 +73,8 @@ namespace loot { void SaveFilterState(const std::string& filterId, const std::string& value); std::string ApplyUserEdits(const YAML::Node& pluginMetadata); - YAML::Node Handler::GenerateDerivedMetadata(const std::string& pluginName); - YAML::Node Handler::GenerateDerivedMetadata(const Plugin& file, const Plugin& masterlist, const Plugin& userlist); + YAML::Node GenerateDerivedMetadata(const std::string& pluginName); + YAML::Node GenerateDerivedMetadata(const Plugin& file, const Plugin& masterlist, const Plugin& userlist); void CopyToClipboard(const std::string& text); void SendProgressUpdate(CefRefPtr frame, const std::string& message); @@ -84,10 +83,10 @@ namespace loot { }; class LootHandler : public CefClient, - public CefDisplayHandler, - public CefLifeSpanHandler, - public CefLoadHandler, - public CefRequestHandler { + public CefDisplayHandler, + public CefLifeSpanHandler, + public CefLoadHandler, + public CefRequestHandler { public: LootHandler(); ~LootHandler(); @@ -102,13 +101,13 @@ namespace loot { virtual CefRefPtr GetLoadHandler() OVERRIDE; virtual bool OnProcessMessageReceived(CefRefPtr browser, - CefProcessId source_process, - CefRefPtr message) OVERRIDE; + CefProcessId source_process, + CefRefPtr message) OVERRIDE; // CefDisplayHandler methods //-------------------------- virtual void OnTitleChange(CefRefPtr browser, - const CefString& title) OVERRIDE; + const CefString& title) OVERRIDE; // CefLifeSpanHandler methods //--------------------------- @@ -119,23 +118,22 @@ namespace loot { // CefLoadHandler methods //----------------------- virtual void OnLoadError(CefRefPtr browser, - CefRefPtr frame, - ErrorCode errorCode, - const CefString& errorText, - const CefString& failedUrl) OVERRIDE; + CefRefPtr frame, + ErrorCode errorCode, + const CefString& errorText, + const CefString& failedUrl) OVERRIDE; // CefRequestHandler methods //-------------------------- - virtual CefRefPtr GetRequestHandler() OVERRIDE{ return this; } - virtual bool OnBeforeBrowse(CefRefPtr< CefBrowser > browser, - CefRefPtr< CefFrame > frame, - CefRefPtr< CefRequest > request, - bool is_redirect) OVERRIDE; + virtual bool OnBeforeBrowse(CefRefPtr< CefBrowser > browser, + CefRefPtr< CefFrame > frame, + CefRefPtr< CefRequest > request, + bool is_redirect) OVERRIDE; // Request that all existing browser windows close. void CloseAllBrowsers(bool force_close); diff --git a/src/gui/main_win.cpp b/src/gui/main_win.cpp index 7e8656c5..74983e47 100644 --- a/src/gui/main_win.cpp +++ b/src/gui/main_win.cpp @@ -144,4 +144,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd boost::filesystem::remove_all(boost::filesystem::current_path() / "pdf.dll"); return 0; -} \ No newline at end of file + +#ifdef _WIN32 +} +#endif \ No newline at end of file