Author: gedmurphy Date: Mon Nov 12 15:32:32 2007 New Revision: 30386
URL: http://svn.reactos.org/svn/reactos?rev=30386&view=rev Log: - refactor .rdp reading - fix the way the settings are saved - fix a few other small bugs which I've forgotten about now
Modified: trunk/reactos/base/applications/mstsc/connectdialog.c trunk/reactos/base/applications/mstsc/precomp.h trunk/reactos/base/applications/mstsc/settings.c trunk/reactos/base/applications/mstsc/win32.c
Modified: trunk/reactos/base/applications/mstsc/connectdialog.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/con... ============================================================================== --- trunk/reactos/base/applications/mstsc/connectdialog.c (original) +++ trunk/reactos/base/applications/mstsc/connectdialog.c Mon Nov 12 15:32:32 2007 @@ -516,7 +516,7 @@ WCHAR Pixel[64]; DWORD index, i, num; DWORD MaxBpp = 0; - DWORD width, height; + INT width, height, pos = 0; UINT types[4];
pInfo->CurrentDisplayDevice = pInfo->DisplayDeviceList; /* Update global variable */ @@ -599,48 +599,27 @@ width = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopwidth"); height = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopheight");
- if (width && height) + if (width != -1 && height != -1) { for (index = 0; index < pInfo->CurrentDisplayDevice->ResolutionsCount; index++) { if (pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == width && pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == height) { - SendDlgItemMessageW(pInfo->hDisplayPage, - IDC_GEOSLIDER, - TBM_SETPOS, - TRUE, - index); + pos = index; break; } } - - if (LoadStringW(hInst, - IDS_PIXEL, - Pixel, - sizeof(Pixel) / sizeof(WCHAR))) - { -#ifdef _MSC_VER - _swprintf(Buffer, - Pixel, - width, - height, - Pixel); -#else - swprintf(Buffer, - Pixel, - width, - height, - Pixel); -#endif - - SendDlgItemMessageW(pInfo->hDisplayPage, - IDC_SETTINGS_RESOLUTION_TEXT, - WM_SETTEXT, - 0, - (LPARAM)Buffer); - } - } + } + + /* set slider position */ + SendDlgItemMessageW(pInfo->hDisplayPage, + IDC_GEOSLIDER, + TBM_SETPOS, + TRUE, + pos); + + OnResolutionChanged(pInfo, pos); }
Modified: trunk/reactos/base/applications/mstsc/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/pre... ============================================================================== --- trunk/reactos/base/applications/mstsc/precomp.h (original) +++ trunk/reactos/base/applications/mstsc/precomp.h Mon Nov 12 15:32:32 2007 @@ -16,7 +16,7 @@
#define MAXKEY 256 #define MAXVALUE 256 - +#define NUM_SETTINGS 4 extern LPWSTR lpSettings[];
typedef struct _SETTINGS @@ -90,8 +90,9 @@ BITMAP bitmap; } INFO, *PINFO;
+BOOL InitRdpSettings(PRDPSETTINGS pRdpSettings); BOOL OpenRDPConnectDialog(HINSTANCE hInstance, PRDPSETTINGS pRdpSettings); -PRDPSETTINGS LoadRdpSettingsFromFile(LPWSTR lpFile); +BOOL LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings, LPWSTR lpFile); BOOL SaveRdpSettingsToFile(LPWSTR lpFile, PRDPSETTINGS pRdpSettings); INT GetIntegerFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue); LPWSTR GetStringFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);
Modified: trunk/reactos/base/applications/mstsc/settings.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/set... ============================================================================== --- trunk/reactos/base/applications/mstsc/settings.c (original) +++ trunk/reactos/base/applications/mstsc/settings.c Mon Nov 12 15:32:32 2007 @@ -1,15 +1,13 @@
#include <precomp.h>
-#define NUM_SETTINGS 6 +/* update NUM_SETTINGS in precomp.h */ LPWSTR lpSettings[NUM_SETTINGS] = { - L"screen mode id", L"desktopwidth", L"desktopheight", L"session bpp", L"full address", - L"compression", };
VOID @@ -84,12 +82,12 @@ { if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0) { - if (pRdpSettings->pSettings[i].Type == L'i') - { - pRdpSettings->pSettings[i].Value.i = Value; - bRet = TRUE; - break; - } + if (pRdpSettings->pSettings[i].Type == 0) + pRdpSettings->pSettings[i].Type = L'i'; + + pRdpSettings->pSettings[i].Value.i = Value; + bRet = TRUE; + break; } } } @@ -113,12 +111,12 @@ { if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0) { - if (pRdpSettings->pSettings[i].Type == L's') - { - wcscpy(pRdpSettings->pSettings[i].Value.s, lpValue); - bRet = TRUE; - break; - } + if (pRdpSettings->pSettings[i].Type == 0) + pRdpSettings->pSettings[i].Type = L's'; + + wcscpy(pRdpSettings->pSettings[i].Value.s, lpValue); + bRet = TRUE; + break; } } } @@ -232,89 +230,50 @@ LPWSTR lpBuffer) { LPWSTR lpStr = lpBuffer; - WCHAR lpKey[MAXKEY]; - WCHAR lpValue[MAXVALUE]; - INT NumSettings = 0; - INT s; - - if (lpStr) - { - /* get number of settings */ - while (*lpStr) - { - if (*lpStr == L'\n') - NumSettings++; - lpStr++; - } - lpStr = lpBuffer; - - if (NumSettings == 0) - return; - - /* move past unicode byte order */ - if (lpStr[0] == 0xFEFF || lpStr[0] == 0xFFFE) - lpStr += 1; - - pRdpSettings->pSettings = HeapAlloc(GetProcessHeap(), - 0, - sizeof(SETTINGS) * NumSettings); - if (pRdpSettings->pSettings) - { - pRdpSettings->NumSettings = NumSettings; - - for (s = 0; s < NumSettings; s++) - { - INT i = 0, k; - - /* get a key */ - while (*lpStr != L':') - { - lpKey[i++] = *lpStr++; - } - lpKey[i] = 0; - - for (k = 0; k < NUM_SETTINGS; k++) - { - if (wcscmp(lpSettings[k], lpKey) == 0) - { - wcscpy(pRdpSettings->pSettings[s].Key, lpKey); - - /* get the type */ - lpStr++; - if (*lpStr == L'i' || *lpStr == L's') - pRdpSettings->pSettings[s].Type = *lpStr; - - lpStr += 2; - - /* get a value */ - i = 0; - while (*lpStr != L'\r') - { - lpValue[i++] = *lpStr++; - } - lpValue[i] = 0; - - if (pRdpSettings->pSettings[s].Type == L'i') - { - pRdpSettings->pSettings[s].Value.i = _wtoi(lpValue); - } - else if (pRdpSettings->pSettings[s].Type == L's') - { - wcscpy(pRdpSettings->pSettings[s].Value.s, lpValue); - } - else - pRdpSettings->pSettings[s].Type = 0; - } - } - - /* move onto next setting */ - while (*lpStr != L'\n') - { - lpStr++; - } - lpStr++; - } - } + WCHAR szSeps[] = L":\r\n"; + LPWSTR lpToken; + BOOL bFound; + INT i; + + /* move past unicode byte order */ + if (lpStr[0] == 0xFEFF || lpStr[0] == 0xFFFE) + lpStr += 1; + + lpToken = wcstok(lpStr, szSeps); + while (lpToken) + { + bFound = FALSE; + + for (i = 0; i < pRdpSettings->NumSettings && !bFound; i++) + { + if (wcscmp(lpToken, pRdpSettings->pSettings[i].Key) == 0) + { + lpToken = wcstok(NULL, szSeps); + if (lpToken[0] == L'i') + { + pRdpSettings->pSettings[i].Type = lpToken[0]; + lpToken = wcstok(NULL, szSeps); + pRdpSettings->pSettings[i].Value.i = _wtoi(lpToken); + } + else if (lpToken[0] == L's') + { + pRdpSettings->pSettings[i].Type = lpToken[0]; + lpToken = wcstok(NULL, szSeps); + wcscpy(pRdpSettings->pSettings[i].Value.s, lpToken); + } + bFound = TRUE; + } + } + + /* move past the type and value */ + if (!bFound) + { + lpToken = wcstok(NULL, szSeps); + lpToken = wcstok(NULL, szSeps); + } + + /* move to next key */ + lpToken = wcstok(NULL, szSeps); } }
@@ -372,7 +331,7 @@ bWrite ? GENERIC_WRITE : GENERIC_READ, 0, NULL, - bWrite ? OPEN_EXISTING: CREATE_ALWAYS, + bWrite ? CREATE_ALWAYS : OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_HIDDEN, NULL); } @@ -442,17 +401,18 @@ }
-PRDPSETTINGS -LoadRdpSettingsFromFile(LPWSTR lpFile) -{ - PRDPSETTINGS pRdpSettings = NULL; +BOOL +LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings, + LPWSTR lpFile) +{ WCHAR pszPath[MAX_PATH]; HANDLE hFile; + BOOL bRet = FALSE;
/* use default file */ if (lpFile == NULL) { -#ifndef __REACTOS__ +#ifndef __REACTOS__ // remove when this is working HRESULT hr; LPITEMIDLIST lpidl= NULL;
@@ -480,28 +440,52 @@ { LPWSTR lpBuffer = NULL;
- pRdpSettings = HeapAlloc(GetProcessHeap(), - 0, - sizeof(RDPSETTINGS)); - if (pRdpSettings) - { - hFile = OpenRdpFile(lpFile, FALSE); - if (hFile) - { - lpBuffer = ReadRdpFile(hFile); - if (lpBuffer) - { - ParseSettings(pRdpSettings, lpBuffer); - - HeapFree(GetProcessHeap(), - 0, - lpBuffer); - } - - CloseRdpFile(hFile); - } - } - } - - return pRdpSettings; -} + hFile = OpenRdpFile(lpFile, FALSE); + if (hFile) + { + lpBuffer = ReadRdpFile(hFile); + if (lpBuffer) + { + ParseSettings(pRdpSettings, lpBuffer); + + HeapFree(GetProcessHeap(), + 0, + lpBuffer); + + bRet = TRUE; + } + + CloseRdpFile(hFile); + } + } + + return bRet; +} + + +BOOL +InitRdpSettings(PRDPSETTINGS pRdpSettings) +{ + BOOL bRet = FALSE; + + pRdpSettings->pSettings = HeapAlloc(GetProcessHeap(), + 0, + sizeof(SETTINGS) * NUM_SETTINGS); + if (pRdpSettings->pSettings) + { + INT i; + + for (i = 0; i < NUM_SETTINGS; i++) + { + wcscpy(pRdpSettings->pSettings[i].Key, lpSettings[i]); + pRdpSettings->pSettings[i].Type = (WCHAR)0; + pRdpSettings->pSettings[i].Value.i = 0; + } + + pRdpSettings->NumSettings = NUM_SETTINGS; + + bRet = TRUE; + } + + return bRet; +}
Modified: trunk/reactos/base/applications/mstsc/win32.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/win... ============================================================================== --- trunk/reactos/base/applications/mstsc/win32.c (original) +++ trunk/reactos/base/applications/mstsc/win32.c Mon Nov 12 15:32:32 2007 @@ -1301,38 +1301,47 @@
if (WSAStartup(MAKEWORD(2, 0), &d) == 0) { - pRdpSettings = LoadRdpSettingsFromFile(NULL); - + pRdpSettings = HeapAlloc(GetProcessHeap(), + 0, + sizeof(RDPSETTINGS)); if (pRdpSettings) { - //mi_process_cl(lpCmdLine) - if (OpenRDPConnectDialog(hInstance, - pRdpSettings)) + pRdpSettings->pSettings = NULL; + pRdpSettings->NumSettings = 0; + + if (InitRdpSettings(pRdpSettings)) { - char szValue[MAXVALUE]; - - uni_to_str(szValue, GetStringFromSettings(pRdpSettings, L"full address")); - - strcpy(g_servername, szValue); - //g_port = 3389; - strcpy(g_username, ""); - strcpy(g_password, ""); - g_server_depth = GetIntegerFromSettings(pRdpSettings, L"session bpp"); - if (g_server_depth > 16) g_server_depth = 16; /* hack, we don't support 24bpp yet */ - g_width = GetIntegerFromSettings(pRdpSettings, L"desktopwidth"); - g_height = GetIntegerFromSettings(pRdpSettings, L"desktopheight"); - g_screen_width = GetSystemMetrics(SM_CXSCREEN); - g_screen_height = GetSystemMetrics(SM_CYSCREEN); - g_xoff = GetSystemMetrics(SM_CXEDGE) * 2; - g_yoff = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYEDGE) * 2; - - ui_main(); - ret = 0; + LoadRdpSettingsFromFile(pRdpSettings, NULL); + + //mi_process_cl(lpCmdLine) + if (OpenRDPConnectDialog(hInstance, + pRdpSettings)) + { + char szValue[MAXVALUE]; + + uni_to_str(szValue, GetStringFromSettings(pRdpSettings, L"full address")); + + strcpy(g_servername, szValue); + //g_port = 3389; + strcpy(g_username, ""); + strcpy(g_password, ""); + g_server_depth = GetIntegerFromSettings(pRdpSettings, L"session bpp"); + if (g_server_depth > 16) g_server_depth = 16; /* hack, we don't support 24bpp yet */ + g_width = GetIntegerFromSettings(pRdpSettings, L"desktopwidth"); + g_height = GetIntegerFromSettings(pRdpSettings, L"desktopheight"); + g_screen_width = GetSystemMetrics(SM_CXSCREEN); + g_screen_height = GetSystemMetrics(SM_CYSCREEN); + g_xoff = GetSystemMetrics(SM_CXEDGE) * 2; + g_yoff = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYEDGE) * 2; + + ui_main(); + ret = 0; + } + + HeapFree(GetProcessHeap(), + 0, + pRdpSettings->pSettings); } - - HeapFree(GetProcessHeap(), - 0, - pRdpSettings->pSettings);
HeapFree(GetProcessHeap(), 0,