Click here to Skip to main content
15,881,089 members
Articles / Desktop Programming / MFC

Exile 1.8 - The Password Manager

Rate me:
Please Sign up or sign in to vote.
4.57/5 (51 votes)
6 Mar 20058 min read 254.8K   7.4K   111  
Yet another password manager.
// OptionsDialog.cpp : implementation file
//

#include "stdafx.h"
#include "exile.h"
#include "OptionsDialog.h"
#include "Registry.h"
#include "messagebox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COptionsDialog dialog


COptionsDialog::COptionsDialog(CWnd* pParent /*=NULL*/)
	: CDialog(COptionsDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(COptionsDialog)
	m_bMinimizeToTray = FALSE;
	m_bReloadLastStorage = FALSE;
	m_bAutosave = FALSE;
	m_bAutosort = FALSE;
	m_bSmartType = FALSE;
	//}}AFX_DATA_INIT
}


void COptionsDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COptionsDialog)
	DDX_Control(pDX, IDC_HOTKEY, m_ctrlHotKey);
	DDX_Control(pDX, IDC_SORTORDER, m_ctrlSortOrder);
	DDX_Check(pDX, IDC_MINIMIZETOTRAY, m_bMinimizeToTray);
	DDX_Check(pDX, IDC_RELOADSTORAGE, m_bReloadLastStorage);
	DDX_Check(pDX, IDC_AUTOSAVE, m_bAutosave);
	DDX_Check(pDX, IDC_AUTOSORT, m_bAutosort);
	DDX_Check(pDX, IDC_SMARTTYPE, m_bSmartType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COptionsDialog, CDialog)
	//{{AFX_MSG_MAP(COptionsDialog)
	ON_BN_CLICKED(IDC_RESTORE, OnRestore)
	ON_BN_CLICKED(IDC_AUTOSORT, OnAutosort)
	ON_BN_CLICKED(IDC_SMARTTYPE, OnSmarttype)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COptionsDialog message handlers

void COptionsDialog::OnRestore() 
{
	TCHAR szModule[MAX_PATH];

	if(!GetModuleFileName(0, szModule, MAX_PATH)) // Failure
		return;

	BeginWaitCursor();

	CRegistry reg;
	CString strCmd;

	reg.SetRootKey(HKEY_CLASSES_ROOT);	

	// Add entry in HKEY_CLASSES_ROOT about
	// .pws file type...
	reg.CreateKey(".pws");
	reg.WriteString("", "octalforty.Exile.PasswordStorage");

	reg.CreateKey("octalforty.Exile.PasswordStorage");
	reg.WriteString("", "octalforty Exile Password Storage"); // Document type name

	reg.CreateKey("octalforty.Exile.PasswordStorage\\Shell");
	reg.WriteString("", "Open"); // Default action

	strCmd.Format("\"%s\", 0", szModule);

	reg.CreateKey("octalforty.Exile.PasswordStorage\\DefaultIcon");
	reg.WriteString("", strCmd); // Default icon

	reg.CreateKey("octalforty.Exile.PasswordStorage\\Shell\\Open");
	reg.WriteString("", "&Open"); // Command string

	strCmd.Format("\"%s\" \"%%1\"", szModule);

	reg.CreateKey("octalforty.Exile.PasswordStorage\\Shell\\Open\\Command");
	reg.WriteString("", strCmd); // Command itself

	EndWaitCursor();
}

BOOL COptionsDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// Sort Order
	for(int n = 0; n < sizeof(g_aSortOrder) / sizeof(g_aSortOrder[0]); ++n)
	{
		m_ctrlSortOrder.InsertString(n, g_aSortOrder[n].szName);
	} // for

	m_ctrlSortOrder.SetCurSel(m_nSort);
	m_ctrlSortOrder.EnableWindow(m_bAutosort);
	
	m_ctrlHotKey.SetHotKey(m_wKeyCode, m_wModifiers);
	m_ctrlHotKey.EnableWindow(m_bSmartType);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

int COptionsDialog::GetSortOrder()
{
	return m_nSort;
}

void COptionsDialog::OnAutosort() 
{
	UpdateData();
	m_ctrlSortOrder.EnableWindow(m_bAutosort);
}

void COptionsDialog::OnOK() 
{
	UpdateData();

	if((m_bAutosort) && (CB_ERR == m_ctrlSortOrder.GetCurSel()))
	{
		MessageBoxEx(*this, IDS_SELECTSORTORDER, IDS_TITLE);
		return;
	} // if

	m_nSort = m_ctrlSortOrder.GetCurSel();
	m_ctrlHotKey.GetHotKey(m_wKeyCode, m_wModifiers);

	CDialog::OnOK();
}

void COptionsDialog::OnSmarttype() 
{
	UpdateData();

	m_ctrlHotKey.EnableWindow(m_bSmartType);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

Comments and Discussions