Skip to content

Commit

Permalink
Work around std::filesystem being unavailable on mac w/ warnings
Browse files Browse the repository at this point in the history
The version of the macOS sdk we're using doesn't implement it,
 see more detailed in-code comment included in this commit
  • Loading branch information
bluebandit21 committed Mar 11, 2024
1 parent d8373f3 commit d701bde
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/Etterna/Screen/Others/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "Etterna/Actor/Gameplay/Player.h"
#include "Etterna/Models/NoteData/NoteDataUtil.h"
#include "Etterna/Singletons/ReplayManager.h"
#include "Etterna/Screen/Others/ScreenPrompt.h"
#include "Etterna/Screen/Others/ScreenPrompt.h"

#include <filesystem>
#include <algorithm>
Expand Down Expand Up @@ -484,12 +484,12 @@ ScreenSelectMusic::Input(const InputEventPlus& input)
if (CachePackForRanking(GAMESTATE->m_sLastSongGroup))
return true;
} else {
// most likely hovering a non pack section
// most likely hovering a non pack section
}
} else {
if (CachePackForRanking(GAMESTATE->m_pCurSong->m_sGroupName))
return true;
}
}
} else if (bHoldingCtrl &&
input.DeviceI.button == KEY_BACK &&
input.type == IET_FIRST_PRESS && m_MusicWheel.IsSettled()) {
Expand Down Expand Up @@ -950,11 +950,11 @@ ScreenSelectMusic::ChangeSteps(PlayerNumber pn, int dir)
void
ScreenSelectMusic::HandleMessage(const Message& msg)
{
if (msg == Message_FavoritesUpdated) {
if (msg == Message_FavoritesUpdated) {
// this makes the favorite icon appear if the wheel isnt moving
if (m_MusicWheel.IsSettled()) {
m_MusicWheel.RebuildWheelItems(0);
}
}
}

ScreenWithMenuElements::HandleMessage(msg);
Expand Down Expand Up @@ -1143,6 +1143,12 @@ ScreenSelectMusic::HandleScreenMessage(const ScreenMessage& SM)
void
ScreenSelectMusic::OnConfirmSongDeletion()
{
//Temporary hacky workaround -- std::filesystem is unavailable before the macOS 10.15 sdk, and we're currently using an old sdk for backwards compatibility.
//Do nothing until this is properly implemented
#if defined(__APPLE__)
#warning "ScreenSelectMusic::OnConfirmSongDeletion is unimplemented for mac target!"
Locator::getLogger()->warn("Deleting songs unimplemented on macOS! (ScreenSelectMusic::OnConfirmSongDeletion)");
#else
auto* deletedSong = m_pSongAwaitingDeletionConfirmation;
if (!deletedSong) {
Locator::getLogger()->warn("Attempted to delete a null song (ScreenSelectMusic::OnConfirmSongDeletion)");
Expand All @@ -1155,14 +1161,14 @@ ScreenSelectMusic::OnConfirmSongDeletion()
const std::filesystem::path songDir = std::filesystem::u8path(p);

// flush the deleted song from any caches
SONGMAN->UnlistSong(deletedSong);

SONGMAN->UnlistSong(deletedSong);

// stop the music because this holds a file handle
SOUND->StopMusic();
SOUND->Flush();
SOUND->Flush();

// refresh the song list
m_MusicWheel.ReloadSongList(false, "");
m_MusicWheel.ReloadSongList(false, "");

// delete the song directory from disk
Locator::getLogger()->info("Deleting song directory: {}", songDir.generic_string());
Expand All @@ -1177,11 +1183,12 @@ ScreenSelectMusic::OnConfirmSongDeletion()
Locator::getLogger()->error("There was an error while trying to remove "
"the song directory {} - {}",
songDir.generic_string(),
e.what());
e.what());
}
m_pSongAwaitingDeletionConfirmation = nullptr;
m_pSongAwaitingDeletionConfirmation = nullptr;

MESSAGEMAN->Broadcast("DeletedCurrentSong");
#endif
}

bool
Expand Down Expand Up @@ -1382,7 +1389,7 @@ ScreenSelectMusic::AfterMusicChange()
GAMESTATE->m_pCurSteps.Set(nullptr);
if (GAMESTATE->m_SortOrder == SORT_GROUP) {
// when hovering groups, set group to the hovered one
GAMESTATE->m_sLastSongGroup = m_MusicWheel.GetSelectedSection();
GAMESTATE->m_sLastSongGroup = m_MusicWheel.GetSelectedSection();
}
if (b_PreviewNoteFieldIsActive)
// if previewnotefield we are moving out of a pack
Expand Down Expand Up @@ -1602,15 +1609,15 @@ ScreenSelectMusic::PauseSampleMusic()
// us we didnt really pause anything (wow who would have thought)
GAMESTATE->SetPaused(success && pMusic->m_bPaused);
});
}

}

bool
ScreenSelectMusic::DeleteCurrentSong()
ScreenSelectMusic::DeleteCurrentSong()
{
Song* songToDelete = GAMESTATE->m_pCurSong;

if (songToDelete != nullptr && PREFSMAN->m_bAllowSongDeletion.Get()) {
m_pSongAwaitingDeletionConfirmation = songToDelete;
m_pSongAwaitingDeletionConfirmation = songToDelete;

ScreenPrompt::s_bMustResetInputRedirAtClose = true;
ScreenPrompt::Prompt(SM_ConfirmDeleteSong,
Expand Down Expand Up @@ -1749,8 +1756,8 @@ ScreenSelectMusic::AddCurrentChartToActivePlaylist()
GAMESTATE->m_pCurSong->GetDisplayMainTitle().c_str(),
SONGMAN->activeplaylist.c_str()));
return true;
}

}

bool
ScreenSelectMusic::CachePackForRanking(const std::string& pack)
{
Expand Down Expand Up @@ -2044,7 +2051,7 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
{
p->PlayCurrentSongSampleMusic(true, BArg(1), BArg(2));
return 0;
}
}
static int DeleteCurrentSong(T* p, lua_State* L)
{
lua_pushboolean(L, p->DeleteCurrentSong());
Expand Down Expand Up @@ -2079,15 +2086,15 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
{
lua_pushboolean(L, p->AddCurrentChartToActivePlaylist());
return 1;
}
static int CachePackForRanking(T* p, lua_State* L)
}
static int CachePackForRanking(T* p, lua_State* L)
{
if (lua_isnoneornil(L, 1)) {
lua_pushboolean(
L,
p->CachePackForRanking(p->GetMusicWheel()->GetSelectedSection()));
p->CachePackForRanking(p->GetMusicWheel()->GetSelectedSection()));
} else {
lua_pushboolean(L, p->CachePackForRanking(SArg(1)));
lua_pushboolean(L, p->CachePackForRanking(SArg(1)));
}

return 1;
Expand Down

0 comments on commit d701bde

Please sign in to comment.