1 | // PropPaths.cpp : implementation file |
---|
2 | // |
---|
3 | |
---|
4 | #include "PropPaths.h" |
---|
5 | #include "shlobj.h" |
---|
6 | |
---|
7 | #ifdef _DEBUG |
---|
8 | #define new DEBUG_NEW |
---|
9 | #undef THIS_FILE |
---|
10 | static char THIS_FILE[] = __FILE__; |
---|
11 | #endif |
---|
12 | |
---|
13 | ///////////////////////////////////////////////////////////////////////////// |
---|
14 | // CPropPaths dialog |
---|
15 | |
---|
16 | |
---|
17 | CPropPaths::CPropPaths() |
---|
18 | : CPropertyPage(CPropPaths::IDD) |
---|
19 | { |
---|
20 | //{{AFX_DATA_INIT(CPropPaths) |
---|
21 | // NOTE: the ClassWizard will add member initialization here |
---|
22 | //}}AFX_DATA_INIT |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | void CPropPaths::DoDataExchange(CDataExchange* pDX) |
---|
27 | { |
---|
28 | CDialog::DoDataExchange(pDX); |
---|
29 | //{{AFX_DATA_MAP(CPropPaths) |
---|
30 | DDX_Control(pDX, IDC_MOTDFILE, m_motdfile); |
---|
31 | DDX_Control(pDX, IDC_EDIT_MOTD, m_edit_motd); |
---|
32 | DDX_Control(pDX, IDC_CONFIGDIR, m_configdir); |
---|
33 | DDX_Control(pDX, IDC_BROWSE_MOTD, m_browse_motd); |
---|
34 | DDX_Control(pDX, IDC_BROWSE_CONFIG, m_browse_config); |
---|
35 | //}}AFX_DATA_MAP |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | BEGIN_MESSAGE_MAP(CPropPaths, CPropertyPage) |
---|
40 | //{{AFX_MSG_MAP(CPropPaths) |
---|
41 | ON_BN_CLICKED(IDC_BROWSE_CONFIG, OnBrowseConfig) |
---|
42 | ON_BN_CLICKED(IDC_BROWSE_MOTD, OnBrowseMotd) |
---|
43 | ON_BN_CLICKED(IDC_EDIT_MOTD, OnEditMotd) |
---|
44 | //}}AFX_MSG_MAP |
---|
45 | END_MESSAGE_MAP() |
---|
46 | |
---|
47 | ///////////////////////////////////////////////////////////////////////////// |
---|
48 | // CPropPaths message handlers |
---|
49 | |
---|
50 | void CPropPaths::OnOK() |
---|
51 | { |
---|
52 | CString tmp; |
---|
53 | m_configdir.GetWindowText(tmp); |
---|
54 | |
---|
55 | if (tmp.GetLength() > 0 |
---|
56 | && tmp.GetAt(tmp.GetLength() - 1) != '/' |
---|
57 | && tmp.GetAt(tmp.GetLength() - 1) != '\\') |
---|
58 | { |
---|
59 | tmp = tmp + "\\"; |
---|
60 | } |
---|
61 | |
---|
62 | WriteProfileString("configdir", tmp); |
---|
63 | |
---|
64 | m_motdfile.GetWindowText(tmp); |
---|
65 | WriteProfileString("motdfile", tmp); |
---|
66 | |
---|
67 | CPropertyPage::OnOK(); |
---|
68 | } |
---|
69 | |
---|
70 | void CPropPaths::OnBrowseConfig() |
---|
71 | { |
---|
72 | BROWSEINFO bi = { 0 }; |
---|
73 | bi.lpszTitle = _T("Choose a config directory"); |
---|
74 | LPITEMIDLIST pidl = SHBrowseForFolder(&bi); |
---|
75 | if( pidl != 0) |
---|
76 | { |
---|
77 | TCHAR path[MAX_PATH]; |
---|
78 | if( SHGetPathFromIDList (pidl, path) ) { |
---|
79 | m_configdir.SetWindowText(path); |
---|
80 | } |
---|
81 | |
---|
82 | IMalloc * imalloc = 0; |
---|
83 | if ( SUCCEEDED (SHGetMalloc (&imalloc)) ) |
---|
84 | { |
---|
85 | imalloc->Free(pidl); |
---|
86 | imalloc->Release(); |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | void CPropPaths::OnBrowseMotd() |
---|
92 | { |
---|
93 | CFileDialog f(TRUE); |
---|
94 | |
---|
95 | if(f.DoModal() == IDOK) { |
---|
96 | m_motdfile.SetWindowText(f.GetPathName()); |
---|
97 | } |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | void CPropPaths::OnEditMotd() |
---|
102 | { |
---|
103 | CString loc;m_motdfile.GetWindowText(loc); |
---|
104 | ShellExecute(this->GetSafeHwnd(), NULL, loc, NULL, NULL, SW_SHOWNORMAL); |
---|
105 | } |
---|
106 | |
---|
107 | BOOL CPropPaths::OnInitDialog() |
---|
108 | { |
---|
109 | CPropertyPage::OnInitDialog(); |
---|
110 | |
---|
111 | m_configdir.SetWindowText(GetProfileString("configdir", "")); |
---|
112 | m_motdfile.SetWindowText(GetProfileString("motdfile", "")); |
---|
113 | |
---|
114 | return TRUE; |
---|
115 | } |
---|