Skip to content

Commit

Permalink
randy from futurama
Browse files Browse the repository at this point in the history
  • Loading branch information
RayDeeUx committed Sep 28, 2024
1 parent e7d95ae commit 61acc25
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/MenuLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class $modify(MenuLayerMLHook, MenuLayer) {
if (!useCustomSongs) toWriteToFile = toWriteToFile.append(fmt::format(" # Song: {} by {}", songName, songArtist));
auto test = utils::file::readString(m_fields->blacklistFile);
if (test.isErr()) return log::info("error reading blacklist file!");
auto result = geode::utils::file::writeString(m_fields->blacklistFile, test.unwrap().append(fmt::format("{}", toWriteToFile)));
auto result = geode::utils::file::writeString(m_fields->blacklistFile, test.unwrap().append(fmt::format("{}\n", toWriteToFile)));
if (result.isErr()) return log::info("error blacklisting song {}", currentSong);
m_fields->songManager.clearSongs();
Utils::populateVector(useCustomSongs);
Expand Down
8 changes: 8 additions & 0 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ void SongManager::setCalledOnce(bool value) {
bool SongManager::getCalledOnce() {
return m_calledOnce;
}

void SongManager::addToBlacklist(std::string song = SongManager::get().getCurrentSong()) {
m_blacklist.push_back(song);
}

std::vector<std::string> SongManager::getBlacklist() {
return m_blacklist;
}
3 changes: 3 additions & 0 deletions src/SongManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SongManager {
void update(float);
bool getCalledOnce();
void setCalledOnce(bool);
void addToBlacklist(std::string);
std::vector<std::string> getBlacklist();

private:
SongManager();
Expand All @@ -26,4 +28,5 @@ class SongManager {
std::string m_currentSong;
bool m_isMenuLoop;
bool m_calledOnce = false;
std::vector<std::string> m_blacklist;
};
7 changes: 4 additions & 3 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,13 @@ void Utils::populateVector(bool customSongs) {
*/

std::vector<std::string> blacklist {};
std::vector<std::string> otherBlacklist = SongManager::get().getBlacklist();

if (auto blacklistPath = std::filesystem::exists(configDir / R"(blacklist.txt)")) {
std::ifstream blacklistFile((configDir / R"(blacklist.txt)"));
std::string blacklistString;
while (std::getline(blacklistFile, blacklistString)) {
if (blacklistString.starts_with('#')) continue;
if (blacklistString.starts_with('#') || blacklistString.empty()) continue;
blacklist.push_back(blacklistString);
geode::log::info("{}", blacklistString);
}
Expand All @@ -236,7 +237,7 @@ void Utils::populateVector(bool customSongs) {
const auto& filePath = file.path();
auto filePathString = filePath.string();

if (!Utils::isSupportedExtension(filePathString) || std::ranges::find(blacklist, filePathString) != blacklist.end() || std::ranges::find(blacklist, filePath.filename().string()) != blacklist.end()) continue;
if (!Utils::isSupportedExtension(filePathString) || std::ranges::find(blacklist, filePathString) != blacklist.end() || std::ranges::find(otherBlacklist, filePathString) != otherBlacklist.end()) continue;

geode::log::debug("Adding custom song: {}", filePath.filename().string());
SongManager::get().addSong(filePathString);
Expand All @@ -261,7 +262,7 @@ void Utils::populateVector(bool customSongs) {

std::string songPath = downloadManager->pathForSong(song->m_songID);

if (!Utils::isSupportedExtension(songPath) || std::ranges::find(blacklist, songPath) != blacklist.end()) continue;
if (!Utils::isSupportedExtension(songPath) || std::ranges::find(blacklist, songPath) != blacklist.end() || std::ranges::find(otherBlacklist, songPath) != otherBlacklist.end()) continue;

geode::log::debug("Adding Newgrounds/Music Library song: {}", songPath);
SongManager::get().addSong(songPath);
Expand Down

0 comments on commit 61acc25

Please sign in to comment.