From 5c9a44dfb8b5d1590c66ec74cfeb1b7ca092f036 Mon Sep 17 00:00:00 2001 From: Kosmas Raptis Date: Wed, 28 Jul 2021 18:51:44 +0300 Subject: [PATCH] Add theme menu as start of theme support --- Includes/findThemes.cpp | 36 ++++++++++++++++++++++++++++++++++++ Includes/findThemes.h | 12 ++++++++++++ Includes/menu.cpp | 30 ++++++++++++++++++++++++++++++ Includes/menu.hpp | 9 +++++++++ Makefile | 2 +- sampleconfig.json | 5 +++++ 6 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 Includes/findThemes.cpp create mode 100644 Includes/findThemes.h diff --git a/Includes/findThemes.cpp b/Includes/findThemes.cpp new file mode 100644 index 0000000..4016592 --- /dev/null +++ b/Includes/findThemes.cpp @@ -0,0 +1,36 @@ +// +// Created by kosmas on 28/7/21. +// + +#include "findThemes.h" +#include "outputLine.h" +#ifdef NXDK +#include +#endif + +void findThemes(std::string const& path, MenuThemes *list) { + std::string workPath = path; + if (workPath.back() != '\\') { + workPath += '\\'; + } + std::string searchMask = workPath + "*"; + + WIN32_FIND_DATA findFileData; + HANDLE hFind; + std::string tmp; + + hFind = FindFirstFile(searchMask.c_str(), &findFileData); + if (hFind == INVALID_HANDLE_VALUE) { + outputLine("FindFirstHandle() failed!\n"); + } + + do { + if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + std::string type = path.substr(path.find(".") + 1); + if (type == "nevoxtheme") { + tmp = path + findFileData.cFileName; + list->addNode(std::make_shared(findFileData.cFileName, tmp)); + } + } + } while (FindNextFile(hFind, &findFileData) != 0); +} diff --git a/Includes/findThemes.h b/Includes/findThemes.h new file mode 100644 index 0000000..33dfc29 --- /dev/null +++ b/Includes/findThemes.h @@ -0,0 +1,12 @@ +// +// Created by kosmas on 28/7/21. +// + +#ifndef NEVOLUTIONX_FINDTHEMES_H +#define NEVOLUTIONX_FINDTHEMES_H + +#include "menu.hpp" + +void findThemes(std::string const& path, MenuThemes *list); + +#endif //NEVOLUTIONX_FINDTHEMES_H diff --git a/Includes/menu.cpp b/Includes/menu.cpp index 1bc5091..82ffa06 100644 --- a/Includes/menu.cpp +++ b/Includes/menu.cpp @@ -4,6 +4,7 @@ #include "outputLine.h" #include "findXBE.h" +#include "findThemes.h" #include "settingsMenu.hpp" #ifdef NXDK #include @@ -130,6 +131,31 @@ void MenuXbe::execute(Menu *menu) { } } +/****************************************************************************************** + MenuThemes +******************************************************************************************/ + +MenuThemes::MenuThemes(MenuNode *parent, std::string const& label, std::string const& path) : + MenuNode(parent, label), path(path) { + findThemes(path, this); + +} + +MenuThemes::~MenuThemes() { + +} + +void MenuThemes::execute(Menu *menu) { + if (menu->getCurrentMenu() != this) { + menu->setCurrentMenu(this); + } + else { + if (childNodes.size() > selected) { + this->childNodes.at(selected)->execute(menu); + } + } +} + /****************************************************************************************** MenuLaunch ******************************************************************************************/ @@ -189,6 +215,10 @@ Menu::Menu(const Config &config, Renderer &renderer) : renderer(renderer), rootN std::shared_ptr newNode = std::make_shared(currentMenu, e["label"]); this->rootNode.addNode(newNode); } + else if (!static_cast(e["type"]).compare("themes")) { + std::shared_ptr newNode = std::make_shared(currentMenu, e["label"], e["path"]); + this->rootNode.addNode(newNode); + } } } diff --git a/Includes/menu.hpp b/Includes/menu.hpp index 91f8dd1..dd984f0 100644 --- a/Includes/menu.hpp +++ b/Includes/menu.hpp @@ -54,6 +54,15 @@ class MenuXbe : public MenuNode { std::string path; }; +class MenuThemes : public MenuNode { +public: + MenuThemes(MenuNode *parent, std::string const& label, std::string const& path); + ~MenuThemes(); + void execute(Menu *menu); +protected: + std::string path; +}; + class MenuLaunch : public MenuItem { public: MenuLaunch(std::string const& label, std::string const& path); diff --git a/Makefile b/Makefile index 818cb83..45b2df7 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ INCDIR = $(CURDIR)/Includes RESOURCEDIR = $(CURDIR)/Resources SRCS += $(CURDIR)/main.cpp $(INCDIR)/outputLine.cpp \ - $(INCDIR)/subsystems.cpp $(INCDIR)/findXBE.cpp \ + $(INCDIR)/subsystems.cpp $(INCDIR)/findXBE.cpp $(INCDIR)/findThemes.cpp \ $(INCDIR)/renderer.cpp $(INCDIR)/font.cpp $(INCDIR)/networking.cpp \ $(INCDIR)/ftpServer.cpp $(INCDIR)/ftpConnection.cpp \ $(INCDIR)/menu.cpp $(INCDIR)/langMenu.cpp $(INCDIR)/timeMenu.cpp \ diff --git a/sampleconfig.json b/sampleconfig.json index 4e6b178..8915b25 100644 --- a/sampleconfig.json +++ b/sampleconfig.json @@ -43,6 +43,11 @@ { "label": "Some stupid submenu", "type": "submenu" + }, + { + "label": "Themes", + "type": "themes", + "path": "F:\\Themes" } ] }