4 /* update NUM_SETTINGS in precomp.h */
5 LPWSTR lpSettings
[NUM_SETTINGS
] =
16 SaveAllSettings(PINFO pInfo
)
19 WCHAR szValue
[MAXVALUE
];
22 if (GetDlgItemText(pInfo
->hGeneralPage
,
27 SetStringToSettings(pInfo
->pRdpSettings
,
32 /* resolution and fullscreen*/
33 ret
= SendDlgItemMessage(pInfo
->hDisplayPage
,
40 SetIntegerToSettings(pInfo
->pRdpSettings
,
42 (ret
== SendDlgItemMessageW(pInfo
->hDisplayPage
, IDC_GEOSLIDER
, TBM_GETRANGEMAX
, 0, 0)) ? 2 : 1);
43 SetIntegerToSettings(pInfo
->pRdpSettings
,
45 pInfo
->DisplayDeviceList
->Resolutions
[ret
].dmPelsWidth
);
46 SetIntegerToSettings(pInfo
->pRdpSettings
,
48 pInfo
->DisplayDeviceList
->Resolutions
[ret
].dmPelsHeight
);
52 ret
= SendDlgItemMessage(pInfo
->hDisplayPage
,
59 ret
= SendDlgItemMessage(pInfo
->hDisplayPage
,
66 SetIntegerToSettings(pInfo
->pRdpSettings
,
73 if (GetDlgItemText(pInfo
->hGeneralPage
,
78 SetStringToSettings(pInfo
->pRdpSettings
,
86 SetIntegerToSettings(PRDPSETTINGS pRdpSettings
,
96 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
98 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
100 if (pRdpSettings
->pSettings
[i
].Type
== 0)
101 pRdpSettings
->pSettings
[i
].Type
= L
'i';
103 pRdpSettings
->pSettings
[i
].Value
.i
= Value
;
115 SetStringToSettings(PRDPSETTINGS pRdpSettings
,
125 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
127 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
129 if (pRdpSettings
->pSettings
[i
].Type
== 0)
130 pRdpSettings
->pSettings
[i
].Type
= L
's';
132 wcscpy(pRdpSettings
->pSettings
[i
].Value
.s
, lpValue
);
144 GetIntegerFromSettings(PRDPSETTINGS pRdpSettings
,
153 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
155 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
157 if (pRdpSettings
->pSettings
[i
].Type
== L
'i')
159 Value
= pRdpSettings
->pSettings
[i
].Value
.i
;
171 GetStringFromSettings(PRDPSETTINGS pRdpSettings
,
174 LPWSTR lpValue
= NULL
;
180 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
182 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
184 if (pRdpSettings
->pSettings
[i
].Type
== L
's')
186 lpValue
= pRdpSettings
->pSettings
[i
].Value
.s
;
198 WriteRdpFile(HANDLE hFile
,
199 PRDPSETTINGS pRdpSettings
)
201 WCHAR line
[MAXKEY
+ MAXVALUE
+ 4];
202 DWORD BytesToWrite
, BytesWritten
;
206 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
208 /* only write out values in the lpSettings struct */
209 for (k
= 0; k
< NUM_SETTINGS
; k
++)
211 if (wcscmp(lpSettings
[k
], pRdpSettings
->pSettings
[i
].Key
) == 0)
213 if (pRdpSettings
->pSettings
[i
].Type
== L
'i')
215 _snwprintf(line
, MAXKEY
+ MAXVALUE
+ 4, L
"%s:i:%d\r\n",
216 pRdpSettings
->pSettings
[i
].Key
,
217 pRdpSettings
->pSettings
[i
].Value
.i
);
221 _snwprintf(line
, MAXKEY
+ MAXVALUE
+ 4, L
"%s:s:%s\r\n",
222 pRdpSettings
->pSettings
[i
].Key
,
223 pRdpSettings
->pSettings
[i
].Value
.s
);
226 BytesToWrite
= wcslen(line
) * sizeof(WCHAR
);
228 bRet
= WriteFile(hFile
,
233 if (!bRet
|| BytesWritten
== 0)
244 ParseSettings(PRDPSETTINGS pRdpSettings
,
247 LPWSTR lpStr
= lpBuffer
;
248 WCHAR szSeps
[] = L
":\r\n";
249 WCHAR szNewline
[] = L
"\r\n";
254 /* move past unicode byte order */
255 if (lpStr
[0] == 0xFEFF || lpStr
[0] == 0xFFFE)
258 lpToken
= wcstok(lpStr
, szSeps
);
263 for (i
= 0; i
< pRdpSettings
->NumSettings
&& !bFound
; i
++)
265 if (wcscmp(lpToken
, pRdpSettings
->pSettings
[i
].Key
) == 0)
267 lpToken
= wcstok(NULL
, szSeps
);
268 if (lpToken
[0] == L
'i')
270 pRdpSettings
->pSettings
[i
].Type
= lpToken
[0];
271 lpToken
= wcstok(NULL
, szSeps
);
273 pRdpSettings
->pSettings
[i
].Value
.i
= _wtoi(lpToken
);
275 else if (lpToken
[0] == L
's')
277 pRdpSettings
->pSettings
[i
].Type
= lpToken
[0];
278 lpToken
= wcstok(NULL
, szNewline
);
280 wcscpy(pRdpSettings
->pSettings
[i
].Value
.s
, lpToken
);
286 /* move past the type and value */
288 lpToken
= wcstok(NULL
, szNewline
);
290 /* move to next key */
291 lpToken
= wcstok(NULL
, szSeps
);
297 ReadRdpFile(HANDLE hFile
)
299 LPWSTR lpBuffer
= NULL
;
300 DWORD BytesToRead
, BytesRead
;
305 BytesToRead
= GetFileSize(hFile
, NULL
);
308 lpBuffer
= HeapAlloc(GetProcessHeap(),
313 bRes
= ReadFile(hFile
,
320 lpBuffer
[BytesRead
/ 2] = 0;
324 HeapFree(GetProcessHeap(),
339 OpenRdpFile(LPWSTR path
, BOOL bWrite
)
345 hFile
= CreateFileW(path
,
346 bWrite
? GENERIC_WRITE
: GENERIC_READ
,
349 bWrite
? CREATE_ALWAYS
: OPEN_EXISTING
,
350 FILE_ATTRIBUTE_NORMAL
| FILE_ATTRIBUTE_HIDDEN
,
359 CloseRdpFile(HANDLE hFile
)
367 SaveRdpSettingsToFile(LPWSTR lpFile
,
368 PRDPSETTINGS pRdpSettings
)
370 WCHAR pszPath
[MAX_PATH
];
374 /* use default file */
379 LPITEMIDLIST lpidl
= NULL
;
381 hr
= SHGetFolderLocation(NULL
,
388 if (SHGetPathFromIDListW(lpidl
, pszPath
))
390 wcscat(pszPath
, L
"\\Default.rdp");
392 CoTaskMemFree(lpidl
);
396 wcscpy(pszPath
, L
"C:\\Default.rdp");
403 hFile
= OpenRdpFile(lpFile
, TRUE
);
406 if (WriteRdpFile(hFile
, pRdpSettings
))
420 LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings
,
423 WCHAR pszPath
[MAX_PATH
];
427 /* use default file */
430 #ifndef __REACTOS__ // remove when this is working
432 LPITEMIDLIST lpidl
= NULL
;
434 hr
= SHGetFolderLocation(NULL
,
441 if (SHGetPathFromIDListW(lpidl
, pszPath
))
443 wcscat(pszPath
, L
"\\Default.rdp");
445 CoTaskMemFree(lpidl
);
449 wcscpy(pszPath
, L
"C:\\Default.rdp");
456 LPWSTR lpBuffer
= NULL
;
458 hFile
= OpenRdpFile(lpFile
, FALSE
);
461 lpBuffer
= ReadRdpFile(hFile
);
464 ParseSettings(pRdpSettings
, lpBuffer
);
466 HeapFree(GetProcessHeap(),
482 InitRdpSettings(PRDPSETTINGS pRdpSettings
)
486 pRdpSettings
->pSettings
= HeapAlloc(GetProcessHeap(),
488 sizeof(SETTINGS
) * NUM_SETTINGS
);
489 if (pRdpSettings
->pSettings
)
493 for (i
= 0; i
< NUM_SETTINGS
; i
++)
495 wcscpy(pRdpSettings
->pSettings
[i
].Key
, lpSettings
[i
]);
496 pRdpSettings
->pSettings
[i
].Type
= (WCHAR
)0;
497 pRdpSettings
->pSettings
[i
].Value
.i
= 0;
500 pRdpSettings
->NumSettings
= NUM_SETTINGS
;