public static FileFormat GetFileFormat(string file)
        {
            string extension = Path.GetExtension(file).Substring(1);

            if (extension == "xml")
            {
                return(FileFormat.Xml);
            }
            else if (smallArchiveExtensions.Contains(extension))
            {
                return(FileFormat.SmallArchive);
            }
            else if (propertyExtensions.Contains(extension))
            {
                return(FileFormat.Property);
            }
            else if (adfExtensions.Contains(extension))
            {
                return(FileFormat.Adf);
            }
            else if (unknownExtensions.Contains(extension))
            {
                return(FileFormat.Unknown);
            }

            System.Diagnostics.Debug.WriteLine("Defining file format of ." + extension);

            if (GibbedsTools.CanConvert(file, GibbedsTools.convertAdf))
            {
                adfExtensions.Add(extension);
                Settings.user.adfExtensions.Add(extension);
                return(FileFormat.Adf);
            }
            else if (GibbedsTools.CanConvert(file, GibbedsTools.convertProperty))
            {
                propertyExtensions.Add(extension);
                Settings.user.propertyExtensions.Add(extension);
                return(FileFormat.Property);
            }
            else if (GibbedsTools.CanConvert(file, GibbedsTools.smallUnpack))
            {
                smallArchiveExtensions.Add(extension);
                Settings.user.smallArchiveExtensions.Add(extension);
                return(FileFormat.SmallArchive);
            }

            unknownExtensions.Add(extension);
            Settings.user.unknownExtensions.Add(extension);

            return(FileFormat.Unknown);
        }
Beispiel #2
0
        public static List <string> GetFile(string fileName)
        {
            Settings.SetBusyContent("Finding default files for " + fileName + "...");

            var result      = new List <string>();
            var cachedFiles = Directory.EnumerateFiles(Settings.defaultFiles, Path.GetFileNameWithoutExtension(fileName) + "_*" + Path.GetExtension(fileName), SearchOption.AllDirectories);

            foreach (var file in cachedFiles)
            {
                result.Add(file);
            }
            //Find file from jc3 folders

            var fileLists = new List <string>();

            fileLists.AddRange(Directory.EnumerateFiles(Path.Combine(Settings.user.JC3Folder, "archives_win64"), "*", SearchOption.AllDirectories).Where(name => Regex.IsMatch(name, "game_hash_names[0-9]+\\.txt")));
            fileLists = fileLists.OrderBy(s => int.Parse(Path.GetFileNameWithoutExtension(s).Substring(15))).ToList <string>();
            if (Directory.Exists(Path.Combine(Settings.user.JC3Folder, "dlc")))
            {
                var dlcFileLists = Directory.EnumerateFiles(Path.Combine(Settings.user.JC3Folder, "dlc"), "*", SearchOption.AllDirectories).Where(name => Regex.IsMatch(name, "game_hash_names[0-9]+\\.txt")).ToList <string>();
                dlcFileLists = dlcFileLists.OrderBy(s => int.Parse(Path.GetFileNameWithoutExtension(s).Substring(15))).ToList <string>();
                fileLists.AddRange(dlcFileLists);
            }
            if (Directory.Exists(Path.Combine(Settings.user.JC3Folder, "patch_win64")))
            {
                var patchFileLists = Directory.EnumerateFiles(Path.Combine(Settings.user.JC3Folder, "patch_win64")).Where(name => Regex.IsMatch(name, "game_hash_names[0-9]+\\.txt")).ToList <string>();
                patchFileLists = patchFileLists.OrderBy(s => int.Parse(Path.GetFileNameWithoutExtension(s).Substring(15))).ToList <string>();
                fileLists.AddRange(patchFileLists);
            }


            var fileInfos = new List <DefaultFileInformation>();

            foreach (string fileList in fileLists)
            {
                string[] lines = File.ReadAllLines(fileList);
                foreach (string line in lines)
                {
                    if (line.Contains(fileName))
                    {
                        string num     = Path.GetFileName(fileList).Substring(15, Path.GetFileName(fileList).Length - 15 - 4);
                        string tabFile = Path.Combine(Path.GetDirectoryName(fileList), "game" + num + ".tab");
                        fileInfos.Add(new DefaultFileInformation(line, tabFile));
                    }
                }
            }

            if (result.Count == fileInfos.Count)
            {
                return(result);                //return result;
            }

            foreach (string file in result)
            {
                File.Delete(file);
            }

            Settings.SetBusyContent("Extracting default files from Just Cause 3 archives...");

            foreach (var fileInfo in fileInfos)
            {
                var    outputPath      = TempFolder.GetTempFile();
                string extractedFolder = GibbedsTools.Unpack(fileInfo.tabFile, outputPath, fileInfo.hash + "\\.*");

                if (extractedFolder == null)
                {
                    continue;
                }

                var files = Directory.EnumerateFiles(extractedFolder, fileInfo.hash + ".*", SearchOption.AllDirectories);
                foreach (string file in files)
                {
                    if (new FileInfo(file).Length != fileInfo.size)
                    {
                        continue;
                    }
                    string newPath = Path.Combine(Settings.defaultFiles, fileInfo.relativePath);
                    newPath = Util.GetUniqueFile(newPath);

                    if (!Directory.Exists(Path.GetDirectoryName(newPath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(newPath));
                    }
                    File.Move(file, newPath);
                    if (File.Exists(newPath))
                    {
                        result.Add(newPath);
                    }
                    break;
                }
            }
            return(result);
        }
Beispiel #3
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);
            }
        }