Пример #1
0
        private static async Task ExtractBinary(BinaryPathControl control, string?outputPath)
        {
            if (string.IsNullOrWhiteSpace(outputPath) || string.IsNullOrWhiteSpace(control.BinaryPath) || !Directory.Exists(outputPath) || !File.Exists(control.BinaryPath))
            {
                return;
            }

            await Task.Run(() =>
            {
                try
                {
                    IBinaryFileHandler fileHandler = control.BinaryFileType switch
                    {
                        BinaryFileType.Particle => new ParticleFileHandler(),
                        _ => new ResourceFileHandler(control.BinaryFileType),
                    };

                    fileHandler.ExtractBinary(control.BinaryPath, outputPath, control.Progress);
                    App.Instance.Dispatcher.Invoke(() => control.Progress.Report("Completed successfully.", 1));
                }
                catch (Exception ex)
                {
                    App.Instance.Dispatcher.Invoke(() =>
                    {
                        App.Instance.ShowError("Extracting binary did not complete successfully", $"An error occurred while extracting '{control.BinaryFileType.ToString().ToLower(CultureInfo.InvariantCulture)}' binary.", ex);
                        control.Progress.Report("Execution did not complete successfully.");
                    });
                }
            });
        }
        private static async Task MakeBinary(BinaryPathControl control)
        {
            if (string.IsNullOrWhiteSpace(control.BinaryPath) || !File.Exists(control.BinaryPath))
            {
                return;
            }

            await Task.Run(() =>
            {
                try
                {
                    IBinaryFileHandler fileHandler = control.BinaryFileType switch
                    {
                        BinaryFileType.Particle => new ParticleFileHandler(),
                        _ => new ResourceFileHandler(control.BinaryFileType),
                    };

                    List <AssetTabControl> assetTabControls = new List <AssetTabControl>();
                    switch (control.BinaryFileType)
                    {
                    case BinaryFileType.Audio:
                        assetTabControls.Add(App.Instance.MainWindow !.AudioAudioAssetTabControl);
                        break;

                    case BinaryFileType.Core:
                        assetTabControls.Add(App.Instance.MainWindow !.CoreShadersAssetTabControl);
                        break;

                    case BinaryFileType.Dd:
                        assetTabControls.Add(App.Instance.MainWindow !.DdModelBindingsAssetTabControl);
                        assetTabControls.Add(App.Instance.MainWindow !.DdModelsAssetTabControl);
                        assetTabControls.Add(App.Instance.MainWindow !.DdShadersAssetTabControl);
                        assetTabControls.Add(App.Instance.MainWindow !.DdTexturesAssetTabControl);
                        break;

                    case BinaryFileType.Particle:
                        assetTabControls.Add(App.Instance.MainWindow !.ParticleParticlesAssetTabControl);
                        break;
                    }

                    fileHandler.MakeBinary(assetTabControls.SelectMany(atc => atc.GetAssets()).ToList(), control.BinaryPath, control.Progress);

                    App.Instance.Dispatcher.Invoke(() => control.Progress.Report("Completed successfully.", 1));
                }
                catch (Exception ex)
                {
                    App.Instance.Dispatcher.Invoke(() =>
                    {
                        App.Instance.ShowError("Making binary did not complete successfully", $"An error occurred while making '{control.BinaryFileType.ToString().ToLower(CultureInfo.InvariantCulture)}' binary.", ex);
                        control.Progress.Report("Execution did not complete successfully.");
                    });
                }
            });
        }
Пример #3
0
            public Parser(Stream stream, IBinaryFileHandler handler)
            {
                Debug.Assert(stream != null);
                Debug.Assert(stream.CanRead);
                Debug.Assert(stream.CanSeek);
                Debug.Assert(handler != null);

                m_stream  = stream;
                m_handler = handler;

                m_reader = new BinaryReader(stream);
            }
Пример #4
0
        public void Parse(Stream stream, IBinaryFileHandler handler)
        {
            var parser = new Parser(stream, handler);

            parser.Parse();
        }