Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | unit SFXAutoRun; |
2 | |||
3 | interface |
||
4 | |||
5 | uses |
||
6 | SysUtils, Windows, IniFiles, ShellAPI; |
||
7 | |||
8 | type |
||
9 | TExecuteSFXAutoRunResult = record |
||
10 | AutoRunSectionAvailable: boolean; |
||
11 | ExecutionSucceed: boolean; |
||
12 | HInstance: Integer; |
||
13 | OpenUnzippedContent: boolean; |
||
14 | end; |
||
15 | |||
16 | function ExecuteSFXAutoRun(ADirectory: string): TExecuteSFXAutoRunResult; |
||
17 | |||
18 | implementation |
||
19 | |||
20 | function StrToShowCmd(s: String): Integer; |
||
21 | begin |
||
22 | s := UpperCase(s); |
||
23 | if s = 'SW_HIDE' then |
||
24 | result := SW_HIDE |
||
25 | else if s = 'SW_MAXIMIZE' then |
||
26 | result := SW_MAXIMIZE |
||
27 | else if s = 'SW_MINIMIZE' then |
||
28 | result := SW_MINIMIZE |
||
29 | else if s = 'SW_RESTORE' then |
||
30 | result := SW_RESTORE |
||
31 | else if s = 'SW_SHOW' then |
||
32 | result := SW_SHOW |
||
33 | else if s = 'SW_SHOWDEFAULT' then |
||
34 | result := SW_SHOWDEFAULT |
||
35 | else if s = 'SW_SHOWMAXIMIZED' then |
||
36 | result := SW_SHOWMAXIMIZED |
||
37 | else if s = 'SW_SHOWMINIMIZED' then |
||
38 | result := SW_SHOWMINIMIZED |
||
39 | else if s = 'SW_SHOWMINNOACTIVE' then |
||
40 | result := SW_SHOWMINNOACTIVE |
||
41 | else if s = 'SW_SHOWNA' then |
||
42 | result := SW_SHOWNA |
||
43 | else if s = 'SW_SHOWNOACTIVATE' then |
||
44 | result := SW_SHOWNOACTIVATE |
||
45 | else if s = 'SW_SHOWNORMAL' then |
||
46 | result := SW_SHOWNORMAL |
||
47 | else |
||
48 | result := -1; |
||
49 | end; |
||
50 | |||
51 | function ExecuteSFXAutoRun(ADirectory: string): TExecuteSFXAutoRunResult; |
||
52 | var |
||
53 | x: TIniFile; |
||
54 | Operation, FileName, Parameters, Directory, ShowCmd: string; |
||
55 | XShowCmd: Integer; |
||
56 | XOperation, XFileName, XParameters, XDirectory: PChar; |
||
57 | const |
||
58 | AR = 'AutoRun.inf'; |
||
59 | Section = 'AutoSFX'; |
||
60 | begin |
||
61 | result.AutoRunSectionAvailable := false; |
||
62 | result.ExecutionSucceed := false; |
||
63 | result.HInstance := -1; |
||
64 | result.OpenUnzippedContent := true; |
||
65 | |||
66 | if not DirectoryExists(ADirectory) then Exit; |
||
67 | ADirectory := IncludeTrailingPathDelimiter(ADirectory); |
||
68 | if not FileExists(ADirectory + AR) then Exit; |
||
69 | |||
70 | x := TIniFile.Create(ADirectory + AR); |
||
71 | try |
||
72 | if not x.SectionExists(Section) then Exit; |
||
73 | result.AutoRunSectionAvailable := true; |
||
74 | |||
75 | Operation := x.ReadString(Section, 'Operation', 'open'); |
||
76 | FileName := x.ReadString(Section, 'FileName', ''); |
||
77 | if FileName = '' then Exit; |
||
78 | Parameters := x.ReadString(Section, 'Parameters', ''); |
||
79 | Directory := x.ReadString(Section, 'Directory', ''); |
||
80 | ShowCmd := x.ReadString(Section, 'ShowCmd', 'SW_NORMAL'); |
||
81 | |||
82 | if UpperCase(Operation) = 'NULL' then |
||
83 | begin |
||
84 | XOperation := nil |
||
85 | end |
||
86 | else |
||
87 | begin |
||
88 | XOperation := PChar(Operation); |
||
89 | end; |
||
90 | XFileName := PChar(FileName); |
||
91 | XParameters := PChar(Parameters); |
||
92 | XDirectory := PChar(Directory); |
||
93 | XShowCmd := StrToShowCmd(ShowCmd); |
||
94 | |||
95 | // Since our application will now terminate, I let the handle be 0. |
||
96 | result.HInstance := ShellExecute(0, XOperation, XFileName, XParameters, XDirectory, XShowCmd); |
||
97 | result.ExecutionSucceed := result.HInstance > 32; |
||
98 | |||
99 | result.OpenUnzippedContent := x.ReadBool(Section, 'OpenUnzippedContent', true) |
||
100 | finally |
||
101 | x.Free; |
||
102 | end; |
||
103 | end; |
||
104 | |||
105 | end. |