private static void UpdateTranslationFiles(TranslationProject project, BackgroundWorker worker)
        {
            var containers = project.Game.GetContainers(project.InstallationPath);

            foreach (var container in containers)
            {
                if (worker.CancellationPending)
                {
                    worker.ReportProgress(0, "CANCELADO");
                    throw new UserCancelException();
                }

                var translationContainer =
                    project.FileContainers.FirstOrDefault(x => x.Path == container.Path && x.Type == container.Type);

                var addNewContainer = false;
                var addedFiles      = 0;

                if (translationContainer == null)
                {
                    translationContainer = new TranslationFileContainer(container.Path, container.Type);
                    addNewContainer      = true;
                }

                var extractionContainerPath = Path.Combine(project.ContainersFolder, translationContainer.Id);
                Directory.CreateDirectory(extractionContainerPath);

                var containerPath = Path.GetFullPath(Path.Combine(project.InstallationPath, container.Path));

                worker.ReportProgress(0, $"Procesando {container.Path}...");
                if (container.Type == ContainerType.CompressedFile)
                {
                    if (File.Exists(containerPath))
                    {
                        if (addNewContainer)
                        {
                            project.Game.PreprocessContainer(translationContainer, containerPath, extractionContainerPath);
                            project.Game.ExtractFile(containerPath, extractionContainerPath);
                        }

                        foreach (var fileSearch in container.FileSearches)
                        {
                            worker.ReportProgress(0, $"Buscando {fileSearch.RelativePath}\\{fileSearch.SearchPattern}...");
                            var foundFiles = fileSearch.GetFiles(extractionContainerPath);

                            foreach (var f in foundFiles)
                            {
                                var relativePath = PathHelper.GetRelativePath(extractionContainerPath, Path.GetFullPath(f));
                                var type         = fileSearch.FileType;

                                var translationFile = translationContainer.Files.FirstOrDefault(x => x.RelativePath == relativePath);

                                if (translationFile == null)
                                {
                                    try
                                    {
                                        translationFile = (TranslationFile)Activator.CreateInstance(type, f,
                                                                                                    project.ChangesFolder, project.Game.FileEncoding);
                                    }
                                    catch (MissingMethodException e)
                                    {
                                        translationFile =
                                            (TranslationFile)Activator.CreateInstance(type, f, project.ChangesFolder);
                                    }
                                    catch (Exception e)
                                    {
                                        translationFile = new TranslationFile(f, project.ChangesFolder);
                                    }

                                    translationFile.RelativePath = relativePath;

                                    if (translationFile.Type == FileType.TextFile)
                                    {
                                        if (translationFile.SubtitleCount > 0)
                                        {
                                            translationContainer.AddFile(translationFile);
                                            addedFiles++;
                                        }
                                    }
                                    else
                                    {
                                        translationContainer.AddFile(translationFile);
                                        addedFiles++;
                                    }
                                }
                            }
                        }

                        project.Game.PostprocessContainer(translationContainer, containerPath, extractionContainerPath);

                        worker.ReportProgress(0, $"{addedFiles} ficheros encontrados y añadidos");
                    }
                    else
                    {
                        worker.ReportProgress(0, $"ERROR: No existe el fichero comprimido {containerPath}");
                        continue;
                    }
                }
                else
                {
                    project.Game.PreprocessContainer(translationContainer, containerPath, extractionContainerPath);
                    foreach (var fileSearch in container.FileSearches)
                    {
                        worker.ReportProgress(0, $"Buscando {fileSearch.RelativePath}\\{fileSearch.SearchPattern}...");
                        var foundFiles = fileSearch.GetFiles(containerPath);

                        foreach (var f in foundFiles)
                        {
                            var relativePath = PathHelper.GetRelativePath(containerPath, Path.GetFullPath(f));

                            var destinationFileName = Path.GetFullPath(Path.Combine(extractionContainerPath, relativePath));
                            var destPath            = Path.GetDirectoryName(destinationFileName);
                            Directory.CreateDirectory(destPath);

                            if (!File.Exists(destinationFileName))
                            {
                                File.Copy(f, destinationFileName);
                            }

                            var type = fileSearch.FileType;

                            var translationFile = translationContainer.Files.FirstOrDefault(x => x.RelativePath == relativePath);

                            if (translationFile == null)
                            {
                                try
                                {
                                    translationFile = (TranslationFile)Activator.CreateInstance(type,
                                                                                                destinationFileName, project.ChangesFolder, project.Game.FileEncoding);
                                }
                                catch (MissingMethodException e)
                                {
                                    translationFile =
                                        (TranslationFile)Activator.CreateInstance(type, destinationFileName,
                                                                                  project.ChangesFolder);
                                }
                                catch (Exception e)
                                {
                                    translationFile = new TranslationFile(destinationFileName, project.ChangesFolder);
                                }

                                translationFile.RelativePath = relativePath;

                                if (translationFile.Type == FileType.TextFile)
                                {
                                    if (translationFile.SubtitleCount > 0)
                                    {
                                        translationContainer.AddFile(translationFile);
                                        addedFiles++;
                                    }
                                }
                                else
                                {
                                    translationContainer.AddFile(translationFile);
                                    addedFiles++;
                                }
                            }
                        }

                        project.Game.PostprocessContainer(translationContainer, containerPath, extractionContainerPath);
                        worker.ReportProgress(0, $"{addedFiles} ficheros encontrados y añadidos");
                    }
                }

                if (addNewContainer && translationContainer.Files.Count > 0)
                {
                    project.FileContainers.Add(translationContainer);
                }
            }
        }
예제 #2
0
 public virtual void PostprocessContainer(TranslationFileContainer container, string containerPath, string extractionPath)
 {
 }