diff --git a/diskmount.c b/diskmount.c index 06c9797..fd42d81 100644 --- a/diskmount.c +++ b/diskmount.c @@ -20,6 +20,7 @@ #include "asprintf.h" #include "json.h" #include "jsonutil.h" +#include "strcasecmp.h" #include "diskbrowser.h" #include "diskmount.h" @@ -34,7 +35,7 @@ static char *wantedItemID; static GSString32 devName; static boolean processFile(json_value *fileObj); -static void MountFile(char *itemID, char *fileName); +static void MountFile(char *itemID, char *fileName, char *fileExt); void DoMount(void) { unsigned int itemNumber = NextMember2(0, (Handle)disksListHandle); @@ -108,16 +109,21 @@ static boolean processFile(json_value *fileObj) { if (nameExt == NULL) return true; if (strcmp(nameExt + 1, wantedExt) == 0) { - MountFile(wantedItemID, name->u.string.ptr); + MountFile(wantedItemID, name->u.string.ptr, nameExt + 1); return false; } return true; } -static void MountFile(char *itemID, char *fileName) { +static void MountFile(char *itemID, char *fileName, char *fileExt) { static struct MountURLRec mountURLRec = {sizeof(struct MountURLRec)}; + if (strcasecmp(fileExt, "woz") == 0 || strcasecmp(fileExt, "nib") == 0) { + ShowErrorAlert(UNSUPPORTED_IMAGE_TYPE, mountErrorAlert); + return; + } + char *fileURL = NULL; asprintf(&fileURL, "http://archive.org/download/%s/%s", itemID, fileName); if (fileURL == NULL) { @@ -128,7 +134,16 @@ static void MountFile(char *itemID, char *fileName) { mountURLRec.result = NETDISK_NOT_PRESENT; mountURLRec.url = fileURL; mountURLRec.flags = flgUseCache; - mountURLRec.format = formatAutoDetect; + + if (strcasecmp(fileExt, "do") == 0) { + mountURLRec.format = formatDOSOrder; + } else if (strcasecmp(fileExt, "po") == 0) { + mountURLRec.format = formatRaw; + } else if (strcasecmp(fileExt, "2mg") == 0) { + mountURLRec.format = format2mg; + } else { + mountURLRec.format = formatAutoDetect; + } SendRequest(MountURL, sendToName|stopAfterOne, (Long)NETDISK_REQUEST_NAME, (Long)&mountURLRec, NULL); diff --git a/netdiskerror.c b/netdiskerror.c index ee12e9d..baaf8a0 100644 --- a/netdiskerror.c +++ b/netdiskerror.c @@ -44,6 +44,12 @@ char *ErrorString(enum NetDiskError err) { case NOT_MULTIPLE_OF_BLOCK_SIZE: return "The file is not a multiple of 512 bytes. It may not be a disk " "image file, or is not in a supported format."; + case NOT_SPECIFIED_IMAGE_TYPE: + return "The file is not a valid disk image of the type specified by " + "its file name."; + case UNSUPPORTED_IMAGE_TYPE: + return "This disk image is of a type not supported by NetDisk, such " + "as NIB or WOZ."; /* JSON processing errors */ case JSON_PARSING_ERROR: diff --git a/netdiskerror.h b/netdiskerror.h index 342f7f4..1ba8f22 100644 --- a/netdiskerror.h +++ b/netdiskerror.h @@ -40,6 +40,7 @@ enum NetDiskError { UNSUPPORTED_2IMG_FILE = 600, NOT_MULTIPLE_OF_BLOCK_SIZE, NOT_SPECIFIED_IMAGE_TYPE, + UNSUPPORTED_IMAGE_TYPE, /* Errors related to processing JSON result in the disk browser */ JSON_PARSING_ERROR = 900,