.bra {
.ket }

; $VER: xDM v1.2 (17.5.95)

Cd >ENV:origcd

If NOT EXISTS ENV:xdm
   If NOT EXISTS ENVARC:xdm
      Echo >ENV:xdm "T:" NOLINE
   Else
      Copy >NIL: ENVARC:xdm TO ENV:
   EndIf
EndIf

LAB begin
RequestChoice >ENV:xdmaction "xDM" "Select Action" "Compress" "Decompress" "QUIT"

If $xdmaction EQ "0"
   Skip getout
EndIf

LAB startpack
RequestChoice >ENV:xdmdev "xDM" "Select Drive" "DF0:" "DF1:" "DF2:" "DF3:" "RAD:" "BACK"

If $xdmdev EQ "0"
   Skip cleanup
EndIf

Eval >ENV:xdmdrvdef $xdmdev - 1
Echo >ENV:xdmdrive "DF$xdmdrvdef:"

If $xdmdev EQ "5"
   If NOT EXISTS RAD:
      Echo "Mounting RAD and restarting..."
      Mount SYS:Storage/DOSDrivers/RAD
      Skip cleanup
   EndIf
   Echo >ENV:xdmdrive "RAD:"
Endif

If $xdmaction EQ "1"
   Skip compress
EndIf

If $xdmaction EQ "2"
   Skip decompress
EndIf

LAB compress
RequestFile >ENV:xdmdest FILE ".xdm" PATTERN "#?.xdm" TITLE "Select Destination File" NOICONS

If WARN
   Skip cleanup
EndIf

Echo "[42mxDM - ©1995 Adam Chapman & Dirk Vael[0m"
Echo "Creating disk image... Please wait!"
Cd $xdm
dd -c1760 -r$xdmdrive xDM.dsk

If ERROR
   Echo "Sorry, an error has occured... Was the disk in the drive?"
   Skip cleanup
EndIf

Echo "Archiving image... Please wait!"
Cd $xdm
LZX -3 -X0 -U0 -M1024 a $xdmdest xDM.dsk 
List $xdmdest LFormat %L >ENV:size
Echo "The 880K disk was mashed into an archive of [4;1m$size[0m bytes!"
Skip cleanup

LAB decompress
RequestFile >ENV:xdmdest FILE ".xdm" PATTERN "#?.xdm" TITLE "Select Archive" NOICONS

If WARN
   Skip cleanup
EndIf

Echo "[42mxDM - ©1995 Adam Chapman & Dirk Vael[0m"
Echo "Decompressing image... Please wait!"
LZX -X0 e $xdmdest $xdm
Echo "Recreating disk image... Please wait!"
Cd $xdm
dd -c1760 -w$xdmdrive xDM.dsk

If ERROR
   Echo "Sorry, an error has occured... Was the disk in the drive?"
   Skip cleanup
EndIf

Echo "Process complete!"
DiskChange $xdmdrive

LAB cleanup
Cd $xdm
Delete >NIL: xDM.dsk
Cd ENV:
Delete >NIL: xdmdev xdmdrvdef xdmdrive xdmdest xdmaction
Skip begin BACK

LAB getout
Cd $xdm
Delete >NIL: xDM.dsk
Cd ENV:
Delete >NIL: size xdmdev xdmdrvdef xdmdrive xdmdest xdmaction
Cd "$origcd"
Delete >NIL: ENV:origcd
