Exemple #1
0
        private async void CombineClicked(object sender, RoutedEventArgs e)
        {
            if (runningTask != null && !runningTask.IsCompleted)
            {
                busyIndicator.IsBusy = true;
                await Task.Run(() =>
                {
                    runningTask.Wait();
                });

                busyIndicator.IsBusy = false;
            }


            if (fileList.Items.Count < 2)
            {
                ErrorDialog.Show("You need to select at least 2 files");
                return;
            }

            var fileName = Path.GetFileName(fileList.Items[0].File);

            foreach (Item item in fileList.Items)
            {
                if (Path.GetFileName(item.File) != fileName)
                {
                    ErrorDialog.Show("All files must have the same name");
                }
            }

            busyIndicator.IsBusy = true;
            try
            {
                var items            = fileList.Items.Select(item => item.File).ToList <string>();
                var alertCollissions = rbAdvancedCombine.IsChecked == true;
                await Task.Run(() =>
                {
                    Combiner.Combine(items, alertCollissions);
                });

                busyIndicator.IsBusy = false;
                MessageBox.Show(this, "Combined mod can be found in dropzone folder", "Success", MessageBoxButton.OK, MessageBoxImage.None);
            }
            catch (Exception ex)
            {
                busyIndicator.IsBusy = false;
                Errors.Handle("Failed to combine mods", ex);
            }
            busyIndicator.BusyContent = "Deleting temporary files";
            runningTask = TempFolder.ClearAsync();
        }
        public async void AddFileToList(string file)
        {
            if (Directory.Exists(file))
            {
                ErrorDialog.Show("Can't combine directories");
                return;
            }
            FileStream stream = null;

            try
            {
                stream = File.Open(file, FileMode.Open, FileAccess.Read);
            }
            catch (Exception ex)
            {
                Errors.Handle(ex);
                return;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }

            if (!await FileFormats.IsKnownFormat(file))
            {
                ErrorDialog.Show("Can't combine " + Path.GetExtension(file) + " files. If you need to combine these let me know at jc3mods.com");
                return;
            }

            foreach (Item item in Items)
            {
                if (Path.Equals(item.File, file))
                {
                    return;
                }
            }

            Items.Add(new Item(file));
        }
Exemple #3
0
        static Settings()
        {
            Directory.CreateDirectory(defaultFiles);

            var settingsPath = Path.Combine(files, "settings.json");

            if (File.Exists(settingsPath))
            {
                try
                {
                    user = JsonConvert.DeserializeObject <UserSettings>(File.ReadAllText(settingsPath));
                }
                catch (Exception ex)
                {
                    Errors.Handle(ex);
                    user = new UserSettings();
                }
            }
            else
            {
                user = new UserSettings();
            }

            var localPath = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "JC3 Mod Combiner");

            Directory.CreateDirectory(localPath);
            var localDataPath = Path.Combine(localPath, "data.json");

            if (File.Exists(localDataPath))
            {
                local = JsonConvert.DeserializeObject <LocalSettings>(File.ReadAllText(localDataPath));
            }
            else
            {
                local = new LocalSettings();
            }
        }
Exemple #4
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;
        }