added basic adding
c520d85 parent: 4cdcc77 modified
CMakeLists.txt +5 -4 | @@ -1,11 +1,14 @@ | ||
| 1 | 1 | cmake_minimum_required(VERSION 3.14) |
| 2 | +set(CMAKE_CXX_STANDARD 20) | |
| 3 | +set(CMAKE_CXX_STANDARD_REQUIRED True) | |
| 4 | +project(fluffy LANGUAGES CXX VERSION 1.0.0) | |
| 2 | 5 | |
| 3 | 6 | include(FetchContent) |
| 4 | 7 | |
| 5 | 8 | set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) |
| 6 | 9 | FetchContent_Declare(ftxui |
| 7 | 10 | GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui |
| 8 | - GIT_TAG v5.0.0 | |
| 11 | + GIT_TAG v4.0.0 | |
| 9 | 12 | ) |
| 10 | 13 | FetchContent_MakeAvailable(ftxui) |
| 11 | 14 | if(NOT ftxui_POPULATED) |
| @@ -13,10 +16,8 @@ if(NOT ftxui_POPULATED) | ||
| 13 | 16 | add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 14 | 17 | endif() |
| 15 | 18 | |
| 16 | -project(fluffy LANGUAGES CXX VERSION 1.0.0) | |
| 17 | 19 | |
| 18 | -set(CMAKE_CXX_STANDARD 20) | |
| 19 | -set(CMAKE_CXX_STANDARD_REQUIRED True) | |
| 20 | + | |
| 20 | 21 | |
| 21 | 22 | |
| 22 | 23 | find_package(SQLite3 REQUIRED) |
| @@ -1,11 +1,14 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.14) | 1 | cmake_minimum_required(VERSION 3.14) |
| 2 | +set(CMAKE_CXX_STANDARD 20) | ||
| 3 | +set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
| 4 | +project(fluffy LANGUAGES CXX VERSION 1.0.0) | ||
| 2 | 5 | ||
| 3 | include(FetchContent) | 6 | include(FetchContent) |
| 4 | 7 | ||
| 5 | set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) | 8 | set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) |
| 6 | FetchContent_Declare(ftxui | 9 | FetchContent_Declare(ftxui |
| 7 | GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui | 10 | GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui |
| 8 | - GIT_TAG v5.0.0 | 11 | + GIT_TAG v4.0.0 |
| 9 | ) | 12 | ) |
| 10 | FetchContent_MakeAvailable(ftxui) | 13 | FetchContent_MakeAvailable(ftxui) |
| 11 | if(NOT ftxui_POPULATED) | 14 | if(NOT ftxui_POPULATED) |
| @@ -13,10 +16,8 @@ if(NOT ftxui_POPULATED) | |||
| 13 | add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL) | 16 | add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 14 | endif() | 17 | endif() |
| 15 | 18 | ||
| 16 | -project(fluffy LANGUAGES CXX VERSION 1.0.0) | ||
| 17 | 19 | ||
| 18 | -set(CMAKE_CXX_STANDARD 20) | 20 | + |
| 19 | -set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | find_package(SQLite3 REQUIRED) | 23 | find_package(SQLite3 REQUIRED) |
modified
src/main.cpp +29 -7 | @@ -43,22 +43,20 @@ void execute_sql_command(sqlite3* database, std::string command) { | ||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | -void addGame(sqlite3* database, std::string name, std::string path) { | |
| 47 | - static int val = 1; | |
| 46 | +void addGame(sqlite3* database, int id, std::string name, std::string path) { | |
| 48 | 47 | std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; |
| 49 | - command += std::to_string(val) + ", '" + name + "', \"" + path + "\");"; | |
| 50 | - val++; | |
| 48 | + command += std::to_string(id) + ", '" + name + "', \"" + path + "\");"; | |
| 51 | 49 | execute_sql_command(database, command); |
| 52 | 50 | } |
| 53 | 51 | |
| 54 | 52 | void initialize_database(sqlite3* database) { |
| 55 | 53 | execute_sql_command(database, database_initialization_command); |
| 56 | - addGame(database, "Devastating Fog", ""); | |
| 57 | - addGame(database, "No Pirates Here!", ""); | |
| 54 | + addGame(database, 1, "Devastating Fog", ""); | |
| 55 | + addGame(database, 2, "No Pirates Here!", ""); | |
| 58 | 56 | printMessage("Database Initialized"); |
| 59 | 57 | } |
| 60 | 58 | |
| 61 | -int main() { | |
| 59 | +int main(int argc, char const *argv[]) { | |
| 62 | 60 | bool newCreation = not std::filesystem::exists("data.db"); |
| 63 | 61 | |
| 64 | 62 | char* messageError; |
| @@ -98,6 +96,30 @@ int main() { | ||
| 98 | 96 | } |
| 99 | 97 | sqlite3_finalize(stmt); |
| 100 | 98 | |
| 99 | + if (argc == 2) { | |
| 100 | + return 0; | |
| 101 | + } | |
| 102 | + | |
| 103 | + if (argc == 4) { | |
| 104 | + std::string command{ argv[1] }; | |
| 105 | + std::string gameName{ argv[2] }; | |
| 106 | + auto localPath = std::filesystem::path(argv[3]); | |
| 107 | + std::string globalPath = std::filesystem::absolute(localPath).string(); | |
| 108 | + | |
| 109 | + std::string temp{}; | |
| 110 | + for (const auto a : globalPath) { | |
| 111 | + if (a != ' ') { | |
| 112 | + temp += a; | |
| 113 | + } | |
| 114 | + else { | |
| 115 | + temp += "\' \'"; | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + addGame(database, games.size() + 1, gameName, temp); | |
| 120 | + return 0; | |
| 121 | + } | |
| 122 | + | |
| 101 | 123 | int exit_id = games.size(); |
| 102 | 124 | int choice = 0; |
| 103 | 125 | do { |
| @@ -43,22 +43,20 @@ void execute_sql_command(sqlite3* database, std::string command) { | |||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | -void addGame(sqlite3* database, std::string name, std::string path) { | 46 | +void addGame(sqlite3* database, int id, std::string name, std::string path) { |
| 47 | - static int val = 1; | ||
| 48 | std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; | 47 | std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; |
| 49 | - command += std::to_string(val) + ", '" + name + "', \"" + path + "\");"; | 48 | + command += std::to_string(id) + ", '" + name + "', \"" + path + "\");"; |
| 50 | - val++; | ||
| 51 | execute_sql_command(database, command); | 49 | execute_sql_command(database, command); |
| 52 | } | 50 | } |
| 53 | 51 | ||
| 54 | void initialize_database(sqlite3* database) { | 52 | void initialize_database(sqlite3* database) { |
| 55 | execute_sql_command(database, database_initialization_command); | 53 | execute_sql_command(database, database_initialization_command); |
| 56 | - addGame(database, "Devastating Fog", ""); | 54 | + addGame(database, 1, "Devastating Fog", ""); |
| 57 | - addGame(database, "No Pirates Here!", ""); | 55 | + addGame(database, 2, "No Pirates Here!", ""); |
| 58 | printMessage("Database Initialized"); | 56 | printMessage("Database Initialized"); |
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | -int main() { | 59 | +int main(int argc, char const *argv[]) { |
| 62 | bool newCreation = not std::filesystem::exists("data.db"); | 60 | bool newCreation = not std::filesystem::exists("data.db"); |
| 63 | 61 | ||
| 64 | char* messageError; | 62 | char* messageError; |
| @@ -98,6 +96,30 @@ int main() { | |||
| 98 | } | 96 | } |
| 99 | sqlite3_finalize(stmt); | 97 | sqlite3_finalize(stmt); |
| 100 | 98 | ||
| 99 | + if (argc == 2) { | ||
| 100 | + return 0; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + if (argc == 4) { | ||
| 104 | + std::string command{ argv[1] }; | ||
| 105 | + std::string gameName{ argv[2] }; | ||
| 106 | + auto localPath = std::filesystem::path(argv[3]); | ||
| 107 | + std::string globalPath = std::filesystem::absolute(localPath).string(); | ||
| 108 | + | ||
| 109 | + std::string temp{}; | ||
| 110 | + for (const auto a : globalPath) { | ||
| 111 | + if (a != ' ') { | ||
| 112 | + temp += a; | ||
| 113 | + } | ||
| 114 | + else { | ||
| 115 | + temp += "\' \'"; | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + addGame(database, games.size() + 1, gameName, temp); | ||
| 120 | + return 0; | ||
| 121 | + } | ||
| 122 | + | ||
| 101 | int exit_id = games.size(); | 123 | int exit_id = games.size(); |
| 102 | int choice = 0; | 124 | int choice = 0; |
| 103 | do { | 125 | do { |