diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index b50f05253..b7d4b4c44 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -200,12 +200,12 @@ const std::string FileData::getMediaDirectory() const std::string FileData::getMediafilePath(std::string subdirectory, std::string mediatype) const { - const char* extList[2] = { ".png", ".jpg" }; + std::vector extList = { ".png", ".jpg" }; // Look for an image file in the media directory. std::string tempPath = getMediaDirectory() + mSystemName + "/" + subdirectory + "/" + getDisplayName(); - for (int i = 0; i < 2; i++) { + for (int i = 0; i < extList.size(); i++) { std::string mediaPath = tempPath + extList[i]; if (Utils::FileSystem::exists(mediaPath)) return mediaPath; @@ -214,7 +214,7 @@ const std::string FileData::getMediafilePath(std::string subdirectory, std::stri // No media found in the media directory, so look // for local art as well (if configured to do so). if (Settings::getInstance()->getBool("ROMDirGameMedia")) { - for (int i = 0; i < 2; i++) { + for (int i = 0; i < extList.size(); i++) { std::string localMediaPath = mEnvData->mStartPath + "/images/" + getDisplayName() + "-" + mediatype + extList[i]; if (Utils::FileSystem::exists(localMediaPath)) @@ -273,11 +273,11 @@ const std::string FileData::getThumbnailPath() const const std::string FileData::getVideoPath() const { - const char* extList[5] = { ".avi", ".mkv", ".mov", ".mp4", ".wmv" }; + std::vector extList = { ".avi", ".mkv", ".mov", ".mp4", ".wmv" }; std::string tempPath = getMediaDirectory() + mSystemName + "/videos/" + getDisplayName(); // Look for media in the media directory. - for (int i = 0; i < 5; i++) { + for (int i = 0; i < extList.size(); i++) { std::string mediaPath = tempPath + extList[i]; if (Utils::FileSystem::exists(mediaPath)) return mediaPath; @@ -287,7 +287,7 @@ const std::string FileData::getVideoPath() const // for local art as well (if configured to do so). if (Settings::getInstance()->getBool("ROMDirGameMedia")) { - for (int i = 0; i < 5; i++) { + for (int i = 0; i < extList.size(); i++) { std::string localMediaPath = mEnvData->mStartPath + "/videos/" + getDisplayName() + "-video" + extList[i]; if (Utils::FileSystem::exists(localMediaPath)) diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index 1469f3373..4e5cd3103 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -26,10 +26,6 @@ enum FileType { PLACEHOLDER = 3 }; -// Used for loading/saving gamelist.xml. -const char* fileTypeToString(FileType type); -FileType stringToFileType(const char* str); - // A tree node that holds information for a file. class FileData { diff --git a/es-app/src/Gamelist.cpp b/es-app/src/Gamelist.cpp index ad40b0cf5..6315f1ccb 100644 --- a/es-app/src/Gamelist.cpp +++ b/es-app/src/Gamelist.cpp @@ -116,13 +116,13 @@ void parseGamelist(SystemData* system) std::string relativeTo = system->getStartPath(); bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles"); - const char* tagList[2] = { "game", "folder" }; + std::vector tagList = { "game", "folder" }; FileType typeList[2] = { GAME, FOLDER }; for (int i = 0; i < 2; i++) { - const char* tag = tagList[i]; + std::string tag = tagList[i]; FileType type = typeList[i]; - for (pugi::xml_node fileNode = root.child(tag); fileNode; fileNode = - fileNode.next_sibling(tag)) { + for (pugi::xml_node fileNode = root.child(tag.c_str()); fileNode; fileNode = + fileNode.next_sibling(tag.c_str())) { const std::string path = Utils::FileSystem::resolveRelativePath(fileNode.child("path").text().get(), relativeTo, false); @@ -179,10 +179,10 @@ void parseGamelist(SystemData* system) } void addFileDataNode(pugi::xml_node& parent, const FileData* file, - const char* tag, SystemData* system) + const std::string& tag, SystemData* system) { // Create game and add to parent node. - pugi::xml_node newNode = parent.append_child(tag); + pugi::xml_node newNode = parent.append_child(tag.c_str()); // Write metadata. file->metadata.appendToXML(newNode, true, system->getStartPath()); @@ -258,7 +258,7 @@ void updateGamelist(SystemData* system) // Iterate through all files, checking if they're already in the XML file. for (std::vector::const_iterator fit = files.cbegin(); fit != files.cend(); ++fit) { - const char* tag = ((*fit)->getType() == GAME) ? "game" : "folder"; + const std::string tag = ((*fit)->getType() == GAME) ? "game" : "folder"; // Do not touch if it wasn't changed and is not flagged for deletion. if (!(*fit)->metadata.wasChanged() && !(*fit)->getDeletionFlag()) @@ -266,8 +266,8 @@ void updateGamelist(SystemData* system) // Check if the file already exists in the XML file. // If it does, remove the entry before adding it back. - for (pugi::xml_node fileNode = root.child(tag); fileNode; - fileNode = fileNode.next_sibling(tag)) { + for (pugi::xml_node fileNode = root.child(tag.c_str()); fileNode; + fileNode = fileNode.next_sibling(tag.c_str())) { pugi::xml_node pathNode = fileNode.child("path"); if (!pathNode) { LOG(LogError) << "<" << tag << "> node contains no child"; diff --git a/es-app/src/PlatformId.cpp b/es-app/src/PlatformId.cpp index 602f695af..d66bfd027 100644 --- a/es-app/src/PlatformId.cpp +++ b/es-app/src/PlatformId.cpp @@ -9,10 +9,11 @@ #include "PlatformId.h" #include +#include namespace PlatformIds { - const char* PlatformNames[PLATFORM_COUNT + 1] = { + std::vector PlatformNames = { "unknown", // Nothing set. "3do", @@ -124,20 +125,20 @@ namespace PlatformIds "invalid" }; - PlatformId getPlatformId(const char* str) + PlatformId getPlatformId(const std::string& str) { - if (str == nullptr) + if (str == "") return PLATFORM_UNKNOWN; for (unsigned int i = 1; i < PLATFORM_COUNT; i++) { - if (strcmp(PlatformNames[i], str) == 0) + if (PlatformNames[i] == str) return (PlatformId)i; } return PLATFORM_UNKNOWN; } - const char* getPlatformName(PlatformId id) + const std::string getPlatformName(PlatformId id) { return PlatformNames[id]; } diff --git a/es-app/src/PlatformId.h b/es-app/src/PlatformId.h index 84fbbe257..f9ed9f8de 100644 --- a/es-app/src/PlatformId.h +++ b/es-app/src/PlatformId.h @@ -9,6 +9,8 @@ #ifndef ES_APP_PLATFORM_ID_H #define ES_APP_PLATFORM_ID_H +#include + namespace PlatformIds { enum PlatformId : unsigned int { @@ -123,8 +125,8 @@ namespace PlatformIds PLATFORM_COUNT }; - PlatformId getPlatformId(const char* str); - const char* getPlatformName(PlatformId id); + PlatformId getPlatformId(const std::string& str); + const std::string getPlatformName(PlatformId id); } #endif // ES_APP_PLATFORM_ID_H diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index e87687931..dd8f008ab 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -206,7 +206,7 @@ void SystemData::indexAllGameFilters(const FileData* folder) } } -std::vector readList(const std::string& str, const char* delims = " \t\r\n,") +std::vector readList(const std::string& str, const std::string& delims = " \t\r\n,") { std::vector ret; @@ -285,11 +285,11 @@ bool SystemData::loadConfig() cmd = system.child("command").text().get(); // Platform ID list - const char* platformList = system.child("platform").text().get(); + const std::string platformList = system.child("platform").text().get(); std::vector platformStrs = readList(platformList); std::vector platformIds; for (auto it = platformStrs.cbegin(); it != platformStrs.cend(); it++) { - const char* str = it->c_str(); + std::string str = it->c_str(); PlatformIds::PlatformId platformId = PlatformIds::getPlatformId(str); if (platformId == PlatformIds::PLATFORM_IGNORE) { @@ -301,7 +301,7 @@ bool SystemData::loadConfig() // If there appears to be an actual platform ID supplied // but it didn't match the list, generate a warning. - if (str != nullptr && str[0] != '\0' && platformId == PlatformIds::PLATFORM_UNKNOWN) + if (str != "" && platformId == PlatformIds::PLATFORM_UNKNOWN) LOG(LogWarning) << "Unknown platform for system \"" << name << "\" (platform \"" << str << "\" from list \"" << platformList << "\")"; else if (platformId != PlatformIds::PLATFORM_UNKNOWN) diff --git a/es-app/src/VolumeControl.cpp b/es-app/src/VolumeControl.cpp index cdd595fd3..27f43e300 100644 --- a/es-app/src/VolumeControl.cpp +++ b/es-app/src/VolumeControl.cpp @@ -26,11 +26,11 @@ // the rest of the volume control code in here compiles and works fine. #if defined(__linux__) #if defined(_RPI_) || defined(_VERO4K_) -const char * VolumeControl::mixerName = "PCM"; +const std::string VolumeControl::mixerName = "PCM"; #else -const char * VolumeControl::mixerName = "Master"; +const std::string VolumeControl::mixerName = "Master"; #endif -const char * VolumeControl::mixerCard = "default"; +const std::string VolumeControl::mixerCard = "default"; #endif std::weak_ptr VolumeControl::sInstance; @@ -113,19 +113,19 @@ void VolumeControl::init() if (mixerHandle == nullptr) { // Allow user to override the AudioCard and AudioDevice in es_settings.cfg. #if defined(_RPI_) - mixerCard = Settings::getInstance()->getString("AudioCard").c_str(); - mixerName = Settings::getInstance()->getString("AudioDevice").c_str(); + mixerCard = Settings::getInstance()->getString("AudioCard"); + mixerName = Settings::getInstance()->getString("AudioDevice"); #endif snd_mixer_selem_id_alloca(&mixerSelemId); // Sets simple-mixer index and name. snd_mixer_selem_id_set_index(mixerSelemId, mixerIndex); - snd_mixer_selem_id_set_name(mixerSelemId, mixerName); + snd_mixer_selem_id_set_name(mixerSelemId, mixerName.c_str()); // Open mixer. if (snd_mixer_open(&mixerHandle, 0) >= 0) { LOG(LogDebug) << "VolumeControl::init() - Opened ALSA mixer"; // Ok, attach to defualt card. - if (snd_mixer_attach(mixerHandle, mixerCard) >= 0) { + if (snd_mixer_attach(mixerHandle, mixerCard.c_str()) >= 0) { LOG(LogDebug) << "VolumeControl::init() - Attached to default card"; // Ok, register simple element class. if (snd_mixer_selem_register(mixerHandle, nullptr, nullptr) >= 0) { @@ -253,7 +253,7 @@ void VolumeControl::deinit() // #error TODO: Not implemented for MacOS yet!!! #elif defined(__linux__) if (mixerHandle != nullptr) { - snd_mixer_detach(mixerHandle, mixerCard); + snd_mixer_detach(mixerHandle, mixerCard.c_str()); snd_mixer_free(mixerHandle); snd_mixer_close(mixerHandle); mixerHandle = nullptr; diff --git a/es-app/src/VolumeControl.h b/es-app/src/VolumeControl.h index 106e01a53..9c28b3aba 100644 --- a/es-app/src/VolumeControl.h +++ b/es-app/src/VolumeControl.h @@ -30,8 +30,8 @@ class VolumeControl #if defined(__APPLE__) // #error TODO: Not implemented for MacOS yet!!! #elif defined(__linux__) - static const char * mixerName; - static const char * mixerCard; + static const std::string mixerName; + static const std::string mixerCard; int mixerIndex; snd_mixer_t* mixerHandle; snd_mixer_elem_t* mixerElem; diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 21e94fb43..792bf87bf 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -938,7 +938,7 @@ void GuiMenu::onSizeChanged() mVersion.setPosition(0, mSize.y() - mVersion.getSize().y()); } -void GuiMenu::addEntry(const char* name, unsigned int color, +void GuiMenu::addEntry(const std::string& name, unsigned int color, bool add_arrow, const std::function& func) { std::shared_ptr font = Font::get(FONT_SIZE_MEDIUM); diff --git a/es-app/src/guis/GuiMenu.h b/es-app/src/guis/GuiMenu.h index 2107680fb..3e5022ad0 100644 --- a/es-app/src/guis/GuiMenu.h +++ b/es-app/src/guis/GuiMenu.h @@ -26,7 +26,7 @@ public: private: void close(bool closeAllWindows); - void addEntry(const char* name, unsigned int color, + void addEntry(const std::string& name, unsigned int color, bool add_arrow, const std::function& func); void addVersionInfo(); diff --git a/es-app/src/guis/GuiScraperMenu.cpp b/es-app/src/guis/GuiScraperMenu.cpp index 094ebe7cf..a3c56a67d 100644 --- a/es-app/src/guis/GuiScraperMenu.cpp +++ b/es-app/src/guis/GuiScraperMenu.cpp @@ -579,7 +579,7 @@ std::queue GuiScraperMenu::getSearches( return queue; } -void GuiScraperMenu::addEntry(const char* name, unsigned int color, +void GuiScraperMenu::addEntry(const std::string& name, unsigned int color, bool add_arrow, const std::function& func) { std::shared_ptr font = Font::get(FONT_SIZE_MEDIUM); diff --git a/es-app/src/guis/GuiScraperMenu.h b/es-app/src/guis/GuiScraperMenu.h index 0b6340e11..70f7bc292 100644 --- a/es-app/src/guis/GuiScraperMenu.h +++ b/es-app/src/guis/GuiScraperMenu.h @@ -37,7 +37,7 @@ private: void pressedStart(); void start(); - void addEntry(const char* name, unsigned int color, + void addEntry(const std::string&, unsigned int color, bool add_arrow, const std::function& func); void openAccountSettings(); void openContentSettings(); diff --git a/es-app/src/guis/GuiScreensaverOptions.cpp b/es-app/src/guis/GuiScreensaverOptions.cpp index 1b2f829fb..74d4d8de4 100644 --- a/es-app/src/guis/GuiScreensaverOptions.cpp +++ b/es-app/src/guis/GuiScreensaverOptions.cpp @@ -15,7 +15,7 @@ #include "guis/GuiMsgBox.h" #include "Settings.h" -GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const char* title) +GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const std::string& title) : GuiSettings(window, title) { // Screensaver timer. diff --git a/es-app/src/guis/GuiScreensaverOptions.h b/es-app/src/guis/GuiScreensaverOptions.h index ee6b3f13e..9423ab6fe 100644 --- a/es-app/src/guis/GuiScreensaverOptions.h +++ b/es-app/src/guis/GuiScreensaverOptions.h @@ -15,7 +15,7 @@ class GuiScreensaverOptions : public GuiSettings { public: - GuiScreensaverOptions(Window* window, const char* title); + GuiScreensaverOptions(Window* window, const std::string& title); private: void openSlideshowScreensaverOptions(); diff --git a/es-app/src/scrapers/ScreenScraper.cpp b/es-app/src/scrapers/ScreenScraper.cpp index 4cc8c1430..656493fff 100644 --- a/es-app/src/scrapers/ScreenScraper.cpp +++ b/es-app/src/scrapers/ScreenScraper.cpp @@ -143,7 +143,7 @@ pugi::xml_node find_child_by_attribute_list(const pugi::xml_node& node_parent, { for (auto _val : attribute_values) { for (pugi::xml_node node : node_parent.children(node_name.c_str())) { - if (strcmp(node.attribute(attribute_name.c_str()).value(), _val.c_str()) == 0) + if (node.attribute(attribute_name.c_str()).value() == _val) return node; } } diff --git a/es-app/src/views/gamelist/BasicGameListView.h b/es-app/src/views/gamelist/BasicGameListView.h index f4aa9daac..e9fd71282 100644 --- a/es-app/src/views/gamelist/BasicGameListView.h +++ b/es-app/src/views/gamelist/BasicGameListView.h @@ -30,7 +30,7 @@ public: virtual FileData* getLastEntry() override; virtual FileData* getFirstGameEntry() override; - virtual const char* getName() const override { return "basic"; } + virtual std::string getName() const override { return "basic"; } virtual std::vector getHelpPrompts() override; virtual void launch(FileData* game) override; diff --git a/es-app/src/views/gamelist/DetailedGameListView.cpp b/es-app/src/views/gamelist/DetailedGameListView.cpp index cf3cc9104..0b085b1d0 100644 --- a/es-app/src/views/gamelist/DetailedGameListView.cpp +++ b/es-app/src/views/gamelist/DetailedGameListView.cpp @@ -150,9 +150,9 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr& them initMDLabels(); std::vector labels = getMDLabels(); assert(labels.size() == 8); - const char* lblElements[8] = { - "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher", - "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount" + std::vector lblElements = { + "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher", + "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount" }; for (unsigned int i = 0; i < labels.size(); i++) @@ -161,9 +161,9 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr& them initMDValues(); std::vector values = getMDValues(); assert(values.size() == 8); - const char* valElements[8] = { - "md_rating", "md_releasedate", "md_developer", "md_publisher", - "md_genre", "md_players", "md_lastplayed", "md_playcount" + std::vector valElements = { + "md_rating", "md_releasedate", "md_developer", "md_publisher", + "md_genre", "md_players", "md_lastplayed", "md_playcount" }; for (unsigned int i = 0; i < values.size(); i++) diff --git a/es-app/src/views/gamelist/DetailedGameListView.h b/es-app/src/views/gamelist/DetailedGameListView.h index d53a46000..f0b0202a9 100644 --- a/es-app/src/views/gamelist/DetailedGameListView.h +++ b/es-app/src/views/gamelist/DetailedGameListView.h @@ -21,7 +21,7 @@ public: virtual void onShow() override; virtual void onThemeChanged(const std::shared_ptr& theme) override; - virtual const char* getName() const override { return "detailed"; } + virtual std::string getName() const override { return "detailed"; } virtual void launch(FileData* game) override; protected: diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index 69b1fae53..9b302021a 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -282,7 +282,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr& theme) initMDLabels(); std::vector labels = getMDLabels(); assert(labels.size() == 8); - const char* lblElements[8] = { + std::vector lblElements = { "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher", "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount" }; @@ -293,7 +293,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr& theme) initMDValues(); std::vector values = getMDValues(); assert(values.size() == 8); - const char* valElements[8] = { + std::vector valElements = { "md_rating", "md_releasedate", "md_developer", "md_publisher", "md_genre", "md_players", "md_lastplayed", "md_playcount" }; diff --git a/es-app/src/views/gamelist/GridGameListView.h b/es-app/src/views/gamelist/GridGameListView.h index a07f7f71a..610d9d5f7 100644 --- a/es-app/src/views/gamelist/GridGameListView.h +++ b/es-app/src/views/gamelist/GridGameListView.h @@ -36,7 +36,7 @@ public: virtual bool input(InputConfig* config, Input input) override; - virtual const char* getName() const override { return "grid"; } + virtual std::string getName() const override { return "grid"; } virtual std::vector getHelpPrompts() override; virtual void launch(FileData* game) override; diff --git a/es-app/src/views/gamelist/IGameListView.h b/es-app/src/views/gamelist/IGameListView.h index 29c09faf5..369882556 100644 --- a/es-app/src/views/gamelist/IGameListView.h +++ b/es-app/src/views/gamelist/IGameListView.h @@ -52,7 +52,7 @@ public: virtual void remove(FileData* game, bool deleteFile) = 0; virtual void removeMedia(FileData* game) = 0; - virtual const char* getName() const = 0; + virtual std::string getName() const = 0; virtual void launch(FileData* game) = 0; virtual HelpStyle getHelpStyle() override; diff --git a/es-app/src/views/gamelist/VideoGameListView.cpp b/es-app/src/views/gamelist/VideoGameListView.cpp index 4983be869..8f0d0c105 100644 --- a/es-app/src/views/gamelist/VideoGameListView.cpp +++ b/es-app/src/views/gamelist/VideoGameListView.cpp @@ -175,9 +175,9 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr& theme) initMDLabels(); std::vector labels = getMDLabels(); assert(labels.size() == 8); - const char* lblElements[8] = { - "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher", - "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount" + std::vector lblElements = { + "md_lbl_rating", "md_lbl_releasedate", "md_lbl_developer", "md_lbl_publisher", + "md_lbl_genre", "md_lbl_players", "md_lbl_lastplayed", "md_lbl_playcount" }; for (unsigned int i = 0; i < labels.size(); i++) @@ -186,9 +186,9 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr& theme) initMDValues(); std::vector values = getMDValues(); assert(values.size() == 8); - const char* valElements[8] = { - "md_rating", "md_releasedate", "md_developer", "md_publisher", - "md_genre", "md_players", "md_lastplayed", "md_playcount" + std::vector valElements = { + "md_rating", "md_releasedate", "md_developer", "md_publisher", + "md_genre", "md_players", "md_lastplayed", "md_playcount" }; for (unsigned int i = 0; i < values.size(); i++) diff --git a/es-app/src/views/gamelist/VideoGameListView.h b/es-app/src/views/gamelist/VideoGameListView.h index 32d0b771f..4f6988d1f 100644 --- a/es-app/src/views/gamelist/VideoGameListView.h +++ b/es-app/src/views/gamelist/VideoGameListView.h @@ -24,7 +24,7 @@ public: virtual void onShow() override; virtual void onThemeChanged(const std::shared_ptr& theme) override; - virtual const char* getName() const override { return "video"; } + virtual std::string getName() const override { return "video"; } virtual void launch(FileData* game) override; protected: diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index d26659845..8da686e11 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -355,7 +355,7 @@ void GuiComponent::setHiddenValue(const std::string& /*value*/) { } -void GuiComponent::textInput(const char* text) +void GuiComponent::textInput(const std::string& text) { for (auto iter = mChildren.cbegin(); iter != mChildren.cend(); iter++) (*iter)->textInput(text); diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index a01e9896c..249267aee 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -41,7 +41,7 @@ public: GuiComponent(Window* window); virtual ~GuiComponent(); - virtual void textInput(const char* text); + virtual void textInput(const std::string& text); // Called when input is received. // Return true if the input is consumed, false if diff --git a/es-core/src/HttpReq.cpp b/es-core/src/HttpReq.cpp index 6b698a65e..ca8822071 100644 --- a/es-core/src/HttpReq.cpp +++ b/es-core/src/HttpReq.cpp @@ -190,7 +190,7 @@ std::string HttpReq::getContent() const return mContent.str(); } -void HttpReq::onError(const char* msg) +void HttpReq::onError(const std::string& msg) { mErrorMsg = msg; } diff --git a/es-core/src/HttpReq.h b/es-core/src/HttpReq.h index afa7d0747..85ea2b7f6 100644 --- a/es-core/src/HttpReq.h +++ b/es-core/src/HttpReq.h @@ -67,7 +67,7 @@ public: private: static size_t write_content(void* buff, size_t size, size_t nmemb, void* req_ptr); - void onError(const char* msg); + void onError(const std::string& msg); // God dammit libcurl why can't you have some way to check the status of an // individual handle why do I have to handle ALL messages at once. diff --git a/es-core/src/ImageIO.h b/es-core/src/ImageIO.h index afa548bdd..60c83b03b 100644 --- a/es-core/src/ImageIO.h +++ b/es-core/src/ImageIO.h @@ -15,8 +15,8 @@ class ImageIO { public: - static std::vector loadFromMemoryRGBA32(const unsigned char * data, - const size_t size, size_t & width, size_t & height); + static std::vector loadFromMemoryRGBA32(const unsigned char* data, + const size_t size, size_t& width, size_t& height); static void flipPixelsVert(unsigned char* imagePx, const size_t& width, const size_t& height); }; diff --git a/es-core/src/MameNames.cpp b/es-core/src/MameNames.cpp index f1c19705a..d7d74300c 100644 --- a/es-core/src/MameNames.cpp +++ b/es-core/src/MameNames.cpp @@ -16,6 +16,7 @@ #include "utils/StringUtil.h" #include "Log.h" +#include #include #include @@ -171,19 +172,5 @@ const bool MameNames::isDevice(const std::string& _deviceName) const bool MameNames::find(std::vector devices, const std::string& name) { - size_t start = 0; - size_t end = devices.size(); - - while (start < end) { - const size_t index = (start + end) / 2; - const int compare = strcmp(devices[index].c_str(), name.c_str()); - - if (compare < 0) - start = index + 1; - else if (compare > 0) - end = index; - else - return true; - } - return false; + return (std::find(devices.begin(), devices.end(), name) != devices.end()); } diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 3b9ad8d55..60b765922 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -198,13 +198,13 @@ std::map mVariables; -std::string resolvePlaceholders(const char* in) +std::string resolvePlaceholders(const std::string& in) { - std::string inStr(in); + if (in.empty()) + return in; - if (inStr.empty()) - return inStr; - - const size_t variableBegin = inStr.find("${"); - const size_t variableEnd = inStr.find("}", variableBegin); + const size_t variableBegin = in.find("${"); + const size_t variableEnd = in.find("}", variableBegin); if ((variableBegin == std::string::npos) || (variableEnd == std::string::npos)) - return inStr; + return in; - std::string prefix = inStr.substr(0, variableBegin); - std::string replace = inStr.substr(variableBegin + 2, variableEnd - (variableBegin + 2)); - std::string suffix = resolvePlaceholders(inStr.substr(variableEnd + 1).c_str()); + std::string prefix = in.substr(0, variableBegin); + std::string replace = in.substr(variableBegin + 2, variableEnd - (variableBegin + 2)); + std::string suffix = resolvePlaceholders(in.substr(variableEnd + 1).c_str()); return prefix + mVariables[replace] + suffix; } @@ -377,7 +375,7 @@ void ThemeData::parseViews(const pugi::xml_node& root) if (!node.attribute("name")) throw error << "View missing \"name\" attribute!"; - const char* delim = " \t\r\n,"; + const std::string delim = " \t\r\n,"; const std::string nameAttr = node.attribute("name").as_string(); size_t prevOff = nameAttr.find_first_not_of(delim, 0); size_t off = nameAttr.find_first_of(delim, prevOff); @@ -410,7 +408,7 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view) if (elemTypeIt == sElementMap.cend()) throw error << "Unknown element of type \"" << node.name() << "\"!"; - const char* delim = " \t\r\n,"; + const std::string delim = " \t\r\n,"; const std::string nameAttr = node.attribute("name").as_string(); size_t prevOff = nameAttr.find_first_not_of(delim, 0); size_t off = nameAttr.find_first_of(delim, prevOff); @@ -502,7 +500,7 @@ void ThemeData::parseElement(const pugi::xml_node& root, break; } case COLOR: { - element.properties[node.name()] = getHexColor(str.c_str()); + element.properties[node.name()] = getHexColor(str); break; } case FLOAT: { diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index b5967215f..01f51ffd4 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -131,7 +131,7 @@ void Window::deinit() Renderer::deinit(); } -void Window::textInput(const char* text) +void Window::textInput(const std::string& text) { if (peekGui()) peekGui()->textInput(text); @@ -530,19 +530,18 @@ void Window::setHelpPrompts(const std::vector& prompts, const HelpSt std::sort(addPrompts.begin(), addPrompts.end(), [](const HelpPrompt& a, const HelpPrompt& b) -> bool { - static const char* map[] = { - "up/down/left/right", - "up/down", - "left/right", - "a", "b", "x", "y", "l", "r", - "start", "select", - nullptr + static const std::vector map = { + "up/down/left/right", + "up/down", + "left/right", + "a", "b", "x", "y", "l", "r", + "start", "select" }; int i = 0; int aVal = 0; int bVal = 0; - while (map[i] != nullptr) { + while (i < map.size()) { if (a.first == map[i]) aVal = i; if (b.first == map[i]) diff --git a/es-core/src/Window.h b/es-core/src/Window.h index 00cf5bd22..259e41b6e 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -65,9 +65,9 @@ public: GuiComponent* peekGui(); inline int getGuiStackSize() { return static_cast(mGuiStack.size()); } - void textInput(const char* text); + void textInput(const std::string& text); void input(InputConfig* config, Input input); - void logInput(InputConfig * config, Input input); + void logInput(InputConfig* config, Input input); void update(int deltaTime); void render(); diff --git a/es-core/src/components/AnimatedImageComponent.cpp b/es-core/src/components/AnimatedImageComponent.cpp index 36498bcea..9f655aa61 100644 --- a/es-core/src/components/AnimatedImageComponent.cpp +++ b/es-core/src/components/AnimatedImageComponent.cpp @@ -24,7 +24,7 @@ void AnimatedImageComponent::load(const AnimationDef* def) assert(def->frameCount >= 1); for (size_t i = 0; i < def->frameCount; i++) { - if (def->frames[i].path != nullptr && + if (def->frames[i].path != "" && !ResourceManager::getInstance()->fileExists(def->frames[i].path)) { LOG(LogError) << "Missing animation frame " << i << " (\"" << def->frames[i].path << "\")"; diff --git a/es-core/src/components/AnimatedImageComponent.h b/es-core/src/components/AnimatedImageComponent.h index 268a52ae7..09f604b29 100644 --- a/es-core/src/components/AnimatedImageComponent.h +++ b/es-core/src/components/AnimatedImageComponent.h @@ -14,7 +14,7 @@ class ImageComponent; struct AnimationFrame { - const char* path; + std::string path; int time; }; diff --git a/es-core/src/components/ComponentGrid.cpp b/es-core/src/components/ComponentGrid.cpp index 2b65caa7f..12eaa3e67 100644 --- a/es-core/src/components/ComponentGrid.cpp +++ b/es-core/src/components/ComponentGrid.cpp @@ -358,7 +358,7 @@ void ComponentGrid::render(const Transform4x4f& parentTrans) } } -void ComponentGrid::textInput(const char* text) +void ComponentGrid::textInput(const std::string& text) { const GridEntry* selectedEntry = getCellAt(mCursor); if (selectedEntry != nullptr && selectedEntry->canFocus) diff --git a/es-core/src/components/ComponentGrid.h b/es-core/src/components/ComponentGrid.h index b62d89e6a..0deb455fc 100644 --- a/es-core/src/components/ComponentGrid.h +++ b/es-core/src/components/ComponentGrid.h @@ -48,7 +48,7 @@ public: unsigned int border = GridFlags::BORDER_NONE, GridFlags::UpdateType updateType = GridFlags::UPDATE_ALWAYS); - void textInput(const char* text) override; + void textInput(const std::string& text) override; bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; void render(const Transform4x4f& parentTrans) override; diff --git a/es-core/src/components/ComponentList.cpp b/es-core/src/components/ComponentList.cpp index 73379c046..8f0b04c6a 100644 --- a/es-core/src/components/ComponentList.cpp +++ b/es-core/src/components/ComponentList.cpp @@ -357,7 +357,7 @@ void ComponentList::updateElementSize(const ComponentListRow& row) (*it)->setSize(width, (*it)->getSize().y()); } -void ComponentList::textInput(const char* text) +void ComponentList::textInput(const std::string& text) { if (!size()) return; diff --git a/es-core/src/components/ComponentList.h b/es-core/src/components/ComponentList.h index 2d57739d0..7cf17458a 100644 --- a/es-core/src/components/ComponentList.h +++ b/es-core/src/components/ComponentList.h @@ -62,7 +62,7 @@ public: void addRow(const ComponentListRow& row, bool setCursorHere = false); - void textInput(const char* text) override; + void textInput(const std::string& text) override; bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; void render(const Transform4x4f& parentTrans) override; diff --git a/es-core/src/components/HelpComponent.cpp b/es-core/src/components/HelpComponent.cpp index eaf97965a..57d051792 100644 --- a/es-core/src/components/HelpComponent.cpp +++ b/es-core/src/components/HelpComponent.cpp @@ -22,7 +22,7 @@ #define ICON_TEXT_SPACING 8 // Space between [icon] and [text] (px). #define ENTRY_SPACING 16 // Space between [text] and next [icon] (px). -static const std::map ICON_PATH_MAP { +static const std::map ICON_PATH_MAP { { "up/down", ":/help/dpad_updown.svg" }, { "left/right", ":/help/dpad_leftright.svg" }, { "up/down/left/right", ":/help/dpad_all.svg" }, diff --git a/es-core/src/components/TextEditComponent.cpp b/es-core/src/components/TextEditComponent.cpp index ec8b0b6bb..3fb6e9058 100644 --- a/es-core/src/components/TextEditComponent.cpp +++ b/es-core/src/components/TextEditComponent.cpp @@ -62,7 +62,7 @@ std::string TextEditComponent::getValue() const return mText; } -void TextEditComponent::textInput(const char* text) +void TextEditComponent::textInput(const std::string& text) { if (mEditing) { mCursorRepeatDir = 0; @@ -75,7 +75,7 @@ void TextEditComponent::textInput(const char* text) } else { mText.insert(mCursor, text); - mCursor += static_cast(strlen(text)); + mCursor += static_cast(text.size()); } } diff --git a/es-core/src/components/TextEditComponent.h b/es-core/src/components/TextEditComponent.h index 123894dcb..69688224c 100644 --- a/es-core/src/components/TextEditComponent.h +++ b/es-core/src/components/TextEditComponent.h @@ -21,7 +21,7 @@ class TextEditComponent : public GuiComponent public: TextEditComponent(Window* window); - void textInput(const char* text) override; + void textInput(const std::string& text) override; bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; void render(const Transform4x4f& parentTrans) override; diff --git a/es-core/src/guis/GuiComplexTextEditPopup.cpp b/es-core/src/guis/GuiComplexTextEditPopup.cpp index 7c8c02018..5c4696d56 100644 --- a/es-core/src/guis/GuiComplexTextEditPopup.cpp +++ b/es-core/src/guis/GuiComplexTextEditPopup.cpp @@ -25,12 +25,12 @@ GuiComplexTextEditPopup::GuiComplexTextEditPopup( const std::string& initValue, const std::function& okCallback, bool multiLine, - const char* acceptBtnText, - const char* saveConfirmationText, - const char* loadBtnText, - const char* loadBtnHelpText, - const char* clearBtnText, - const char* clearBtnHelpText, + const std::string& acceptBtnText, + const std::string& saveConfirmationText, + const std::string& loadBtnText, + const std::string& loadBtnHelpText, + const std::string& clearBtnText, + const std::string& clearBtnHelpText, bool hideCancelButton) : GuiComponent(window), mHelpStyle(helpstyle), diff --git a/es-core/src/guis/GuiComplexTextEditPopup.h b/es-core/src/guis/GuiComplexTextEditPopup.h index 5eb562eec..7725f2db3 100644 --- a/es-core/src/guis/GuiComplexTextEditPopup.h +++ b/es-core/src/guis/GuiComplexTextEditPopup.h @@ -30,12 +30,12 @@ public: const std::string& initValue, const std::function& okCallback, bool multiLine, - const char* acceptBtnText = "OK", - const char* saveConfirmationText = "SAVE CHANGES?", - const char* loadBtnText = "LOAD", - const char* loadBtnHelpText = "load default", - const char* clearBtnText = "CLEAR", - const char* clearBtnHelpText = "clear", + const std::string& acceptBtnText = "OK", + const std::string& saveConfirmationText = "SAVE CHANGES?", + const std::string& loadBtnText = "LOAD", + const std::string& loadBtnHelpText = "load default", + const std::string& clearBtnText = "CLEAR", + const std::string& clearBtnHelpText = "clear", bool hideCancelButton = false); bool input(InputConfig* config, Input input) override; diff --git a/es-core/src/guis/GuiDetectDevice.cpp b/es-core/src/guis/GuiDetectDevice.cpp index 9fb134fee..1dc7768cf 100644 --- a/es-core/src/guis/GuiDetectDevice.cpp +++ b/es-core/src/guis/GuiDetectDevice.cpp @@ -66,7 +66,7 @@ GuiDetectDevice::GuiDetectDevice( mGrid.setEntry(mMsg1, Vector2i(0, 2), false, true); - const char* msg2str = firstRun ? + const std::string msg2str = firstRun ? "PRESS ESC TO SKIP (OR F4 TO QUIT AT ANY TIME)." : "PRESS ESC TO CANCEL."; mMsg2 = std::make_shared(mWindow, msg2str, Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); diff --git a/es-core/src/guis/GuiInputConfig.cpp b/es-core/src/guis/GuiInputConfig.cpp index bf357b300..f818e6ef2 100644 --- a/es-core/src/guis/GuiInputConfig.cpp +++ b/es-core/src/guis/GuiInputConfig.cpp @@ -16,10 +16,10 @@ #include "Window.h" struct InputConfigStructure { - const char* name; + std::string name; const bool skippable; - const char* dispName; - const char* icon; + std::string dispName; + std::string icon; }; static const int inputCount = 22; @@ -355,7 +355,7 @@ bool GuiInputConfig::assign(Input input, int inputId) // generate an error. (If it's the same as what it was before, allow it.) if (mTargetConfig->getMappedTo(input).size() > 0 && !mTargetConfig->isMappedTo(GUI_INPUT_CONFIG_LIST[inputId].name, input) && - strcmp(GUI_INPUT_CONFIG_LIST[inputId].name, "HotKeyEnable") != 0) { + GUI_INPUT_CONFIG_LIST[inputId].name != "HotKeyEnable") { error(mMappings.at(inputId), "Already mapped!"); return false; } diff --git a/es-core/src/guis/GuiTextEditPopup.cpp b/es-core/src/guis/GuiTextEditPopup.cpp index 899321f54..7bb23a046 100644 --- a/es-core/src/guis/GuiTextEditPopup.cpp +++ b/es-core/src/guis/GuiTextEditPopup.cpp @@ -21,8 +21,8 @@ GuiTextEditPopup::GuiTextEditPopup( const std::string& initValue, const std::function& okCallback, bool multiLine, - const char* acceptBtnText, - const char* saveConfirmationText) + const std::string& acceptBtnText, + const std::string& saveConfirmationText) : GuiComponent(window), mHelpStyle(helpstyle), mBackground(window, ":/graphics/frame.png"), diff --git a/es-core/src/guis/GuiTextEditPopup.h b/es-core/src/guis/GuiTextEditPopup.h index 0853c78ae..c5bd1eb1a 100644 --- a/es-core/src/guis/GuiTextEditPopup.h +++ b/es-core/src/guis/GuiTextEditPopup.h @@ -26,8 +26,8 @@ public: const std::string& initValue, const std::function& okCallback, bool multiLine, - const char* acceptBtnText = "OK", - const char* saveConfirmationText = "SAVE CHANGES?"); + const std::string& acceptBtnText = "OK", + const std::string& saveConfirmationText = "SAVE CHANGES?"); bool input(InputConfig* config, Input input) override; void onSizeChanged() override; diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index 692e44317..0ca4a7038 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -55,7 +55,7 @@ namespace Renderer #if !defined(NDEBUG) #define GL_CHECK_ERROR(Function) (Function, _GLCheckError(#Function)) - static void _GLCheckError(const char* _funcName) + static void _GLCheckError(const std::string& _funcName) { const GLenum errorCode = glGetError(); diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index ae6e4e26b..a132b5055 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -569,7 +569,7 @@ TextCache* Font::buildTextCache( if (character == '\n') { y += getHeight(lineSpacing); x = offset[0] + (xLen != 0 ? getNewlineStartOffset(text, - (const unsigned int)cursor /* cursor is already advanced */, + static_cast(cursor) /* cursor is already advanced */, xLen, alignment) : 0); continue; } diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index d9296b365..486531ffd 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -15,6 +15,7 @@ #include "renderers/Renderer.h" #include "resources/ResourceManager.h" #include "ThemeData.h" + #include #include FT_FREETYPE_H #include @@ -82,7 +83,7 @@ public: int getSize() const; inline const std::string& getPath() const { return mPath; } - inline static const char* getDefaultPath() { return FONT_PATH_REGULAR; } + inline static std::string getDefaultPath() { return FONT_PATH_REGULAR; } static std::shared_ptr getFromTheme(const ThemeData::ThemeElement* elem, unsigned int properties, const std::shared_ptr& orig); diff --git a/es-core/src/resources/TextureResource.cpp b/es-core/src/resources/TextureResource.cpp index 60b7038cd..b68f84f7b 100644 --- a/es-core/src/resources/TextureResource.cpp +++ b/es-core/src/resources/TextureResource.cpp @@ -81,7 +81,7 @@ void TextureResource::initFromMemory(const char* data, size_t length) assert(mTextureData != nullptr); mTextureData->releaseVRAM(); mTextureData->releaseRAM(); - mTextureData->initImageFromMemory((const unsigned char*)data, length); + mTextureData->initImageFromMemory(reinterpret_cast(data), length); // Get the size from the texture data. mSize = Vector2i(static_cast(mTextureData->width()), static_cast(mTextureData->height())); diff --git a/es-core/src/utils/StringUtil.cpp b/es-core/src/utils/StringUtil.cpp index 4a36908f8..cd7637c5d 100644 --- a/es-core/src/utils/StringUtil.cpp +++ b/es-core/src/utils/StringUtil.cpp @@ -208,7 +208,7 @@ namespace Utils std::string removeParenthesis(const std::string& _string) { - static const char remove[4] = { '(', ')', '[', ']' }; + static std::vector remove = { '(', ')', '[', ']' }; std::string string = _string; size_t start; size_t end; @@ -217,9 +217,9 @@ namespace Utils while (!done) { done = true; - for (size_t i = 0; i < sizeof(remove); i += 2) { - end = string.find_first_of(remove[i + 1]); - start = string.find_last_of( remove[i + 0], end); + for (size_t i = 0; i < remove.size(); i += 2) { + end = string.find_first_of(remove[i + 1]); + start = string.find_last_of(remove[i + 0], end); if ((start != std::string::npos) && (end != std::string::npos)) { string.erase(start, end - start + 1);