Beispiel #1
0
        public MainWindow()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler((object sender, UnhandledExceptionEventArgs args) =>
            {
                File.WriteAllText(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "crash.txt"), args.ExceptionObject.ToString());
                Application.Current.Shutdown();
            });

#if !DEBUG
            if (Settings.user.checkForUpdates && System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                try
                {
                    WebClient webClient = new WebClient();
                    webClient.DownloadStringCompleted += (DownloadStringCompletedEventHandler)((sender, e) =>
                    {
                        if (e.Error != null)
                        {
                            return;
                        }
                        string result = e.Result;
                        string match = Regex.Match(result, @"<b>Version</b>r[0-9]+<").Value;
                        int newestRevision = int.Parse(Regex.Match(match, "r[0-9]+").Value.Substring(1));
                        Debug.WriteLine(newestRevision + "");
                        if (newestRevision > Settings.revision && System.Windows.MessageBox.Show("Current version: r" + Settings.revision + "\nNewest version: r" + newestRevision + "\nOpen justcause3mods.com mod page?", "New version available", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                        {
                            Process.Start("http://justcause3mods.com/mods/mod-combiner/");
                        }
                    });
                    webClient.DownloadStringTaskAsync("http://justcause3mods.com/mods/mod-combiner/");
                }
                catch (Exception e)
                {
                    Errors.Handle("Failed to check for new version", e);
                }
            }
#endif

            var oldSettings = Path.Combine(Settings.local.lastInstallPath, @"Files\settings.json");
            if (File.Exists(oldSettings))
            {
                Settings.user = JsonConvert.DeserializeObject <UserSettings>(File.ReadAllText(oldSettings));
            }
            InitializeComponent();
            RenderOptions.SetBitmapScalingMode(img, BitmapScalingMode.Linear);
            Title += " r" + Settings.revision;

            if (Settings.user.JC3Folder == null || !Directory.Exists(Settings.user.JC3Folder))
            {
                try
                {
                    RegistryKey regKey = Registry.CurrentUser;
                    regKey = regKey.OpenSubKey(@"Software\Valve\Steam");

                    if (regKey != null)
                    {
                        var installpath = regKey.GetValue("SteamPath").ToString() + @"/SteamApps/common/Just Cause 3";
                        if (Directory.Exists(installpath))
                        {
                            if (MessageBox.Show("Just Cause 3 folder found at\n" + installpath, "Set as JC3 path?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                            {
                                Settings.user.JC3Folder = installpath;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Errors.Handle(ex);
                }

                while (Settings.user.JC3Folder == null || !Directory.Exists(Settings.user.JC3Folder))
                {
                    var dialog = new VistaFolderBrowserDialog();
                    dialog.Description            = "Select Just Cause 3 folder";
                    dialog.UseDescriptionForTitle = true;
                    var result = dialog.ShowDialog();
                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        if (Directory.Exists(dialog.SelectedPath))
                        {
                            Settings.user.JC3Folder = dialog.SelectedPath;
                        }
                    }
                    else if (result == System.Windows.Forms.DialogResult.Cancel)
                    {
                        Application.Current.Shutdown();
                    }
                }
            }


            Directory.CreateDirectory(Path.Combine(Settings.user.JC3Folder, "dropzone"));

            Items          = new ObservableCollection <Item>();
            fileList.Items = Items;

            Settings.mainWindow = this;
        }