Rajada
4th September 2011 15:50 UTC
Ini edit not being observed by installer
I have an installer that edits the ini file of a particular application. The installer basically changes the value of an integer to a non-zero value (the exact number depends on the situation). If the ini line has a value of zero, the exe carries out function A (just using placeholder names) and if the value is not zero it carries out function B.
If I edit the number in the ini with a text editor everything runs fine afterwards. If I let the installer edit the value, then exit the installer and run the exe everything still runs fine. The problem comes in if I have the exe listed as the program to run after installation is complete. If I run the exe using the checkbox at the end of the installer (close installer and run exe), the exe acts as if the ini value is 0, no matter what it really is set to.
Is there some ini save function I need to call to get this to behave the correct way?
MSG
4th September 2011 17:46 UTC
First of all, verify that the value is correctly set to non-zero, before you click Finish on the finish page.
Second, what OS is this? Admin or user? What directory is the ini file in?
demiller9
4th September 2011 18:33 UTC
Did you use the FlushINI command?
Rajada
4th September 2011 21:35 UTC
To be honest, I acquired the main installer source code from a friend who didn't want to work on it anymore. The flush ini function is nowhere to be found in the script. What is its usage and what effects does it have?
My OS is Windows 7, but the same problem has been confirmed on machines as old as Windows XP. The installer runs as an administrator by default. The ini is installed to a user chosen directory that is confirmed to have a prerequisite application. I can open the ini before, during and after installation and confirm that the non-zero value is there, it just seems like it is being ignored.
This is the tidbit of code that I think is most relevant.
Function checkUpdaterINI
   IfFileExists "$INSTDIR\Updater2\updater.ini" 0 copy
        ${ConfigRead} "$INSTDIR\Updater2\updater.ini" "LastUpdate = " $R1
${If} $R1 >= 17 ; Skip INI, leave it alone
      ; Greater than or equal to INI number
      Goto done
      
${Else} ; Update INI
       ; Less than update INI number
        Push "$INSTDIR\Updater2\updater.ini" ; file to modify
        Push "LastUpdate" ; string that a line must begin with
        Push "LastUpdate = 17" ; string to replace whole line with
        Call ReplaceLineStr
       Goto done
${EndIf}
        copy: ; Overide entire INI
                SetOutPath "$INSTDIR\Updater2"
                File "NerfCP\Updater2\updater.ini"
         Goto done
         
        done:
FunctionEnd
     
    
      Afrow UK
      4th September 2011 22:28 UTC
      Use ReadINIStr/WriteINIStr if possible. I'm not sure this still applies to Windows 7 but on 9x INI files were cached in memory and so you had to use FlushINI to write the buffers to disk.
      
      Stu
     
    
      MSG
      5th September 2011 05:47 UTC
      
      
        Originally posted by Rajada
        The flush ini function is nowhere to be found in the script. What is its usage and what effects does it have?
      
As is often the case, it's all in the manual: 
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2.8
      
      
        Originally posted by Rajada
        The installer runs as an administrator by default.
      
There's no such thing as a default admin. If you need admin you have to enforce it (using the userinfo plugin in .onInit for example).
    
 
    
      Roger_wgnr
      5th September 2011 06:05 UTC
      What code is in the ReplaceLineStr function? this is where the INI actually gets updated from what I see. You push values to the stack and Call ReplaceLineStr, I imagine that the values are Pop'd in this function and the INI updated.
     
    
      Rajada
      5th September 2011 08:10 UTC
      Well here's the thing, this installer was coded with a very old version of NSIS. My thought is I should rewrite this now to use WriteIniString like my other updated bits of code and include the flushing function. If that doesn't solve the problem I'll have to do more digging.
      
      And sorry about the confusion, it installs components fine with the current user account settings, so I know that isn't the issue. All I meant is that it asks on all systems I've tested to install as an administrator and works fine every time.