public static async Task <bool> IsKnownFormat(string file) { if (Path.GetExtension(file) == "") { return(false); } FileFormat format = FileFormat.Unknown; await Task.Run(() => { format = FileFormats.GetFileFormat(file); }); return(format != FileFormat.Unknown); }
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); }
private static void Combine(List <string> originalFiles, List <string> files, FileFormat fileFormat, string outputPath) { Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); if (fileFormat == FileFormat.Property) { 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) { 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.ConvertAdf(xmlOutputPath, outputPath); } 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) { OverrideCombine(originalFiles, files, outputPath, false); } else if (fileFormat == FileFormat.SmallArchive) { 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)) { 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); } GibbedsTools.SmallPack(originalUnpacked[originalUnpacked.Count - 1], outputPath); } }