diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-02 19:47:19 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-02 19:47:19 -0500 |
| commit | 5b7bf82edb672d5d5dbd8b1de64532aeec695661 (patch) | |
| tree | 7de8d174a75f06f0f11ed5f3de4e17e8e7912c2c /database.cpp | |
| parent | 13aab8498a0a2d4494a088f1235a0e80c078bdcf (diff) | |
| download | lunatic-5b7bf82edb672d5d5dbd8b1de64532aeec695661.tar.gz lunatic-5b7bf82edb672d5d5dbd8b1de64532aeec695661.tar.bz2 lunatic-5b7bf82edb672d5d5dbd8b1de64532aeec695661.zip | |
Handled games with no images
For games where no images could be downloaded from Steam, which happens if a game has been removed from the store, the bot will now use a default background. This image is copyright Nintendo.
Diffstat (limited to 'database.cpp')
| -rw-r--r-- | database.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
| diff --git a/database.cpp b/database.cpp index 953c217..19ba0e0 100644 --- a/database.cpp +++ b/database.cpp | |||
| @@ -82,6 +82,47 @@ achievement database::getRandomAchievement() const | |||
| 82 | return result; | 82 | return result; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | bool database::doesGameHaveImages(int gameId) const | ||
| 86 | { | ||
| 87 | std::string queryString = "SELECT COUNT(*) FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1"; | ||
| 88 | |||
| 89 | sqlite3_stmt* ppstmt; | ||
| 90 | if (sqlite3_prepare_v2( | ||
| 91 | ppdb_, | ||
| 92 | queryString.c_str(), | ||
| 93 | queryString.length(), | ||
| 94 | &ppstmt, | ||
| 95 | NULL) != SQLITE_OK) | ||
| 96 | { | ||
| 97 | std::string errorMsg = sqlite3_errmsg(ppdb_); | ||
| 98 | sqlite3_finalize(ppstmt); | ||
| 99 | |||
| 100 | throw std::logic_error(errorMsg); | ||
| 101 | } | ||
| 102 | |||
| 103 | if (sqlite3_bind_int(ppstmt, 1, gameId) != SQLITE_OK) | ||
| 104 | { | ||
| 105 | std::string errorMsg = sqlite3_errmsg(ppdb_); | ||
| 106 | sqlite3_finalize(ppstmt); | ||
| 107 | |||
| 108 | throw std::logic_error(errorMsg); | ||
| 109 | } | ||
| 110 | |||
| 111 | if (sqlite3_step(ppstmt) != SQLITE_ROW) | ||
| 112 | { | ||
| 113 | std::string errorMsg = sqlite3_errmsg(ppdb_); | ||
| 114 | sqlite3_finalize(ppstmt); | ||
| 115 | |||
| 116 | throw std::logic_error(errorMsg); | ||
| 117 | } | ||
| 118 | |||
| 119 | int result = sqlite3_column_int(ppstmt, 0); | ||
| 120 | |||
| 121 | sqlite3_finalize(ppstmt); | ||
| 122 | |||
| 123 | return (result > 0); | ||
| 124 | } | ||
| 125 | |||
| 85 | std::string database::getRandomImageForGame(int gameId) const | 126 | std::string database::getRandomImageForGame(int gameId) const |
| 86 | { | 127 | { |
| 87 | std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1"; | 128 | std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1"; |
