Announcement

Collapse
No announcement yet.

Installer and Uninstaller Redundancy

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

  • Installer and Uninstaller Redundancy

    I'm a newbie to NSIS and I can't figure out how
    to use the same functions for the installer and the uninstaller. Since the uninstaller functions must start
    with the un-prefix and the installer functions must not,
    my code is starting look horrible. E.g, I'm using
    the EnumUsersReg.nsh module/file in both the installer and in the uninstaller and I had to copy the file and rename
    every macro and function. Since no sensible language could
    force this kind of redundancy I assume that it can be solved somehow. But how?

    /Tomas

  • #2
    It is not the language, but I agree sharing functions between Installer and Uninstaller could be improved.

    Reason: Actually you are building TWO applications, an INSTALLER and an UNINSTALLER. Since you could need routines in your Installer you do not need in you uninstaller including them in both would make the unistaller unnessecair bigger filesize.
    "Just do it"

    Comment


    • #3
      Ok. But is it possible to achieve my goal somehow? I cannot
      implement two versions of every function I'm using. It is madness!

      Comment


      • #4
        You can use a macro.
        code:
        !macro myfunc un
        Function ${un}myfunc
        Call ${un}someotherfunc
        DetailPrint something
        FunctionEnd
        !macroend

        !insertmacro myfunc ""
        !insertmacro myfunc "un."

        NSIS FAQ | NSIS Home Page | Donate $
        "I hear and I forget. I see and I remember. I do and I understand." -- Confucius

        Comment


        • #5
          Thanks, it works great!
          You've saved my day.

          Comment


          • #6
            Good codeing! Although obvious if you know it all....
            .. but that is not the situation for everyone.

            IDEA: Maybe somwhere to add example to the Wiki.
            "Just do it"

            Comment


            • #7
              I have just made an example here.
              "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
              NSIS 3 POSIX Ninja
              Wiki Profile

              Comment


              • #8
                Ah yes, but what happens if I want to use an existing function, like, say ${WordFind}?

                PHP Code:
                !macro myfunc un
                Function ${un}myfunc
                  
                ${WordFind$CMDLINE "/" "E+$8" $7
                  DetailPrint something
                FunctionEnd
                !macroend

                !insertmacro myfunc ""
                !insertmacro myfunc "un." 
                doesn't work (obviously)...

                Comment


                • #9
                  Then you adapt the existing function to a similar scheme

                  btw, this use of macros to create both an installer and an uninstaller function is in the NSIS help. It's sadly hidden in the "Scripting Structure > 2.3.6 Compiler Commands" topic, though.

                  Comment


                  • #10
                    code:
                    !macro myfunc un
                    Function ${un}myfunc
                    ${${un}WordFind} $CMDLINE "/" "E+$8" $7
                    DetailPrint something
                    FunctionEnd
                    !macroend

                    !insertmacro myfunc ""
                    !insertmacro myfunc "un."

                    NSIS FAQ | NSIS Home Page | Donate $
                    "I hear and I forget. I see and I remember. I do and I understand." -- Confucius

                    Comment


                    • #11
                      ${${un}WordFind} $CMDLINE "/" "E+$8" $7
                      Oooh, I didn't know I could do that (really I should have tried before assuming, or read TFM...).
                      Just out of interest, is there any limit to the number of levels?

                      Comment


                      • #12
                        Nope, no limit.
                        NSIS FAQ | NSIS Home Page | Donate $
                        "I hear and I forget. I see and I remember. I do and I understand." -- Confucius

                        Comment


                        • #13
                          Similar problem, but with macro which take a variable

                          I have following code in a .nsh file:

                          !define Test "!insertmacro Test"

                          !macro Test Var
                          Push "${Var}"
                          Call Test
                          !macroend

                          Function Test
                          Exch $0
                          .....
                          Pop $0
                          FunctionEnd

                          I call this macro from a .nsi file with:

                          ${Test} "Value"

                          How should I use this in an Uninstall section? I have tried to do as explained in previous posts. I put my function Test inside a "DualFunction" macro like myfunc, but I got a error that said I have wrong number of parameters to my function call. Anyone that has a suggestion?

                          Best regards, Frode

                          Comment

                          Working...
                          X