This repository has been archived by the owner on Apr 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFindDisc.pas
131 lines (110 loc) · 3.61 KB
/
FindDisc.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// LEGO(R) Stunt Rally Alternate Installer
// Created 2013-2014 Triangle717
// <http://Triangle717.WordPress.com/>
// Contains source code from Grim Fandango Setup
// Copyright (c) 2007-2008 Bgbennyboy
// <http://quick.mixnmojo.com/>
[Code]
var
DrvLetters: array of AnsiString;
function GetDriveType( lpDisk: AnsiString ): Integer;
external '[email protected] stdcall';
function GetLogicalDriveStrings( nLenDrives: LongInt; lpDrives: AnsiString ): Integer;
external '[email protected] stdcall';
const
// Ensure this is a Stunt Rally disc
UniqueFile_1 = '_avi_\intro.avi';
DRIVE_UNKNOWN = 0; // The drive type cannot be determined.
DRIVE_NO_ROOT_DIR = 1; // The root path is invalid. For example, no volume is mounted at the path.
DRIVE_REMOVABLE = 2; // The disk can be removed from the drive.
DRIVE_FIXED = 3; // The disk cannot be removed from the drive.
DRIVE_REMOTE = 4; // The drive is a remote (network) drive.
DRIVE_CDROM = 5; // The drive is a CD-ROM drive.
DRIVE_RAMDISK = 6; // The drive is a RAM disk.
//Convert disk type to string
function DriveTypeString( dtype: Integer ): AnsiString ;
begin
case dtype of
DRIVE_NO_ROOT_DIR : Result := 'Root path invalid';
DRIVE_REMOVABLE : Result := 'Removable';
DRIVE_FIXED : Result := 'Fixed';
DRIVE_REMOTE : Result := 'Network';
DRIVE_CDROM : Result := 'CD-ROM';
DRIVE_RAMDISK : Result := 'Ram disk';
else
Result := 'Unknown';
end;
end;
procedure FindAllCdDrives();
var
n: Integer;
drivesletters: AnsiString; lenletters: Integer;
drive: AnsiString;
disktype, posnull: Integer;
sd: AnsiString;
begin
//get the system drive
sd := UpperCase(ExpandConstant('{sd}'));
//get all drives letters of system
drivesletters := StringOfChar( ' ', 64 );
lenletters := GetLogicalDriveStrings( 63, drivesletters );
SetLength( drivesletters , lenletters );
drive := '';
n := 0;
while ( (Length(drivesletters) > 0) ) do
begin
posnull := Pos( #0, drivesletters );
if posnull > 0 then
begin
drive:= UpperCase( Copy( drivesletters, 1, posnull - 1 ) );
// get number type of disk
disktype := GetDriveType( drive );
//Make sure its a cd drive
if disktype = DRIVE_CDROM then
begin
SetArrayLength(DrvLetters, N+1);
DrvLetters[n] := drive;
n := n + 1;
end;
drivesletters := Copy( drivesletters, posnull+1, Length(drivesletters));
end;
end;
end;
function FindUniqueFile(): Ansistring;
var
i: integer;
begin
for i:=0 to GetArrayLength(DrvLetters) -1 do
begin
// A LEGO Stunt Rally disc was detected
if FileExists( DrvLetters[i] + UniqueFile_1) then
begin
result:=DrvLetters[i];
exit;
end
end;
result:='';
end;
function GetSourceCdDrive(): Ansistring;
begin
FindAllCdDrives();
if GetArrayLength(DrvLetters) < 1 then
begin
MsgBox('No disc drive was found on your computer.', mbError, MB_OK);
Abort;
end;
if FindUniqueFile() <> '' then
begin
//MsgBox('', mbError, MB_OK);
end
else
begin
while FindUniqueFile() = '' do
begin
if MsgBox('Is there a LEGO Stunt Rally CD in your computer? If not, please insert it and press OK.', mbConfirmation, MB_OKCANCEL or MB_DEFBUTTON1) = IDOK then
else
Abort;
end;
end;
Result:=FindUniqueFile();
end;