View Single Post
Old 03-07-2008   #5 (permalink)
flutophilus


 
 

RE: VS2005 Setup Project File with Property 'Permanent' is uninsta

For completenes, another way to save a config file is to use a custom
installer class, here's my effort, fwiw.

' Custom action to run in setup at instal time. Create install log and
copy the saved config file to live
' (prevents overwrite of user settings by test settings after first
install).
' To run this automatically just put the primary output for this project
under the "custom action - install" tag
' in the setup project
Public Overrides Sub Install(ByVal stateSaver As
System.Collections.IDictionary)

' Uses reflection to find the location of the config file.
Dim Asm As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly
' Asm.Location is location and name of .exe in the installation folder
Dim strExeLoc As String = Asm.Location

' the name of the install-to folder
Dim strInstallFolder As String
strInstallFolder = strExeLoc
' strip out name of executable
strInstallFolder =
strInstallFolder.Remove(strInstallFolder.LastIndexOf("\"),
Len(strInstallFolder) - _
strInstallFolder.LastIndexOf("\"))

Dim installlog As New System.IO.StreamWriter(strInstallFolder &
"\Installation.log")
installlog.AutoFlush = True

Try

installlog.WriteLine("Starting installation of the config file")
installlog.WriteLine("Install folder: " & strInstallFolder)

Dim strSavedConfigLoc As String = _
strExeLoc & ".config.saved" ' derive the name of the saved
config

installlog.WriteLine("Location of the saved config file: " &
strSavedConfigLoc)

Dim FileInfo As System.IO.FileInfo = New
System.IO.FileInfo(strSavedConfigLoc)

If Not FileInfo.Exists Then
installlog.WriteLine("No saved config file: " &
strSavedConfigLoc)
installlog.WriteLine("Config will be installed using test
settings from setup ")
Else
Dim strLiveConfigLoc As String = _
strExeLoc & ".config" ' derive the name of the saved
config
System.IO.File.Delete(strLiveConfigLoc)
System.IO.File.Copy(strSavedConfigLoc, strLiveConfigLoc)
installlog.WriteLine("Config file copied from: " &
strSavedConfigLoc & " to: " & strLiveConfigLoc)

End If

Finally
installlog.WriteLine("Ending installation")
installlog.Close()
End Try

End Sub

'Custom action to run in setup - log the uninstall and save the config
file
' To run this automatically just put the primary output for this project
under the "custom action - install" tag
' in the setup project
Public Overrides Sub UnInstall(ByVal stateSaver As
System.Collections.IDictionary)

' Uses reflection to find the location of the config file.
Dim Asm As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly
' Asm.Location is location and name of .exe in the installation folder
Dim strExeLoc As String = Asm.Location

' the name of the install-to folder
Dim strInstallFolder As String
strInstallFolder = strExeLoc
' strip out name of executable
strInstallFolder =
strInstallFolder.Remove(strInstallFolder.LastIndexOf("\"),
Len(strInstallFolder) - _
strInstallFolder.LastIndexOf("\"))

Dim installlog As New System.IO.StreamWriter(strInstallFolder &
"\Installation.log")
installlog.AutoFlush = True

Try

installlog.WriteLine("Starting uninstallation of the config file")
installlog.WriteLine("Install folder: " & strInstallFolder)

Dim strLiveConfigLoc As String = _
strExeLoc & ".config" ' derive the name of the config

installlog.WriteLine("Location of the config file: " &
strLiveConfigLoc)

Dim FileInfo As System.IO.FileInfo = New
System.IO.FileInfo(strLiveConfigLoc)

If Not FileInfo.Exists Then
installlog.WriteLine("No live config file: " &
strLiveConfigLoc)
installlog.WriteLine("Config will not be saved ")
Else
Dim strSavedConfigLoc As String = _
strExeLoc & ".config.saved" ' derive the name of the
saved config
System.IO.File.Delete(strSavedConfigLoc)
System.IO.File.Copy(strLiveConfigLoc, strSavedConfigLoc)
installlog.WriteLine("Config file copied from: " &
strLiveConfigLoc & " to: " & strSavedConfigLoc)

End If

Finally
installlog.WriteLine("Ending uninstallation")
installlog.Close()
End Try

End Sub

My System SpecsSystem Spec