Old 17th November 2017, 16:34   #1
Dxmega
Junior Member
 
Join Date: Nov 2017
Posts: 4
About Detect Drives function

I've been looking for a while (3 hours ;~ how to implement this function (http://nsis.sourceforge.net/Detect_Drives) in my program.

Im really new to nsis and I can't find any example using that so as my last resort I've posted here.

Whenever I add the function directly to the code, because I dont know any other way, and I call it from the section I have it like this:
code:
Push "All Local Drives" ; Drive types used for the search. See "Drive Types".
Push $0
GetFunctionAddress $0 "CallbackFunction" ; Custom callback function name.
Exch $0
Call DetectDrives



I always get an error on te CallbackFunction.

Processed 1 file, writing output (x86-ansi):
Adding plug-ins initializing function... Done!
Error: resolving install function "CallbackFunction" in install section "" (0)
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process

I don't know if Im doing anything wrong or its missing anything.

How do I fix this?

Note: Im trying to use this function to get the Driver Letter from a pendrive.

Thanks in advance
-Dxmega
Dxmega is offline   Reply With Quote
Old 17th November 2017, 17:29   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,767
Did you delete your stackoverflow question? I was about to ask, do you only care about the volume name?

CallbackFunction is a function you have to implement yourself, it is called once for each drive.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th November 2017, 23:12   #3
Dxmega
Junior Member
 
Join Date: Nov 2017
Posts: 4
Yes I did indeed delete the stack over flow question, because I thought I didnt correctly asked it how I should.

Id like to know the name well the letter more exactly like: E:/ or C:/ or D:/.
Dxmega is offline   Reply With Quote
Old 17th November 2017, 23:32   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,767
I know you want the drive letter but we need to know what you can use to identify the drive. On Stackoverflow you said something about a name? Kingston? Is that the volume label? Is there anything else you can look for? A file on the thumb drive?

I was going to answer you on Stackoverflow with code checking the volume label but you deleted it too soon.

Edit:

From your deleted question

Quote:
I wanted to make an installer that would check if a folder existed inside a Usb flash drive.
Do you know the name of a folder that is always present on the drive?

Quote:
The name of the pen could be a constant, ex: KINGSTON.
Is this the volume label?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 18th November 2017, 00:21   #5
Dxmega
Junior Member
 
Join Date: Nov 2017
Posts: 4
I do know the name of the folder inside of the pendrive. (The folder will never leave the pendrive.)

And

KINGSTON is the name of the pendrive aka Volume Label.
Dxmega is offline   Reply With Quote
Old 18th November 2017, 15:01   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,767
Something like this perhaps:

PHP Code:
!include LogicLib.nsh


Section
StrCpy 
$"" Drive not found
System
::Call 'KERNEL32::GetLogicalDrives()i.r1'
${For} $2 0 25
    IntOp 
$3 1 << $2
    IntOp 
$$& $3
    
${IfThen} $${|} ${Continue} ${|}
    
IntOp $3 65 + $'A' drive id
    IntFmt 
$"%c:\" $3
    System::Call 'KERNEL32::GetVolumeInformation(tr3,t.r4,i
${NSIS_MAX_STRLEN},*i,*i,*i,t,i${NSIS_MAX_STRLEN})i.r5'
    DetailPrint Debug:$3=$4
    
${If} $5 <> 0
    
${AndIf} $4 == "KINGSTON"
        DetailPrint "
Debug:Found drive $3 with volume name $4"
        
${If} ${FileExists} "$3\MySpecialFolder\*"
            DetailPrint "
Debug:Found special folder on $3"
            StrCpy $9 $3
        
${EndIf}
    
${EndIf}
${Next}

${If} $9 != ""
    DetailPrint "
My drive=$9"
${EndIf}
SectionEnd 
This does not check the drive type but I don't really think that is important if you are checking two other things.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 23rd November 2017, 08:34   #7
Dxmega
Junior Member
 
Join Date: Nov 2017
Posts: 4
Im sorry I couldn't reply sooner, my pendrive stopped working so I couldn't test it.
However this is exactly what I needed!
Thank you .
Dxmega is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump