//
// MusicDownloadManager::onDownloadSongCompleted from 0x10015685c to 0x1001569c0 (356 bytes)
//
// 2 xrefs:
// > MusicDownloadManager::downloadSong @ 0x1001564fc
// > MusicDownloadManager::downloadCustomSong @ 0x10015672c
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
void __fastcall MusicDownloadManager::onDownloadSongCompleted(
MusicDownloadManager *a1,
cocos2d::extension::CCHttpClient *a2,
cocos2d::extension::CCHttpResponse *a3)
{
cocos2d::extension::CCHttpRequest *pHttpRequest; // x8
const char *p_tag; // x0
__int64 v7; // x20
cocos2d::CCString *v8; // x0
const char *CString; // x0
std::string *p_p; // x0
FILE *v11; // x22
SongInfoObject *SongInfoObject; // x0
int v13; // w8
GameManager *v14; // x0
GJSongError v15; // w2
std::string __p; // [xsp+8h] [xbp-38h] BYREF
pHttpRequest = a3->_pHttpRequest;
p_tag = (const char *)&pHttpRequest->_tag;
if ( pHttpRequest->_tag.m_data.m_short.shortStorage.__elems_[22] < 0 )
p_tag = *(const char **)p_tag;
v7 = atoi(p_tag);
v8 = (cocos2d::CCString *)sub_100268F4C("d_%i", v7);
CString = cocos2d::CCString::getCString(v8);
MusicDownloadManager::removeDLFromActive(a1, CString);
if ( a3->_succeed )
{
MusicDownloadManager::pathForSong(v7, &__p);
if ( (__p.__r_.__value_.__r.__words[2] & 0x8000000000000000LL) == 0LL )
p_p = &__p;
else
p_p = (std::string *)__p.__r_.__value_.__r.__words[0];
v11 = fopen((const char *)p_p, "wb");
if ( v11 )
{
fwrite(a3->_responseData.__begin_, 1u, a3->_responseData.__end_ - a3->_responseData.__begin_, v11);
fclose(v11);
SongInfoObject = MusicDownloadManager::getSongInfoObject(a1, v7);
if ( SongInfoObject )
{
v13 = a1->m_songPriority + 1;
a1->m_songPriority = v13;
SongInfoObject->m_priority = v13;
}
v14 = GameManager::sharedState();
if ( !GameManager::getGameVariable(v14, "0018") )
MusicDownloadManager::limitDownloadedSongs(a1);
MusicDownloadManager::downloadSongFinished(a1, v7);
}
else
{
MusicDownloadManager::downloadSongFailed(a1, v7, (GJSongError)0);
}
if ( SHIBYTE(__p.__r_.__value_.__r.__words[2]) < 0 )
operator delete(__p.__r_.__value_.__l.__data_);
}
else
{
if ( a3->_pHttpRequest->_shouldCancel )
v15 = DownloadCancelled;
else
v15 = 0;
MusicDownloadManager::downloadSongFailed(a1, v7, v15);
}
}