Ejemplo n.º 1
0
        private bool ShouldUnpack(EraFileExpander expander, string path)
        {
            if (expander.ExpanderOptions.Test(EraFileExpanderOptions.DontOverwriteExistingFiles))
            {
                // it's an XMB file and the user didn't say NOT to translate them
                if (ResourceUtils.IsXmbFile(path) && !expander.ExpanderOptions.Test(EraFileExpanderOptions.DontTranslateXmbFiles))
                {
                    ResourceUtils.RemoveXmbExtension(ref path);
                }

                if (System.IO.File.Exists(path))
                {
                    return(false);
                }
            }

            if (expander.ExpanderOptions.Test(EraFileExpanderOptions.IgnoreNonDataFiles))
            {
                if (!ResourceUtils.IsDataBasedFile(path))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool TryUnpack(IO.EndianStream blockStream, string workPath, EraFileExpander expander, EraFileEntryChunk file)
        {
            if (IsIgnoredLocalFile(file.FileName))
            {
                return(false);
            }

            string full_path = System.IO.Path.Combine(workPath, file.FileName);

            if (ResourceUtils.IsLocalScenarioFile(file.FileName))
            {
                return(false);
            }
            else if (!ShouldUnpack(expander, full_path))
            {
                return(false);
            }

            CreatePathForUnpacking(full_path);

            UnpackToDisk(blockStream, full_path, expander, file);
            return(true);
        }
Ejemplo n.º 3
0
        private void UnpackToDisk(IO.EndianStream blockStream, string fullPath, EraFileExpander expander, EraFileEntryChunk file)
        {
            byte[] buffer = file.GetBuffer(blockStream);

            using (var fs = System.IO.File.Create(fullPath))
            {
                fs.Write(buffer, 0, buffer.Length);
            }

            System.IO.File.SetCreationTimeUtc(fullPath, file.FileDateTime);
            System.IO.File.SetLastWriteTimeUtc(fullPath, file.FileDateTime);

            if (ResourceUtils.IsXmbFile(fullPath))
            {
                if (!expander.ExpanderOptions.Test(EraFileExpanderOptions.DontTranslateXmbFiles))
                {
                    var va_size       = Shell.ProcessorSize.x32;
                    var builtFor64Bit = expander.Options.Test(EraFileUtilOptions.x64);
                    if (builtFor64Bit)
                    {
                        va_size = Shell.ProcessorSize.x64;
                    }

                    TransformXmbToXml(buffer, fullPath, blockStream.ByteOrder, va_size);
                }
            }
            else if (ResourceUtils.IsScaleformFile(fullPath))
            {
                if (expander.ExpanderOptions.Test(EraFileExpanderOptions.DecompressUIFiles))
                {
                    bool success = false;

                    try
                    {
                        success = DecompressUIFileToDisk(buffer, fullPath);
                    }
                    catch (Exception ex)
                    {
                        Debug.Trace.Resource.TraceEvent(System.Diagnostics.TraceEventType.Error, TypeExtensions.kNone,
                                                        "Exception during {0} of '{1}': {2}",
                                                        EraFileExpanderOptions.DecompressUIFiles, fullPath, ex);
                        success = false;
                    }

                    if (!success && expander.VerboseOutput != null)
                    {
                        expander.VerboseOutput.WriteLine("Option {0} failed on '{1}'",
                                                         EraFileExpanderOptions.DecompressUIFiles, fullPath);
                    }
                }
                if (expander.ExpanderOptions.Test(EraFileExpanderOptions.TranslateGfxFiles))
                {
                    var result = TransformGfxToSwfFileResult.Failed;

                    try
                    {
                        result = TransformGfxToSwfFile(buffer, fullPath);
                    }
                    catch (Exception ex)
                    {
                        Debug.Trace.Resource.TraceEvent(System.Diagnostics.TraceEventType.Error, TypeExtensions.kNone,
                                                        "Exception during {0} of '{1}': {2}",
                                                        EraFileExpanderOptions.TranslateGfxFiles, fullPath, ex);
                    }

                    if (expander.VerboseOutput != null)
                    {
                        if (result == TransformGfxToSwfFileResult.Failed)
                        {
                            expander.VerboseOutput.WriteLine("Option {0} failed on '{1}'",
                                                             EraFileExpanderOptions.TranslateGfxFiles, fullPath);
                        }
                        else if (result == TransformGfxToSwfFileResult.InputIsAlreadySwf)
                        {
                            expander.VerboseOutput.WriteLine("Option {0} skipped on '{1}', it is already an SWF-based file",
                                                             EraFileExpanderOptions.TranslateGfxFiles, fullPath);
                        }
                    }
                }
            }
        }