Talk:FileAssoc: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(added suggestion to fix problem with first example)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== quotes fix for COMMAND ==
Hi,
previous post: obvisously the File Class description is missing in the sample after the file class ID.
In the command if you use double quotes like in myExe.exe "%1", the script will think you have 5 parameters to WriteRegExp ( Nsis 2.12 ).
Since it's unlikely anyone will use single quotes in a command, I suggest to fix it by remplacing the double quotes around {COMMAND} in the macro by single quotes:
WriteRegStr HKCR "${FILECLASS}\shell\open\command" "" '${COMMAND}'
Cedric.
: Even better, backticks. Done. --[[User:Kichik|kichik]] 03:45, 31 December 2005 (PST)
== Missing param in example ==
I've just fixed this. Discussion archived below. [[Special:Contributions/127.0.0.1|127.0.0.1]] 18:09, 16 February 2013 (UTC)
There is a bug in the script (I think...)
There is a bug in the script (I think...)


Line 30: Line 50:
* the "Open with My App" is what shows up in the context menu
* the "Open with My App" is what shows up in the context menu
[[Special:Contributions/86.135.85.25|86.135.85.25]] 23:04, 28 October 2010 (UTC)
[[Special:Contributions/86.135.85.25|86.135.85.25]] 23:04, 28 October 2010 (UTC)
<p>
How does one start a new comment??  I am not clever enough to figure it out ... nonetheless ...</p>
Hello - I think APP_UNASSOCIATE can be improved.  As written, it does not correctly cleanup the .${EXT} key.  In my tests on Win2k and WinXP, the following correctly restores a _backup {
${FILECLASS} pointer, or deletes the .${EXT} key entirely if it is no longer in use.


== quotes fix for COMMAND ==
!macro APP_UNASSOCIATE EXT FILECLASS 
  ; Restore the previously associated file class if it differs
  ReadRegStr $R0 HKCR ".${EXT}" `${FILECLASS}_backup`
  DeleteRegValue HKCR ".${EXT}" `${FILECLASS}_backup` 
  StrCmp $R0 "" +3                      ; No original association
  WriteRegStr HKCR ".${EXT}" "" "$R0"
  Goto +2
  DeleteRegKey HKCR ".${EXT}"
  DeleteRegKey HKCR `${FILECLASS}`


Hi,
!macroend


previous post: obvisously the File Class description is missing in the sample after the file class ID.
Also, in both the install macros, the _backup key is overwritten upon re-install of the application, losing the needed value:  following are the first lines of APP_ASSOCIATE showing my fix (2 lines w/comments):


In the command if you use double quotes like in myExe.exe "%1", the script will think you have 5 parameters to WriteRegExp ( Nsis 2.12 ).
!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
Since it's unlikely anyone will use single quotes in a command, I suggest to fix it by remplacing the double quotes around {COMMAND} in the macro by single quotes:
  ; Backup the previously associated file class
 
  ReadRegStr $R0 HKCR ".${EXT}" ""
WriteRegStr HKCR "${FILECLASS}\shell\open\command" "" '${COMMAND}'
  StrCmp $R0 "" +3                ; Nothing to backup
  StrCmp $R0 "${FILECLASS}" +2   ; Don't overwrite original during a re-install
  WriteRegStr HKCR ".${EXT}" "${FILECLASS}_backup" "$R0"


Cedric.
Thanks for posting the original - it was quite useful. And +2 for very good documentation :-)
 
: Even better, backticks. Done. --[[User:Kichik|kichik]] 03:45, 31 December 2005 (PST)

Latest revision as of 18:18, 10 April 2019

quotes fix for COMMAND

Hi,

previous post: obvisously the File Class description is missing in the sample after the file class ID.

In the command if you use double quotes like in myExe.exe "%1", the script will think you have 5 parameters to WriteRegExp ( Nsis 2.12 ). Since it's unlikely anyone will use single quotes in a command, I suggest to fix it by remplacing the double quotes around {COMMAND} in the macro by single quotes:

WriteRegStr HKCR "${FILECLASS}\shell\open\command" "" '${COMMAND}'

Cedric.

Even better, backticks. Done. --kichik 03:45, 31 December 2005 (PST)

Missing param in example

I've just fixed this. Discussion archived below. 127.0.0.1 18:09, 16 February 2013 (UTC)


There is a bug in the script (I think...)

In the example you call with five parameters:

; !insertmacro APP_ASSOCIATE "txt" "myapp.textfile" "$INSTDIR\myapp.exe,0" \

; "Open with myapp" "$INSTDIR\myapp.exe $\"%1$\""

but in the fuction header there is six patrameters declared:


!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND


There must be somthing wrong here or?

/Pontus

Perhaps a better example would be:
  !insertmacro APP_ASSOCIATE "myext" "myapp.myext" \
    "My App File" "$INSTDIR\myapp.exe,0" \
    "Open with My App" "$INSTDIR\myapp.exe $\"%1$\""
  • the "My App File" is what shows up in the Explorer details view
  • the "Open with My App" is what shows up in the context menu

86.135.85.25 23:04, 28 October 2010 (UTC)

How does one start a new comment?? I am not clever enough to figure it out ... nonetheless ...

Hello - I think APP_UNASSOCIATE can be improved. As written, it does not correctly cleanup the .${EXT} key. In my tests on Win2k and WinXP, the following correctly restores a _backup { ${FILECLASS} pointer, or deletes the .${EXT} key entirely if it is no longer in use.

!macro APP_UNASSOCIATE EXT FILECLASS

 ; Restore the previously associated file class if it differs
 ReadRegStr $R0 HKCR ".${EXT}" `${FILECLASS}_backup`
 DeleteRegValue HKCR ".${EXT}" `${FILECLASS}_backup`  
 StrCmp $R0 "" +3                       ; No original association
 WriteRegStr HKCR ".${EXT}" "" "$R0"	
 Goto +2
 DeleteRegKey HKCR ".${EXT}"	
 DeleteRegKey HKCR `${FILECLASS}`	

!macroend

Also, in both the install macros, the _backup key is overwritten upon re-install of the application, losing the needed value: following are the first lines of APP_ASSOCIATE showing my fix (2 lines w/comments):

!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND

 ; Backup the previously associated file class
 ReadRegStr $R0 HKCR ".${EXT}" ""
 StrCmp $R0 "" +3                ; Nothing to backup
 StrCmp $R0 "${FILECLASS}" +2    ; Don't overwrite original during a re-install
 WriteRegStr HKCR ".${EXT}" "${FILECLASS}_backup" "$R0" 

Thanks for posting the original - it was quite useful. And +2 for very good documentation :-)