juk3n/fluffypublic Fork
⑂ 9c36b11
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Merge pull request #6 from Juk3n/5-adding-the-game-with-command-fluffy-add-game_name-local_pathUnverified

5 adding the game with command fluffy add game name local path
Adrian Duraj committed 2024-06-15T12:12:02+02:00 Browse files
9c36b11 parents: 4cdcc77 523550e
modified CMakeLists.txt +5 -4
@@ -1,11 +1,14 @@
11 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)
25
36 include(FetchContent)
47
58 set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
69 FetchContent_Declare(ftxui
710 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
8- GIT_TAG v5.0.0
11+ GIT_TAG v4.0.0
912 )
1013 FetchContent_MakeAvailable(ftxui)
1114 if(NOT ftxui_POPULATED)
@@ -13,10 +16,8 @@ if(NOT ftxui_POPULATED)
1316 add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
1417 endif()
1518
16-project(fluffy LANGUAGES CXX VERSION 1.0.0)
1719
18-set(CMAKE_CXX_STANDARD 20)
19-set(CMAKE_CXX_STANDARD_REQUIRED True)
20+
2021
2122
2223 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(ftxui9 FetchContent_Declare(ftxui
7 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui10 GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
8- GIT_TAG v5.0.011+ 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 +44 -8
@@ -43,22 +43,54 @@ void execute_sql_command(sqlite3* database, std::string command) {
4343 }
4444 }
4545
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) {
4847 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 + "\");";
5149 execute_sql_command(database, command);
5250 }
5351
5452 void initialize_database(sqlite3* database) {
5553 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!", "");
5856 printMessage("Database Initialized");
5957 }
6058
61-int main() {
59+void handleCommand(int argc, char const *argv[], sqlite3* database) {
60+ std::string command{};
61+ switch (argc) {
62+ case 2:
63+ command = argv[1];
64+ if (command == "show") {
65+ for (const auto& [game, path] : games) {
66+ std::cout << game << ": " << path << std::endl;
67+ }
68+ }
69+ break;
70+ case 4:
71+ command = argv[1];
72+ if (command == "add") {
73+ std::string gameName{ argv[2] };
74+ auto localPath = std::filesystem::path(argv[3]);
75+ std::string globalPath = std::filesystem::absolute(localPath).lexically_normal().string();
76+
77+ std::string temp{};
78+ for (const auto a : globalPath) {
79+ if (a != ' ') {
80+ temp += a;
81+ }
82+ else {
83+ temp += "\' \'";
84+ }
85+ }
86+
87+ addGame(database, games.size() + 1, gameName, temp);
88+ }
89+ break;
90+ }
91+}
92+
93+int main(int argc, char const *argv[]) {
6294 bool newCreation = not std::filesystem::exists("data.db");
6395
6496 char* messageError;
@@ -91,13 +123,17 @@ int main() {
91123 const unsigned char* gameName = sqlite3_column_text(stmt, 1);
92124 const unsigned char* gamePath = sqlite3_column_text(stmt, 2);
93125
94- std::cout << gameName << ": " << gamePath << std::endl;
95126 std::string name{reinterpret_cast<const char*>(gameName)};
96127 std::string path{reinterpret_cast<const char*>(gamePath)};
97128 games[name] = path;
98129 }
99130 sqlite3_finalize(stmt);
100131
132+ if (argc > 1) {
133+ handleCommand(argc, argv, database);
134+ return 0;
135+ }
136+
101137 int exit_id = games.size();
102138 int choice = 0;
103139 do {
@@ -43,22 +43,54 @@ 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+void handleCommand(int argc, char const *argv[], sqlite3* database) {
60+ std::string command{};
61+ switch (argc) {
62+ case 2:
63+ command = argv[1];
64+ if (command == "show") {
65+ for (const auto& [game, path] : games) {
66+ std::cout << game << ": " << path << std::endl;
67+ }
68+ }
69+ break;
70+ case 4:
71+ command = argv[1];
72+ if (command == "add") {
73+ std::string gameName{ argv[2] };
74+ auto localPath = std::filesystem::path(argv[3]);
75+ std::string globalPath = std::filesystem::absolute(localPath).lexically_normal().string();
76+
77+ std::string temp{};
78+ for (const auto a : globalPath) {
79+ if (a != ' ') {
80+ temp += a;
81+ }
82+ else {
83+ temp += "\' \'";
84+ }
85+ }
86+
87+ addGame(database, games.size() + 1, gameName, temp);
88+ }
89+ break;
90+ }
91+}
92+
93+int main(int argc, char const *argv[]) {
62 bool newCreation = not std::filesystem::exists("data.db");94 bool newCreation = not std::filesystem::exists("data.db");
63 95
64 char* messageError;96 char* messageError;
@@ -91,13 +123,17 @@ int main() {
91 const unsigned char* gameName = sqlite3_column_text(stmt, 1);123 const unsigned char* gameName = sqlite3_column_text(stmt, 1);
92 const unsigned char* gamePath = sqlite3_column_text(stmt, 2);124 const unsigned char* gamePath = sqlite3_column_text(stmt, 2);
93 125
94- std::cout << gameName << ": " << gamePath << std::endl;
95 std::string name{reinterpret_cast<const char*>(gameName)};126 std::string name{reinterpret_cast<const char*>(gameName)};
96 std::string path{reinterpret_cast<const char*>(gamePath)};127 std::string path{reinterpret_cast<const char*>(gamePath)};
97 games[name] = path;128 games[name] = path;
98 }129 }
99 sqlite3_finalize(stmt);130 sqlite3_finalize(stmt);
100 131
132+ if (argc > 1) {
133+ handleCommand(argc, argv, database);
134+ return 0;
135+ }
136+
101 int exit_id = games.size();137 int exit_id = games.size();
102 int choice = 0;138 int choice = 0;
103 do {139 do {