Skip to content
This repository was archived by the owner on Jun 15, 2025. It is now read-only.

Commit 0f9049f

Browse files
committed
Support unblock protected view
1 parent 8111d09 commit 0f9049f

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

Plugin.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
using QuickLook.Common.Plugin;
1819
using System;
1920
using System.IO;
2021
using System.Linq;
2122
using System.Windows;
22-
using QuickLook.Common.Plugin;
23+
using System.Windows.Controls;
24+
using UnblockZoneIdentifier;
2325

2426
namespace QuickLook.Plugin.OfficeViewer;
2527

@@ -55,11 +57,42 @@ public bool CanHandle(string path)
5557

5658
public void Prepare(string path, ContextObject context)
5759
{
58-
context.SetPreferredSizeFit(new Size { Width = 800, Height = 800 }, 0.8);
60+
context.SetPreferredSizeFit(new Size { Width = 1000, Height = 800 }, 0.8);
5961
}
6062

6163
public void View(string path, ContextObject context)
6264
{
65+
// MS Office interface does not allow loading of protected view (It's also possible that I haven't found a way)
66+
// Therefore, we need to predict in advance and then let users choose whether to lift the protection
67+
if (ZoneIdentifierManager.IsZoneBlocked(path))
68+
{
69+
context.Title = $"[PROTECTED VIEW] {Path.GetFileName(path)}";
70+
71+
MessageBoxResult result = MessageBox.Show(
72+
"""
73+
Be careful - files from the Internet can contain viruses.
74+
The MS Office interface prevents loading in Protected View.
75+
76+
Would you like OfficeViewer-Native to unblock the ZoneIdentifier of Internet?
77+
""",
78+
"PROTECTED VIEW",
79+
MessageBoxButton.YesNo,
80+
MessageBoxImage.Question
81+
);
82+
83+
if (result == MessageBoxResult.Yes)
84+
{
85+
ZoneIdentifierManager.UnblockZone(path);
86+
}
87+
else
88+
{
89+
context.ViewerContent = new Label() { Content = "The MS Office interface prevents loading in Protected View." };
90+
context.Title = $"[PROTECTED VIEW] {Path.GetFileName(path)}";
91+
context.IsBusy = false;
92+
return;
93+
}
94+
}
95+
6396
_panel = new PreviewPanel();
6497
context.ViewerContent = _panel;
6598
context.Title = Path.GetFileName(path);

QuickLook.Plugin.OfficeViewer.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
</ProjectReference>
7676
</ItemGroup>
7777

78-
<!--<ItemGroup>
79-
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
80-
</ItemGroup>-->
78+
<ItemGroup>
79+
<PackageReference Include="UnblockZoneIdentifier " Version="1.0.0" />
80+
</ItemGroup>
8181

8282
</Project>

0 commit comments

Comments
 (0)