Announcement

Collapse
No announcement yet.

Destination Folder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Destination Folder

    How can I dynamically set MUI_PRODUCT_DIR?? I want to be able to put anything in destination folder.

    Any help is appreciated.

  • #2
    You don't need define anything. Use the $INSTDIR variable. This is the default variable used to install program files in, contains the install folder written by the user.

    To put files in the folder written in $INSTDIR var, use:

    code:
    SetOutPath $INSTDIR
    And use "File" commands after.

    If want to put files in a subfolder of $INSTDIR:

    code:
    SetOutPath $INSTDIR\SubFolder
    Where SubFolder is the subfolder name.

    If you want another variable to use it, try using the default $0-$9, $R0-$R9 variables.
    My Wiki Pages

    Working now on:
    New projects. (language: any)

    Comment


    • #3
      I should say how can I override
      InstallDir "$PROGRAMFILES\${MUI_PRODUCT_DIR}"

      so that "Destination Folder" would show up with a value I have in registry.

      Comment


      • #4
        You could scrap MUI_PRODUCT_DIR define, and use

        StrCpy $INSTDIR "C:\whatever"

        Or

        StrCpy $INSTDIR "C:\whatever${MUI_PRODUCT_DIR}"

        -Stu

        Comment


        • #5
          OK but then how could I make it to show up in the Destination folder? This code can not be put outside a Section.

          Comment


          • #6
            Place in Function .onInit

            -Stu

            Comment


            • #7
              It worked

              Thanks a bunch!! I put my function call in the init function and it worked...for anyone's reference here it is...

              Function installDirectory
              ; set $INSTDIR to registry value if previous installation detected
              ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "Installed"
              StrCmp $0 "" NotPresent Present
              NotPresent:
              WriteRegStr HKCU "SOFTWARE\Sandvine" "Installed" "1"
              WriteRegStr HKCU "SOFTWARE\Sandvine" "InstalledDirectory" "$INSTDIR"
              StrCpy $INSTDIR "$PROGRAMFILES\${MUI_PRODUCT_DIR}"

              Goto Done
              Present:
              ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "InstalledDirectory"
              StrCpy $INSTDIR "$0"

              Done:
              FunctionEnd

              Comment


              • #8
                Wow, everyone are speaking faster today! Three persons posting in the same time!
                My Wiki Pages

                Working now on:
                New projects. (language: any)

                Comment


                • #9
                  You don't need that StrCpy in there if used like this:

                  InstallDir "$PROGRAMFILES\${MUI_PRODUCT_DIR}"

                  Function InstallDirectory
                  ; set $INSTDIR to registry value if previous installation detected
                  ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "Installed"
                  StrCmp $0 "" NotPresent Present
                  NotPresent:
                  WriteRegStr HKCU "SOFTWARE\Sandvine" "Installed" "1"
                  WriteRegStr HKCU "SOFTWARE\Sandvine" "InstalledDirectory" "$INSTDIR"

                  Goto Done
                  Present:
                  ReadRegStr $0 HKCU "SOFTWARE\Sandvine" "InstalledDirectory"
                  StrCpy $INSTDIR "$0"

                  Done:
                  FunctionEnd

                  I was also thinking that maybe you should write the install directory and Installed 1 to the registry after installation.
                  The user may quit and not install the software, though on re-run it will assume that the installation has already taken place.

                  -Stu

                  Comment


                  • #10
                    Good point. I will change the code to take care of that scanario ...effectivelly write to registry after all the files have been copied for some other section.

                    Comment


                    • #11
                      No, use inside .onInstallSuccess Function.
                      The code will then be called when the user clicks the Finish button.

                      -Stu

                      Comment


                      • #12
                        Hmmm... there is a much easier way to handle the situation of figuring out an install dir while defaulting to whatever was used by an existing installation.

                        Just take a look at both the InstallDir and InstallDirRegKey documentation - the NSIS guys put some effort into solving this particular problem, since it is so common.

                        This whole mess can usually be handled by something like this:

                        PHP Code:
                        InstallDir "$PROGRAMFILES\RFtpPRO"
                        InstallDirRegKey HKCU "Software\RHpS\RFtp\Settings" "AppFile" 
                        The "InstallDir" sets up your default, and the "InstallDirRegKey" attempts to override it if there is already a path set in whatever reg entry you tell it to look in... note that it is smart, and if the the reg entry has a path to an .exe file, the filename will be stripped, leaving only the directories.

                        Finally, note that these are "configuration" statements, and are not actually in a section (or a .on<anything>).

                        Comment


                        • #13
                          Ack, the backslashes got removed by the "PHP" quoting. Sigh. Here is what that should look like, if anyone was confused:

                          InstallDir "$PROGRAMFILES\RFtpPRO"
                          InstallDirRegKey HKCU "Software\RHpS\RFtp\Settings" "AppFile"

                          Comment


                          • #14
                            Use [ code] [/code ]

                            -Stu

                            Comment


                            • #15
                              Or when using the [PHP ] and [/PHP ] (without that space) use two insteed of one "\".

                              In Example:

                              [PHP ]StrCpy $INSTDIR "C:\\Folder\\SubFolder"[/PHP ]
                              My Wiki Pages

                              Working now on:
                              New projects. (language: any)

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎