GetDrives: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Added category links.) |
m (Adding new author and category links.) |
||
Line 1: | Line 1: | ||
{ | {{PageAuthor|Instructor}} | ||
== Links == | == Links == | ||
; Latest version of headers "nsh.zip": | ; Latest version of headers "nsh.zip": | ||
Line 219: | Line 217: | ||
FunctionEnd</highlight-nsis> | FunctionEnd</highlight-nsis> | ||
[[ | [[Category:Disk, Path & File Functions]] |
Revision as of 12:14, 24 June 2005
Author: Instructor (talk, contrib) |
Links
- Latest version of headers "nsh.zip"
- http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost
If function used without header then put function in script before call it
The Function
/* ____________________________________________________________________________ GetDrives v1.3 ____________________________________________________________________________ Thanks deguix (Based on his idea of Function "DetectDrives") Find all available drives in the system. Syntax: ${GetDrives} "[Option]" "Function" "[Option]" ; [FDD+HDD+CDROM+NET+RAM] ; FDD Floppy Disk Drives ; HDD Hard Disk Drives ; CDROM CD-ROM Drives ; NET Network Drives ; RAM RAM Disk Drives ; ; [ALL] ; Find all drives by letter (default) ; "Function" ; Callback function then found Function "Function" ; $9 "drive letter" (a:\ c:\ ...) ; $8 "drive type" (FDD HDD ...) ; $R0-$R9 are not used (save data in them). ; ... Push $var ; If $var="StopGetDrives" Then exit from function FunctionEnd Example1: Section ${GetDrives} "FDD+CDROM" "Example1" SectionEnd Function Example1 MessageBox MB_OK "$9 ($8 Drive)" Push $0 FunctionEnd Example2: Section ${GetDrives} "ALL" "Example2" SectionEnd Function Example2 MessageBox MB_OK "$9 ($8 Drive)" Push $0 FunctionEnd Example3 (Get type of drive): Section StrCpy $R0 "D:\" ;Drive letter StrCpy $R1 "invalid" ${GetDrives} "ALL" "Example3" MessageBox MB_OK "Type of drive $R0 is $R1" SectionEnd Function Example3 StrCmp $9 $R0 0 +3 StrCpy $R1 $8 StrCpy $0 StopGetDrives Push $0 FunctionEnd*/ ;--------------------------------------------------------------------------- Function GetDrives !define GetDrives `!insertmacro GetDrivesCall` !macro GetDrivesCall _DRV _FUNC Push $0 Push `${_DRV}` GetFunctionAddress $0 `${_FUNC}` Push `$0` Call GetDrives Pop $0 !macroend Exch $1 Exch Exch $0 Exch Push $2 Push $3 Push $4 Push $5 Push $8 Push $9 System::Alloc 1024 Pop $2 StrCmp $0 ALL drivestring StrCmp $0 '' 0 typeset StrCpy $0 ALL goto drivestring typeset: StrCpy $5 -1 IntOp $5 $5 + 1 StrCpy $8 $0 1 $5 StrCmp $8$0 '' enumex StrCmp $8 '' +2 StrCmp $8 '+' 0 -4 StrCpy $8 $0 $5 IntOp $5 $5 + 1 StrCpy $0 $0 '' $5 StrCmp $8 'FDD' 0 +3 StrCpy $5 2 goto drivestring StrCmp $8 'HDD' 0 +3 StrCpy $5 3 goto drivestring StrCmp $8 'NET' 0 +3 StrCpy $5 4 goto drivestring StrCmp $8 'CDROM' 0 +3 StrCpy $5 5 goto drivestring StrCmp $8 'RAM' 0 typeset StrCpy $5 6 drivestring: System::Call 'kernel32::GetLogicalDriveStringsA(i,i) i(1024,r2)' enumok: System::Call 'kernel32::lstrlenA(t) i(i r2) .r3' StrCmp $3$0 '0ALL' enumex StrCmp $3 0 typeset System::Call 'kernel32::GetDriveTypeA(t) i (i r2) .r4' StrCmp $0 ALL +2 StrCmp $4 $5 letter enumnext StrCmp $4 2 0 +3 StrCpy $8 FDD goto letter StrCmp $4 3 0 +3 StrCpy $8 HDD goto letter StrCmp $4 4 0 +3 StrCpy $8 NET goto letter StrCmp $4 5 0 +3 StrCpy $8 CDROM goto letter StrCmp $4 6 0 enumex StrCpy $8 RAM letter: System::Call '*$2(&t1024 .r9)' Push $0 Push $1 Push $2 Push $3 Push $4 Push $5 Push $8 Call $1 Pop $9 Pop $8 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 StrCmp $9 'StopGetDrives' enumex enumnext: IntOp $2 $2 + $3 IntOp $2 $2 + 1 goto enumok enumex: System::Free $2 Pop $9 Pop $8 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 FunctionEnd