Beispiel #1
0
        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);
            }

            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> GetDefaultFiles(string 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.files, "Filenames", "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>();

            var dlcFileLists = Directory.EnumerateFiles(Path.Combine(Settings.files, "Filenames", "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);

            var patchFileLists = Directory.EnumerateFiles(Path.Combine(Settings.files, "Filenames", "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);
            }

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

            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);
        }
        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;
        }
        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);
            }
        }