mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
Remove usage of strcpy and use _s versions of file opening
This commit is contained in:
parent
65f78a3653
commit
3a22f1b916
|
|
@ -1321,26 +1321,23 @@ void SoundEngine::playMusicUpdate()
|
|||
const bool isCD = (m_musicID >= m_iStream_CD_1);
|
||||
const char* folder = isCD ? "cds/" : "music/";
|
||||
|
||||
FILE* pFile = fopen((char*)m_szStreamName, "rb");
|
||||
if (pFile)
|
||||
FILE* pFile = nullptr;
|
||||
if (fopen_s(&pFile, reinterpret_cast<char*>(m_szStreamName), "rb") == 0 && pFile)
|
||||
{
|
||||
fclose(pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* extensions[] = { ".wav" }; // only wav works outside of binka files to my knowledge, i've only tested ogg, wav, mp3 and only wav worked out of the bunch
|
||||
|
||||
int count = sizeof(extensions) / sizeof(extensions[0]);
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
strcpy((char*)m_szStreamName, m_szMusicPath);
|
||||
strcat((char*)m_szStreamName, folder);
|
||||
strcat((char*)m_szStreamName, m_szStreamFileA[m_musicID]);
|
||||
strcat((char*)m_szStreamName, extensions[i]);
|
||||
int n = sprintf_s(reinterpret_cast<char*>(m_szStreamName), 512, "%s%s%s%s", m_szMusicPath, folder, m_szStreamFileA[m_musicID], extensions[i]);
|
||||
if (n < 0) continue;
|
||||
|
||||
pFile = fopen((char*)m_szStreamName, "rb");
|
||||
if (pFile) // probably a better way to check if the file exists
|
||||
if (fopen_s(&pFile, reinterpret_cast<char*>(m_szStreamName), "rb") == 0 && pFile)
|
||||
{
|
||||
fclose(pFile);
|
||||
found = true;
|
||||
|
|
@ -1354,7 +1351,6 @@ void SoundEngine::playMusicUpdate()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
app.DebugPrintf("Starting streaming - %s\n",m_szStreamName);
|
||||
|
||||
// Don't actually open in this thread, as it can block for ~300ms.
|
||||
|
|
|
|||
Loading…
Reference in a new issue