Interaction logic for MainWindow.xaml
        public void SaveSettings(Settings settings)
        {
            try
            {
                var writer = new System.Xml.Serialization.XmlSerializer(typeof (Settings));
                var folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Util.SettingsPath);
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                var filePath = Path.Combine(folderPath, SettingsFileName);
                var wfile = new StreamWriter(filePath);
                writer.Serialize(wfile, settings);
                wfile.Close();
            }
            catch (Exception e)
            {
                Util.Log(e.Message);
                //Failed
            }
        }
        public Settings LoadSettings()
        {
            var result = new Settings();
            try
            {
                var folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Util.SettingsPath);
                var filePath = Path.Combine(folderPath, SettingsFileName);
                if (!File.Exists(filePath)) return result;

                System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(Settings));
                var file = new StreamReader(filePath);
                var settings = (Settings)reader.Deserialize(file);
                result = settings;
                file.Close();
            }
            catch (Exception e)
            {
                Util.Log(e.Message);
                //Failed
            }
            return result;
        }
        public MainWindowModel(BootstrapperApplication bootstrapper)
        {
            this.IsThinking = false;
            this.Bootstrapper = bootstrapper;
            this.Bootstrapper.PlanPackageBegin += SetPackagePlannedState;
            this.Bootstrapper.PlanMsiFeature += SetFeaturePlannedState;
            this.Bootstrapper.PlanComplete += PlanComplete;

            _settingsStorage = new SettingsStorage();
            _settings = _settingsStorage.LoadSettings();

            if (_settings.GtaPath == null)
            {
                _settings.GtaPath = "";
            }

            if (!Util.IsValidGtaFolder(_settings.GtaPath))
            {
                var registryPath = Util.GetGtaInstallPathFromRegistry();
                if (Util.IsValidGtaFolder(registryPath))
                {
                    _settings.GtaPath = registryPath;
                }
                else
                {
                    _settings.GtaPath = "";
                }
            }
            StatusText = "Ready.";
            _updater = new Updater(_settings);
            _updater.ModInstalled += UpdaterOnModInstalled;
            _updater.ScriptHookVInstalled += UpdaterOnScriptHookVInstalled;
            _updater.ScriptHookVRemoved += UpdaterOnScriptHookVRemoved;
            _updater.ModRemoved += UpdaterOnModRemoved;
            _updater.UpdatesChecked += UpdaterOnUpdatesChecked;
        }