コード例 #1
0
        /// <summary>
        /// Loads the specified WMO group file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the model group.</param>
        /// <returns>A WMO object, containing just the specified model group.</returns>
        public static WMO LoadWorldModelGroup(FileReference fileReference)
        {
            // Get the file name of the root object
            string modelRootPath = fileReference.FilePath.Remove(fileReference.FilePath.Length - 8, 4);

            // Extract it and load just this model group
            try
            {
                byte[] fileData = fileReference.PackageGroup.ExtractFile(modelRootPath);
                if (fileData != null)
                {
                    WMO    worldModel     = new WMO(fileData);
                    byte[] modelGroupData = fileReference.Extract();

                    if (modelGroupData != null)
                    {
                        worldModel.AddModelGroup(new ModelGroup(modelGroupData));
                    }

                    return(worldModel);
                }
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn(
                    $"Failed to load the model group \"{fileReference.FilePath}\" due to an invalid sector table (\"{fex.Message}\").");

                return(null);
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Exports the mipmaps in the image.
        /// </summary>
        public void RunExport()
        {
            this.ItemExportListStore.Foreach(delegate(ITreeModel model, TreePath path, TreeIter iter)
            {
                bool bShouldExport = (bool)this.ItemExportListStore.GetValue(iter, 0);

                if (bShouldExport)
                {
                    FileReference referenceToExport = this.ReferenceMapping[(string)this.ItemExportListStore.GetValue(iter, 1)];

                    string exportPath = "";
                    if (this.Config.GetShouldKeepFileDirectoryStructure())
                    {
                        string parentDirectoryOfFile = this.ExportTarget.FilePath.ConvertPathSeparatorsToCurrentNativeSeparator();

                        exportPath =
                            $"{this.ExportDirectoryFileChooserButton.Filename}{System.IO.Path.DirectorySeparatorChar}{parentDirectoryOfFile}{System.IO.Path.DirectorySeparatorChar}{referenceToExport.GetReferencedItemName()}";
                    }
                    else
                    {
                        exportPath = $"{this.ExportDirectoryFileChooserButton.Filename}{System.IO.Path.DirectorySeparatorChar}{referenceToExport.GetReferencedItemName()}";
                    }

                    Directory.CreateDirectory(Directory.GetParent(exportPath).FullName);

                    byte[] fileData = referenceToExport.Extract();
                    if (fileData != null)
                    {
                        File.WriteAllBytes(exportPath, fileData);
                    }
                }

                return(false);
            });
        }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: datphL/Everlook
        /// <summary>
        /// Handles extraction of files from the archive triggered by a context menu press.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private void OnExtractContextItemActivated(object sender, EventArgs e)
        {
            FileReference fileReference = GetSelectedReference();

            string cleanFilepath = fileReference.FilePath.ConvertPathSeparatorsToCurrentNativeSeparator();
            string exportpath;

            if (this.Config.GetShouldKeepFileDirectoryStructure())
            {
                exportpath = this.Config.GetDefaultExportDirectory() + cleanFilepath;
                Directory.CreateDirectory(Directory.GetParent(exportpath).FullName);
            }
            else
            {
                string filename = IOPath.GetFileName(cleanFilepath);
                exportpath = this.Config.GetDefaultExportDirectory() + filename;
                Directory.CreateDirectory(Directory.GetParent(exportpath).FullName);
            }

            byte[] file = fileReference.Extract();
            if (file != null)
            {
                File.WriteAllBytes(exportpath, file);
            }
        }
コード例 #4
0
ファイル: MP3AudioAsset.cs プロジェクト: znerxx/Everlook
        /// <summary>
        /// Initializes a new instance of the <see cref="MP3AudioAsset"/> class.
        /// </summary>
        /// <param name="fileReference">The reference to create the asset from.</param>
        /// <exception cref="ArgumentException">Thrown if the reference is not an MP3 audio file.</exception>
        /// <exception cref="ArgumentNullException">Thrown if the file data can't be extracted.</exception>
        public MP3AudioAsset(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            if (fileReference.GetReferencedFileType() != WarcraftFileType.MP3Audio)
            {
                throw new ArgumentException
                      (
                          "The provided file reference was not an MP3 audio file.", nameof(fileReference)
                      );
            }

            var fileBytes = fileReference.Extract();

            if (fileBytes == null)
            {
                throw new ArgumentException("The file data could not be extracted.", nameof(fileReference));
            }

            this.PCMStream     = new MP3Stream(new MemoryStream(fileBytes));
            this.Channels      = ((MP3Stream)this.PCMStream).ChannelCount;
            this.BitsPerSample = 16;
            this.SampleRate    = ((MP3Stream)this.PCMStream).Frequency;
        }
コード例 #5
0
        /// <summary>
        /// Loads the specified image from the archives and deserializes it into a bitmap.
        /// </summary>
        /// <param name="fileReference">A reference to an image.</param>
        /// <returns>A bitmap containing the image data pointed to by the reference.</returns>
        public static Bitmap LoadBitmapImage(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            Bitmap image;

            try
            {
                var fileData = fileReference.Extract();
                using (var ms = new MemoryStream(fileData))
                {
                    image = new Bitmap(ms);
                }
            }
            catch (FileNotFoundException fex)
            {
                Log.Warn(
                    $"Failed to load the image \"{fileReference.FilePath}\": {fex}");
                throw;
            }

            return(image);
        }
コード例 #6
0
        /// <summary>
        /// Loads the specified BLP image from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">A reference to a BLP image.</param>
        /// <returns>A BLP object containing the image data pointed to by the reference.</returns>
        public static BLP LoadBinaryImage(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            BLP image;

            try
            {
                var fileData = fileReference.Extract();

                try
                {
                    image = new BLP(fileData);
                }
                catch (FileLoadException fex)
                {
                    Log.Warn(
                        $"FileLoadException when loading BLP image: {fex.Message}\n" +
                        $"Please report this on GitHub or via email.");
                    throw;
                }
            }
            catch (FileNotFoundException fex)
            {
                Log.Warn($"Failed to extract image: {fex}");
                throw;
            }

            return(image);
        }
コード例 #7
0
        /// <summary>
        /// Loads the specified WMO group file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the model group.</param>
        /// <returns>A WMO object, containing just the specified model group.</returns>
        public static WMO LoadWorldModelGroup(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            // Get the file name of the root object
            string modelRootPath = fileReference.FilePath.Remove(fileReference.FilePath.Length - 8, 4);

            WMO worldModel;

            // Extract it and load just this model group
            try
            {
                byte[] rootData = fileReference.Context.Assets.ExtractFile(modelRootPath);
                worldModel = new WMO(rootData);

                byte[] modelGroupData = fileReference.Extract();
                worldModel.AddModelGroup(new ModelGroup(modelGroupData));
            }
            catch (FileNotFoundException fex)
            {
                Log.Warn($"Failed to load the model group \"{fileReference.FilePath}\": {fex}");
                throw;
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn($"Failed to load the model group \"{fileReference.FilePath}\" due to an invalid sector table (\"{fex}\")");
                throw;
            }

            return(worldModel);
        }
コード例 #8
0
        /// <summary>
        /// Loads the specified game model from the archives and deserializes it into an <see cref="MDX"/> model.
        /// </summary>
        /// <param name="fileReference">A reference to a model.</param>
        /// <returns>An object containing the model data pointed to by the reference.</returns>
        public static MDX LoadGameModel(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            MDX model;

            try
            {
                byte[] fileData = fileReference.Extract();
                model = new MDX(fileData);

                if (model.Version >= WarcraftVersion.Wrath)
                {
                    // Load external skins
                    var modelFilename  = Path.GetFileNameWithoutExtension(fileReference.Filename);
                    var modelDirectory = fileReference.FileDirectory.Replace(Path.DirectorySeparatorChar, '\\');

                    List <MDXSkin> skins = new List <MDXSkin>();
                    for (int i = 0; i < model.SkinCount; ++i)
                    {
                        var modelSkinPath = $"{modelDirectory}\\{modelFilename}{i:D2}.skin";
                        var skinData      = fileReference.Context.Assets.ExtractFile(modelSkinPath);

                        using (var ms = new MemoryStream(skinData))
                        {
                            using (var br = new BinaryReader(ms))
                            {
                                var skinIdentifier = new string(br.ReadChars(4));
                                if (skinIdentifier != "SKIN")
                                {
                                    break;
                                }

                                skins.Add(br.ReadMDXSkin(model.Version));
                            }
                        }
                    }

                    model.SetSkins(skins);
                }
            }
            catch (FileNotFoundException fex)
            {
                Log.Warn($"Failed to load the model \"{fileReference.FilePath}\": {fex}");
                throw;
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn($"Failed to load the model \"{fileReference.FilePath}\" due to an invalid sector table (\"{fex.Message}\").");
                throw;
            }

            return(model);
        }
コード例 #9
0
        /// <summary>
        /// TODO: Refactor this and LoadWorldModelGroup
        /// Loads the specified WMO file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the WMO root object.</param>
        /// <returns>A WMO object.</returns>
        public static WMO LoadWorldModel(FileReference fileReference)
        {
            try
            {
                byte[] fileData = fileReference.Extract();
                if (fileData != null)
                {
                    WMO worldModel = new WMO(fileData);

                    string modelPathWithoutExtension = Path.GetFileNameWithoutExtension(fileReference.FilePath);
                    for (int i = 0; i < worldModel.GroupCount; ++i)
                    {
                        // Extract the groups as well
                        string modelGroupPath = $"{modelPathWithoutExtension}_{i:D3}.wmo";

                        try
                        {
                            byte[] modelGroupData = fileReference.PackageGroup.ExtractFile(modelGroupPath);

                            if (modelGroupData != null)
                            {
                                worldModel.AddModelGroup(new ModelGroup(modelGroupData));
                            }
                        }
                        catch (InvalidFileSectorTableException fex)
                        {
                            Log.Warn(
                                $"Failed to load the model group \"{modelGroupPath}\" due to an invalid sector table (\"{fex.Message}\").");

                            return(null);
                        }
                    }

                    return(worldModel);
                }
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn(
                    $"Failed to load the model \"{fileReference.FilePath}\" due to an invalid sector table (\"{fex.Message}\").");

                return(null);
            }

            return(null);
        }
コード例 #10
0
        /// <summary>
        /// Loads the specified WMO file from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">The archive reference to the WMO root object.</param>
        /// <returns>A WMO object.</returns>
        public static WMO LoadWorldModel(FileReference fileReference)
        {
            if (fileReference == null)
            {
                throw new ArgumentNullException(nameof(fileReference));
            }

            WMO worldModel;

            try
            {
                var fileData = fileReference.Extract();
                worldModel = new WMO(fileData);

                var modelPathWithoutExtension = $"{fileReference.FileDirectory.Replace('/', '\\')}\\" +
                                                $"{Path.GetFileNameWithoutExtension(fileReference.Filename)}";
                for (var i = 0; i < worldModel.GroupCount; ++i)
                {
                    // Extract the groups as well
                    var modelGroupPath = $"{modelPathWithoutExtension}_{i:D3}.wmo";

                    try
                    {
                        var modelGroupData = fileReference.Context.Assets.ExtractFile(modelGroupPath);
                        worldModel.AddModelGroup(new ModelGroup(modelGroupData));
                    }
                    catch (FileNotFoundException fex)
                    {
                        Log.Warn($"Failed to load model group \"{modelGroupPath}\": {fex}.");
                        throw;
                    }
                }
            }
            catch (InvalidFileSectorTableException fex)
            {
                Log.Warn
                (
                    $"Failed to load the model \"{fileReference.FilePath}\" due to an invalid sector table " +
                    $"(\"{fex.Message}\")."
                );
                throw;
            }

            return(worldModel);
        }
コード例 #11
0
        /// <summary>
        /// Loads the specified BLP image from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">A reference to a BLP image.</param>
        /// <returns></returns>
        public static BLP LoadBinaryImage(FileReference fileReference)
        {
            byte[] fileData = fileReference.Extract();
            if (fileData != null)
            {
                try
                {
                    return(new BLP(fileData));
                }
                catch (FileLoadException fex)
                {
                    Log.Warn($"FileLoadException when loading BLP image: {fex.Message}\n" +
                             $"Please report this on GitHub or via email.");
                }
            }

            return(null);
        }
コード例 #12
0
ファイル: DataLoadingRoutines.cs プロジェクト: bmjoy/Everlook
        /// <summary>
        /// Loads the specified BLP image from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">A reference to a BLP image.</param>
        /// <returns>A BLP object containing the image data pointed to by the reference.</returns>
        public static BLP LoadBinaryImage(FileReference fileReference)
        {
            byte[] fileData = fileReference.Extract();
            if (fileData != null)
            {
                try
                {
                    return(new BLP(fileData));
                }
                catch (FileLoadException fex)
                {
                    Log.Warn($"FileLoadException when loading BLP image: {fex.Message}\n" +
                             $"Please report this on GitHub or via email.");
                }
            }

            Log.Warn(
                $"Failed to load the image \"{fileReference.FilePath}\". The file data could not be extracted.");
            return(null);
        }
コード例 #13
0
        /// <summary>
        /// Loads the specified BLP image from the archives and deserialize it.
        /// </summary>
        /// <param name="fileReference">A reference to a BLP image.</param>
        /// <returns></returns>
        public static Bitmap LoadBitmapImage(FileReference fileReference)
        {
            byte[] fileData = fileReference.Extract();
            if (fileData != null)
            {
                try
                {
                    using (MemoryStream ms = new MemoryStream(fileData))
                    {
                        return(new Bitmap(ms));
                    }
                }
                catch (FileLoadException fex)
                {
                    Log.Warn($"FileLoadException when loading bitmap image: {fex.Message}\n" +
                             $"Please report this on GitHub or via email.");
                }
            }

            return(null);
        }
コード例 #14
0
        /// <summary>
        /// Loads the information from the image into the UI.
        /// </summary>
        private void LoadInformation()
        {
            var imageFilename = IOPath.GetFileNameWithoutExtension
                                (
                _exportTarget.FilePath.ConvertPathSeparatorsToCurrentNativeSeparator()
                                );

            this.Title = $"Export Image | {imageFilename}";

            var file = _exportTarget.Extract();

            _image = new BLP(file);

            _exportFormatComboBox.Active = (int)_config.DefaultImageExportFormat;

            _mipLevelListStore.Clear();
            foreach (var mipString in _image.GetMipMapLevelStrings())
            {
                _mipLevelListStore.AppendValues(true, mipString);
            }

            _exportDirectoryFileChooserButton.SetFilename(_config.DefaultExportDirectory);
        }
コード例 #15
0
ファイル: MainWindow.cs プロジェクト: Fiver/Everlook
        /// <summary>
        /// Handles double-clicking on files in the explorer.
        /// </summary>
        /// <param name="o">The sending object.</param>
        /// <param name="args">Arguments describing the row that was activated.</param>
        private void OnGameExplorerRowActivated(object o, RowActivatedArgs args)
        {
            TreeIter selectedIter;

            this.GameExplorerTreeView.Selection.GetSelected(out selectedIter);

            FileReference fileReference = this.FiletreeBuilder.NodeStorage.GetItemReferenceFromIter(selectedIter);

            if (fileReference == null)
            {
                return;
            }

            if (fileReference.IsFile)
            {
                if (string.IsNullOrEmpty(fileReference.FilePath))
                {
                    return;
                }

                switch (fileReference.GetReferencedFileType())
                {
                // Warcraft-typed standard files
                case WarcraftFileType.AddonManifest:
                case WarcraftFileType.AddonManifestSignature:
                case WarcraftFileType.ConfigurationFile:
                case WarcraftFileType.Hashmap:
                case WarcraftFileType.XML:
                case WarcraftFileType.INI:
                case WarcraftFileType.PDF:
                case WarcraftFileType.HTML:
                {
                    byte[] fileData = fileReference.Extract();
                    if (fileData != null)
                    {
                        // create a temporary file and write the data to it.
                        string tempPath = IOPath.GetTempPath() + fileReference.Filename;
                        if (File.Exists(tempPath))
                        {
                            File.Delete(tempPath);
                        }

                        using (Stream tempStream = File.Open(tempPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read))
                        {
                            tempStream.Write(fileData, 0, fileData.Length);
                            tempStream.Flush();
                        }

                        // Hand off the file to the operating system.
                        System.Diagnostics.Process.Start(tempPath);
                    }

                    break;
                }
                }
            }
            else
            {
                this.GameExplorerTreeView.ExpandRow(this.FiletreeBuilder.NodeStorage.GetPath(selectedIter), false);
            }
        }