|
| 1 | +// Copyright © 2017-2025 QL-Win Contributors |
| 2 | +// |
| 3 | +// This file is part of QuickLook program. |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +using QuickLook.Common.Commands; |
| 19 | +using QuickLook.Common.Controls; |
| 20 | +using QuickLook.Common.Helpers; |
| 21 | +using QuickLook.Common.Plugin.MoreMenu; |
| 22 | +using QuickLook.Plugin.ArchiveViewer.CompoundFileBinary; |
| 23 | +using System; |
| 24 | +using System.Collections.Generic; |
| 25 | +using System.IO; |
| 26 | +using System.Reflection; |
| 27 | +using System.Threading.Tasks; |
| 28 | +using System.Windows.Input; |
| 29 | +using WindowsAPICodePack.Dialogs; |
| 30 | + |
| 31 | +namespace QuickLook.Plugin.ArchiveViewer; |
| 32 | + |
| 33 | +public partial class Plugin |
| 34 | +{ |
| 35 | + public ICommand ExtractToDirectoryCommand { get; } |
| 36 | + |
| 37 | + public Plugin() |
| 38 | + { |
| 39 | + ExtractToDirectoryCommand = new AsyncRelayCommand(ExtractToDirectoryAsync); |
| 40 | + } |
| 41 | + |
| 42 | + public IEnumerable<IMenuItem> GetMenuItems() |
| 43 | + { |
| 44 | + if (_path.EndsWith(".eif", StringComparison.OrdinalIgnoreCase)) |
| 45 | + { |
| 46 | + string translationFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Translations.config"); |
| 47 | + |
| 48 | + yield return new MoreMenuItem() |
| 49 | + { |
| 50 | + Icon = FontSymbols.MoveToFolder, |
| 51 | + Header = TranslationHelper.Get("MW_ExtractToDirectory", translationFile), |
| 52 | + MenuItems = null, |
| 53 | + Command = ExtractToDirectoryCommand, |
| 54 | + }; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + public async Task ExtractToDirectoryAsync() |
| 59 | + { |
| 60 | + using CommonOpenFileDialog dialog = new() |
| 61 | + { |
| 62 | + IsFolderPicker = true, |
| 63 | + }; |
| 64 | + |
| 65 | + if (dialog.ShowDialog() == CommonFileDialogResult.Ok) |
| 66 | + { |
| 67 | + await Task.Run(() => |
| 68 | + { |
| 69 | + if (_path.EndsWith(".cfb", StringComparison.OrdinalIgnoreCase)) |
| 70 | + { |
| 71 | + CompoundFileExtractor.ExtractToDirectory(_path, dialog.FileName); |
| 72 | + } |
| 73 | + else if (_path.EndsWith(".eif", StringComparison.OrdinalIgnoreCase)) |
| 74 | + { |
| 75 | + CompoundFileExtractor.ExtractToDirectory(_path, dialog.FileName); |
| 76 | + |
| 77 | + string faceDatPath = Path.Combine(dialog.FileName, "face.dat"); |
| 78 | + |
| 79 | + if (File.Exists(faceDatPath)) |
| 80 | + { |
| 81 | + Dictionary<string, Dictionary<string, int>> faceDat = FaceDatDecoder.Decode(File.ReadAllBytes(faceDatPath)); |
| 82 | + _ = faceDat; |
| 83 | + } |
| 84 | + } |
| 85 | + }); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments