Streaming and cross-platform fixes

This commit is contained in:
eray orçunus 2020-10-12 20:30:49 +03:00
parent 96f36d16ae
commit be6b97b5d8
2 changed files with 28 additions and 14 deletions

View file

@ -240,9 +240,8 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size)
CdReadInfo *pChannel = &gpReadInfo[channel]; CdReadInfo *pChannel = &gpReadInfo[channel];
ASSERT( pChannel != nil ); ASSERT( pChannel != nil );
if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) { if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) {
if (pChannel->nSectorOffset == _GET_OFFSET(offset) && pChannel->nSectorsToRead >= size) if (pChannel->hFile == hImage - 1 && pChannel->nSectorOffset == _GET_OFFSET(offset) && pChannel->nSectorsToRead >= size)
return STREAM_SUCCESS; return STREAM_SUCCESS;
flushStream[channel] = 1; flushStream[channel] = 1;
@ -293,7 +292,6 @@ CdStreamGetStatus(int32 channel)
if ( pChannel->nStatus != STREAM_NONE ) if ( pChannel->nStatus != STREAM_NONE )
{ {
int32 status = pChannel->nStatus; int32 status = pChannel->nStatus;
pChannel->nStatus = STREAM_NONE; pChannel->nStatus = STREAM_NONE;
return status; return status;
@ -322,6 +320,7 @@ CdStreamSync(int32 channel)
pthread_kill(pChannel->pChannelThread, SIGUSR1); pthread_kill(pChannel->pChannelThread, SIGUSR1);
if (pChannel->bReading) { if (pChannel->bReading) {
pChannel->bLocked = true; pChannel->bLocked = true;
while (pChannel->bLocked)
sem_wait(pChannel->pDoneSemaphore); sem_wait(pChannel->pDoneSemaphore);
} }
#else #else
@ -329,8 +328,8 @@ CdStreamSync(int32 channel)
if (pChannel->bReading) { if (pChannel->bReading) {
pChannel->bLocked = true; pChannel->bLocked = true;
pthread_kill(_gCdStreamThread, SIGUSR1); pthread_kill(_gCdStreamThread, SIGUSR1);
while (pChannel->bLocked)
sem_wait(pChannel->pDoneSemaphore); sem_wait(pChannel->pDoneSemaphore);
} }
#endif #endif
pChannel->bReading = false; pChannel->bReading = false;
@ -341,7 +340,7 @@ CdStreamSync(int32 channel)
if ( pChannel->nSectorsToRead != 0 ) if ( pChannel->nSectorsToRead != 0 )
{ {
pChannel->bLocked = true; pChannel->bLocked = true;
while (pChannel->bLocked)
sem_wait(pChannel->pDoneSemaphore); sem_wait(pChannel->pDoneSemaphore);
} }
@ -443,9 +442,9 @@ void *CdStreamThread(void *param)
#endif #endif
pChannel->nSectorsToRead = 0; pChannel->nSectorsToRead = 0;
if ( pChannel->bLocked ) if ( pChannel->bLocked )
{ {
pChannel->bLocked = 0;
sem_post(pChannel->pDoneSemaphore); sem_post(pChannel->pDoneSemaphore);
} }
pChannel->bReading = false; pChannel->bReading = false;

View file

@ -27,13 +27,28 @@ void GetLocalTime_CP(SYSTEMTIME *out) {
#ifndef _WIN32 #ifndef _WIN32
HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) { HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) {
char newpathname[32]; char newpathname[32];
strncpy(newpathname, pathname, 32); strncpy(newpathname, pathname, 32);
char* path = strtok(newpathname, "\\*"); char* path = strtok(newpathname, "*");
// Case-sensitivity and backslashes...
char *real = casepath(path);
if (real) {
real[strlen(real)] = '*';
char *extension = strtok(NULL, "*");
if (extension)
strcat(real, extension);
strncpy(newpathname, real, 32);
free(real);
path = strtok(newpathname, "*");
}
strncpy(firstfile->folder, path, sizeof(firstfile->folder)); strncpy(firstfile->folder, path, sizeof(firstfile->folder));
// Both w/ extension and w/o extension is ok // Both w/ extension and w/o extension is ok
if (strlen(path) + 2 != strlen(pathname)) if (strlen(path) + 1 != strlen(pathname))
strncpy(firstfile->extension, strtok(NULL, "\\*"), sizeof(firstfile->extension)); strncpy(firstfile->extension, strtok(NULL, "*"), sizeof(firstfile->extension));
else else
strncpy(firstfile->extension, "", sizeof(firstfile->extension)); strncpy(firstfile->extension, "", sizeof(firstfile->extension));
@ -52,8 +67,8 @@ bool FindNextFile(HANDLE d, WIN32_FIND_DATA* finddata) {
while ((file = readdir((DIR*)d)) != NULL) { while ((file = readdir((DIR*)d)) != NULL) {
// We only want "DT_REG"ular Files, but reportedly some FS and OSes gives DT_UNKNOWN as type. // We only want "DT_REG"ular Files, but reportedly some FS and OSes gives DT_UNKNOWN as type.
if ((file->d_type == DT_UNKNOWN || file->d_type == DT_REG) && if ((file->d_type == DT_UNKNOWN || file->d_type == DT_REG || file->d_type == DT_LNK) &&
(extensionLen == 0 || strncmp(&file->d_name[strlen(file->d_name) - extensionLen], finddata->extension, extensionLen) == 0)) { (extensionLen == 0 || strncasecmp(&file->d_name[strlen(file->d_name) - extensionLen], finddata->extension, extensionLen) == 0)) {
sprintf(relativepath, "%s/%s", finddata->folder, file->d_name); sprintf(relativepath, "%s/%s", finddata->folder, file->d_name);
realpath(relativepath, path); realpath(relativepath, path);