I'll make another donation if someone finds a way to do this?
DVD/CD verification
77 posts
Simply use ${OrUnless} and ${OrIf} where you check for size and file existence to add more cases.
Hi kichik, that's great that it's possible. Could you perhaps use my code and make an example, not sure where to or how to use what you're suggesting, gimme something to try please. I got all this code from this topic, I know the basics but whenever I try something there's always a typo or error.
For example:
${Unless} $R1 = ${FILE1_YOU_CARE_ABOUTSIZE}
${OrUnless} $R1 = ${FILE2_YOU_CARE_ABOUTSIZE}${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
${OrIf} ${FileExists} "$9\${FILE2_YOU_CARE_ABOUT}"OK thanks will try some things there.
It's giving invalid file on target disk which means it failing unless all defined files are present I think.
Here's the code I've got ..
Here's the code I've got ..
!define FILE1_YOU_CARE_ABOUT "x.x"
!define FILE1_YOU_CARE_ABOUTSIZE "123"
!define FILE2_YOU_CARE_ABOUT "x.x"
!define FILE2_YOU_CARE_ABOUTSIZE "123"
!define FILE3_YOU_CARE_ABOUT "x.x"
!define FILE3_YOU_CARE_ABOUTSIZE "123"
var FileDrive ; blank if file not exist
Section
StrCpy $FileDrive ""
${GetDrives} "CDROM" "checkdrive"
${If} "$FileDrive" == ""
Abort "Please insert GTR2 DVD or CD and try again, verification failed."
${EndIf}
${GetSize} "$FileDrive" "/M=${FILE1_YOU_CARE_ABOUT} /S=0B /G=0" $R1 $R2 $R3
${GetSize} "$FileDrive" "/M=${FILE2_YOU_CARE_ABOUT} /S=0B /G=0" $R1 $R2 $R3
${GetSize} "$FileDrive" "/M=${FILE3_YOU_CARE_ABOUT} /S=0B /G=0" $R1 $R2 $R3
${Unless} $R1 = ${FILE1_YOU_CARE_ABOUTSIZE}
${OrUnless} $R1 = ${FILE2_YOU_CARE_ABOUTSIZE}
${OrUnless} $R1 = ${FILE3_YOU_CARE_ABOUTSIZE}
Abort "Invalid file on target disk $FileDrive"
${EndUnless}
SectionEnd
Section "EOAA GT V1.00"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File /r "X:\X\*.*"
; Write the installation path into the registry
WriteRegStr HKLM "SOFTWARE\EOAA GT" "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "DisplayName" "EOAA GT V1.00"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "UninstallString" '"$INSTDIR\Uninstall EOAA GT.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "NoRepair" 1
WriteUninstaller "Uninstall EOAA GT.exe"
SectionEnd
Function checkdrive
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
${OrIf} ${FileExists} "$9\${FILE2_YOU_CARE_ABOUT}"
${OrIf} ${FileExists} "$9\${FILE3_YOU_CARE_ABOUT}"
StrCpy $FileDrive "$9"
Push "StopGetDrives"
${Else}
Push "continue"
${EndIf}
FunctionEnd
LogicLib.nsi has ElseUnless, seems to be working with ElseUnless need to do more testing though.
No ElseUnless allows installation to run regardless of file size has to be OrUnless but it's not working ATM.
This IMO ought to work, if it doesn't find file1, having file2 or file3 present will permit installer to run but for some reason it's giving the "Invalid file on target disk $FileDrive" error, I know file1 is present and of correct size so it can only mean that it's expecting file2 and file3 to be there also. Perhaps it needs OrGetSize?
Section
StrCpy $FileDrive ""
${GetDrives} "CDROM" "checkdrive"
${If} "$FileDrive" == ""
Abort "Please insert GTR2 DVD or CD and try again, verification failed."
${EndIf}
${GetSize} "$FileDrive" "/M=${FILE1_YOU_CARE_ABOUT} /S=0B /G=0" $R1 $R2 $R3
${Unless} $R1 = ${FILE1_YOU_CARE_ABOUTSIZE}
${GetSize} "$FileDrive" "/M=${FILE2_YOU_CARE_ABOUT} /S=0B /G=0" $R1 $R2 $R3
${OrUnless} $R1 = ${FILE2_YOU_CARE_ABOUTSIZE}
${GetSize} "$FileDrive" "/M=${FILE3_YOU_CARE_ABOUT} /S=0B /G=0" $R1 $R2 $R3
${OrUnless} $R1 = ${FILE3_YOU_CARE_ABOUTSIZE}
Abort "Invalid file on target disk $FileDrive"
${EndUnless}
SectionEnd
You can't lace ${GetSize} calls between ${Unless} and ${OrUnless}. Get all the sizes into variables and then compare them all at once, or get the size and compare separately.
I'm sorry I don't know what you mean can I have another example please?
${GetSize} "$FileDrive" "/M=${FILE1_YOU_CARE_ABOUT} /S=0B /G=0" $0 $R2 $R3
${GetSize} "$FileDrive" "/M=${FILE2_YOU_CARE_ABOUT} /S=0B /G=0" $1 $R2 $R3
${GetSize} "$FileDrive" "/M=${FILE3_YOU_CARE_ABOUT} /S=0B /G=0" $2 $R2 $R3
${Unless} $1 = ${FILE1_YOU_CARE_ABOUTSIZE}
${OrUnless} $2 = ${FILE2_YOU_CARE_ABOUTSIZE}
${OrUnless} $3 = ${FILE3_YOU_CARE_ABOUTSIZE}That's what I tried the first time but it say invalid file on target disk. This code require that all 3 files be present doesn't it, if not present abort. I want it to search for file1 and file2 and file3, if ANY of the files are are found and the size is correct, installation continues. It only needs to find one correct file.
I think I got the LogicLib logic setup correctly. I don't have a computer setup to test it, so try this code on your own to see if it works:
var WhichVersion ; used to keep track of which version you need to install
Function .onInit
${GetDrives} "CDROM" "checkdrive"
${If} $WhichVersion = 0
MessageBox MB_OK "Abort Message"
abort
${EndIf}
; at this point, you could set set section flags based on the value of $WhichVersion
FunctionEnd
Function checkdrive
StrCpy $WhichVersion 0
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
${GetSize} "$9" "\M=${FILE1_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE1_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 1
${EndIf}
${OrIf} ${FileExists} "$9\${FILE2_YOU_CARE_ABOUT}"
${GetSize} "$9" "\M=${FILE2_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE2_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 2
${EndIf}
${OrIf} ${FileExists} "$9\${FILE3_YOU_CARE_ABOUT}"
${GetSize} "$9" "\M=${FILE3_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE3_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 3
${EndIf}
${EndIf}
; Continue ${GetDrives} if you haven't found what you needed:
${If} $WhichVersion = 0
Push "continue"
${Else}
push "StopGetDrives"
${EndIf}
FunctionEnd
That's great thanks Comperio. I tried it and it aborts even though I'm sure the definitions are correct and CD is in CDROM drive. It needs to continue if WhichVersion(x) is present.
Here is the code, probably not right ..
Here is the code, probably not right ..
var WhichVersion ; used to keep track of which version you need to install
Section "EOAA GT V1.00"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File /r "x:\x\*.*"
; Write the installation path into the registry
WriteRegStr HKLM "SOFTWARE\EOAA GT" "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "DisplayName" "EOAA GT V1.00"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "UninstallString" '"$INSTDIR\Uninstall EOAA GT.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "NoRepair" 1
WriteUninstaller "Uninstall EOAA GT.exe"
SectionEnd
Function .onInit
${GetDrives} "CDROM" "checkdrive"
${If} $WhichVersion = 0
MessageBox MB_OK "Abort Message"
abort
${EndIf}
; at this point, you could set set section flags based on the value of $WhichVersion
FunctionEnd
Function checkdrive
StrCpy $WhichVersion 0
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
${GetSize} "$9" "\M=${FILE1_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE1_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 1
${EndIf}
${OrIf} ${FileExists} "$9\${FILE2_YOU_CARE_ABOUT}"
${GetSize} "$9" "\M=${FILE2_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE2_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 2
${EndIf}
${OrIf} ${FileExists} "$9\${FILE3_YOU_CARE_ABOUT}"
${GetSize} "$9" "\M=${FILE3_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE3_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 3
${EndIf}
${EndIf}
; Continue ${GetDrives} if you haven't found what you needed:
${If} $WhichVersion = 0
Push "continue"
${Else}
push "StopGetDrives"
${EndIf}
FunctionEnd
Is a typo \M, works with /M. Donation heading NSIS's way, thanks Comperio! 👍
Here's the full code ..
Here's the full code ..
; EOAA GT.nsi
; The name of the installer
Name "EOAA GT V1.00"
; The file to write
OutFile "EOAA GT V1.00.exe"
; The default installation directory
InstallDir $PROGRAMFILES\rFactor
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\EOAA GT" "Install_Dir"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;--------------------------------
!include "FileFunc.nsh"
!include "logiclib.nsh"
!insertmacro GetSize
!insertmacro GetDrives
!define FILE1_YOU_CARE_ABOUT "x.x"
!define FILE1_YOU_CARE_ABOUTSIZE "123"
!define FILE2_YOU_CARE_ABOUT "x.x"
!define FILE2_YOU_CARE_ABOUTSIZE "456"
!define FILE3_YOU_CARE_ABOUT "x.x"
!define FILE3_YOU_CARE_ABOUTSIZE "789"
var WhichVersion ; used to keep track of which version you need to install
Function .onInit
${GetDrives} "CDROM" "checkdrive"
${If} $WhichVersion = 0
MessageBox MB_OK "Abort Message"
abort
${EndIf}
; at this point, you could set set section flags based on the value of $WhichVersion
FunctionEnd
Function checkdrive
StrCpy $WhichVersion 0
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
${GetSize} "$9" "/M=${FILE1_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE1_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 1
${EndIf}
${OrIf} ${FileExists} "$9\${FILE2_YOU_CARE_ABOUT}"
${GetSize} "$9" "/M=${FILE2_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE2_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 2
${EndIf}
${OrIf} ${FileExists} "$9\${FILE3_YOU_CARE_ABOUT}"
${GetSize} "$9" "/M=${FILE3_YOU_CARE_ABOUT} /S=0B /G=0" $1 $2 $3
${If} $1 = ${FILE3_YOU_CARE_ABOUTSIZE}
StrCpy $WhichVersion 3
${EndIf}
${EndIf}
; Continue ${GetDrives} if you haven't found what you needed:
${If} $WhichVersion = 0
Push "continue"
${Else}
push "StopGetDrives"
${EndIf}
FunctionEnd
Section "EOAA GT V1.00"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File /r "C:\Folder\Folder\*.*"
; Write the installation path into the registry
WriteRegStr HKLM "SOFTWARE\EOAA GT" "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "DisplayName" "EOAA GT V1.00"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "UninstallString" '"$INSTDIR\Uninstall EOAA GT.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT" "NoRepair" 1
WriteUninstaller "Uninstall EOAA GT.exe"
SectionEnd
; Uninstaller
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\EOAA GT"
DeleteRegKey HKLM "SOFTWARE\EOAA GT"
; Remove files and uninstaller
Delete "$INSTDIR\Uninstall EOAA GT.exe"
Delete "$INSTDIR\rFm\EOAA GT.tga"
Delete "$INSTDIR\rFm\EOAA GT_logo.tga"
Delete "$INSTDIR\rFm\EOAA GT.rfm"
Delete "$INSTDIR\rFm\EOAA GT.bik"
; Remove directories used
RMDir /r "$INSTDIR\GameData\Vehicles\EOAA GT"
RMDir /r "$INSTDIR\GameData\Helmets\EOAA GT"
RMDir /r "$INSTDIR\GameData\Sounds\E_GT"
RMDir /r "$INSTDIR\UIData\EOAA GT"
RMDir /r "$INSTDIR\Music\EOAA GT"
SectionEnd
LOL!
I was just trying this again and was getting same result and couldn't figure it out. I didn't see your reply about "\M" until I had already spend about an hour of troubleshooting! 😳
I'm glad you figured it out! 👍
I was just trying this again and was getting same result and couldn't figure it out. I didn't see your reply about "\M" until I had already spend about an hour of troubleshooting! 😳
I'm glad you figured it out! 👍