|
|
1.1.1.6 root 1: /* Legal Notice: The source code contained in this file has been derived from
2: the source code of Encryption for the Masses 2.02a, which is Copyright (c)
3: 1998-99 Paul Le Roux and which is covered by the 'License Agreement for
4: Encryption for the Masses'. Modifications and additions to that source code
1.1.1.7 ! root 5: contained in this file are Copyright (c) 2004-2006 TrueCrypt Foundation and
1.1.1.6 root 6: Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.0
7: the full text of which is contained in the file License.txt included in
8: TrueCrypt binary and source code distribution archives. */
9:
10: #include "Tcdefs.h"
11: #include "Combo.h"
12: #include "Dlgcode.h"
13: #include "Xml.h"
1.1 root 14:
15: #include <time.h>
16:
1.1.1.6 root 17: #define SIZEOF_MRU_LIST 20
1.1 root 18:
19: void
20: AddComboItem (HWND hComboBox, char *lpszFileName)
21: {
22: LPARAM nIndex;
23:
24: nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1,
25: (LPARAM) & lpszFileName[0]);
26:
27: if (nIndex == CB_ERR && *lpszFileName)
28: {
1.1.1.6 root 29: time_t lTime = time (NULL);
1.1 root 30: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & lpszFileName[0]);
31: if (nIndex != CB_ERR)
32: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) lTime);
33: }
34:
35: if (nIndex != CB_ERR && *lpszFileName)
36: nIndex = SendMessage (hComboBox, CB_SETCURSEL, nIndex, 0);
37:
38: if (*lpszFileName == 0)
39: {
40: SendMessage (hComboBox, CB_SETCURSEL, (WPARAM) - 1, 0);
41: }
42: }
43:
44:
45: LPARAM
46: MoveEditToCombo (HWND hComboBox)
47: {
48: char szTmp[256] =
49: {0};
50:
51: GetWindowText (hComboBox, szTmp, sizeof (szTmp));
52:
53: if (strlen (szTmp) > 0)
54: {
55: LPARAM nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1,
56: (LPARAM) & szTmp[0]);
57: if (nIndex == CB_ERR)
58: {
1.1.1.6 root 59: time_t lTime = time (NULL);
1.1 root 60: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & szTmp[0]);
61: if (nIndex != CB_ERR)
62: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
63: }
64: else
65: {
1.1.1.6 root 66: time_t lTime = time (NULL);
1.1 root 67: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime);
68: }
69:
70: return nIndex;
71: }
72:
73: return SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
74: }
75:
76: int
77: GetOrderComboIdx (HWND hComboBox, int *nIdxList, int nElems)
78: {
79: int x = (int) SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
80: if (x != CB_ERR)
81: {
82: int i, nHighIdx = CB_ERR;
1.1.1.6 root 83: time_t lHighTime = -1;
1.1 root 84:
85: for (i = 0; i < x; i++)
86: {
1.1.1.6 root 87: time_t lTime = SendMessage (hComboBox, CB_GETITEMDATA, (WPARAM) i, 0);
1.1 root 88: if (lTime > lHighTime)
89: {
90: int n;
91: for (n = 0; n < nElems; n++)
92: if (nIdxList[n] == i)
93: break;
94: if (n == nElems)
95: {
96: lHighTime = lTime;
97: nHighIdx = i;
98: }
99: }
100: }
101:
102: return nHighIdx;
103: }
104:
105: return CB_ERR;
106: }
107:
108: LPARAM
109: UpdateComboOrder (HWND hComboBox)
110: {
111: LPARAM nIndex;
112:
113: nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0);
114:
115: if (nIndex != CB_ERR)
116: {
1.1.1.6 root 117: time_t lTime = time (NULL);
1.1 root 118: nIndex = SendMessage (hComboBox, CB_SETITEMDATA, (WPARAM) nIndex,
119: (LPARAM) lTime);
120: }
121:
122: return nIndex;
123: }
124:
125: void
1.1.1.6 root 126: LoadCombo (HWND hComboBox)
1.1 root 127: {
1.1.1.6 root 128: DWORD size;
129: char *history = LoadFile (GetConfigPath (FILE_HISTORY), &size);
130: char *xml = history;
131: char volume[MAX_PATH];
1.1 root 132:
1.1.1.6 root 133: if (xml == NULL) return;
1.1 root 134:
1.1.1.6 root 135: while (xml = XmlFindElement (xml, "volume"))
136: {
137: XmlNodeText (xml, volume, sizeof (volume));
138: AddComboItem (hComboBox, volume);
139: xml++;
1.1 root 140: }
141:
142: SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
143:
1.1.1.6 root 144: free (history);
1.1 root 145: }
146:
147: void
1.1.1.6 root 148: DumpCombo (HWND hComboBox, int bClear)
1.1 root 149: {
1.1.1.6 root 150: FILE *f;
1.1 root 151: int i, nComboIdx[SIZEOF_MRU_LIST];
152:
1.1.1.6 root 153: if (bClear)
154: {
155: DeleteFile (GetConfigPath (FILE_HISTORY));
156: return;
157: }
158:
159: f = fopen (GetConfigPath (FILE_HISTORY), "w");
160: if (f == NULL) return;
161:
162: XmlWriteHeader (f);
163: fputs ("\n\t<history>", f);
164:
1.1 root 165: /* combo list part:- get mru items */
166: for (i = 0; i < SIZEOF_MRU_LIST; i++)
1.1.1.6 root 167: nComboIdx[i] = GetOrderComboIdx (hComboBox, &nComboIdx[0], i);
1.1 root 168:
169: /* combo list part:- write out mru items */
170: for (i = 0; i < SIZEOF_MRU_LIST; i++)
171: {
1.1.1.6 root 172: char szTmp[MAX_PATH] = { 0 };
173:
174: if (SendMessage (hComboBox, CB_GETLBTEXTLEN, nComboIdx[i], 0) < sizeof (szTmp))
1.1 root 175: SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]);
176:
1.1.1.6 root 177: if (szTmp[0] != 0)
178: fprintf (f, "\n\t\t<volume>%s</volume>", szTmp);
1.1 root 179: }
1.1.1.6 root 180:
181: fputs ("\n\t</history>", f);
182: XmlWriteFooter (f);
183: fclose (f);
1.1 root 184: }
185:
186: void
187: ClearCombo (HWND hComboBox)
188: {
189: int i;
190: for (i = 0; i < SIZEOF_MRU_LIST; i++)
191: {
192: SendMessage (hComboBox, CB_DELETESTRING, 0, 0);
193: }
194: }
195:
196: int
197: IsComboEmpty (HWND hComboBox)
198: {
199: return SendMessage (hComboBox, CB_GETCOUNT, 0, 0) < 1;
200: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.