Skip to content

Commit aa6b603

Browse files
committed
Merge branch 'no_history'
2 parents d18bb0a + 18725c9 commit aa6b603

14 files changed

+350
-148
lines changed

cppcryptfs/cppcryptfs.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ BOOL CcppcryptfsApp::InitInstance()
174174

175175
CMountPropertyPage mount;
176176

177-
RecentItems ritems(TEXT("Folders"), TEXT("LastDir"), mount.m_numLastDirs);
177+
RecentItems ritems(CPPCRYPTFS_FOLDERS_SECTION, TEXT("LastDir"), mount.m_numLastDirs);
178178

179179
ritems.Populate(mount.m_lastDirs, TEXT("C:\\"));
180180

181-
RecentItems ritems4(TEXT("ConfigPaths"), TEXT("LastConfig"), mount.m_numLastConfigs);
181+
RecentItems ritems4(CPPCRYPTFS_CONFIGPATHS_SECTION, TEXT("LastConfig"), mount.m_numLastConfigs);
182182

183183
ritems4.Populate(mount.m_lastConfigs, TEXT("C:\\"));
184184

@@ -188,11 +188,11 @@ BOOL CcppcryptfsApp::InitInstance()
188188

189189
CCreatePropertyPage create;
190190

191-
RecentItems ritems2(TEXT("Folders"), TEXT("LastDir"), create.m_numLastDirs);
191+
RecentItems ritems2(CPPCRYPTFS_FOLDERS_SECTION, TEXT("LastDir"), create.m_numLastDirs);
192192

193193
ritems2.Populate(create.m_lastDirs, TEXT("C:\\"));
194194

195-
RecentItems ritems3(TEXT("ConfigPaths"), TEXT("LastConfig"), create.m_numLastConfigs);
195+
RecentItems ritems3(CPPCRYPTFS_CONFIGPATHS_SECTION, TEXT("LastConfig"), create.m_numLastConfigs);
196196

197197
ritems3.Populate(create.m_lastConfigs, TEXT("C:\\"));
198198

@@ -247,6 +247,34 @@ BOOL CcppcryptfsApp::InitInstance()
247247
return FALSE;
248248
}
249249

250+
BOOL CcppcryptfsApp::WriteProfileInt(LPCWSTR section, LPCWSTR entry, INT val)
251+
{
252+
if (lstrcmpi(section, L"Settings") && NeverSaveHistory()) {
253+
return TRUE;
254+
}
255+
256+
return CWinApp::WriteProfileInt(section, entry, val);
257+
}
258+
259+
BOOL CcppcryptfsApp::WriteProfileString(LPCWSTR section, LPCWSTR entry, LPCWSTR val)
260+
{
261+
if (lstrcmpi(section, L"Settings") && NeverSaveHistory()) {
262+
return TRUE;
263+
}
264+
265+
return CWinApp::WriteProfileString(section, entry, val);
266+
}
267+
268+
BOOL CcppcryptfsApp::WriteProfileBinary(LPCWSTR section, LPCWSTR entry, LPBYTE pData, UINT nBytes)
269+
{
270+
if (lstrcmpi(section, L"Settings") && NeverSaveHistory()) {
271+
return TRUE;
272+
}
273+
274+
return CWinApp::WriteProfileBinary(section, entry, pData, nBytes);
275+
}
276+
277+
250278
void CcppcryptfsApp::SendArgsToRunningInstance(HWND hWnd)
251279
{
252280
static_assert(sizeof(WCHAR) == sizeof(wchar_t), "sizeof(WCHAR) != sizeof(wchar_t).");

cppcryptfs/cppcryptfs.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ using namespace std;
4646

4747
#define CPPCRYPTFS_COPYDATA_CMDLINE_MAXLEN (64*1024) // keep small because of VirtualLock()
4848

49+
#define CPPCRYPTFS_REG_PATH L"Software\\cppcryptfs\\cppcryptfs\\"
50+
51+
#define CPPCRYPTFS_FOLDERS_SECTION L"Folders"
52+
#define CPPCRYPTFS_CONFIGPATHS_SECTION L"ConfigPaths"
53+
#define CPPCRYPTFS_MOUNTPOINTS_SECTION L"MountPoints"
54+
4955
typedef struct struct_CopyDataCmdLine {
5056
DWORD dwPid; // process whose console should be attached to for printing error messages
5157
WCHAR szCmdLine[1]; // command line (null-terminated)
@@ -69,7 +75,11 @@ class CcppcryptfsApp : public CWinApp
6975

7076
// Overrides
7177
public:
72-
virtual BOOL InitInstance();
78+
virtual BOOL InitInstance() override;
79+
80+
virtual BOOL WriteProfileInt(LPCWSTR section, LPCWSTR entry, INT val) override;
81+
virtual BOOL WriteProfileString(LPCWSTR section, LPCWSTR entry, LPCWSTR val) override;
82+
virtual BOOL WriteProfileBinary(LPCWSTR section, LPCWSTR entry, LPBYTE pData, UINT nBytes) override;
7383

7484
// Implementation
7585

cppcryptfs/cppcryptfs.rc

236 Bytes
Binary file not shown.

cppcryptfs/resource.h

184 Bytes
Binary file not shown.

cppcryptfs/ui/CryptPropertySheet.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ BEGIN_MESSAGE_MAP(CCryptPropertySheet, CPropertySheet)
103103
ON_WM_COPYDATA()
104104
ON_WM_WINDOWPOSCHANGING()
105105
ON_WM_DEVICECHANGE()
106+
// ON_WM_QUERYENDSESSION()
107+
ON_WM_ENDSESSION()
106108
END_MESSAGE_MAP()
107109

108110

@@ -288,3 +290,14 @@ BOOL CCryptPropertySheet::OnDeviceChange( UINT nEventType, DWORD_PTR dwData )
288290

289291
return CPropertySheet::OnDeviceChange(nEventType, dwData);
290292
}
293+
294+
295+
void CCryptPropertySheet::OnEndSession(BOOL bEnding)
296+
{
297+
CPropertySheet::OnEndSession(bEnding);
298+
299+
if (bEnding) {
300+
unmount_all(false);
301+
wait_for_all_unmounted();
302+
}
303+
}

cppcryptfs/ui/CryptPropertySheet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class CCryptPropertySheet : public CPropertySheet
6565
afx_msg BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct);
6666
afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndpos);
6767
afx_msg BOOL OnDeviceChange(UINT nEventType, DWORD_PTR dwData);
68+
afx_msg void OnEndSession(BOOL bEnding);
6869
};
6970

7071

cppcryptfs/ui/MountPropertyPage.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,9 @@ BOOL CMountPropertyPage::OnInitDialog()
585585
m_password.SetLimitText(MAX_PASSWORD_LEN);
586586

587587
CComboBox *pCombo = (CComboBox*)GetDlgItem(IDC_PATH);
588-
if (pCombo)
589-
pCombo->LimitText(MAX_PATH);
588+
if (pCombo) {
589+
pCombo->LimitText(MAX_PATH);
590+
}
590591

591592
pCombo = (CComboBox*)GetDlgItem(IDC_CONFIG_PATH);
592593
if (pCombo)
@@ -887,7 +888,8 @@ BOOL CMountPropertyPage::OnSetActive()
887888

888889
RecentItems ritems(TEXT("Folders"), TEXT("LastDir"), m_numLastDirs);
889890

890-
ritems.Populate(m_lastDirs, TEXT("C:\\"));
891+
const auto path_initial_default = TEXT("C:\\");
892+
ritems.Populate(m_lastDirs, path_initial_default);
891893

892894
CComboBox *pBox = (CComboBox*)GetDlgItem(IDC_PATH);
893895

@@ -917,7 +919,7 @@ BOOL CMountPropertyPage::OnSetActive()
917919

918920
RecentItems ritems2(TEXT("ConfigPaths"), TEXT("LastConfig"), m_numLastConfigs);
919921

920-
ritems2.Populate(m_lastConfigs, TEXT("C:\\"));
922+
ritems2.Populate(m_lastConfigs, path_initial_default);
921923

922924
BOOL save_passwords_enabled = theApp.GetProfileInt(L"Settings", L"EnableSavingPasswords", ENABLE_SAVING_PASSWORDS_DEFAULT) != 0;
923925

@@ -984,15 +986,26 @@ BOOL CMountPropertyPage::OnSetActive()
984986
}
985987
}
986988

987-
988-
989989
CWnd *pSavePwWnd = GetDlgItem(IDC_SAVE_PASSWORD);
990990
if (pSavePwWnd)
991991
pSavePwWnd->EnableWindow(save_passwords_enabled);
992992

993993
if (!save_passwords_enabled)
994994
CheckDlgButton(IDC_SAVE_PASSWORD, FALSE);
995995

996+
// set focus to password if path contains text that is not the default path
997+
CComboBox *pCombo = (CComboBox*)GetDlgItem(IDC_PATH);
998+
if (pCombo) {
999+
CString path;
1000+
pCombo->GetWindowTextW(path);
1001+
if (path.GetLength() > 0 && path != path_initial_default) {
1002+
auto pPass = GetDlgItem(IDC_PASSWORD);
1003+
if (pPass) {
1004+
pPass->PostMessageW(WM_SETFOCUS);
1005+
}
1006+
}
1007+
}
1008+
9961009
return CCryptPropertyPage::OnSetActive();
9971010
}
9981011

cppcryptfs/ui/RecentItems.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ THE SOFTWARE.
2929
#include "stdafx.h"
3030
#include "recentitems.h"
3131
#include "cppcryptfs.h"
32+
#include "cryptdefaults.h"
33+
#include "util/util.h"
3234

3335
RecentItems::RecentItems(LPCTSTR section, LPCTSTR base, int count)
3436
{
@@ -74,7 +76,7 @@ RecentItems::Add(LPCTSTR item)
7476
{
7577
int i;
7678

77-
79+
bool bSave = !NeverSaveHistory();
7880

7981
CString *lastitems = new CString[m_count];
8082

@@ -97,11 +99,15 @@ RecentItems::Add(LPCTSTR item)
9799

98100
for (i = index; i >= 1; i--) {
99101
AppendIndex(itemname, i);
100-
theApp.WriteProfileStringW(m_section, itemname, lastitems[i-1]);
102+
if (bSave) {
103+
theApp.WriteProfileStringW(m_section, itemname, lastitems[i - 1]);
104+
}
101105
}
102106

103107
AppendIndex(itemname, 0);
104-
theApp.WriteProfileString(m_section, itemname, item);
108+
if (bSave) {
109+
theApp.WriteProfileString(m_section, itemname, item);
110+
}
105111

106112
delete[] lastitems;
107113
}

cppcryptfs/ui/SettingsPropertyPage.cpp

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ THE SOFTWARE.
3333
#include "cppcryptfs.h"
3434
#include "SettingsPropertyPage.h"
3535
#include "afxdialogex.h"
36-
#include "cppcryptfs.h"
36+
#include "util/util.h"
3737
#include "context/cryptcontext.h"
3838
#include "ui/cryptdefaults.h"
3939
#include "util/savedpasswords.h"
@@ -48,6 +48,7 @@ CSettingsPropertyPage::CSettingsPropertyPage()
4848
m_bCaseInsensitive = false;
4949
m_bMountManager = false;
5050
m_bEnableSavingPasswords = false;
51+
m_bNeverSaveHistory = false;
5152
}
5253

5354
CSettingsPropertyPage::~CSettingsPropertyPage()
@@ -70,6 +71,7 @@ BEGIN_MESSAGE_MAP(CSettingsPropertyPage, CPropertyPage)
7071
ON_BN_CLICKED(IDC_MOUNTMANAGER, &CSettingsPropertyPage::OnClickedMountmanager)
7172
ON_BN_CLICKED(IDC_RESETWARNINGS, &CSettingsPropertyPage::OnClickedResetwarnings)
7273
ON_BN_CLICKED(IDC_ENABLE_SAVING_PASSWORDS, &CSettingsPropertyPage::OnClickedEnableSavingPasswords)
74+
ON_BN_CLICKED(IDC_NEVER_SAVE_HISTORY, &CSettingsPropertyPage::OnClickedNeverSaveHistory)
7375
END_MESSAGE_MAP()
7476

7577

@@ -79,7 +81,10 @@ static int buffer_sizes[] = { 4, 8, 16, 32, 64, 128, 256, 512, 1024 };
7981

8082
static int ttls[] = { 0, 1, 2, 5, 10, 15, 30, 45, 60, 90, 120, 300, 600, 900, 1800, 3600};
8183

82-
static const WCHAR* ttl_strings[] = { L"infinite", L"1 second", L"2 seconds", L"5 seconds", L"10 seconds", L"15 seconds", L"30 seconds", L"45 seconds", L"60 seconds", L"90 seconds", L"2 minutes", L"5 minutes", L"10 minutes", L"15 minutes", L"30 minutes", L"1 hour" };
84+
static const WCHAR* ttl_strings[] = { L"infinite", L"1 second", L"2 seconds", L"5 seconds",
85+
L"10 seconds", L"15 seconds", L"30 seconds", L"45 seconds",
86+
L"60 seconds", L"90 seconds", L"2 minutes", L"5 minutes",
87+
L"10 minutes", L"15 minutes", L"30 minutes", L"1 hour" };
8388

8489
BOOL CSettingsPropertyPage::OnInitDialog()
8590
{
@@ -97,17 +102,23 @@ BOOL CSettingsPropertyPage::OnInitDialog()
97102

98103
bool bMountManager = theApp.GetProfileInt(L"Settings", L"MountManager", MOUNTMANAGER_DEFAULT) != 0;
99104

100-
bool bEnableSavingPasswords = theApp.GetProfileInt(L"Settings", L"EnableSavingPasswords", ENABLE_SAVING_PASSWORDS_DEFAULT) != 0;
105+
bool bEnableSavingPasswords = theApp.GetProfileInt(L"Settings", L"EnableSavingPasswords",
106+
ENABLE_SAVING_PASSWORDS_DEFAULT) != 0;
107+
108+
bool bNeverSaveHistory = NeverSaveHistory();
101109

102-
return SetControls(nThreads, bufferblocks, cachettl, bCaseInsensitive, bMountManager, bEnableSavingPasswords);
110+
return SetControls(nThreads, bufferblocks, cachettl, bCaseInsensitive, bMountManager,
111+
bEnableSavingPasswords, bNeverSaveHistory);
103112
}
104113

105-
BOOL CSettingsPropertyPage::SetControls(int nThreads, int bufferblocks, int cachettl, bool bCaseInsensitive, bool bMountManager, bool bEnableSavingPasswords)
114+
BOOL CSettingsPropertyPage::SetControls(int nThreads, int bufferblocks, int cachettl,
115+
bool bCaseInsensitive, bool bMountManager, bool bEnableSavingPasswords, bool bNeverSaveHistory)
106116
{
107117

108118
m_bCaseInsensitive = bCaseInsensitive;
109119
m_bMountManager = bMountManager;
110120
m_bEnableSavingPasswords = bEnableSavingPasswords;
121+
m_bNeverSaveHistory = bNeverSaveHistory;
111122

112123
int i;
113124

@@ -166,7 +177,8 @@ BOOL CSettingsPropertyPage::SetControls(int nThreads, int bufferblocks, int cach
166177

167178
pBox->ResetContent();
168179

169-
static_assert(sizeof(ttls) / sizeof(ttls[0]) == sizeof(ttl_strings) / sizeof(ttl_strings[0]), "mismatch in sizes of ttls/ttl_strings");
180+
static_assert(sizeof(ttls) / sizeof(ttls[0]) == sizeof(ttl_strings) / sizeof(ttl_strings[0]),
181+
"mismatch in sizes of ttls/ttl_strings");
170182

171183
int selitem = 0;
172184

@@ -185,6 +197,8 @@ BOOL CSettingsPropertyPage::SetControls(int nThreads, int bufferblocks, int cach
185197

186198
CheckDlgButton(IDC_ENABLE_SAVING_PASSWORDS, m_bEnableSavingPasswords ? 1 : 0);
187199

200+
CheckDlgButton(IDC_NEVER_SAVE_HISTORY, m_bNeverSaveHistory ? 1 : 0);
201+
188202
return TRUE; // return TRUE unless you set the focus to a control
189203
// EXCEPTION: OCX Property Pages should return FALSE
190204
}
@@ -259,17 +273,21 @@ void CSettingsPropertyPage::SaveSettings()
259273
m_bCaseInsensitive = !m_bCaseInsensitive; // OnBnClickedCaseinsensitive() flips it
260274
m_bMountManager = !m_bMountManager; // ditto
261275
m_bEnableSavingPasswords = !m_bEnableSavingPasswords; // ditto
276+
m_bNeverSaveHistory = !m_bNeverSaveHistory; // ditto
262277

263278
OnBnClickedCaseinsensitive();
264279
OnClickedMountmanager();
265280
OnClickedEnableSavingPasswords();
281+
OnClickedNeverSaveHistory();
266282
}
267283

268284
void CSettingsPropertyPage::OnBnClickedDefaults()
269285
{
270286
// TODO: Add your control notification handler code here
271287

272-
SetControls(PER_FILESYSTEM_THREADS_DEFAULT, BUFFERBLOCKS_DEFAULT, CACHETTL_DEFAULT, CASEINSENSITIVE_DEFAULT, MOUNTMANAGER_DEFAULT, ENABLE_SAVING_PASSWORDS_DEFAULT);
288+
SetControls(PER_FILESYSTEM_THREADS_DEFAULT, BUFFERBLOCKS_DEFAULT, CACHETTL_DEFAULT,
289+
CASEINSENSITIVE_DEFAULT, MOUNTMANAGER_DEFAULT, ENABLE_SAVING_PASSWORDS_DEFAULT,
290+
NEVER_SAVE_HISTORY_DEFAULT);
273291

274292
SaveSettings();
275293
}
@@ -279,7 +297,9 @@ void CSettingsPropertyPage::OnBnClickedRecommended()
279297
{
280298
// TODO: Add your control notification handler code here
281299

282-
SetControls(PER_FILESYSTEM_THREADS_RECOMMENDED, BUFFERBLOCKS_RECOMMENDED, CACHETTL_RECOMMENDED, CASEINSENSITIVE_RECOMMENDED, MOUNTMANAGER_RECOMMENDED, ENABLE_SAVING_PASSWORDS_RECOMMENDED);
300+
SetControls(PER_FILESYSTEM_THREADS_RECOMMENDED, BUFFERBLOCKS_RECOMMENDED, CACHETTL_RECOMMENDED,
301+
CASEINSENSITIVE_RECOMMENDED, MOUNTMANAGER_RECOMMENDED, ENABLE_SAVING_PASSWORDS_RECOMMENDED,
302+
NEVER_SAVE_HISTORY_RECOMMENDED);
283303

284304
SaveSettings();
285305
}
@@ -315,6 +335,11 @@ void CSettingsPropertyPage::OnClickedEnableSavingPasswords()
315335
CheckDlgButton(IDC_ENABLE_SAVING_PASSWORDS, m_bEnableSavingPasswords ? 1 : 0);
316336

317337
if (m_bEnableSavingPasswords) {
338+
339+
if (m_bNeverSaveHistory) {
340+
MessageBox(L"Passwords will not be saved if \"Never save history\" is turned on.",
341+
L"cppcryptfs", MB_OK | MB_ICONINFORMATION);
342+
}
318343
theApp.WriteProfileInt(L"Settings", L"EnableSavingPasswords", TRUE);
319344
} else {
320345
theApp.WriteProfileInt(L"Settings", L"EnableSavingPasswords", FALSE);
@@ -331,3 +356,48 @@ void CSettingsPropertyPage::OnClickedEnableSavingPasswords()
331356
}
332357
}
333358
}
359+
360+
361+
void CSettingsPropertyPage::OnClickedNeverSaveHistory()
362+
{
363+
// TODO: Add your control notification handler code here
364+
365+
m_bNeverSaveHistory = !m_bNeverSaveHistory;
366+
367+
CheckDlgButton(IDC_NEVER_SAVE_HISTORY, !!m_bNeverSaveHistory);
368+
369+
theApp.WriteProfileInt(L"Settings", L"NeverSaveHistory", !!m_bNeverSaveHistory);
370+
371+
if (m_bNeverSaveHistory) {
372+
373+
if (m_bEnableSavingPasswords) {
374+
MessageBox(L"If you turn on \"Never save history\", saved passwords will not be deleted, but new passwords will not "
375+
L"be saved. To delete any saved passwords, uncheck \"Enable saved passwords\".",
376+
L"cppcryptfs", MB_OK | MB_ICONINFORMATION);
377+
}
378+
379+
wstring mes;
380+
wstring error;
381+
382+
// DeleteAllRegistryValues() returns false if there is nothing to delete and
383+
// with an empty error message. So use the message to accumulate real errors
384+
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH CPPCRYPTFS_FOLDERS_SECTION, mes);
385+
error += mes;
386+
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH CPPCRYPTFS_CONFIGPATHS_SECTION, mes);
387+
error += mes;
388+
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH CPPCRYPTFS_MOUNTPOINTS_SECTION, mes);
389+
error += mes;
390+
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH L"MountPoint", mes);
391+
error += mes;
392+
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH L"MountFlags", mes);
393+
error += mes;
394+
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH L"MountOptions", mes);
395+
error += mes;
396+
DeleteAllRegisteryValues(CPPCRYPTFS_REG_PATH L"CreateOptions", mes);
397+
error += mes;
398+
if (!error.empty()) {
399+
MessageBox(L"unable to delete history from registry", L"cppcryptfs",
400+
MB_OK | MB_ICONEXCLAMATION);
401+
}
402+
}
403+
}

0 commit comments

Comments
 (0)