ReactOS  0.4.12-dev-685-gf36cbf7
settings.c
Go to the documentation of this file.
1 
2 #include "precomp.h"
3 
4 /* update NUM_SETTINGS in precomp.h */
6 {
7  L"desktopwidth",
8  L"desktopheight",
9  L"session bpp",
10  L"full address",
11  L"username",
12  L"screen mode id",
13 };
14 
15 VOID
17 {
18  INT ret;
19  WCHAR szValue[MAXVALUE];
20 
21  /* server */
22  if (GetDlgItemText(pInfo->hGeneralPage,
24  szValue,
25  MAXVALUE))
26  {
28  L"full address",
29  szValue);
30  }
31 
32  /* resolution and fullscreen*/
35  TBM_GETPOS,
36  0,
37  0);
38  if (ret != -1)
39  {
41  L"screen mode id",
44  L"desktopwidth",
47  L"desktopheight",
49  }
50 
51  /* bpp */
55  0,
56  0);
57  if (ret != CB_ERR)
58  {
62  ret,
63  0);
64  if (ret != CB_ERR)
65  {
67  L"session bpp",
68  ret);
69  }
70  }
71 
72  /* user name */
73  if (GetDlgItemText(pInfo->hGeneralPage,
75  szValue,
76  MAXVALUE))
77  {
79  L"username",
80  szValue);
81  }
82 }
83 
84 
85 BOOL
87  LPWSTR lpKey,
88  INT Value)
89 {
90  BOOL bRet = FALSE;
91 
92  if (pRdpSettings)
93  {
94  INT i;
95 
96  for (i = 0; i < pRdpSettings->NumSettings; i++)
97  {
98  if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
99  {
100  if (pRdpSettings->pSettings[i].Type == 0)
101  pRdpSettings->pSettings[i].Type = L'i';
102 
103  pRdpSettings->pSettings[i].Value.i = Value;
104  bRet = TRUE;
105  break;
106  }
107  }
108  }
109 
110  return bRet;
111 }
112 
113 
114 BOOL
116  LPWSTR lpKey,
117  LPWSTR lpValue)
118 {
119  BOOL bRet = FALSE;
120 
121  if (pRdpSettings)
122  {
123  INT i;
124 
125  for (i = 0; i < pRdpSettings->NumSettings; i++)
126  {
127  if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
128  {
129  if (pRdpSettings->pSettings[i].Type == 0)
130  pRdpSettings->pSettings[i].Type = L's';
131 
132  wcscpy(pRdpSettings->pSettings[i].Value.s, lpValue);
133  bRet = TRUE;
134  break;
135  }
136  }
137  }
138 
139  return bRet;
140 }
141 
142 
143 INT
145  LPWSTR lpKey)
146 {
147  INT Value = -1;
148 
149  if (pRdpSettings)
150  {
151  INT i;
152 
153  for (i = 0; i < pRdpSettings->NumSettings; i++)
154  {
155  if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
156  {
157  if (pRdpSettings->pSettings[i].Type == L'i')
158  {
159  Value = pRdpSettings->pSettings[i].Value.i;
160  break;
161  }
162  }
163  }
164  }
165 
166  return Value;
167 }
168 
169 
170 LPWSTR
172  LPWSTR lpKey)
173 {
174  LPWSTR lpValue = NULL;
175 
176  if (pRdpSettings)
177  {
178  INT i;
179 
180  for (i = 0; i < pRdpSettings->NumSettings; i++)
181  {
182  if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
183  {
184  if (pRdpSettings->pSettings[i].Type == L's')
185  {
186  lpValue = pRdpSettings->pSettings[i].Value.s;
187  break;
188  }
189  }
190  }
191  }
192 
193  return lpValue;
194 }
195 
196 
197 static BOOL
199  PRDPSETTINGS pRdpSettings)
200 {
201  WCHAR line[MAXKEY + MAXVALUE + 4];
202  DWORD BytesToWrite, BytesWritten;
203  BOOL bRet;
204  INT i, k;
205 
206  for (i = 0; i < pRdpSettings->NumSettings; i++)
207  {
208  /* only write out values in the lpSettings struct */
209  for (k = 0; k < NUM_SETTINGS; k++)
210  {
211  if (wcscmp(lpSettings[k], pRdpSettings->pSettings[i].Key) == 0)
212  {
213  if (pRdpSettings->pSettings[i].Type == L'i')
214  {
215  _snwprintf(line, MAXKEY + MAXVALUE + 4, L"%s:i:%d\r\n",
216  pRdpSettings->pSettings[i].Key,
217  pRdpSettings->pSettings[i].Value.i);
218  }
219  else
220  {
221  _snwprintf(line, MAXKEY + MAXVALUE + 4, L"%s:s:%s\r\n",
222  pRdpSettings->pSettings[i].Key,
223  pRdpSettings->pSettings[i].Value.s);
224  }
225 
226  BytesToWrite = wcslen(line) * sizeof(WCHAR);
227 
228  bRet = WriteFile(hFile,
229  line,
230  BytesToWrite,
231  &BytesWritten,
232  NULL);
233  if (!bRet || BytesWritten == 0)
234  return FALSE;
235  }
236  }
237  }
238 
239  return TRUE;
240 }
241 
242 
243 static VOID
246 {
247  LPWSTR lpStr = lpBuffer;
248  WCHAR szSeps[] = L":\r\n";
249  WCHAR szNewline[] = L"\r\n";
250  LPWSTR lpToken;
251  BOOL bFound;
252  INT i;
253 
254  /* move past unicode byte order */
255  if (lpStr[0] == 0xFEFF || lpStr[0] == 0xFFFE)
256  lpStr += 1;
257 
258  lpToken = wcstok(lpStr, szSeps);
259  while (lpToken)
260  {
261  bFound = FALSE;
262 
263  for (i = 0; i < pRdpSettings->NumSettings && !bFound; i++)
264  {
265  if (wcscmp(lpToken, pRdpSettings->pSettings[i].Key) == 0)
266  {
267  lpToken = wcstok(NULL, szSeps);
268  if (lpToken[0] == L'i')
269  {
270  pRdpSettings->pSettings[i].Type = lpToken[0];
271  lpToken = wcstok(NULL, szSeps);
272  if (lpToken != NULL)
273  pRdpSettings->pSettings[i].Value.i = _wtoi(lpToken);
274  }
275  else if (lpToken[0] == L's')
276  {
277  pRdpSettings->pSettings[i].Type = lpToken[0];
278  if (lpToken[2] == 13 || lpToken[2] == 10 || lpToken[2] == 0)
279  lpToken[0] = 0; // terminate string
280  else
281  lpToken = wcstok(NULL, szNewline);
282  if (lpToken != NULL)
283  wcscpy(pRdpSettings->pSettings[i].Value.s, lpToken);
284  }
285  bFound = TRUE;
286  }
287  }
288 
289  /* move past the type and value */
290  if (!bFound)
291  lpToken = wcstok(NULL, szNewline);
292 
293  /* move to next key */
294  lpToken = wcstok(NULL, szSeps);
295  }
296 }
297 
298 
299 static LPWSTR
301 {
302  LPWSTR lpBuffer = NULL;
303  DWORD BytesToRead, BytesRead;
304  BOOL bRes;
305 
306  if (hFile)
307  {
308  BytesToRead = GetFileSize(hFile, NULL);
309  if (BytesToRead)
310  {
312  0,
313  BytesToRead + 2);
314  if (lpBuffer)
315  {
316  bRes = ReadFile(hFile,
317  lpBuffer,
318  BytesToRead,
319  &BytesRead,
320  NULL);
321  if (bRes)
322  {
323  lpBuffer[BytesRead / 2] = 0;
324  }
325  else
326  {
328  0,
329  lpBuffer);
330 
331  lpBuffer = NULL;
332  }
333  }
334  }
335  }
336 
337  return lpBuffer;
338 }
339 
340 
341 static HANDLE
343 {
344  HANDLE hFile = NULL;
345 
346  if (path)
347  {
349  bWrite ? GENERIC_WRITE : GENERIC_READ,
350  0,
351  NULL,
352  bWrite ? CREATE_ALWAYS : OPEN_EXISTING,
354  NULL);
355  }
356 
357  return hFile;
358 }
359 
360 
361 static VOID
363 {
364  if (hFile)
366 }
367 
368 
369 BOOL
371  PRDPSETTINGS pRdpSettings)
372 {
373  WCHAR pszPath[MAX_PATH];
374  HANDLE hFile;
375  BOOL bRet = FALSE;
376 
377  /* use default file */
378  if (lpFile == NULL)
379  {
380  HRESULT hr;
381  LPITEMIDLIST lpidl= NULL;
382 
385  NULL,
386  0,
387  &lpidl);
388  if (hr == S_OK)
389  {
390  if (SHGetPathFromIDListW(lpidl, pszPath))
391  {
392  wcscat(pszPath, L"\\Default.rdp");
393  lpFile = pszPath;
394  CoTaskMemFree(lpidl);
395  }
396  }
397  }
398 
399  if (lpFile)
400  {
401  hFile = OpenRdpFile(lpFile, TRUE);
402  if (hFile)
403  {
404  if (WriteRdpFile(hFile, pRdpSettings))
405  {
406  bRet = TRUE;
407  }
408 
410  }
411  }
412 
413  return bRet;
414 }
415 
416 
417 BOOL
419  LPWSTR lpFile)
420 {
421  WCHAR pszPath[MAX_PATH];
422  HANDLE hFile;
423  BOOL bRet = FALSE;
424 
425  /* use default file */
426  if (lpFile == NULL)
427  {
428  HRESULT hr;
429  LPITEMIDLIST lpidl= NULL;
430 
433  NULL,
434  0,
435  &lpidl);
436  if (hr == S_OK)
437  {
438  if (SHGetPathFromIDListW(lpidl, pszPath))
439  {
440  wcscat(pszPath, L"\\Default.rdp");
441  lpFile = pszPath;
442  CoTaskMemFree(lpidl);
443  }
444  }
445  }
446 
447  if (lpFile)
448  {
449  LPWSTR lpBuffer = NULL;
450 
451  hFile = OpenRdpFile(lpFile, FALSE);
452  if (hFile)
453  {
455  if (lpBuffer)
456  {
457  ParseSettings(pRdpSettings, lpBuffer);
458 
460  0,
461  lpBuffer);
462 
463  bRet = TRUE;
464  }
465 
467  }
468  }
469 
470  return bRet;
471 }
472 
473 
474 BOOL
476 {
477  BOOL bRet = FALSE;
478 
479  pRdpSettings->pSettings = HeapAlloc(GetProcessHeap(),
480  0,
481  sizeof(SETTINGS) * NUM_SETTINGS);
482  if (pRdpSettings->pSettings)
483  {
484  INT i;
485 
486  for (i = 0; i < NUM_SETTINGS; i++)
487  {
488  wcscpy(pRdpSettings->pSettings[i].Key, lpSettings[i]);
489  pRdpSettings->pSettings[i].Type = (WCHAR)0;
490  pRdpSettings->pSettings[i].Value.i = 0;
491  }
492 
493  pRdpSettings->NumSettings = NUM_SETTINGS;
494 
495  bRet = TRUE;
496  }
497 
498  return bRet;
499 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
BOOL SaveRdpSettingsToFile(LPWSTR lpFile, PRDPSETTINGS pRdpSettings)
Definition: settings.c:370
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static LPWSTR ReadRdpFile(HANDLE hFile)
Definition: settings.c:300
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
HRESULT hr
Definition: shlfolder.c:183
BOOL SetIntegerToSettings(PRDPSETTINGS pRdpSettings, LPWSTR lpKey, INT Value)
Definition: settings.c:86
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CB_GETITEMDATA
Definition: winuser.h:1911
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
LPWSTR GetStringFromSettings(PRDPSETTINGS pRdpSettings, LPWSTR lpKey)
Definition: settings.c:171
LPWSTR lpSettings[NUM_SETTINGS]
Definition: settings.c:5
BOOL LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings, LPWSTR lpFile)
Definition: settings.c:418
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
_Check_return_ _CRTIMP wchar_t *__cdecl wcstok(_Inout_opt_z_ wchar_t *_Str, _In_z_ const wchar_t *_Delim)
#define TBM_GETRANGEMAX
Definition: commctrl.h:2005
BOOL InitRdpSettings(PRDPSETTINGS pRdpSettings)
Definition: settings.c:475
#define IDC_NAMEEDIT
Definition: resource.h:22
#define SendDlgItemMessage
Definition: winuser.h:5708
PDISPLAY_DEVICE_ENTRY DisplayDeviceList
Definition: precomp.h:86
#define WCHAR
Definition: msvc.h:43
int32_t INT
Definition: typedefs.h:56
BOOL SetStringToSettings(PRDPSETTINGS pRdpSettings, LPWSTR lpKey, LPWSTR lpValue)
Definition: settings.c:115
HWND hGeneralPage
Definition: precomp.h:90
#define CB_GETCURSEL
Definition: winuser.h:1904
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NUM_SETTINGS
Definition: precomp.h:30
#define TBM_GETPOS
Definition: commctrl.h:2003
#define GENERIC_WRITE
Definition: nt_native.h:90
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:163
#define IDC_GEOSLIDER
Definition: resource.h:19
static HANDLE OpenRdpFile(LPWSTR path, BOOL bWrite)
Definition: settings.c:342
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
union _SETTINGS::@13 Value
Definition: parser.c:48
#define OPEN_EXISTING
Definition: compat.h:426
#define CB_ERR
Definition: winuser.h:2389
PRDPSETTINGS pRdpSettings
Definition: precomp.h:85
static VOID CloseRdpFile(HANDLE hFile)
Definition: settings.c:362
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetDlgItemText
Definition: winuser.h:5651
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
PSETTINGS pSettings
Definition: precomp.h:45
LONG HRESULT
Definition: typedefs.h:77
#define MAXKEY
Definition: precomp.h:28
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDC_SERVERCOMBO
Definition: resource.h:15
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
INT i
Definition: precomp.h:38
static const WCHAR L[]
Definition: oid.c:1250
VOID SaveAllSettings(PINFO pInfo)
Definition: settings.c:16
#define IDC_BPPCOMBO
Definition: resource.h:20
#define GENERIC_READ
Definition: compat.h:124
DWORD dmPelsWidth
Definition: precomp.h:54
_In_ HANDLE hFile
Definition: mswsock.h:90
PRESOLUTION_INFO Resolutions
Definition: precomp.h:77
static LPCTSTR lpKey
Definition: virtmem.c:13
static VOID ParseSettings(PRDPSETTINGS pRdpSettings, LPWSTR lpBuffer)
Definition: settings.c:244
DWORD dmPelsHeight
Definition: precomp.h:55
WCHAR Type
Definition: precomp.h:36
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define S_OK
Definition: intsafe.h:59
#define CREATE_ALWAYS
Definition: disk.h:72
Definition: precomp.h:83
WCHAR Key[MAXKEY]
Definition: precomp.h:35
Definition: services.c:325
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
INT GetIntegerFromSettings(PRDPSETTINGS pRdpSettings, LPWSTR lpKey)
Definition: settings.c:144
static BOOL WriteRdpFile(HANDLE hFile, PRDPSETTINGS pRdpSettings)
Definition: settings.c:198
#define CreateFileW
Definition: compat.h:400
#define CSIDL_PERSONAL
Definition: shlobj.h:2008
HWND hDisplayPage
Definition: precomp.h:91
INT NumSettings
Definition: precomp.h:46
#define MAXVALUE
Definition: precomp.h:29
HRESULT WINAPI SHGetFolderLocation(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2598
WCHAR * LPWSTR
Definition: xmlstorage.h:184
WCHAR s[MAXVALUE]
Definition: precomp.h:39
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
int k
Definition: mpi.c:3369
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255