void MIOMusic_PreLoad (char *pmPathName) { char myFilePath [4096]; void *myMDInfo = NULL; PreLoadFile *myFile; /* File name is <pmPath>.wav */ if (stricmp (".wav", &pmPathName [strlen (pmPathName) - 4]) == 0) { if (MIOFile_ConvertPath (pmPathName, NULL, myFilePath, NO_TRAILING_SLASH)) { myMDInfo = MDIOMusic_PreLoadWAVE (myFilePath); } return; } else { SET_ERRNO(E_MUSIC_UNKNOWN_FILE_TYPE); } if (myMDInfo != NULL) { myFile = (PreLoadFile *) malloc (sizeof (PreLoadFile)); myFile -> pathName = malloc (strlen (myFilePath) + 1); strcpy (myFile -> pathName, myFilePath); myFile -> mdInfo = myMDInfo; myFile -> next = stPreLoadHead; stPreLoadHead = myFile; } } // MIOMusic_PreLoad
void MIOFile_Copy (const OOTstring pmSrcPath, const OOTstring pmDestPath) { char mySrcPath [1024]; char myDestPath [1024]; // Convert to full path name if (!MIOFile_ConvertPath (pmSrcPath, NULL, mySrcPath, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return; } // Check that file to be copied exists if (!MDIOFile_Exists (mySrcPath, FILE_ONLY)) { // if MDIOFile_Exists returned false, then the error message was set // to indicate why. return; } // Convert to full path name if (!MIOFile_ConvertPath (pmDestPath, NULL, myDestPath, ALLOW_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return; } if (MIODir_Exists (myDestPath)) { // Add the file name component from pmSrcPath to myDestPath char myPath [1024], myFileName [1024]; MIOFile_SplitPath (myPath, myFileName, myDestPath); MIOFile_CreatePath (myDestPath, myDestPath, myFileName); } else { // MIODir_Exists may have set the error code. SET_ERRNO (E_NO_ERROR); } MDIOFile_Copy (mySrcPath, myDestPath); } // MIOFile_Copy
void MIOFile_Rename (OOTstring pmPathName, OOTstring pmNewPathName) { char myPathName [1024]; char myNewPathName [1024]; // Convert to full path name if (!MIOFile_ConvertPath (pmPathName, NULL, myPathName, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return; } // Check that file to be copied exists if (!MDIOFile_Exists (myPathName, FILE_OR_DIR)) { // if MDIOFile_Exists returned false, then the error message was set // to indicate why. return; } // Convert to full path name if (!MIOFile_ConvertPath (pmNewPathName, NULL, myNewPathName, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return; } if (MDIOFile_Exists (myNewPathName, FILE_ONLY)) { SET_ERRMSG (E_FSYS_FILE_EXISTS, "A data file '%s' already exists", myNewPathName); } else if (MIODir_Exists (myNewPathName)) { SET_ERRMSG (E_FSYS_FILE_EXISTS, "A directory '%s' already exists", myNewPathName); } else { // MIODir_Exists may have set the error code. SET_ERRNO (E_NO_ERROR); MDIOFile_Rename (myPathName, myNewPathName); } } // MIOFile_Rename
BOOL MIOFile_Exists (char *pmPathName) { char myPathName [1024]; // Convert to full path name if (!MIOFile_ConvertPath (pmPathName, NULL, myPathName, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return FALSE; } return MDIOFile_Exists (myPathName, FILE_ONLY); } // MIOFile_Exists
OOTint MIOFile_DiskFree (OOTstring pmPathName) { char myPathName [4096]; // Convert to full path name if (!MIOFile_ConvertPath (pmPathName, NULL, myPathName, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return -1; } return MDIOFile_DiskFree (myPathName); } // MIOFile_DiskFree
void MIOFile_Status (OOTstring pmPathName, OOTint *pmFileSize, OOTint *pmAttrib, OOTint *pmFileTime) { char myPathName [1024]; // Convert to full path name if (!MIOFile_ConvertPath (pmPathName, NULL, myPathName, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return; } MDIOFile_Status (myPathName, pmFileSize, pmAttrib, pmFileTime); } // MIOFile_Status
void MIOFile_FullPath (OOTstring pmNewPath, const OOTstring pmOldPath) { char myPathName [4096]; // Convert to full path name if (!MIOFile_ConvertPath (pmOldPath, myPathName, NULL, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. pmNewPath [0] = 0; return; } strncpy (pmNewPath, myPathName, 255); pmNewPath [255] = 0; } // MIOFile_FullPath
void MIOFile_Parent (OOTstring pmNewPath, const OOTstring pmOldPath) { char myPath [4096]; char *myRoot, *myPtr; // Convert to full path name if (!MIOFile_ConvertPath (pmOldPath, myPath, NULL, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. pmNewPath [0] = 0; return; } // return if root directory if (MIOFile_GetRootDir (myPath, &myRoot)) { strcpy (pmNewPath, pmOldPath); SET_ERRNO (E_FILE_CANNOT_GET_PARENT_OF_ROOT); return; } // At this point, we are guaranteed that the path does not end in a / // Back up until we reach a slash and discard it, or hit the root. myPtr = &myPath [strlen (myPath) - 1]; while (*myPtr != '/') { myPtr--; } if (myPtr < myRoot) { myPtr++; } strncpy (pmNewPath, myPath, myPtr - myPath); pmNewPath [myPtr - myPath] = 0; } // MIOFile_Parent
void MIOFile_Delete (OOTstring pmPathName) { char myPathName [4096]; // Convert to full path name if (!MIOFile_ConvertPath (pmPathName, NULL, myPathName, NO_TRAILING_SLASH)) { // if MIOFile_ConvertPath returned false, then the error message was // set to indicate why. return; } // Check that file to be copied exists if (MDIOFile_Exists (myPathName, FILE_ONLY)) { MDIOFile_Delete (myPathName); } else { // if MDIOFile_Exists returned false, then the error message was set // to indicate why. return; } } // MIOFile_Delete
BOOL MIOMusic_PlayFile (EventDescriptor *pmEvent, OOTstring pmPath) { char myFilePath[4096]; int myKind; int mySoundID; Sound *mySound; PreLoadFile *myPtr = stPreLoadHead; if (!stAllowSound) { SET_ERRNO(E_MUSIC_DISABLED); return FALSE; } /* File name is "CD" or "CD:<track>" */ if ((strlen (pmPath) >= 2) && (((pmPath [0] == 'c') || (pmPath [0] == 'C')) && ((pmPath [1] == 'd') || (pmPath [1] == 'D')) && ((pmPath [2] == 0) || (pmPath [2] == ':')))) { if (MDIOMusic_FileCDPlay (&pmPath [2], &myKind, &mySoundID)) { mySound = (Sound *) malloc (sizeof (Sound)); mySound -> fileKind = myKind; mySound -> soundID = mySoundID; pmEvent -> mode = EventMode_PlayFileDone; pmEvent -> count = (int) mySound; return TRUE; } } if (!MIOFile_ConvertPath (pmPath, NULL, myFilePath, NO_TRAILING_SLASH)) { return FALSE; } while (myPtr != NULL) { if (stricmp (myPtr -> pathName, myFilePath) == 0) { if (MDIOMusic_PreLoadPlay (myPtr -> mdInfo, &myKind, &mySoundID)) { mySound = (Sound *) malloc (sizeof (Sound)); mySound -> fileKind = myKind; mySound -> soundID = mySoundID; pmEvent -> mode = EventMode_PlayFileDone; pmEvent -> count = (int) mySound; return TRUE; } return FALSE; } myPtr = myPtr -> next; } // while /* File name is <pmPath>.wav */ if (stricmp (".wav", &myFilePath [strlen (myFilePath) - 4]) == 0) { if (MDIOMusic_FileWAVEPlay (myFilePath, &myKind, &mySoundID)) { mySound = (Sound *) malloc (sizeof (Sound)); mySound -> fileKind = myKind; mySound -> soundID = mySoundID; pmEvent -> mode = EventMode_PlayFileDone; pmEvent -> count = (int) mySound; return TRUE; } return FALSE; } /* File name is <pmPath>.mp3 */ if (stricmp (".mp3", &myFilePath [strlen (myFilePath) - 4]) == 0) { if (MDIOMusic_FileMP3Play (myFilePath, &myKind, &mySoundID)) { mySound = (Sound *) malloc (sizeof (Sound)); mySound -> fileKind = myKind; mySound -> soundID = mySoundID; pmEvent -> mode = EventMode_PlayFileDone; pmEvent -> count = (int) mySound; return TRUE; } return FALSE; } /* File name is <pmPath>.mid */ if ((stricmp (".mid", &myFilePath [strlen (myFilePath) - 4]) == 0) || (stricmp (".midi", &myFilePath [strlen (myFilePath) - 5]) == 0)) { if (MDIOMusic_FileMIDIPlay (myFilePath, &myKind, &mySoundID)) { mySound = (Sound *) malloc (sizeof (Sound)); mySound -> fileKind = myKind; mySound -> soundID = mySoundID; pmEvent -> mode = EventMode_PlayFileDone; pmEvent -> count = (int) mySound; return TRUE; } return FALSE; } SET_ERRNO(E_MUSIC_UNKNOWN_FILE_TYPE); return FALSE; } // MIOMusic_PlayFile