Exemple #1
0
        public static void Combine(List <string> files, bool notifyCollissions)
        {
            Settings.SetBusyContent("Combining...");
            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 = DefaultFiles.GetFile(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, "dropzone", 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 Task <bool> IsKnownFormat(string file)
        {
            if (Path.GetExtension(file) == "")
            {
                return(false);
            }
            Settings.SetBusyContent("Determining file format for " + Path.GetFileName(file));
            FileFormat format = FileFormat.Unknown;
            await Task.Run(() =>
            {
                format = FileFormats.GetFileFormat(file);
            });

            Settings.SetBusyContent(null);

            return(format != FileFormat.Unknown);
        }
        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 #4
0
        private static void Combine(List <string> originalFiles, List <string> files, FileFormat fileFormat, string outputPath)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

            if (fileFormat == FileFormat.Property)
            {
                Settings.SetBusyContent("Combining " + Path.GetFileName(originalFiles[0]));

                List <string> originalXml = originalFiles.Select(originalFile => GibbedsTools.ConvertProperty(originalFile, TempFolder.GetTempFile(), GibbedsTools.ConvertMode.Export)).ToList();
                List <string> xmlFiles    = files.Select(originalFile => GibbedsTools.ConvertProperty(originalFile, TempFolder.GetTempFile(), GibbedsTools.ConvertMode.Export)).ToList();

                var xmlOutputPath = TempFolder.GetTempFile();
                Combine(originalXml, xmlFiles, FileFormat.Xml, xmlOutputPath);

                GibbedsTools.ConvertProperty(xmlOutputPath, outputPath, GibbedsTools.ConvertMode.Import);
            }
            else if (fileFormat == FileFormat.Adf)
            {
                Settings.SetBusyContent("Combining " + Path.GetFileName(originalFiles[0]));

                OverrideCombine(originalFiles, files, outputPath, true);
            }
            else if (fileFormat == FileFormat.Xml)
            {
                var fileNames = rootFiles;
                if (files != rootFiles)
                {
                    fileNames = rootFiles.Select(item => Path.Combine(item, Path.GetFileName(originalFiles[0]))).ToList <string>();
                }
                XmlCombiner.Combine(originalFiles, files, fileNames, notifyCollissions, outputPath);
            }
            else if (fileFormat == FileFormat.Unknown)
            {
                Settings.SetBusyContent("Combining " + Path.GetFileName(originalFiles[0]));

                OverrideCombine(originalFiles, files, outputPath, false);
            }
            else if (fileFormat == FileFormat.SmallArchive)
            {
                Settings.SetBusyContent("Unpacking " + Path.GetFileName(originalFiles[0]));

                var originalUnpacked = originalFiles.Select(file => GibbedsTools.SmallUnpack(file, TempFolder.GetTempFile())).ToList();
                var unpackedFiles    = files.Select(file => GibbedsTools.SmallUnpack(file, TempFolder.GetTempFile())).ToList();

                foreach (string file in Directory.EnumerateFiles(originalUnpacked[originalUnpacked.Count - 1], "*", SearchOption.AllDirectories))
                {
                    Settings.SetBusyContent("Combining " + Path.GetFileName(file));
                    var correspondingOriginals = new List <string>();
                    foreach (var unpackedFile in originalUnpacked)
                    {
                        string path = Path.Combine(unpackedFile, file.Substring(originalUnpacked[0].Length + 1));
                        correspondingOriginals.Add(path);
                    }
                    var correspondingFiles = new List <string>();
                    foreach (string unpackedFile in unpackedFiles)
                    {
                        string path = Path.Combine(unpackedFile, file.Substring(originalUnpacked[0].Length + 1));
                        correspondingFiles.Add(path);
                    }

                    Combine(correspondingOriginals, correspondingFiles, FileFormats.GetFileFormat(file), file);
                }
                Settings.SetBusyContent("Packing " + Path.GetFileName(originalFiles[0]));
                GibbedsTools.SmallPack(originalUnpacked[originalUnpacked.Count - 1], outputPath);
            }
        }