4 /* update NUM_SETTINGS in precomp.h */
5 LPWSTR lpSettings
[NUM_SETTINGS
] =
14 SaveAllSettings(PINFO pInfo
)
17 WCHAR szValue
[MAXVALUE
];
20 if (GetDlgItemText(pInfo
->hGeneralPage
,
25 SetStringToSettings(pInfo
->pRdpSettings
,
31 ret
= SendDlgItemMessage(pInfo
->hDisplayPage
,
38 SetIntegerToSettings(pInfo
->pRdpSettings
,
40 pInfo
->DisplayDeviceList
->Resolutions
[ret
].dmPelsWidth
);
41 SetIntegerToSettings(pInfo
->pRdpSettings
,
43 pInfo
->DisplayDeviceList
->Resolutions
[ret
].dmPelsHeight
);
47 ret
= SendDlgItemMessage(pInfo
->hDisplayPage
,
54 ret
= SendDlgItemMessage(pInfo
->hDisplayPage
,
61 SetIntegerToSettings(pInfo
->pRdpSettings
,
70 SetIntegerToSettings(PRDPSETTINGS pRdpSettings
,
80 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
82 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
84 if (pRdpSettings
->pSettings
[i
].Type
== 0)
85 pRdpSettings
->pSettings
[i
].Type
= L
'i';
87 pRdpSettings
->pSettings
[i
].Value
.i
= Value
;
99 SetStringToSettings(PRDPSETTINGS pRdpSettings
,
109 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
111 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
113 if (pRdpSettings
->pSettings
[i
].Type
== 0)
114 pRdpSettings
->pSettings
[i
].Type
= L
's';
116 wcscpy(pRdpSettings
->pSettings
[i
].Value
.s
, lpValue
);
128 GetIntegerFromSettings(PRDPSETTINGS pRdpSettings
,
137 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
139 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
141 if (pRdpSettings
->pSettings
[i
].Type
== L
'i')
143 Value
= pRdpSettings
->pSettings
[i
].Value
.i
;
155 GetStringFromSettings(PRDPSETTINGS pRdpSettings
,
158 LPWSTR lpValue
= NULL
;
164 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
166 if (wcscmp(pRdpSettings
->pSettings
[i
].Key
, lpKey
) == 0)
168 if (pRdpSettings
->pSettings
[i
].Type
== L
's')
170 lpValue
= pRdpSettings
->pSettings
[i
].Value
.s
;
182 WriteRdpFile(HANDLE hFile
,
183 PRDPSETTINGS pRdpSettings
)
185 WCHAR line
[MAXKEY
+ MAXVALUE
+ 4];
186 DWORD BytesToWrite
, BytesWritten
;
190 for (i
= 0; i
< pRdpSettings
->NumSettings
; i
++)
192 /* only write out values in the lpSettings struct */
193 for (k
= 0; k
< NUM_SETTINGS
; k
++)
195 if (wcscmp(lpSettings
[k
], pRdpSettings
->pSettings
[i
].Key
) == 0)
197 if (pRdpSettings
->pSettings
[i
].Type
== L
'i')
199 _snwprintf(line
, MAXKEY
+ MAXVALUE
+ 4, L
"%s:i:%d\r\n",
200 pRdpSettings
->pSettings
[i
].Key
,
201 pRdpSettings
->pSettings
[i
].Value
.i
);
205 _snwprintf(line
, MAXKEY
+ MAXVALUE
+ 4, L
"%s:s:%s\r\n",
206 pRdpSettings
->pSettings
[i
].Key
,
207 pRdpSettings
->pSettings
[i
].Value
.s
);
210 BytesToWrite
= wcslen(line
) * sizeof(WCHAR
);
212 bRet
= WriteFile(hFile
,
217 if (!bRet
|| BytesWritten
== 0)
228 ParseSettings(PRDPSETTINGS pRdpSettings
,
231 LPWSTR lpStr
= lpBuffer
;
232 WCHAR szSeps
[] = L
":\r\n";
237 /* move past unicode byte order */
238 if (lpStr
[0] == 0xFEFF || lpStr
[0] == 0xFFFE)
241 lpToken
= wcstok(lpStr
, szSeps
);
246 for (i
= 0; i
< pRdpSettings
->NumSettings
&& !bFound
; i
++)
248 if (wcscmp(lpToken
, pRdpSettings
->pSettings
[i
].Key
) == 0)
250 lpToken
= wcstok(NULL
, szSeps
);
251 if (lpToken
[0] == L
'i')
253 pRdpSettings
->pSettings
[i
].Type
= lpToken
[0];
254 lpToken
= wcstok(NULL
, szSeps
);
256 pRdpSettings
->pSettings
[i
].Value
.i
= _wtoi(lpToken
);
258 else if (lpToken
[0] == L
's')
260 pRdpSettings
->pSettings
[i
].Type
= lpToken
[0];
261 lpToken
= wcstok(NULL
, szSeps
);
263 wcscpy(pRdpSettings
->pSettings
[i
].Value
.s
, lpToken
);
269 /* move past the type and value */
272 lpToken
= wcstok(NULL
, szSeps
);
273 lpToken
= wcstok(NULL
, szSeps
);
276 /* move to next key */
277 lpToken
= wcstok(NULL
, szSeps
);
283 ReadRdpFile(HANDLE hFile
)
285 LPWSTR lpBuffer
= NULL
;
286 DWORD BytesToRead
, BytesRead
;
291 BytesToRead
= GetFileSize(hFile
, NULL
);
294 lpBuffer
= HeapAlloc(GetProcessHeap(),
299 bRes
= ReadFile(hFile
,
306 lpBuffer
[BytesRead
/ 2] = 0;
310 HeapFree(GetProcessHeap(),
325 OpenRdpFile(LPWSTR path
, BOOL bWrite
)
331 hFile
= CreateFileW(path
,
332 bWrite
? GENERIC_WRITE
: GENERIC_READ
,
335 bWrite
? CREATE_ALWAYS
: OPEN_EXISTING
,
336 FILE_ATTRIBUTE_NORMAL
| FILE_ATTRIBUTE_HIDDEN
,
345 CloseRdpFile(HANDLE hFile
)
353 SaveRdpSettingsToFile(LPWSTR lpFile
,
354 PRDPSETTINGS pRdpSettings
)
356 WCHAR pszPath
[MAX_PATH
];
360 /* use default file */
365 LPITEMIDLIST lpidl
= NULL
;
367 hr
= SHGetFolderLocation(NULL
,
374 if (SHGetPathFromIDListW(lpidl
, pszPath
))
376 wcscat(pszPath
, L
"\\Default.rdp");
378 CoTaskMemFree(lpidl
);
382 wcscpy(pszPath
, L
"C:\\Default.rdp");
389 hFile
= OpenRdpFile(lpFile
, TRUE
);
392 if (WriteRdpFile(hFile
, pRdpSettings
))
406 LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings
,
409 WCHAR pszPath
[MAX_PATH
];
413 /* use default file */
416 #ifndef __REACTOS__ // remove when this is working
418 LPITEMIDLIST lpidl
= NULL
;
420 hr
= SHGetFolderLocation(NULL
,
427 if (SHGetPathFromIDListW(lpidl
, pszPath
))
429 wcscat(pszPath
, L
"\\Default.rdp");
431 CoTaskMemFree(lpidl
);
435 wcscpy(pszPath
, L
"C:\\Default.rdp");
442 LPWSTR lpBuffer
= NULL
;
444 hFile
= OpenRdpFile(lpFile
, FALSE
);
447 lpBuffer
= ReadRdpFile(hFile
);
450 ParseSettings(pRdpSettings
, lpBuffer
);
452 HeapFree(GetProcessHeap(),
468 InitRdpSettings(PRDPSETTINGS pRdpSettings
)
472 pRdpSettings
->pSettings
= HeapAlloc(GetProcessHeap(),
474 sizeof(SETTINGS
) * NUM_SETTINGS
);
475 if (pRdpSettings
->pSettings
)
479 for (i
= 0; i
< NUM_SETTINGS
; i
++)
481 wcscpy(pRdpSettings
->pSettings
[i
].Key
, lpSettings
[i
]);
482 pRdpSettings
->pSettings
[i
].Type
= (WCHAR
)0;
483 pRdpSettings
->pSettings
[i
].Value
.i
= 0;
486 pRdpSettings
->NumSettings
= NUM_SETTINGS
;