Reg Key and Install Directory for Complete

I'm assuming this is like a print statement with Civ4. Is that correct? How do I set up an "echo"?
 
LOL. OMG. Yes its a Print statement. (Sorry been a long time since I ran into a geek that didn't know "echo" :-) ... Actually I dont think I ever have...hehe.

ECHO : *nix, DOS, 2K/XP+ CMD.exe, functionally equivalent to PRINT - all depending on what language you are writing the code or script in. C actually doesn't have "print" - relying instead on functions like sprintf() or printf() among some others.

I've not used NSIS, but it has to have a way to LOG its variables and/or output.
So Print/Echo or Log that particular line. Then you can narrow it down from there.
 
Print, Echo and Log (with various capitalization choices), doesn't change color in Notepad++, so I don't think they do anything. I searched the NSIS forums and can't find anything helpful. So I posted there, hopefully someone will answer.
 
Wow, well done. I searched those forums and didn't find anything.

This is a little overmy head though. I know I'll need to plug in that plugin and then include it. But how exactly can I use it to print what is going on?

Code:
  Section "-un.StartMenu" SecUnStartMenu

    ;Delete Start Menu Shortcut
    !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
    Delete "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"
    RMDir "$SMPROGRAMS\$StartMenuFolder"
  SectionEnd

Sorry, I know it's kind of wrong to ask others for direct code. But how do I change the above to use RecFind? I'm not understanding his post, or the instructions in the plug in:

http://nsis.sourceforge.net/RecFind:_Recursive_FindFirst,_FindNext,_FindClose

Spoke too soon, I think I get it. Let me test this...

Edit: Yeah, I'm not even sure what this is now that I've tried to use it. Just kills my compiler, says it can't find my debugg.txt which is what I assume I'm telling it to log to???
 
I dont believe you need to use RecFind, something like:
FileWrite "C:\Users\Phungus420\Desktop\UninstallDebug.log" "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"

or define the $UninstallLog variable above, and use:
FileWrite $UninstallLog "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"
 
I'm not getting it. I have the line:
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder

I want it to print a log telling me what this is doing.
FileWrite "C:\Users\Phungus420\Desktop\UninstallDebug.log"

Goes where in relation to
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
In the code?

Or in relation to this line if it's easier.

Delete "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"

I just need to see it in practice once. I have no reference to base this on.
 
Code:
  Section "-un.StartMenu" SecUnStartMenu

    ;Delete Start Menu Shortcut
    !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
    FileWrite "C:\[B]A\DIRECTORY\THAT\ACTUALLY\EXISTS\[/B]Uninstall.log" "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"
    Delete "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"
    RMDir "$SMPROGRAMS\$StartMenuFolder"
  SectionEnd

Dude you need to stop taking stuff so literally,
C:\Users, is the equivalent of C:\Documents and Settings\
many people change that when they install Windows, and Phungus420 is a username, that you likely don't use for Windows, so you would want to replace it with whatever UserName you are logged in under.
 
Thanks. I knew that about C:\Users, was just cutting and pasting. Just needed to see it in the code once to get my bearings on it. Will check it out and see if it says anything useful.
 
It fails to compile. The complaint is:

FileWrite $(user_var: handle input) text

I'm using this line:
FileWrite "${LOG_STUFF}" "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"

Where I have defined LOG_STUFF to be a bunch of things in my Temporary Folder I always mess with stuff in. Both creating text files that exist there (to overwrite), or leaving it empty (in case it writes its own file).
 
Woops, it's a variable, got it fixed.

Edit: Damn, didn't create a log though...
 
Well this is what I have:

Set up the variable, with the other variables:
Var UninstalLog

Define it in un.onInit:
StrCpy $UninstalLog "C:\Documents and Settings\P\Desktop\Temp Desktop Folder\Uninstall.txt"
(also tried Uninstall.log in the example above, tried it with or without a file there by that name)

And attempt to use it in the troubled Start Menu section:
FileWrite "$UninstalLog" "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk"

But I don't gets me no log...
 
Thank you very much for that link. I don't know what's ammater with me with not finding it. Of course I was just looking up Print Statement, and I was searching the forums, should have checked the tuts...

Anyway, that found the problem:

This is the actual folder location:
C:\Documents and Settings\P\Start Menu\Programs\Firaxis Games\Charlemagne

And this is what the script is returning:
C:\Documents and Settings\P\Start Menu\Programs\Charlemagne

So basically When you install you choose where you want to install the start menu (I pick Firaxis games). This isn't getting written down. Ie, the variable $StartMenuFolder isn't returning anything. So it just pulls the parent directory. Any ideas?

Edit:
Correction, just checked it and $StartMenuFolder returns Charlemagne (the mod I'm testing the installer with). So it picks up the mod name, but not the folder it installs into...

Edit2:
I think I'm onto something here:
http://nsis.sourceforge.net/Examples/Modern UI/StartMenu.nsi
Nevermind, just shows exactly what I have...
 
So basically When you install you choose where you want to install the start menu (I pick Firaxis games). This isn't getting written down. Ie, the variable $StartMenuFolder isn't returning anything. So it just pulls the parent directory. Any ideas?

*chuckle* Thats an easy one to know Why its doing what it is doing.

You are requiring the end-user to pick where the ShortCut should go. (Most installs do not do this, they put it where they want, and then know where it was put for uninstall purposes).

When you are uninstalling, the script doesn't know what the end-user picked previously. That needs to be stored somewhere so it can be read back into a variable.

You might find some info here: Advanced Uninstall Log NSIS Header
The modified script is at the bottom of that page, you might get some info from reading the modified script-header.

A number of different functions are utilized, FileSeek, StrCmp, Push, Pop, etc.
Though I believe if you use that Advanced Uninstall Log, you will get a Install.log ;) and the Uninstall then just reverses everything in the log. Without having to quibble over doing it all manually.

You may want to either try using that, or just ask on the winamp boards how to read a string from a file into a variable.
 
Man, I swear NSIS is evil. I can declare a new variable, set it to the exact path I need, but I'm not allowed to do anything with it. I can't call it in the uninstall section (it just comes up blank), and I can't set a constant with it, to be called in the Uninstall section, because it only lets me define constants as variables inside sections or functions, and they disapear outside that section/function when done so. It's like it's trying to make it impossible to fix this... And then to top it all off, you can't call a function in an Un section/Function. So they basically lock everything off....

Edit:

Using this:
Code:
  Section "Start Menu Shortcut" Section4
	!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
	CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
	CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0
	!insertmacro MUI_STARTMENU_WRITE_END
	StrCpy $StartMenuFolder1 "$SMPROGRAMS\$StartMenuFolder"
	!define START_MENU_FOLDER "$StartMenuFolder1"
  SectionEnd
I now have a variable, StartMenuFolder1 that has a value of the Start Menu Folder. Also the Constant START_MENU_FOLDER is the same. I've checked them both, and I can move and reference the variable StartMenuFolder1 around in the install sections of the script (provided it's below where I set it's value), and it retains it's value (the Start Menu Path).. Problem is, if I reference them in an uninstall section, it just comes blank, like they have no value anymore. Is there anyway to get what's inside these into the Uninstall section at all? I'm not seeing it...

Edit2:

Well I tried a really hacky work around, that I'm not sure how or why it failed. Basically I had it write the Variable to a text file it would create on install. This worked, and the document contained the correct path. Then I set it to read that file in the uninstaller. For some reason if I used a user variable, the script failed to compile. If I used one of the default variables like $R1, it compiled, but there was nothing inside it after it was told to read the file. So strange, I was sure that would work. And it's not like Read and Write code is hard, I can't see what's wrong with it (or why using a user variable would fail to compile, but using a default variable would not). For reference this is what I mean:

Spoiler :
Code:
  !define START_MENU_HACK "StartMenuHack.txt"  ;Do not change this block
...


  Var HackStartMenu

...

	StrCpy $StartMenuFolder1 "$SMPROGRAMS\$StartMenuFolder"
        FileOpen $4 "$INSTDIR\Mods\${MOD_LOC}\${START_MENU_HACK}" w
        FileWrite $4 "$StartMenuFolder1"
        FileClose $4

Above all works, was checked, it wrote the file with the correct path.

Code:
    FileOpen $R4 "$INSTDIR\Mods\${MOD_LOC}\${START_MENU_HACK}" r
    FileRead $R4 $HackStartMenu
    FileClose $R4
    Delete "$HackStartMenu\${NAME}.lnk"
    RMDir "$HackStartMenu"
Now the above failed to compile. Complaiend about the FileRead $R4 $HackStartMenu, and said something about the user variable. But the strange thing was using $R2 compiled. But when I checked what was inside of it, it just came out blank. And I did move this to the top of the uninstall functions to make sure the folder wasn't deleted before it had a chance to read it.
 
I don't have much time now, so I'll highlight a few things from my memory of working on the script. I highly recommend going back and reading the docs. :)

1. Constants are defined at compile time and available to all code below them in the file. You cannot call a function that defines a constant and hope to have it defined once the function returns. Again, they are available to lines below them in the file--not after them logically in the flow of the program.

1a. Because of this, you cannot give a constant the value of a variable as variables only exist at runtime.

2. You can definitely call uninstall functions from uninstall functions/sections.

2a. If you want a function available to both install and uninstall, you must define it twice via copy-paste-rename.

3. All variables are global and available everyone after (program-flow-wise) being set. They are not kept across runs, and variables set in the installer do not magically exist in the uninstaller. You must store them somehow (e.g. in the registry) and read them during uninstall.

I was wrong about those start menu macros. I don't think they are storing anything in the registry. They are probably just setting the $SMPROGRAMS variable. I don't remember what they each do nor the purpose of the BEGIN/END combo macros. You can probably look at the source for those macros if you're interested or want to get more of an idea of what's going on.
 
All right, I wrote it to the registry, and it works. :woohoo:

I'm curious though, and just want to make sure I'm doing it right. Functionally it seems to work, but since I'm going to be sharing this script. Just want to make sure the Registry stuff is cricket. Also I'm curious if I can optimize it any, and/or use HKCU instead of HKLM, I'm not sure how these are different, and it just seems that I should be using both, since I am in effect creating two registries here. (note FIRAXIS_REG_ROOT = HKLM)

Here is the relevant code:

Code:
  Section /o "${MOD_LOC}" Section1
    SectionIn RO
    SetOutPath "$INSTDIR1\Mods\${MOD_LOC}"
    File /r "${MYCLSDIR}\*.*"
      ; write uninstall information to the registry
    WriteRegStr ${FIRAXIS_REG_ROOT} "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "DisplayName" "${NAME}"
    WriteRegStr ${FIRAXIS_REG_ROOT} "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "UninstallString" "$INSTDIR1\Mods\${MOD_LOC}\Uninstall.exe"
    WriteRegStr ${FIRAXIS_REG_ROOT} "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir" "$INSTDIR1\Mods\"
    WriteUninstaller "$INSTDIR1\Mods\${MOD_LOC}\Uninstall.exe"
  SectionEnd

  Section "Start Menu Shortcut" Section4
	!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
	CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
	CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${NAME}.lnk" "$INSTDIR1\Civ4BeyondSword.exe" "mod=\${MOD_LOC}" "$INSTDIR\Mods\${MOD_LOC}\${RAW_ICON}" 0
	CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR1\Mods\${MOD_LOC}\Uninstall.exe"
	!insertmacro MUI_STARTMENU_WRITE_END
	StrCpy $StartMenuFolder1 "$SMPROGRAMS\$StartMenuFolder"
	WriteRegStr ${FIRAXIS_REG_ROOT} "Software\Microsoft\Windows\CurrentVersion\Uninstall\${SHORT_NAME}StartMenu" "StartMenuFolder" "$StartMenuFolder1"
   SectionEnd
Code:
  Function un.onInit

    ;get mod install path of from the registy
    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}" "ModInstDir"
	ReadRegStr $R1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${SHORT_NAME}StartMenu" "StartMenuFolder"
  FunctionEnd

Code:
  Section "-un.StartMenu" SecUnStartMenu

    ;Delete Start Menu Shortcut
    Delete "$R1\${NAME}.lnk"
	Delete "$R1\Uninstall.lnk"
    RMDir /r "$R1"
    ;Delete Files
  SectionEnd
  
  Section "un.Core" SecUnCore

    RMDir /r "$0\${MOD_LOC}\*.*"
    ;Remove the installation directory
    RMDir "$0\${MOD_LOC}"
    ;Delete Desktop Shortcut
    Delete "$DESKTOP\${NAME}.lnk"
    ;Delete Quicklaunch Shortcut
    Delete "$QUICKLAUNCH\${SHORT_NAME}.lnk"
  SectionEnd

  Section "-un.Registry" SecUnRegistry

    DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MOD_LOC}"
    DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${SHORT_NAME}StartMenu"
  SectionEnd
 
HKCU = Current User, and each user has their own HKCU registry subtree. HKLM = Local Machine, and all users share that subtree. Giving the option to use one or the other is nice, but 99.999% of users will be using single-user machines where either subtree is fine.

I'm still really curious why it's choosing one subtree during install and a different one during uninstall. :confused:
 
It wasn't, the issue was it wasn't reading the Start Menu Folder correctly. But that's fixed now by having it create it's own registry, and then having the uninstaller reading that.

So my Registry stuff is all fine then? Any ways to optimize it?

Also I have one minor nitpicky detail I can't figure out. On start up you get 4 checkboxes, For the mod and each of the shortcuts you want to install (the mod is locked in checked mode). If you uncheck the Start Menu Shortcut, the MUI_PAGE_STARTMENU Macro still fires, and you are taken the start menu folder selection screen (picking something does nothing at this point, as the option was unchecked, but it acts like it will). Is there anyway to turn off that macro if Section4 is not selected?
 
Back
Top Bottom