Archive: Open with... NSIS


Open with... NSIS
i was wondering if/how i could register a filetype to be opened with a NSIS scripted program (blabla.exe filename.bla). the question would be how to hand over the file as variable within NSIS.


I think, based on makensis.nsi example, it's registry thing, look:


ReadRegStr $1 HKCR ".nsi" ""
StrCmp $1 "" Label1
StrCmp $1 "NSISFile" Label1
WriteRegStr HKCR ".nsi" "backup_val" $1
Label1:
WriteRegStr HKCR ".nsh" "" "NSHFile"
ReadRegStr $0 HKCR "NSHFile" ""
StrCmp $0 "" 0 skipNSHAssoc
WriteRegStr HKCR "NSHFile" "" "NSIS Header File"
WriteRegStr HKCR "NSHFile\shell" "" "open"
WriteRegStr HKCR "NSHFile\DefaultIcon" "" $INSTDIR\makensisw.exe,1
skipNSHAssoc:
WriteRegStr HKCR "NSHFile\shell\open\command" "" 'notepad.exe "%1"'
WriteRegStr HKCR ".nsi" "" "NSISFile"
ReadRegStr $0 HKCR "NSISFile" ""
StrCmp $0 "" 0 skipNSIAssoc
WriteRegStr HKCR "NSISFile" "" "NSIS Script File"
WriteRegStr HKCR "NSISFile\shell" "" "open"
WriteRegStr HKCR "NSISFile\DefaultIcon" "" $INSTDIR\makensisw.exe,1
skipNSIAssoc:
WriteRegStr HKCR "NSISFile\shell\open\command" "" 'notepad.exe "%1"'
WriteRegStr HKCR "NSISFile\shell\compile" "" "Compile NSI"
WriteRegStr HKCR "NSISFile\shell\compile\command" "" '"$INSTDIR\makensisw.exe" "%1"'
WriteRegStr HKCR "NSISFile\shell\compile-bz2" "" "Compile NSI (with bz2)"
WriteRegStr HKCR "NSISFile\shell\compile-bz2\command" "" '"$INSTDIR\makensisw.exe" /X"SetCompressor bzip2" "%1"'
SectionEnd

See my archive page on the related topic. :D

Vytautas


maybe the topic of this was misleading. i want to open a file with a software made with nsis, not with nsis itself.


I think you would need to use the System plugin for that.
After getting hold of the file you will ned to use SendMessage to place the file name in your IO Text box [or whatever]

-Stu


Ok, it's very easy actually.
Use the GetParameters function on the NSIS archive, and that will get hold of the file name that Windows executed your program with.
You need to write registry strings to register your file type too.

-Stu


sounds very nice. will put my script to the archive once its working.

edit: how do i get the parameters only?


* i tried using the GetFileName function to strip the application name (to get the parameters only). didnt work. i guess it can be done with a modified GetParameters, but i dont even understand this one.


Use GetParemeters like so:

Call GetParemeters
Pop $0

$0 = paramater, in this case the file (name) that was double clicked on

E.g.
If the user opened up map.sla, then $0 would be "map.sla" (including quotes)
You can simply write that value to an ini file, or whatever.

-Stu


Originally posted by Afrow UK

If the user opened up map.sla, then $0 would be "map.sla" (including quotes)
this is not quite true. i tested this in the command-line. openening a file containing no spaces in its name, $0 will not contain any quotes. when i open a file with spaces, windows requires using quotes, so $0 will contains quotes.

the problem is that those quotes don't allow me to use the $0 to write it into an ini-file (File=C:\Program Files\Bla\"my file.bla").

You need to remove them.
You will need to add the StrStr and StrReplace functions to your script to get it working:

## Check if $0 has any " in it
Push $0
Push "$\""
Call StrStr
Pop $1
StrCmp $1 "" no_replace
# $1 = "" if no "$\"" was found in string

## Replace all "$\" in string
Push $0
Push "$\"
Push ""
Call StrReplace
Pop $0

no_replace:


-Stu


now i lost it completely. i put this right after my last "pop $0" command?


Sorry, I missed somthing off.
On the StrReplace push:
Push "$\"
change to
Push "$\""

$\" is the same as " but it escapes the command-quotes.

-Stu