amrbashir 1 年間 前
コミット
610693fd10

+ 15 - 104
tooling/bundler/src/bundle/windows/templates/FileAssociation.nsh

@@ -4,132 +4,43 @@
 ; Written by Saivert
 ;
 ; Improved by Nikku<https://github.com/nikku>.
-;
-; Features automatic backup system and UPDATEFILEASSOC macro for
-; shell change notification.
-;
-; |> How to use <|
-; To associate a file with an application so you can double-click it in explorer, use
-; the APP_ASSOCIATE macro like this:
-;
-;   Example:
-;   !insertmacro APP_ASSOCIATE "txt" "myapp.textfile" "Description of txt files" \
-;     "$INSTDIR\myapp.exe,0" "Open with myapp" "$INSTDIR\myapp.exe $\"%1$\""
-;
-; Never insert the APP_ASSOCIATE macro multiple times, it is only meant
-; to associate an application with a single file and using the
-; the "open" verb as default. To add more verbs (actions) to a file
-; use the APP_ASSOCIATE_ADDVERB macro.
-;
-;   Example:
-;   !insertmacro APP_ASSOCIATE_ADDVERB "myapp.textfile" "edit" "Edit with myapp" \
-;     "$INSTDIR\myapp.exe /edit $\"%1$\""
-;
-; To have access to more options when registering the file association use the
-; APP_ASSOCIATE_EX macro. Here you can specify the verb and what verb is to be the
-; standard action (default verb).
-;
-; Note, that this script takes into account user versus global installs.
-; To properly work you must initialize the SHELL_CONTEXT variable via SetShellVarContext.
-;
-; And finally: To remove the association from the registry use the APP_UNASSOCIATE
-; macro. Here is another example just to wrap it up:
-;   !insertmacro APP_UNASSOCIATE "txt" "myapp.textfile"
-;
-; |> Note <|
-; When defining your file class string always use the short form of your application title
-; then a period (dot) and the type of file. This keeps the file class sort of unique.
-;   Examples:
-;   Winamp.Playlist
-;   NSIS.Script
-;   Photoshop.JPEGFile
-;
-; |> Tech info <|
-; The registry key layout for a global file association is:
-;
-; HKEY_LOCAL_MACHINE\Software\Classes
-;     <".ext"> = <applicationID>
-;     <applicationID> = <"description">
-;         shell
-;             <verb> = <"menu-item text">
-;                 command = <"command string">
-;
-;
-; The registry key layout for a per-user file association is:
-;
-; HKEY_CURRENT_USER\Software\Classes
-;     <".ext"> = <applicationID>
-;     <applicationID> = <"description">
-;         shell
-;             <verb> = <"menu-item text">
-;                 command = <"command string">
-;
 
-!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
+!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND APPUSERID EXE PRODUCTNAME
   ; Backup the previously associated file class
   ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" ""
   WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "${FILECLASS}_backup" "$R0"
 
   WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "${FILECLASS}"
+  WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}\OpenWithProgids" "${FILECLASS}" ""
 
   WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}" "" `${DESCRIPTION}`
+  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}" "AppUserModelID" `${APPUSERID}`
   WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\DefaultIcon" "" `${ICON}`
   WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell" "" "open"
   WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open" "" `${COMMANDTEXT}`
   WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open\command" "" `${COMMAND}`
-!macroend
 
-!macro APP_ASSOCIATE_EX EXT FILECLASS DESCRIPTION ICON VERB DEFAULTVERB SHELLNEW COMMANDTEXT COMMAND
-  ; Backup the previously associated file class
-  ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" ""
-  WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "${FILECLASS}_backup" "$R0"
-
-  WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "${FILECLASS}"
-  StrCmp "${SHELLNEW}" "0" +2
-  WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}\ShellNew" "NullFile" ""
-
-  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}" "" `${DESCRIPTION}`
-  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\DefaultIcon" "" `${ICON}`
-  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell" "" `${DEFAULTVERB}`
-  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\${VERB}" "" `${COMMANDTEXT}`
-  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\${VERB}\command" "" `${COMMAND}`
+  WriteRegStr SHELL_CONTEXT "Software\Classes\Applications\${EXE}\SupportedTypes" ".${EXT}" ""
+  WriteRegStr HKLM "Software\Clients\Media\${PRODUCTNAME}\Capabilities\FileAssociations" ".${EXT}" "${FILECLASS}"
 !macroend
 
-!macro APP_ASSOCIATE_ADDVERB FILECLASS VERB COMMANDTEXT COMMAND
-  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\${VERB}" "" `${COMMANDTEXT}`
-  WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\${VERB}\command" "" `${COMMAND}`
+!macro APP_ASSOCIATE_INTO_APPLICATIONS EXE ICON COMMAND
+  WriteRegStr SHELL_CONTEXT "Software\Classes\Applications\${EXE}\DefaultIcon" "" `${ICON}`
+  WriteRegStr SHELL_CONTEXT "Software\Classes\Applications\${EXE}\shell\open\command" "" `${COMMAND}`
 !macroend
 
-!macro APP_ASSOCIATE_REMOVEVERB FILECLASS VERB
-  DeleteRegKey SHELL_CONTEXT `Software\Classes\${FILECLASS}\shell\${VERB}`
+!macro APP_ASSOCIATE_REMOVE_FROM_APPLICATIONS EXE
+  DeleteRegKey SHELL_CONTEXT "Software\Classes\Applications\${EXE}"
 !macroend
 
-
-!macro APP_UNASSOCIATE EXT FILECLASS
-  ; Backup the previously associated file class
+!macro APP_UNASSOCIATE EXT FILECLASS PRODUCTNAME
+  ; Restore the previously backedup associated file class
   ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" `${FILECLASS}_backup`
   WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "$R0"
 
+  DeleteRegValue SHELL_CONTEXT `Software\Classes\.${EXT}` `${FILECLASS}_backup`
+  DeleteRegValue SHELL_CONTEXT `Software\Classes\.${EXT}\OpenWithProgids` "${FILECLASS}"
   DeleteRegKey SHELL_CONTEXT `Software\Classes\${FILECLASS}`
-!macroend
-
-!macro APP_ASSOCIATE_GETFILECLASS OUTPUT EXT
-  ReadRegStr ${OUTPUT} SHELL_CONTEXT "Software\Classes\.${EXT}" ""
-!macroend
-
-
-; !defines for use with SHChangeNotify
-!ifdef SHCNE_ASSOCCHANGED
-!undef SHCNE_ASSOCCHANGED
-!endif
-!define SHCNE_ASSOCCHANGED 0x08000000
-!ifdef SHCNF_FLUSH
-!undef SHCNF_FLUSH
-!endif
-!define SHCNF_FLUSH        0x1000
 
-!macro UPDATEFILEASSOC
-; Using the system.dll plugin to call the SHChangeNotify Win32 API function so we
-; can update the shell.
-  System::Call "shell32::SHChangeNotify(i,i,i,i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_FLUSH}, 0, 0)"
+  DeleteRegKey HKLM "Software\Clients\Media\${PRODUCTNAME}"
 !macroend

+ 14 - 8
tooling/bundler/src/bundle/windows/templates/installer.nsi

@@ -563,11 +563,14 @@ Section Install
   {{/each}}
 
   ; Create file associations
-  {{#each file_associations as |association| ~}}
-    {{#each association.ext as |ext| ~}}
-       !insertmacro APP_ASSOCIATE "{{ext}}" "{{or association.name ext}}" "{{association-description association.description ext}}" "$INSTDIR\${MAINBINARYNAME}.exe,0" "Open with ${PRODUCTNAME}" "$INSTDIR\${MAINBINARYNAME}.exe $\"%1$\""
+  {{#if file_associations}}
+    !insertmacro APP_ASSOCIATE_INTO_APPLICATIONS "${MAINBINARYNAME}.exe" "$INSTDIR\${MAINBINARYNAME}.exe,0" "$INSTDIR\${MAINBINARYNAME}.exe $\"%1$\""
+    {{#each file_associations as |association| ~}}
+      {{#each association.ext as |ext| ~}}
+        !insertmacro APP_ASSOCIATE "{{ext}}" "${PRODUCTNAME}.{{ext}}" "{{association-description association.description ext}}" "$INSTDIR\${MAINBINARYNAME}.exe,0" "Open with ${PRODUCTNAME}" "$INSTDIR\${MAINBINARYNAME}.exe $\"%1$\"" "${BUNDLEID}" "${MAINBINARYNAME}.exe" "${PRODUCTNAME}"
+      {{/each}}
     {{/each}}
-  {{/each}}
+  {{/if}}
 
   ; Register deep links
   {{#each deep_link_protocols as |protocol| ~}}
@@ -693,11 +696,14 @@ Section Uninstall
   {{/each}}
 
   ; Delete app associations
-  {{#each file_associations as |association| ~}}
-    {{#each association.ext as |ext| ~}}
-      !insertmacro APP_UNASSOCIATE "{{ext}}" "{{or association.name ext}}"
+  {{#if file_associations}}
+    !insertmacro APP_ASSOCIATE_REMOVE_FROM_APPLICATIONS "${MAINBINARYNAME}.exe"
+    {{#each file_associations as |association| ~}}
+      {{#each association.ext as |ext| ~}}
+        !insertmacro APP_UNASSOCIATE "{{ext}}" "${PRODUCTNAME}.{{ext}}" "${PRODUCTNAME}"
+      {{/each}}
     {{/each}}
-  {{/each}}
+  {{/if}}
 
   ; Delete deep links
   {{#each deep_link_protocols as |protocol| ~}}