Esempio n. 1
0
        public static void Combine(List <string> files, bool notifyCollissions, string folder)
        {
            rootFiles = files;
            Combiner.notifyCollissions = notifyCollissions;

            var fileFormat = FileFormats.GetFileFormat(files[0]);

            if (fileFormat == FileFormat.Unknown)
            {
                throw new ArgumentException("Can't combine " + Path.GetExtension(files[0]) + " files. If you need to combine these files, let me know at jc3mods.com");
            }

            var originalFiles = GameFiles.GetDefaultFiles(Path.GetFileName(files[0]));

            if (originalFiles.Count == 0)
            {
                throw new Exception("Couldn't find default files for " + Path.GetFileName(files[0]));
            }
            var outputPath = Path.Combine(Settings.user.JC3Folder, folder, originalFiles[0].Substring(Settings.defaultFiles.Length + 1));
            var name       = Path.GetFileNameWithoutExtension(outputPath);

            outputPath = Path.GetDirectoryName(outputPath) + "\\" + name.Substring(0, name.LastIndexOf('_')) + Path.GetExtension(outputPath);
            Combine(originalFiles, files, FileFormats.GetFileFormat(originalFiles[0]), outputPath);
        }
        public static async void InstallMods(List <string> dropzoneFiles, List <string> skyfortressFiles)
        {
            var groupedDropzoneFiles    = GroupFiles(dropzoneFiles);
            var groupedSkyfortressFiles = GroupFiles(skyfortressFiles);

            var progressViewModel = new ProgressDialogViewModel();

            Settings.mainWindow.BusyDialog.DialogContent = progressViewModel;
            Settings.mainWindow.BusyDialog.IsOpen        = true;
            int progress = 0;

            foreach (var value in groupedDropzoneFiles.Values)
            {
                var files = value;
                await Task.Run(() =>
                {
                    if (files.Count == 1)
                    {
                        var file       = GameFiles.GetDefaultFiles(Path.GetFileName(files[0]));
                        var outputPath = Path.Combine(Settings.user.JC3Folder, "dropzone", file[0].Substring(Settings.defaultFiles.Length + 1));
                        var name       = Path.GetFileNameWithoutExtension(outputPath);
                        outputPath     = Path.GetDirectoryName(outputPath) + "\\" + name.Substring(0, name.LastIndexOf('_')) + Path.GetExtension(outputPath);
                        File.Copy(files[files.Count - 1], outputPath, true);
                    }
                    else
                    {
                        try
                        {
                            Combiner.Combine(files, false, "dropzone");
                        }
                        catch (Exception ex)
                        {
                            Errors.Handle("Failed to combine " + files.Count + " mods.", ex);
                            var file       = GameFiles.GetDefaultFiles(Path.GetFileName(files[0]));
                            var outputPath = Path.Combine(Settings.user.JC3Folder, "dropzone", file[0].Substring(Settings.defaultFiles.Length + 1));
                            var name       = Path.GetFileNameWithoutExtension(outputPath);
                            outputPath     = Path.GetDirectoryName(outputPath) + "\\" + name.Substring(0, name.LastIndexOf('_')) + Path.GetExtension(outputPath);
                            File.Copy(files[files.Count - 1], outputPath, true);
                        }
                    }
                });

                progress++;
                progressViewModel.Progress = progress / (groupedDropzoneFiles.Count + groupedSkyfortressFiles.Count);
            }

            foreach (var value in groupedSkyfortressFiles.Values)
            {
                var files = value;
                await Task.Run(() =>
                {
                    if (files.Count == 1)
                    {
                        var file       = GameFiles.GetDefaultFiles(Path.GetFileName(files[0]));
                        var outputPath = Path.Combine(Settings.user.JC3Folder, "dropzone_sky_fortress", file[0].Substring(Settings.defaultFiles.Length + 1));
                        var name       = Path.GetFileNameWithoutExtension(outputPath);
                        outputPath     = Path.GetDirectoryName(outputPath) + "\\" + name.Substring(0, name.LastIndexOf('_')) + Path.GetExtension(outputPath);
                        File.Copy(files[files.Count - 1], outputPath, true);
                    }
                    else
                    {
                        try
                        {
                            Combiner.Combine(files, false, "dropzone_sky_fortress");
                        }
                        catch (Exception ex)
                        {
                            Errors.Handle("Failed to combine " + files.Count + " mods.", ex);
                            var file       = GameFiles.GetDefaultFiles(Path.GetFileName(files[0]));
                            var outputPath = Path.Combine(Settings.user.JC3Folder, "dropzone_sky_fortress", file[0].Substring(Settings.defaultFiles.Length + 1));
                            var name       = Path.GetFileNameWithoutExtension(outputPath);
                            outputPath     = Path.GetDirectoryName(outputPath) + "\\" + name.Substring(0, name.LastIndexOf('_')) + Path.GetExtension(outputPath);
                            File.Copy(files[files.Count - 1], outputPath, true);
                        }
                    }
                });

                progress++;
                progressViewModel.Progress = progress / (groupedDropzoneFiles.Count + groupedSkyfortressFiles.Count);
            }

            if (groupedSkyfortressFiles.Count > 0)
            {
                GibbedsTools.SkyFortressPack();
            }

            Settings.mainWindow.BusyDialog.IsOpen = false;
        }