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