mirror of
https://github.com/sheumann/DiskBrowser.git
synced 2024-09-14 08:54:45 +00:00
Recognize some disk image types based on extension.
This eliminates any possibility of mounting "do" or "po" images with the opposite segment order from what the extension specifies (although that was pretty unlikely anyway). We also now give an error message for the unsupported "woz" and "nib" formats.
This commit is contained in:
parent
31ef70e9c1
commit
87cf5483a3
23
diskmount.c
23
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);
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user