質問

My application keeps user's input for application setting in a XML file. Now suppose I have uninstalled my application but the setting file(xml file) is still there. It has not been removed. I want to use that setting file for my next installation. Is there any way to ask user during installation like "Do you want to use existing setting?". So that I do not need to initialize the setting again after new installation.

役に立ちましたか?

解決

Yes you can do it, First of of all you have to make sure that already created XML file is not being removed when application is uninstalled. By default when you uninstall an application files deployed with the MSI will get removed when its uninstalled. To prevent this go to that specific file property and set Permanent to True.

You have to add installer class to your set up project. within install method check if the XML file exisit. If then display confirmation message to user. based on the user preference either keep old xml file or add a new file to save the new settings again.

public override void Install(System.Collections.IDictionary stateSaver)
{
    //Invoke the base class method
    base.Install(stateSaver);

    if (File.Exists("XML File path"))
       {
           DialogResult result = MessageBox.Show("Do you want to use existing setting?","",MessageBoxButtons.YesNo);

        if (result.Equals(DialogResult.Yes))
           {

           }
        else
           {

           }
       }
}

他のヒント

The easiest solution is to not make this an installer problem. Make settings.xml a file not included in the installer. On first run of the application ask for the settings and setup the XML. Now when the installer uninstalls it'll automatically leave it behind. If they reinstall, your app will still find the settings.xml.

You can also have the installer populate a registry value with the date time installed and have the application put this in settings.xml. If the current registry value and xml values are different time stamps you know there was a reinstall and you can choose to ask the "do you want to keep?" question if you would like.

Now the installer is a simple file copy package without unneeded custom actions that can fail.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top