;
;	SUPER SKiD MARKS (SKiD MARKS 2) TRACK-DISKS HD INSTALLER
;				Done by -Mok-
;	  Greetz to all Prestige members! Now, when you are here
;	                  what are ya gonna do? :-)
;
;check if run from hd...
	set q filelen("C:Delete")
	if q 0 _bahWB
	set q filelen("C:Copy")
	ifnot q 0 _gotWB
_bahWB
	ASK "You must run the install program booted from your HardDrive!" " WILL DO IT " 0 0
	ABORT
_gotWB
;alloc memory for da preview file buffer
	ALLOC 0 50AA 10001
	set prev mem(0)
;alloc memory for directory
	ALLOC 1 400 10001
	set dirmem mem(1)
;check if you want to install the whole game or not
;get source drive
	GETDRIVE
	ASK "Do you want to install the whole game or just the Track Disks 1-4?" "THE WHOLE GAME|TRACK DISKS" 0 0
	ifnot answer 1 _justtracks
	ECHO " Select the subdirectory where I should create 'SM2' dir." 0 0
	PAUSE 50
	ASKDIR
	AT 1 6
	clw	
	ECHO "[1mSKiDMARKS 2 by ACiD SOFTWARE, Cracked by (*) PRESTiGE (*)" 0 0
	ECHO " [32mHD Installer by Mok :-)[0m[31m" 0 0
;delete existing directory with all the contents
	EXE "c:Delete >NIL: %sSM2/#? ALL" fullpath 0
	EXE "c:Delete >NIL: %sSM2" fullpath 0
;check for free space
	FREESPACE Q
	IFBIG Q !5000000 _enuff1
	ASK "You need at least 5 MB of free space to install the game" " _I'LL FIX IT! " 0 0
	ABORT
_enuff1
;create track directory
	MDIR SM2
	DIRICON SM2.info
	CD SM2
	MDIR Gfx
	MDIR Sfx
	MDIR Vehicles
	DOWNLINE
	ECHO " Installing Boot Disk..." 0 0
	UPLINE
_getdisk1
	set q filelen("SKID2:SkidMarks2")
	IF q 0 _getdisk1
	EXE "C:Copy >NIL: SKID2:#? %s" fullpath 0
	EXE "C:Copy >NIL: SKID2:GFX %sGfx" fullpath 0
	EXE "C:Copy >NIL: SKID2:SFX %sSfx" fullpath 0
	EXE "C:Copy >NIL: SKID2:VEHICLES %sVehicles" fullpath 0
;delete not needed mainfile for 1 meg machines
	DEL Skid1Meg
	ECHO " Installing Boot Disk... Done." 0 0
	DOWNLINE
;ask which car disks to install
;set type to aga as default
	set type 0
	ASK "Do you want to install AGA or ECS cars?" " AGA | ECS " 0 0
	if answer 1 _agacars
	set type 1
	go _nodelmini
_agacars
	EXE "C:Delete >NIL: %sVehicles/Mini.ecs" fullpath 0
_nodelmini
	CD Vehicles
	INHIBIT
;ask for disk 1 and read dir
	set disk 1
	set dn 3
	if type 0 _cdisk1
	set disk 3
	set dn 4
_cdisk1
	ASK "Please insert SKID MARKS II CAR DISK %ld and press RETURN" " _DONE | _ABORT " disk 0
	ifnot answer 1 _abort
	rs dirmem 0 400
	ifnot peekl(dirmem) 'car0'+dn _cdisk1
	ECHO " Found Car Disk %ld." disk 0
	DOWNLINE
	r a5 dirmem+c
	set name 'ECS '&FFFFFF00
	if type 1 _ecsloop
	set name 'AGA '&FFFFFF00
_agaloop
	if peek(\a5) 0 _agadone
	r d0 peekl(\a5)&DFDFDF00
	if \d0 name _gotagafile
_aganext
	FREE 2
	r a5 \a5+28
	go _agaloop
_gotagafile
	set n peek(\a5+3)-'0'
	set st peekl(\a5+24)
	set le peekl(\a5+20)
	ALLOC 2 le 10001
	rs mem(2) st le
	ifnot n 0 _notaga0
	] mem(2) le MINI.AGA
	go _aganext
_notaga0
	ifnot n 1 _notaga1
	] mem(2) le PORSCHE.AGA
	go _aganext
_notaga1
	ifnot n 2 _notaga2
	] mem(2) le VW.AGA
	go _aganext
_notaga2
	ifnot n 3 _notaga3
	] mem(2) le CAMARO.AGA
	go _aganext
_notaga3
	ifnot n 4 _notaga4
	] mem(2) le TRUCK.AGA
	go _aganext
_notaga4
	ifnot n 5 _notaga5
	] mem(2) le F1.AGA
	go _aganext
_notaga5
	ifnot n 6 _notaga6
	] mem(2) le COW.AGA
	go _aganext
_notaga6
	ifnot n 7 _notaga7
	] mem(2) le MIDGET.AGA
	go _aganext
_notaga7
	ifnot n 8 _abort
	] mem(2) le CARAVAN.AGA
	go _aganext
_agadone
	if disk 2 _agaalldone
	set dn 2
	set disk 2
	go _cdisk1
_agaalldone
	CD /
	Go _Tracks
_ecsloop
	if peek(\a5) 0 _ecsdone
	r d0 peekl(\a5)&DFDFDF00
	if \d0 name _gotecsfile
_ecsnext
	FREE 2
	r a5 \a5+28
	go _ecsloop
_gotecsfile
	set n peek(\a5+3)-'0'
	set st peekl(\a5+24)
	set le peekl(\a5+20)
	ALLOC 2 le 10001
	rs mem(2) st le
	ifnot n 0 _notecs0
	] mem(2) le MINI.ECS
	go _ecsnext
_notecs0
	ifnot n 1 _notecs1
	] mem(2) le PORSCHE.ECS
	go _ecsnext
_notecs1
	ifnot n 2 _notecs2
	] mem(2) le VW.ECS
	go _ecsnext
_notecs2
	ifnot n 3 _notecs3
	] mem(2) le CAMARO.ECS
	go _ecsnext
_notecs3
	ifnot n 4 _notecs4
	] mem(2) le TRUCK.ECS
	go _ecsnext
_notecs4
	ifnot n 5 _notecs5
	] mem(2) le F1.ecs
	go _ecsnext
_notecs5
	ifnot n 6 _notecs6
	] mem(2) le COW.ecs
	go _ecsnext
_notecs6
	ifnot n 7 _notecs7
	] mem(2) le MIDGET.ecs
	go _ecsnext
_notecs7
	ifnot n 8 _abort
	] mem(2) le CARAVAN.ecs
	go _ecsnext
_ecsdone
	CD /
	Go _Tracks
_justtracks
;ask for destination path and go there
_askagain
	AT 1 6
	CLW
	ECHO "Select the directory of the game on your HD!" 0 0
	PAUSE 50
	ASKDIR
;check if the game is really there
	ifnot filelen("SkidMarks2") 0 _gotgame
	Downline
	ECHO " There's no SkidMarks2 in this directory! Try Again!" 0 0
	PAUSE 50
	go _askagain
_gotgame
	echo " Ok, the path for the game is '%s'" fullpath 0
	pause 50
	AT 1 6
	clw	
	ECHO "[1mSKiDMARKS 2 by ACiD SOFTWARE, Cracked by (*) PRESTiGE (*)" 0 0
	ECHO " [32mTRACK DISKS HD Installer by Mok :-)[0m[31m" 0 0
	downline
	Echo " Deleting any previous installed tracks..." 0 0
;delete existing directory with all the contents
	EXE "c:Delete >NIL: %sTrack/#? ALL" fullpath 0
	EXE "c:Delete >NIL: %sTrack" fullpath 0
	UPLINE
	echo " Deleting any previous installed tracks... Done." 0 0
;check for free space
	FREESPACE Q
	IFBIG Q !2800000 _enuff
	ASK "You need at least 2.8 MB of free space to install the tracks" " _I'LL FIX IT! " 0 0
_abort
	ABORT
_enuff
;create track directory
;inhibit all dos access to selected drive
	INHIBIT
_Tracks
	MDIR Track
	CD Track
;ask for disk 1 and read dir
	set disk 1
_disk1
	ASK "Please insert SKID MARKS II TRACK DISK %ld and press RETURN" " _DONE | _ABORT " disk 0
	ifnot answer 1 _abort
	rs dirmem 0 400
	ifnot peekl(dirmem) 'trak' _disk1
;scan the directory for the header file
	r a5 dirmem+C
_dirloop
	if peek(\a5) 0 _disk1
	r d0 peekl(\a5)&DFDFDFDF
	if \d0 'HEAD' _gotheader
	r a5 \a5+28
	go _dirloop
_headererror
	ASK "Error in Track Header. Installation unsuccessful :-(" "_SHIT" 0 0
	ABORT
_gotheader
	set st peekl(\a5+24)
	set le peekl(\a5+20)
	ifnot le 508e _disk1
;read the track header
	rs prev+1c st le
	ifnot peekw(prev+501c) disk _disk1
	downline
	echo " Track Disk %ld found. Converting..." disk 0
	pokel dirmem 'TRAC'
	pokew dirmem+4 'K0'+disk
;open destination track file
	OPENWAD dirmem
;write preview
	WRITE prev 50AA
	set offset 50AA
	set map 0
	r a4 prev
_fileloop
	set name 'MAP0'+map
	r a5 dirmem+c
_floop
	if peek(\a5) 0 _headererror
	r d0 peekl(\a5)&DFDFDFFF
	if \d0 name _gotfile
	r a5 \a5+28
	go _floop
_gotfile
	set st peekl(\a5+24)
	set le peekl(\a5+20)
	ALLOC 2 le 10001
	rs mem(2) st le
	WRITE mem(2) le
	FREE 2
	pokel \a4 offset
	r a4 \a4+4
	add offset le
	add map 1
	ifnot map 6 _fileloop
	pokel \a4 offset
	SEEKW 0
	WRITE prev 1C
	CLOSEW
	UPLINE
	echo " Track Disk %ld found. Converting...Done." disk 0
	add disk 1
	ifnot disk 5 _disk1
	downline
	downline
	echo "[1m Installation successful...[0m" 0 0
	END
;boooo :) Done...
