2018-08-11 21:33:18 +00:00
|
|
|
#pragma cdev cdevMain
|
|
|
|
|
|
|
|
#include <types.h>
|
|
|
|
#include <stddef.h>
|
2018-08-13 03:01:25 +00:00
|
|
|
#include <stdio.h>
|
2018-10-01 03:47:43 +00:00
|
|
|
#include <string.h>
|
2018-08-11 21:33:18 +00:00
|
|
|
#include <gsos.h>
|
|
|
|
#include <orca.h>
|
|
|
|
#include <quickdraw.h>
|
2018-08-13 03:01:25 +00:00
|
|
|
#include <qdaux.h>
|
2018-08-11 21:33:18 +00:00
|
|
|
#include <window.h>
|
|
|
|
#include <control.h>
|
|
|
|
#include <lineedit.h>
|
|
|
|
#include <desk.h>
|
2018-08-13 03:01:25 +00:00
|
|
|
#include <locator.h>
|
2018-08-15 01:44:08 +00:00
|
|
|
#include <tcpip.h>
|
2018-08-13 03:01:25 +00:00
|
|
|
#include "mounturl.h"
|
2018-10-01 03:47:43 +00:00
|
|
|
#include "strcasecmp.h"
|
2018-08-11 21:33:18 +00:00
|
|
|
|
|
|
|
#define MachineCDEV 1
|
|
|
|
#define BootCDEV 2
|
|
|
|
#define InitCDEV 4
|
|
|
|
#define CloseCDEV 5
|
|
|
|
#define EventsCDEV 6
|
|
|
|
#define CreateCDEV 7
|
|
|
|
#define AboutCDEV 8
|
|
|
|
#define RectCDEV 9
|
|
|
|
#define HitCDEV 10
|
|
|
|
#define RunCDEV 11
|
|
|
|
#define EditCDEV 12
|
|
|
|
|
|
|
|
#define imageURLTxt 2
|
|
|
|
#define urlLine 3
|
|
|
|
#define mountBtn 1
|
|
|
|
//#define optionsPopUp 6
|
|
|
|
//#define trianglePic 7
|
2018-10-02 03:42:33 +00:00
|
|
|
#define useCacheChk 8
|
2018-08-11 21:33:18 +00:00
|
|
|
|
2018-10-08 03:22:09 +00:00
|
|
|
#define imageFormatMenu 300
|
|
|
|
#define formatAutoDetectItem 301
|
|
|
|
#define format2mgItem 302
|
|
|
|
#define formatRawItem 303
|
|
|
|
#define formatDOSOrderItem 304
|
2018-10-18 01:14:40 +00:00
|
|
|
#define formatDiskCopy42Item 305
|
2018-10-08 03:22:09 +00:00
|
|
|
|
2018-08-13 03:44:05 +00:00
|
|
|
#define netDiskMissingError 3000
|
|
|
|
#define mountURLError 3001
|
2018-10-01 03:47:43 +00:00
|
|
|
#define unsupportedProtocolAlert 3002
|
2019-07-15 21:44:57 +00:00
|
|
|
#define marinettiMissingError 3003
|
2019-07-16 01:13:11 +00:00
|
|
|
#define marinettiVersionWarning 3004
|
2018-10-01 03:47:43 +00:00
|
|
|
#define yesBtn 1 /* number of "Yes" button in alert */
|
2018-08-13 03:01:25 +00:00
|
|
|
|
2019-07-16 01:13:11 +00:00
|
|
|
#define DESIRED_MARINETTI_VERSION 0x03006011 /* 3.0b11 */
|
|
|
|
|
2018-08-11 21:33:18 +00:00
|
|
|
extern void FreeAllCDevMem(void);
|
|
|
|
|
|
|
|
char urlBuf[257];
|
|
|
|
|
|
|
|
WindowPtr wPtr = NULL;
|
|
|
|
|
2018-10-02 03:42:33 +00:00
|
|
|
Boolean useCache;
|
|
|
|
|
2018-10-08 03:22:09 +00:00
|
|
|
enum DiskImageFormat format;
|
|
|
|
|
2018-08-13 03:01:25 +00:00
|
|
|
struct MountURLRec mountURLRec = {sizeof(struct MountURLRec)};
|
|
|
|
|
2018-08-11 21:33:18 +00:00
|
|
|
void DoMount(void)
|
|
|
|
{
|
2018-08-13 03:01:25 +00:00
|
|
|
char numStr[6] = "";
|
|
|
|
char *subs[1] = {numStr};
|
2018-09-26 04:55:56 +00:00
|
|
|
static char alertString[200];
|
2018-10-01 03:47:43 +00:00
|
|
|
enum {HTTPS, FTP, OTHER_PROTOCOL} protocol = OTHER_PROTOCOL;
|
2018-08-13 03:01:25 +00:00
|
|
|
|
2018-08-11 21:33:18 +00:00
|
|
|
GetLETextByID(wPtr, urlLine, (StringPtr)&urlBuf);
|
|
|
|
|
2018-10-01 03:47:43 +00:00
|
|
|
if (strncasecmp(urlBuf+1, "https://", 8) == 0) {
|
|
|
|
protocol = HTTPS;
|
|
|
|
subs[0] = "HTTPS";
|
|
|
|
strncpy(urlBuf+2, "http", 4);
|
|
|
|
mountURLRec.url = urlBuf + 2;
|
|
|
|
} else if (strncasecmp(urlBuf+1, "ftp://", 6) == 0) {
|
|
|
|
protocol = FTP;
|
|
|
|
subs[0] = "FTP";
|
|
|
|
strncpy(urlBuf, "http", 4);
|
|
|
|
mountURLRec.url = urlBuf;
|
|
|
|
} else {
|
|
|
|
protocol = OTHER_PROTOCOL;
|
|
|
|
mountURLRec.url = urlBuf + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (protocol == HTTPS || protocol == FTP) {
|
|
|
|
if (AlertWindow(awResource+awCString+awButtonLayout,
|
|
|
|
(Pointer)subs, unsupportedProtocolAlert) != yesBtn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitCursor();
|
2018-08-15 01:44:08 +00:00
|
|
|
TCPIPConnect(NULL);
|
|
|
|
|
2018-08-13 03:01:25 +00:00
|
|
|
mountURLRec.result = NETDISK_NOT_PRESENT;
|
2018-10-02 03:42:33 +00:00
|
|
|
|
|
|
|
mountURLRec.flags = 0;
|
|
|
|
if (useCache) {
|
|
|
|
mountURLRec.flags |= flgUseCache;
|
|
|
|
}
|
2018-10-08 03:22:09 +00:00
|
|
|
|
|
|
|
mountURLRec.format = format;
|
2018-08-13 03:01:25 +00:00
|
|
|
|
|
|
|
SendRequest(MountURL, sendToName|stopAfterOne, (Long)NETDISK_REQUEST_NAME,
|
|
|
|
(Long)&mountURLRec, NULL);
|
|
|
|
|
|
|
|
InitCursor();
|
|
|
|
|
|
|
|
if (mountURLRec.result != OPERATION_SUCCESSFUL) {
|
|
|
|
snprintf(numStr, sizeof(numStr), "%u", mountURLRec.result);
|
2018-09-26 04:55:56 +00:00
|
|
|
snprintf(alertString, sizeof(alertString), "42~%.175s~^#0\0",
|
|
|
|
ErrorString(mountURLRec.result));
|
2018-10-01 03:47:43 +00:00
|
|
|
subs[0] = numStr;
|
2018-09-26 04:55:56 +00:00
|
|
|
AlertWindow(awPointer+awCString+awButtonLayout, (Pointer)subs,
|
|
|
|
(Ref)alertString);
|
2018-08-13 03:25:50 +00:00
|
|
|
|
|
|
|
/* Work around issue where parts of LE caret may flash out of sync */
|
|
|
|
CtlRecHndl ctl = GetCtlHandleFromID(wPtr, urlLine);
|
|
|
|
LEDeactivate((LERecHndl) GetCtlTitle(ctl));
|
|
|
|
if (FindTargetCtl() == ctl) {
|
|
|
|
LEActivate((LERecHndl) GetCtlTitle(ctl));
|
|
|
|
}
|
2018-08-13 03:01:25 +00:00
|
|
|
}
|
2018-08-11 21:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoHit(long ctlID, CtlRecHndl ctlHandle)
|
|
|
|
{
|
|
|
|
if (!wPtr) /* shouldn't happen */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ctlID == mountBtn) {
|
|
|
|
DoMount();
|
2018-10-02 03:42:33 +00:00
|
|
|
} else if (ctlID == useCacheChk) {
|
|
|
|
useCache = !useCache;
|
2018-10-08 03:22:09 +00:00
|
|
|
} else if (ctlID == imageFormatMenu) {
|
|
|
|
switch (GetCtlValue(ctlHandle)) {
|
|
|
|
case formatAutoDetectItem:
|
|
|
|
format = formatAutoDetect;
|
|
|
|
break;
|
|
|
|
case format2mgItem:
|
|
|
|
format = format2mg;
|
|
|
|
break;
|
|
|
|
case formatRawItem:
|
|
|
|
format = formatRaw;
|
|
|
|
break;
|
|
|
|
case formatDOSOrderItem:
|
|
|
|
format = formatDOSOrder;
|
|
|
|
break;
|
2018-10-18 01:14:40 +00:00
|
|
|
case formatDiskCopy42Item:
|
|
|
|
format = formatDiskCopy42;
|
|
|
|
break;
|
2018-10-08 03:22:09 +00:00
|
|
|
}
|
2018-08-11 21:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
long DoMachine(void)
|
|
|
|
{
|
2018-08-13 03:44:05 +00:00
|
|
|
mountURLRec.result = NETDISK_NOT_PRESENT;
|
|
|
|
mountURLRec.url = "";
|
|
|
|
|
|
|
|
SendRequest(MountURL, sendToName|stopAfterOne, (Long)NETDISK_REQUEST_NAME,
|
|
|
|
(Long)&mountURLRec, NULL);
|
|
|
|
|
|
|
|
if (mountURLRec.result == NETDISK_NOT_PRESENT) {
|
2018-08-15 01:44:08 +00:00
|
|
|
InitCursor();
|
2018-08-13 03:44:05 +00:00
|
|
|
AlertWindow(awResource+awButtonLayout, NULL, netDiskMissingError);
|
|
|
|
return 0;
|
2019-07-15 21:44:57 +00:00
|
|
|
} else if (mountURLRec.result == MARINETTI_NOT_PRESENT) {
|
|
|
|
InitCursor();
|
|
|
|
AlertWindow(awResource+awButtonLayout, NULL, marinettiMissingError);
|
|
|
|
return 0;
|
2018-08-13 03:44:05 +00:00
|
|
|
}
|
2019-07-16 01:13:11 +00:00
|
|
|
|
|
|
|
if (TCPIPLongVersion() < DESIRED_MARINETTI_VERSION) {
|
|
|
|
InitCursor();
|
|
|
|
AlertWindow(awResource+awButtonLayout, NULL, marinettiVersionWarning);
|
|
|
|
}
|
2018-08-13 03:44:05 +00:00
|
|
|
|
2018-08-11 21:33:18 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoEdit(Word op)
|
|
|
|
{
|
|
|
|
CtlRecHndl ctl;
|
|
|
|
GrafPortPtr port;
|
|
|
|
|
|
|
|
if (!wPtr)
|
|
|
|
return;
|
|
|
|
port = GetPort();
|
|
|
|
SetPort(wPtr);
|
|
|
|
|
|
|
|
ctl = FindTargetCtl();
|
|
|
|
if (toolerror() || GetCtlID(ctl) != urlLine)
|
|
|
|
goto ret;
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case cutAction: LECut((LERecHndl) GetCtlTitle(ctl));
|
|
|
|
if (LEGetScrapLen() > 0)
|
|
|
|
LEToScrap();
|
|
|
|
break;
|
|
|
|
case copyAction: LECopy((LERecHndl) GetCtlTitle(ctl));
|
|
|
|
if (LEGetScrapLen() > 0)
|
|
|
|
LEToScrap();
|
|
|
|
break;
|
|
|
|
case pasteAction: LEFromScrap();
|
|
|
|
LEPaste((LERecHndl) GetCtlTitle(ctl));
|
|
|
|
break;
|
|
|
|
case clearAction: LEDelete((LERecHndl) GetCtlTitle(ctl));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret:
|
|
|
|
SetPort(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoCreate(WindowPtr windPtr)
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
wPtr = windPtr;
|
|
|
|
mode = (GetMasterSCB() & scbColorMode) ? 640 : 320;
|
|
|
|
NewControl2(wPtr, resourceToResource, mode);
|
2018-10-02 03:42:33 +00:00
|
|
|
useCache = TRUE;
|
2018-08-11 21:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LongWord cdevMain (LongWord data2, LongWord data1, Word message)
|
|
|
|
{
|
|
|
|
long result = 0;
|
|
|
|
|
|
|
|
switch(message) {
|
|
|
|
case MachineCDEV: result = DoMachine(); break;
|
|
|
|
case HitCDEV: DoHit(data2, (CtlRecHndl)data1); break;
|
|
|
|
case EditCDEV: DoEdit(data1 & 0xFFFF); break;
|
|
|
|
case CreateCDEV: DoCreate((WindowPtr)data1); break;
|
|
|
|
case CloseCDEV: wPtr = NULL; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret:
|
|
|
|
FreeAllCDevMem();
|
|
|
|
return result;
|
|
|
|
}
|