-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathviewer.cpp
117 lines (98 loc) · 3.11 KB
/
viewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//****************************************************************************
//
// Copyright (c) ALTAP, spol. s r.o. All rights reserved.
//
// This is a part of the Altap Salamander SDK library.
//
// The SDK is provided "AS IS" and without warranty of any kind and
// ALTAP EXPRESSLY DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE and NON-INFRINGEMENT.
//
//****************************************************************************
#include "precomp.h"
#include "viewer.h"
#include "certdump.h"
void WINAPI HTMLHelpCallback(HWND hWindow, UINT helpID)
{
SalamanderGeneral->OpenHtmlHelp(hWindow, HHCDisplayContext, helpID, FALSE);
}
BOOL InitViewer()
{
if (!InitializeWinLib(PluginNameEN, DLLInstance))
return FALSE;
SetWinLibStrings(LoadStr(IDS_INVALID_NUM), LoadStr(IDS_PLUGINNAME));
SetupWinLibHelp(HTMLHelpCallback);
return TRUE;
}
void ReleaseViewer()
{
ReleaseWinLib(DLLInstance);
}
//
// ****************************************************************************
// CPluginInterfaceForViewer
//
BOOL WINAPI
CPluginInterfaceForViewer::ViewFile(const char *name, int left, int top, int width, int height,
UINT showCmd, BOOL alwaysOnTop, BOOL returnLock, HANDLE *lock,
BOOL *lockOwner, CSalamanderPluginViewerData *viewerData,
int enumFilesSourceUID, int enumFilesCurrentIndex)
{
char szTmpFile[MAX_PATH];
if (SalamanderGeneral->SalGetTempFileName(NULL, "CVW", szTmpFile, TRUE, NULL))
{
// create a temporary file which will be used for certificate info storage
auto hTmpFile = fopen(szTmpFile, "w");
if (!hTmpFile)
return FALSE;
// ask for the password once only per file view
bool show_dlg = true;
// password handler callback
auto pwdHandler = [&show_dlg](char *buf, int size) -> int
{
*buf = 0;
if (!show_dlg)
return -1;
show_dlg = false;
CPasswordDialog dlg(SalamanderGeneral->GetMsgBoxParent(), buf, size);
return (dlg.Execute() == IDOK) ? static_cast<int>(strlen(buf)) : -1;
};
// try out to dump info of the certificate
if (!DumpCertificate(name, hTmpFile, pwdHandler))
{
fclose(hTmpFile);
// fallback, show raw content if decoding of the certificate file has failed
CSalamanderPluginInternalViewerData data{};
data.Size = sizeof(data);
data.FileName = name;
data.Mode = 0;
data.Caption = NULL;
data.WholeCaption = FALSE;
int err = 0;
return SalamanderGeneral->ViewFileInPluginViewer(NULL, &data, FALSE, NULL, "cert_dump.txt", err);
}
fclose(hTmpFile);
// compose viewer window title
char szTitle[2000];
sprintf_s(szTitle, "%s - %s", name, LoadStr(IDS_PLUGINNAME));
// setup built-in viewer
CSalamanderPluginInternalViewerData data;
data.Size = sizeof(data);
data.FileName = szTmpFile;
data.Mode = 0;
data.Caption = szTitle;
data.WholeCaption = TRUE;
int err = 0;
if (SalamanderGeneral->ViewFileInPluginViewer(NULL, &data, TRUE, NULL, "cert_dump.txt", err))
{
return TRUE;
}
}
return FALSE;
}
BOOL WINAPI
CPluginInterfaceForViewer::CanViewFile(const char *name)
{
return TRUE;
}