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