File: DetectDrives.nsi

package info (click to toggle)
octave2.1-forge 2006.03.17%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 16,672 kB
  • ctags: 6,047
  • sloc: cpp: 49,610; ansic: 14,035; perl: 2,789; sh: 2,087; makefile: 1,560; lex: 1,219; tcl: 799; fortran: 422; objc: 202
file content (177 lines) | stat: -rw-r--r-- 3,286 bytes parent folder | download | duplicates (4)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Title: Detect Local Drives
# Author: deguix
# Source: NSIS archive >Browse >Useful Functions >Disk, Path & File Functions
#
# Function to detect available local drives and return their letters
# (with colon and foward slash, like C:/). As my Search File Function,
# this function uses the callback function, for each drive detected.
#
# Calling sequence:
#   !include "DetectDrives.nsi"
#
#   Push "DriveTypes"
#   Push $0
#   GetFunctionAddress $0 "Callback"
#   Exch $0
#   Call DetectDrives
#
# Drive Types:
#
#   Three drive types are available:
#
#     Hard Drives
#     CDROM Drives
#     Diskette Drives
#
#   Separate multiple drive types by '&' (but keep the above order!).
#
#   E.g.,
#      Hard Drives & Diskette Drives
#      CDROM Drives & Diskette Drives
#      Hard Drives & CDROM Drives & Diskette Drives
#
#   To select all, you may also use:
#      All Local Drives
#
# Callback function:
#
#    * On entry, $R0 contains the drive letter detected.
#
#    * On return, push "Stop" to stop, or "Continue" to continue searching.
#
#    * Do not push any other values on the stack without popping them later.
#
#    * Use any variables, but $R0 through $R4 will be overwritten.
#
# Notes:
#   Uses the system and kernel32 plugins repeatedly.  You may get better 
#   performance if you have the following in your .nsi file:
# 
#      SetPluginUnload alwaysoff
#
#   This clue is from reading the docs, not from any tests. YMMV.

Function DetectDrives

Exch
Exch $R0
Exch
Exch $R1
Push $R2
Push $R3
Push $R4
StrCpy $R4 $R1

# Memory for paths
 
System::Alloc 1024 
Pop $R1 

# Get drives 

System::Call 'kernel32::GetLogicalDriveStringsA(i, i) i(1024, R1)' 

enumok: 

# One more drive? 

System::Call 'kernel32::lstrlenA(t) i(i R1) .R2' 
IntCmp $R2 0 enumex 

# Now, search for drives according to user conditions

System::Call 'kernel32::GetDriveTypeA(t) i (i R1) .R3' 

StrCmp $R0 "Hard Drives" 0 +2
StrCmp $R3 3 0 enumnext

StrCmp $R0 "CDROM Drives" 0 +2
StrCmp $R3 5 0 enumnext

StrCmp $R0 "Diskette Drives" 0 +2
StrCmp $R3 2 0 enumnext

StrCmp $R0 "Hard Drives & CDROM Drives" 0 +3
StrCmp $R3 3 +2 0
StrCmp $R3 5 0 enumnext

StrCmp $R0 "Hard Drives & Diskette Drives" 0 +3
StrCmp $R3 3 +2 0
StrCmp $R3 2 0 enumnext

StrCmp $R0 "CDROM Drives & Diskette Drives" 0 +3
StrCmp $R3 5 +2 0
StrCmp $R3 2 0 enumnext

StrCmp $R0 "Hard Drives & CDROM Drives & Diskette Drives" +2 0
StrCmp $R0 "All Local Drives" 0 +4
StrCmp $R3 3 +3 0
StrCmp $R3 5 +2 0
StrCmp $R3 2 0 enumnext

# Get drive path string 

System::Call '*$R1(&t1024 .R3)' 

# Prepare variables for the Callback function

Push $R4
Push $R3
Push $R2
Push $R1
Push $R0

StrCpy $R0 $R3

# Call the Callback function

Call $R4

# Return variables

Push $R5
Exch
Pop $R5

Exch
Pop $R0
Exch
Pop $R1
Exch
Pop $R2
Exch
Pop $R3
Exch
Pop $R4

StrCmp $R5 "Stop" 0 +3
  Pop $R5
  Goto enumex

Pop $R5

enumnext: 

# Next drive path

IntOp $R1 $R1 + $R2 
IntOp $R1 $R1 + 1 
goto enumok 

# End Search

enumex:
 
# Free memory used for paths

System::Free $R1 

# Return original user variables

Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0

FunctionEnd