View Single Post
Old 4th July 2019, 00:22   #6
Nutzzz
Member
 
Join Date: May 2007
Location: Orange County, CA, U.S.A.
Posts: 58
Quote:
Originally Posted by meoit View Post
There are computers with 2 devices, 3 devices, 4 devices, ... how do we know how many devices that the computer has ?.
If you could assume that the disk numbers are contiguous, you could just loop through them until the Errors flag is set. Though that's usually true, it's not always a safe assumption. Assuming this ini file isn't used for any other purpose, I would personally make the section name in square brackets use the %%G number instead of the disk number, and then contiguity would be guaranteed.

Spoiler:
code:
rem ...
SET "strCount=%%G"

SET "strCaption=%%H"

SET "strIndex=%%I"

SET "strSize=%%J"

>>"%InputFile%" CALL ECHO [Disk%%strCount%%]

>>"%InputFile%" CALL ECHO Item=Index%%strIndex%% - %%strCaption%% (%%strSize%%^)
rem ...



Assuming you've done that, you'd loop through them, e.g.:

Spoiler:
code:
!include LogicLib.nsh
# ...
StrCpy $R0 0
ClearErrors
${DoUntil} ${Errors}
ReadINIStr $0 'D:\MyDisks.ini' 'Disk$R0' 'Item'
${IfNot} ${Errors}
${AndIfNot} $0 == ""
# ...
${EndIf}
IntOp $R0 $R0 + 1
${Loop}
ClearErrors



* * * * *

If you need to keep the index as is for some reason, then you'd have to come up with a maximum number beyond which the number of drives is unreasonable. 16, maybe, for a consumer system, but if you might be installing on a server, even though usually you'd expect to find lots of drives hidden behind a RAID pool, theoretically you could have hundreds of disks in a bunch of JBODs, so let's say, 200?

e.g.:

code:
!include LogicLib.nsh
!define MAX_DRIVES 200
# ...
ClearErrors
${For} $R0 0 ${MAX_DRIVES}
ReadINIStr $0 'D:\MyDisks.ini' 'Disk$R0' 'Item'
${IfNot} ${Errors}
${AndIfNot} $0 == ""
# ...
${EndIf}
${Next}
ClearErrors

Nutzzz is offline   Reply With Quote