mirror of
https://gitlab.com/GaryOderNichts/re3-wiiu.git
synced 2025-02-16 18:19:16 +01:00
Fix MP3 finding stack crash
This commit is contained in:
parent
cb3b3855b8
commit
22e8e0eff8
@ -446,18 +446,32 @@ _FindMP3s(void)
|
|||||||
bool8 bInitFirstEntry;
|
bool8 bInitFirstEntry;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
char filepath[MAX_PATH*2];
|
|
||||||
int total_ms;
|
int total_ms;
|
||||||
WIN32_FIND_DATA fd;
|
WIN32_FIND_DATA fd;
|
||||||
|
char filepath[MAX_PATH + sizeof(fd.cFileName)];
|
||||||
|
|
||||||
if (getcwd(_mp3DirectoryPath, MAX_PATH) == NULL) {
|
if (getcwd(_mp3DirectoryPath, MAX_PATH) == NULL) {
|
||||||
perror("getcwd: ");
|
perror("getcwd: ");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strlen(_mp3DirectoryPath) + 1 > MAX_PATH - 10) {
|
||||||
|
// This is not gonna end well
|
||||||
|
printf("MP3 folder path is too long, no place left for file names. MP3 finding aborted.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OutputDebugString("Finding MP3s...");
|
OutputDebugString("Finding MP3s...");
|
||||||
strcpy(path, _mp3DirectoryPath);
|
strcpy(path, _mp3DirectoryPath);
|
||||||
strcat(path, "\\MP3\\");
|
strcat(path, "\\MP3\\");
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
char *actualPath = casepath(path);
|
||||||
|
if (actualPath) {
|
||||||
|
strcpy(path, actualPath);
|
||||||
|
free(actualPath);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
strcpy(_mp3DirectoryPath, path);
|
strcpy(_mp3DirectoryPath, path);
|
||||||
OutputDebugString(_mp3DirectoryPath);
|
OutputDebugString(_mp3DirectoryPath);
|
||||||
@ -470,95 +484,32 @@ _FindMP3s(void)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(filepath, _mp3DirectoryPath);
|
|
||||||
strcat(filepath, fd.cFileName);
|
|
||||||
|
|
||||||
size_t filepathlen = strlen(filepath);
|
|
||||||
|
|
||||||
if ( filepathlen <= 0)
|
|
||||||
{
|
|
||||||
FindClose(hFind);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( _ResolveLink(filepath, filepath) )
|
bShortcut = FALSE;
|
||||||
{
|
bInitFirstEntry = TRUE;
|
||||||
OutputDebugString("Resolving Link");
|
|
||||||
OutputDebugString(filepath);
|
|
||||||
bShortcut = TRUE;
|
|
||||||
} else
|
|
||||||
bShortcut = FALSE;
|
|
||||||
|
|
||||||
aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]);
|
|
||||||
|
|
||||||
if (aStream[0] && aStream[0]->IsOpened())
|
do
|
||||||
{
|
{
|
||||||
total_ms = aStream[0]->GetLengthMS();
|
strcpy(filepath, _mp3DirectoryPath);
|
||||||
delete aStream[0];
|
strcat(filepath, fd.cFileName);
|
||||||
aStream[0] = NULL;
|
|
||||||
|
if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, ".."))
|
||||||
|
continue;
|
||||||
|
|
||||||
OutputDebugString(fd.cFileName);
|
size_t filepathlen = strlen(filepath);
|
||||||
|
|
||||||
_pMP3List = new tMP3Entry;
|
|
||||||
|
|
||||||
if ( _pMP3List == NULL )
|
|
||||||
{
|
|
||||||
FindClose(hFind);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nNumMP3s = 1;
|
|
||||||
|
|
||||||
strcpy(_pMP3List->aFilename, fd.cFileName);
|
|
||||||
|
|
||||||
_pMP3List->nTrackLength = total_ms;
|
|
||||||
|
|
||||||
_pMP3List->pNext = NULL;
|
|
||||||
|
|
||||||
pList = _pMP3List;
|
|
||||||
|
|
||||||
if ( bShortcut )
|
|
||||||
{
|
|
||||||
_pMP3List->pLinkPath = new char[MAX_PATH*2];
|
|
||||||
strcpy(_pMP3List->pLinkPath, filepath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_pMP3List->pLinkPath = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bInitFirstEntry = FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strcat(filepath, " - NOT A VALID MP3");
|
|
||||||
|
|
||||||
OutputDebugString(filepath);
|
|
||||||
|
|
||||||
bInitFirstEntry = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( TRUE )
|
|
||||||
{
|
|
||||||
if ( !FindNextFile(hFind, &fd) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ( bInitFirstEntry )
|
if ( bInitFirstEntry )
|
||||||
{
|
{
|
||||||
strcpy(filepath, _mp3DirectoryPath);
|
if (filepathlen > 0)
|
||||||
strcat(filepath, fd.cFileName);
|
|
||||||
|
|
||||||
size_t filepathlen = strlen(filepath);
|
|
||||||
|
|
||||||
if ( filepathlen > 0 )
|
|
||||||
{
|
{
|
||||||
if ( _ResolveLink(filepath, filepath) )
|
if (_ResolveLink(filepath, filepath))
|
||||||
{
|
{
|
||||||
OutputDebugString("Resolving Link");
|
OutputDebugString("Resolving Link");
|
||||||
OutputDebugString(filepath);
|
OutputDebugString(filepath);
|
||||||
bShortcut = TRUE;
|
bShortcut = TRUE;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
bShortcut = FALSE;
|
bShortcut = FALSE;
|
||||||
if (filepathlen > MAX_PATH) {
|
if (filepathlen > MAX_PATH) {
|
||||||
continue;
|
continue;
|
||||||
@ -571,31 +522,31 @@ _FindMP3s(void)
|
|||||||
total_ms = aStream[0]->GetLengthMS();
|
total_ms = aStream[0]->GetLengthMS();
|
||||||
delete aStream[0];
|
delete aStream[0];
|
||||||
aStream[0] = NULL;
|
aStream[0] = NULL;
|
||||||
|
|
||||||
OutputDebugString(fd.cFileName);
|
OutputDebugString(fd.cFileName);
|
||||||
|
|
||||||
_pMP3List = new tMP3Entry;
|
_pMP3List = new tMP3Entry;
|
||||||
|
|
||||||
if ( _pMP3List == NULL)
|
if (_pMP3List == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
nNumMP3s = 1;
|
nNumMP3s = 1;
|
||||||
|
|
||||||
strcpy(_pMP3List->aFilename, fd.cFileName);
|
strcpy(_pMP3List->aFilename, fd.cFileName);
|
||||||
|
|
||||||
_pMP3List->nTrackLength = total_ms;
|
_pMP3List->nTrackLength = total_ms;
|
||||||
_pMP3List->pNext = NULL;
|
_pMP3List->pNext = NULL;
|
||||||
|
|
||||||
if ( bShortcut )
|
if (bShortcut)
|
||||||
{
|
{
|
||||||
_pMP3List->pLinkPath = new char [MAX_PATH*2];
|
_pMP3List->pLinkPath = new char[MAX_PATH + sizeof(fd.cFileName)];
|
||||||
strcpy(_pMP3List->pLinkPath, filepath);
|
strcpy(_pMP3List->pLinkPath, filepath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_pMP3List->pLinkPath = NULL;
|
_pMP3List->pLinkPath = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pList = _pMP3List;
|
pList = _pMP3List;
|
||||||
|
|
||||||
bInitFirstEntry = FALSE;
|
bInitFirstEntry = FALSE;
|
||||||
@ -606,14 +557,11 @@ _FindMP3s(void)
|
|||||||
OutputDebugString(filepath);
|
OutputDebugString(filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(filepath, _mp3DirectoryPath);
|
|
||||||
strcat(filepath, fd.cFileName);
|
|
||||||
|
|
||||||
size_t filepathlen = strlen(filepath);
|
|
||||||
|
|
||||||
if ( filepathlen > 0 )
|
if ( filepathlen > 0 )
|
||||||
{
|
{
|
||||||
if ( _ResolveLink(filepath, filepath) )
|
if ( _ResolveLink(filepath, filepath) )
|
||||||
@ -621,7 +569,8 @@ _FindMP3s(void)
|
|||||||
OutputDebugString("Resolving Link");
|
OutputDebugString("Resolving Link");
|
||||||
OutputDebugString(filepath);
|
OutputDebugString(filepath);
|
||||||
bShortcut = TRUE;
|
bShortcut = TRUE;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
bShortcut = FALSE;
|
bShortcut = FALSE;
|
||||||
|
|
||||||
aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]);
|
aStream[0] = new CStream(filepath, ALStreamSources[0], ALStreamBuffers[0]);
|
||||||
@ -647,7 +596,7 @@ _FindMP3s(void)
|
|||||||
|
|
||||||
if ( bShortcut )
|
if ( bShortcut )
|
||||||
{
|
{
|
||||||
e->pLinkPath = new char [MAX_PATH*2];
|
e->pLinkPath = new char [MAX_PATH + sizeof(fd.cFileName)];
|
||||||
strcpy(e->pLinkPath, filepath);
|
strcpy(e->pLinkPath, filepath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -666,7 +615,7 @@ _FindMP3s(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (FindNextFile(hFind, &fd));
|
||||||
|
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ typedef void* HANDLE;
|
|||||||
|
|
||||||
struct WIN32_FIND_DATA {
|
struct WIN32_FIND_DATA {
|
||||||
char extension[32]; // for searching
|
char extension[32]; // for searching
|
||||||
char folder[32]; // for searching
|
char folder[MAX_PATH]; // for searching
|
||||||
char cFileName[256]; // because tSkinInfo has it 256
|
char cFileName[256]; // because tSkinInfo has it 256
|
||||||
time_t ftLastWriteTime;
|
time_t ftLastWriteTime;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user