Of course this code can be written for NSIS.
At worst, you write your own C Plugin that does what you are looking to do, and passes back "PASS" or "FAIL" to your Installer.
But personally, I think you won't even need to write a plugin. All the things you need are already in NSIS, you just need to experiment and figure out which ones work for you.
I think probably a combination of GetDrives, and then a combination of "${If} ${FileExists}" and a function to get the file size if the file exists.
To get the filesize, I bummed this code from some article/wiki/faq awhile ago (I can't remember the location right now...):
Function FileSize
Exch $R0 ;Grab the Inputed path file
System::Call 'kernel32::_lopen(t "$R0", i 0) i .r0' ; Call the API to open the file
System::Call 'kernel32::GetFileSize(i $0, i) i .r1' ; Call API to read file size
System::Call 'kernel32::_lclose(i $0) i' ; API to close the opened file
Push $1
FunctionEnd
Finally, I agree with most others here, what you are trying to do is kind of silly, there are so many ways to defeat what you are doing, that its almost laughable.
DVD/CD verification
77 posts
you don't need the system plugin to do that, just use FileSeek to the end and store the new location
I'm lost now! BTW this is not silly! How can generating more sales for the original title be silly!? If the game was uncrackable and it could not be copied this would work fine. Again it's not my fault that games get hacked, my problem is obeying the law and getting the work accepted by the community. If I don't do this, well several sites simply won't have anything to do with it and so not as many people will use it. Anyway this is another debate. I really need help with the code.
I don't know what I'm doing and it seems I need a degree to understand it. If someone could give me some code to work from that would be great. If it's as easy as you say it ought to be then it shouldn't take more than a few minutes of your time. I really would appreciate it and I'll donate some money to NSIS.
I don't know what I'm doing and it seems I need a degree to understand it. If someone could give me some code to work from that would be great. If it's as easy as you say it ought to be then it shouldn't take more than a few minutes of your time. I really would appreciate it and I'll donate some money to NSIS.
I have never used GetDrives, but presumably, your code would look something like:
!define FILE1_YOU_CARE_ABOUT "FILE1.exe"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
${GetDrives} "CDROM" "CheckDrive"
Function CheckDrive
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
Push "$9\${FILE1_YOU_CARE_ABOUT}"
Call FileSize
Pop $R0
${If} $R0 == ${FILE1_YOU_CARE_ABOUTSIZE}
MessageBox MB_OK "PASSED!"
# Set some Global variable here as "passed".
${Endif}
${Endif}
FunctionEnd
!define FILE1_YOU_CARE_ABOUT "FILE1.exe"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
${GetDrives} "CDROM" "CheckDrive"
Function CheckDrive
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
Push "$9\${FILE1_YOU_CARE_ABOUT}"
Call FileSize
Pop $R0
${If} $R0 == ${FILE1_YOU_CARE_ABOUTSIZE}
MessageBox MB_OK "PASSED!"
# Set some Global variable here as "passed".
${Endif}
${Endif}
FunctionEnd
Hm thanks Sheik, this is what I'm using ..
Invalid command: ${If}
But it fails to make an installer, says ..!include "FileFunc.nsh"
!insertmacro Locate
!insertmacro GetDrives
Section "Example2 (required)"
!define FILE1_YOU_CARE_ABOUT "FILE1.exe"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
${GetDrives} "CDROM" "CheckDrive"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File "example2.nsi"
File /r D:\Test\*.*
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_Example2 "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "DisplayName" "NSIS Example2"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
Function CheckDrive
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
Push "$9\${FILE1_YOU_CARE_ABOUT}"
Call FileSize
Pop $R0
${If} $R0 == ${FILE1_YOU_CARE_ABOUTSIZE}
MessageBox MB_OK "PASSED!"
# Set some Global variable here as "passed".
${Endif}
${Endif}
FunctionEnd
Invalid command: ${If}
Invalid command: ${If} == You haven't included logiclib.nsh
I have a question dudes, what if there are more than one cd-rom drives on a system? And what if it is virtual cd-rom like daemon tools?
I have a question dudes, what if there are more than one cd-rom drives on a system? And what if it is virtual cd-rom like daemon tools?
It would be great if I could prevent NSIS scanning virtual drives.
It's now saying this ..
Error: resolving install function "FileSize" in function "CheckDrive"
Note: uninstall functions must begin with "un.", and install functions must not
It's now saying this ..
Error: resolving install function "FileSize" in function "CheckDrive"
Note: uninstall functions must begin with "un.", and install functions must not
Originally posted by Red WineIt would accept the virtual disc, of course
I have a question dudes, what if there are more than one cd-rom drives on a system? And what if it is virtual cd-rom like daemon tools?
As said before: This "Copy Protection" is a farce 🙄
RedWine, Oh, I am not suggesting that this code is in any way smart... See my comment above about it being "silly" =)
He just seems so insistant on doing it, that oh well, what the heck...
Rich_A,
You need to include logiclib.nsh.
Also, my code was just a quasi-example. I literally wrote it while typing a response... I did not attempt to compile it or anything. Also, you need to change:
!define FILE1_YOU_CARE_ABOUT "FILE1.exe"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
To be a file name and filesize that you know exists on the cdrom you are checking.
He just seems so insistant on doing it, that oh well, what the heck...
Rich_A,
You need to include logiclib.nsh.
Also, my code was just a quasi-example. I literally wrote it while typing a response... I did not attempt to compile it or anything. Also, you need to change:
!define FILE1_YOU_CARE_ABOUT "FILE1.exe"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
To be a file name and filesize that you know exists on the cdrom you are checking.
Originally posted by LoRd_MuldeRNo no, the fact that the game can be cracked and copied is a farce but then again perhaps it's intentional.
It would accept the virtual disc, of course
As said before: This "Copy Protection" is a farce 🙄
You also need to add in the code I gave above:
Function FileSize
Exch $R0 ;Grab the Inputed path file
System::Call 'kernel32::_lopen(t "$R0", i 0) i .r0' ; Call the API to open the file
System::Call 'kernel32::GetFileSize(i $0, i) i .r1' ; Call API to read file size
System::Call 'kernel32::_lclose(i $0) i' ; API to close the opened file
Push $1
FunctionEnd
Function FileSize
Exch $R0 ;Grab the Inputed path file
System::Call 'kernel32::_lopen(t "$R0", i 0) i .r0' ; Call the API to open the file
System::Call 'kernel32::GetFileSize(i $0, i) i .r1' ; Call API to read file size
System::Call 'kernel32::_lclose(i $0) i' ; API to close the opened file
Push $1
FunctionEnd
Originally posted by LoRd_MuldeRIf you ask me, the whole thread is a farce 👎
It would accept the virtual disc, of course
As said before: This "Copy Protection" is a farce 🙄
Originally posted by SheikYes it makes an installer now but it installs regardless of the DVD/CD being in the drive. I need it to abort if it cannot find the specified file of specified size.
You also need to add in the code I gave above:
Function FileSize
Exch $R0 ;Grab the Inputed path file
System::Call 'kernel32::_lopen(t "$R0", i 0) i .r0' ; Call the API to open the file
System::Call 'kernel32::GetFileSize(i $0, i) i .r1' ; Call API to read file size
System::Call 'kernel32::_lclose(i $0) i' ; API to close the opened file
Push $1
FunctionEnd
No point talking about copy protection, that's not what I'm trying to do. I want verification. The fact that the game can be cracked, copied and mounted on virtual drive has nothing to do with me. Are you reading my posts or what?
Sure, the code I gave only does the checking for you.
You still need a "Var" that gets set to 0 or 1, to decide if you want to install or not.
Set it to 0 in the oninit function, then set it to 1 if you come across the file/size you are looking for.
Then before you allow the install, check to see if the variable it set to 1. If it is, install, otherwise bail.
You still need a "Var" that gets set to 0 or 1, to decide if you want to install or not.
Set it to 0 in the oninit function, then set it to 1 if you come across the file/size you are looking for.
Then before you allow the install, check to see if the variable it set to 1. If it is, install, otherwise bail.
Originally posted by SheikSuggesting code that you haven't already test doesn't sound as a good idea to me.
RedWine, Oh, I am not suggesting that this code is in any way smart... See my comment above about it being "silly" =)
He just seems so insistant on doing it, that oh well, what the heck...
Rich_A,
You need to include logiclib.nsh.
Also, my code was just a quasi-example. I literally wrote it while typing a response... I did not attempt to compile it or anything. Also, you need to change:
!define FILE1_YOU_CARE_ABOUT "FILE1.exe"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
To be a file name and filesize that you know exists on the cdrom you are checking.
@ Rich_A
You should realize that you can't get some copy protection scheme unless you pay the dedicated designers for this.
Originally posted by SheikFffffffffshhhhh, right over my head that one. I know people say, "In English please" but can I have that "In code please".
Sure, the code I gave only does the checking for you.
You still need a "Var" that gets set to 0 or 1, to decide if you want to install or not.
Set it to 0 in the oninit function, then set it to 1 if you come across the file/size you are looking for.
Then before you allow the install, check to see if the variable it set to 1. If it is, install, otherwise bail.
Here's what it looks like at the moment ..
It's installing like a normal installer at the moment regardless of DVD/CD being in drive or not.
!include "FileFunc.nsh"
!include "logiclib.nsh"
!insertmacro Locate
!insertmacro GetDrives
!define FILE1_YOU_CARE_ABOUT "FILE1.exe"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
Section "Example2 (required)"
${GetDrives} "CDROM" "CheckDrive"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File "example2.nsi"
File /r D:\Test\*.*
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_Example2 "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "DisplayName" "NSIS Example2"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
Function CheckDrive
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
Push "$9\${FILE1_YOU_CARE_ABOUT}"
Call FileSize
Pop $R0
${If} $R0 == ${FILE1_YOU_CARE_ABOUTSIZE}
MessageBox MB_OK "PASSED!"
# Set some Global variable here as "passed".
${Endif}
${Endif}
FunctionEnd
Function FileSize
Exch $R0 ;Grab the Inputed path file
System::Call 'kernel32::_lopen(t "$R0", i 0) i .r0' ; Call the API to open the file
System::Call 'kernel32::GetFileSize(i $0, i) i .r1' ; Call API to read file size
System::Call 'kernel32::_lclose(i $0) i' ; API to close the opened file
Push $1
FunctionEnd
I see you have a function "CheckDrive" specified, but do you ever call it?
If not, do it like this please:
If not, do it like this please:
Section "-CheckDriveSection"
Call CheckDrive
SectionEnd
Section "Example2 (required)"
...
SectionEnd
Function CheckDrive
...
FunctionEnd
Isn't it called on the ${GetDrives} line?
Quite possible. I have no idea what the ${GetDrives} makro does 😕
Hi Sheik, so do the variable need to go in line
# Set some Global variable here as "passed".
If so how please, it's almost complete except for the abort.
I've also discovered that cracked version cannot be used online i.e. racing online. There is a online serial key and I've found the registry entry which is created after entering a valid online serial key. So is there such a thing as ifRegkeyExists?
# Set some Global variable here as "passed".
If so how please, it's almost complete except for the abort.
I've also discovered that cracked version cannot be used online i.e. racing online. There is a online serial key and I've found the registry entry which is created after entering a valid online serial key. So is there such a thing as ifRegkeyExists?
Actually I don't think people will like having to have the original game installed. It only needs the CD verification. Sheik can you please give me the code for the variables you're talking about?
Managed to make ifFileExist search CDROM only but it's not checking file size at the moment. How can I do that?
!include "FileFunc.nsh"
!include "logiclib.nsh"
!insertmacro Locate
!insertmacro GetDrives
!define FILE1_YOU_CARE_ABOUT "Some File.foo"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
Section
${GetDrives} "CDROM" "checkdrive"
SectionEnd
Section "Example2 (required)"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File "example2.nsi"
File /r D:\Test\*.*
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_Example2 "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "DisplayName" "NSIS Example2"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example2" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
Function checkdrive
IfFileExists "$9\${FILE1_YOU_CARE_ABOUT}" ItWasFound
Abort "Origianl disc (or copy of it) was not found!"
ItWasFound:
FunctionEnd
I'm not going to comment on the legality or ask why... But here's some code for you to try. (I just hacked this together, so you may run into a few syntax errors, but it should give you the basic idea.)
And this *should* work even if you have multiple CD drives.
And this *should* work even if you have multiple CD drives.
!include "FileFunc.nsh"
!include "logiclib.nsh"
!insertmacro GetSize
!insertmacro GetDrives
!define FILE1_YOU_CARE_ABOUT "Some File.foo"
!define FILE1_YOU_CARE_ABOUTSIZE "123456789"
var FileDrive ; blank if file not exist
Section
StrCpy $FileDrive ""
${GetDrives} "CDROM" "checkdrive"
${If} "$FileDrive" == ""
Abort "Original disc (or copy of it) was not found!"
${EndIf}
${GetSize} "$FileDrive" "/M=${FILE1_YOU_CARE_ABOUT} /S=0k /G=0" $R1 $R2 $R3
${Unless} $R1 = ${FILE1_YOU_CARE_ABOUT_ABOUTSIZE}
Abort "Invalid file on target disk, $FileDrive!"
${EndUnless}
SectionEnd
Section "Example2 (required)"
; your install code here...
SectionEnd
Function checkdrive
${If} ${FileExists} "$9\${FILE1_YOU_CARE_ABOUT}"
StrCpy $FileDrive "$9"
Push "StopGetDrives"
${Else}
Push "continue"
${EndIf}
FunctionEnd
Thanks Comperio I'll try that later. Why not ask about legal issue, it's important isn't it? Many aren't sure about what is and is not legal. I think this topic has raised some issues for some people regarding the law. Also people don't like to talk about it because they're afraid they might be breaking it, but that's half the problem!
Read my posts here, I've already explained the situation. Conversions of games from one platform to another is not against the law so long as there is proof of purchase and money is not being made. It's considered "fair use". The installer is proof of purchase. I have baught this game and I'm using my own CD to make this installer work. Therefore I'm using it fairly and I'm within my rights. It's the same with any game but many titles have encryted data and I think there are laws against using and cracking encrytped data. But there is no encryption at all in GTR2, that's what's great about it.
Read my posts here, I've already explained the situation. Conversions of games from one platform to another is not against the law so long as there is proof of purchase and money is not being made. It's considered "fair use". The installer is proof of purchase. I have baught this game and I'm using my own CD to make this installer work. Therefore I'm using it fairly and I'm within my rights. It's the same with any game but many titles have encryted data and I think there are laws against using and cracking encrytped data. But there is no encryption at all in GTR2, that's what's great about it.
Your code detects the file Comperio but the size code seems to error. The compiler says ..
1 warning:
unknown variable/constant "{FILE1_YOU_CARE_ABOUT_ABOUTSIZE}" detected, ignoring (macro:_=:1)
It creates the installer though and searches for the file, passes the file search but not the file size. Any ideas? Also, is size in bytes or .. ?
1 warning:
unknown variable/constant "{FILE1_YOU_CARE_ABOUT_ABOUTSIZE}" detected, ignoring (macro:_=:1)
It creates the installer though and searches for the file, passes the file search but not the file size. Any ideas? Also, is size in bytes or .. ?
Looks like you found one of my typos... If that's the only one, consider yourself lucky! 😁
Change "${Unless} $R1 = ${FILE1_YOU_CARE_ABOUT_ABOUTSIZE}"
to "${Unless} $R1 = ${FILE1_YOU_CARE_ABOUTSIZE}"
edit: Also, the size should be KB. If you want bytes, then I belive you can change the "k" to a "b". Look up the GetSize header in the appendix section of NSIS help for more info.
Change "${Unless} $R1 = ${FILE1_YOU_CARE_ABOUT_ABOUTSIZE}"
to "${Unless} $R1 = ${FILE1_YOU_CARE_ABOUTSIZE}"
edit: Also, the size should be KB. If you want bytes, then I belive you can change the "k" to a "b". Look up the GetSize header in the appendix section of NSIS help for more info.
Lol so obvious. OK, I'll try it later thanks again.
Fanatastic it works! Even if it's 1 byte out it won't install. Many many thanks Comperio you are a Major Dude, will make donation now.
I know the last post here was a long time ago but I need more help. There are at least three version of this game available and there may be more. The code I have works for one installer only at a time because the different versions frustratingly have different names and different file sizes. Is there a way to list several files and file sizes, if it finds one it will continue installation?
Here is the relevant code ..
!include "FileFunc.nsh"
!include "logiclib.nsh"
!insertmacro GetSize
!insertmacro GetDrives
!define FILE1_YOU_CARE_ABOUT "XXXXXX.XXX"
!define FILE1_YOU_CARE_ABOUTSIZE "XXXXXXX"
var FileDrive ; blank if file not exist
Section
StrCpy $FileDrive ""
${GetDrives} "CDROM" "checkdrive"
${If} "$FileDrive" == ""
Abort "Message."
${EndIf}
${GetSize} "$FileDrive" "/M=${FILE1_YOU_CARE_ABOUT} /S=0B /G=0" $R1 $R2 $R3
${Unless} $R1 = ${FILE1_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}"
StrCpy $FileDrive "$9"
Push "StopGetDrives"
${Else}
Push "continue"
${EndIf}
FunctionEnd