using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.IO;

namespace StarTrinity
{
    [RunInstaller(true)]
    public class InstallerClass : System.Configuration.Install.Installer
    {
        public InstallerClass()
        {
        }

        public override void Commit(System.Collections.IDictionary savedState)
        {
            base.Commit(savedState);
            try
            {
                File.Delete(DistributedProxySettings.FullSettingsFileName);
            }
            catch
            {
            }

            var settings = new DistributedProxySettings();
            settings.SetSettingValue(DistributedProxySettings.Names.InstallationDate, DateTime.UtcNow.ToString());
            var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StarTrinity.DistributedProxy.exe");
            try
            {
                System.Diagnostics.Process.Start(path);
            }
            catch (Exception exc)
            {
              // System.Windows.Forms.MessageBox.Show("exception: " + exc.ToString() + "\r\n path: " + path);
            }
            DistributedProxy.CreateRegKey();
            // Very important! Removes all those nasty temp files.
            base.Dispose();
        }
    }
}
