juk3n/fluffypublic Fork
⑂ 1fbb4dc
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.

46 prevent from duplication when adding new game (#47)Unverified

* moved add game code to separate function in application class

* added game name duplication validation

---------

Co-authored-by: Adrian Duraj <adrian.duraj@onmail.com>
Adrian Duraj committed 2026-09-21T07:39:14+02:00 Browse files
1fbb4dc parent: 21b1737
modified app/include/fluffyApplication.hpp +1 -1
@@ -36,7 +36,7 @@ fluffy commands:\n\
3636 show Show all games added to library\n\
3737 rm <game_name> Remove game from a library"};
3838
39- auto addGame(Database& database, std::string name, std::string path) -> void;
39+ auto addGame(std::string name, std::string path) -> void;
4040
4141 auto removeGame(Database& database, std::string name) -> void;
4242
@@ -36,7 +36,7 @@ fluffy commands:\n\
36 show Show all games added to library\n\36 show Show all games added to library\n\
37 rm <game_name> Remove game from a library"};37 rm <game_name> Remove game from a library"};
38 38
39- auto addGame(Database& database, std::string name, std::string path) -> void;39+ auto addGame(std::string name, std::string path) -> void;
40 40
41 auto removeGame(Database& database, std::string name) -> void;41 auto removeGame(Database& database, std::string name) -> void;
42 42
modified app/src/fluffyApplication.cpp +25 -14
@@ -31,20 +31,9 @@ auto FluffyApplication::handleCommand(
3131 gameRepository->deleteGame(gameName);
3232 }
3333 else if (command == "add") {
34- std::string gameName{arguments[0]};
35- auto localPath = std::filesystem::path(arguments[1]);
36- std::string globalPath =
37- std::filesystem::absolute(localPath).lexically_normal().string();
38- std::string temp{};
39- for (const auto a : globalPath) {
40- if (a != ' ') {
41- temp += a;
42- } else {
43- temp += "\' \'";
44- }
45- }
46-
47- gameRepository->addGame(gameName, temp);
34+ std::string gameName = arguments[0];
35+ std::string gamePath = arguments[1];
36+ this->addGame(gameName, gamePath);
4837 }
4938 else if (command == "play") {
5039 std::string gameName{arguments[0]};
@@ -61,6 +50,28 @@ auto FluffyApplication::handleCommand(
6150 }
6251 }
6352
53+auto FluffyApplication::addGame(std::string name, std::string path) -> void {
54+ std::string gameName{name};
55+ auto localPath = std::filesystem::path(path);
56+ std::string globalPath =
57+ std::filesystem::absolute(localPath).lexically_normal().string();
58+ std::string temp{};
59+ for (const auto a : globalPath) {
60+ if (a != ' ') {
61+ temp += a;
62+ } else {
63+ temp += "\' \'";
64+ }
65+ }
66+ Game currentGame = gameRepository->getGameByName(gameName);
67+ if (currentGame.getName().length() != 0) {
68+ output->printMessage("Game already exist");
69+ }
70+ else {
71+ gameRepository->addGame(gameName, temp);
72+ }
73+
74+}
6475
6576 auto FluffyApplication::handleFlags(std::vector<std::string> flags) -> void {
6677 for (const auto& flag : flags) {
@@ -31,20 +31,9 @@ auto FluffyApplication::handleCommand(
31 gameRepository->deleteGame(gameName);31 gameRepository->deleteGame(gameName);
32 }32 }
33 else if (command == "add") {33 else if (command == "add") {
34- std::string gameName{arguments[0]};34+ std::string gameName = arguments[0];
35- auto localPath = std::filesystem::path(arguments[1]);35+ std::string gamePath = arguments[1];
36- std::string globalPath =36+ this->addGame(gameName, gamePath);
37- std::filesystem::absolute(localPath).lexically_normal().string();
38- std::string temp{};
39- for (const auto a : globalPath) {
40- if (a != ' ') {
41- temp += a;
42- } else {
43- temp += "\' \'";
44- }
45- }
46-
47- gameRepository->addGame(gameName, temp);
48 }37 }
49 else if (command == "play") {38 else if (command == "play") {
50 std::string gameName{arguments[0]};39 std::string gameName{arguments[0]};
@@ -61,6 +50,28 @@ auto FluffyApplication::handleCommand(
61 }50 }
62 }51 }
63 52
53+auto FluffyApplication::addGame(std::string name, std::string path) -> void {
54+ std::string gameName{name};
55+ auto localPath = std::filesystem::path(path);
56+ std::string globalPath =
57+ std::filesystem::absolute(localPath).lexically_normal().string();
58+ std::string temp{};
59+ for (const auto a : globalPath) {
60+ if (a != ' ') {
61+ temp += a;
62+ } else {
63+ temp += "\' \'";
64+ }
65+ }
66+ Game currentGame = gameRepository->getGameByName(gameName);
67+ if (currentGame.getName().length() != 0) {
68+ output->printMessage("Game already exist");
69+ }
70+ else {
71+ gameRepository->addGame(gameName, temp);
72+ }
73+
74+}
64 75
65 auto FluffyApplication::handleFlags(std::vector<std::string> flags) -> void {76 auto FluffyApplication::handleFlags(std::vector<std::string> flags) -> void {
66 for (const auto& flag : flags) {77 for (const auto& flag : flags) {