- refactor .rdp reading

- fix the way the settings are saved
- fix a few other small bugs which I've forgotten about now

svn path=/trunk/; revision=30386
This commit is contained in:
Ged Murphy 2007-11-12 12:32:32 +00:00
parent ed7a5c7e25
commit 096ed8b631
4 changed files with 143 additions and 170 deletions

View file

@ -516,7 +516,7 @@ FillResolutionsAndColors(PINFO pInfo)
WCHAR Pixel[64]; WCHAR Pixel[64];
DWORD index, i, num; DWORD index, i, num;
DWORD MaxBpp = 0; DWORD MaxBpp = 0;
DWORD width, height; INT width, height, pos = 0;
UINT types[4]; UINT types[4];
pInfo->CurrentDisplayDevice = pInfo->DisplayDeviceList; /* Update global variable */ pInfo->CurrentDisplayDevice = pInfo->DisplayDeviceList; /* Update global variable */
@ -599,48 +599,27 @@ FillResolutionsAndColors(PINFO pInfo)
width = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopwidth"); width = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopwidth");
height = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopheight"); height = GetIntegerFromSettings(pInfo->pRdpSettings, L"desktopheight");
if (width && height) if (width != -1 && height != -1)
{ {
for (index = 0; index < pInfo->CurrentDisplayDevice->ResolutionsCount; index++) for (index = 0; index < pInfo->CurrentDisplayDevice->ResolutionsCount; index++)
{ {
if (pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == width && if (pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == width &&
pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == height) pInfo->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == height)
{ {
pos = index;
break;
}
}
}
/* set slider position */
SendDlgItemMessageW(pInfo->hDisplayPage, SendDlgItemMessageW(pInfo->hDisplayPage,
IDC_GEOSLIDER, IDC_GEOSLIDER,
TBM_SETPOS, TBM_SETPOS,
TRUE, TRUE,
index); pos);
break;
}
}
if (LoadStringW(hInst, OnResolutionChanged(pInfo, pos);
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);
}
}
} }

View file

@ -16,7 +16,7 @@
#define MAXKEY 256 #define MAXKEY 256
#define MAXVALUE 256 #define MAXVALUE 256
#define NUM_SETTINGS 4
extern LPWSTR lpSettings[]; extern LPWSTR lpSettings[];
typedef struct _SETTINGS typedef struct _SETTINGS
@ -90,8 +90,9 @@ typedef struct _INFO
BITMAP bitmap; BITMAP bitmap;
} INFO, *PINFO; } INFO, *PINFO;
BOOL InitRdpSettings(PRDPSETTINGS pRdpSettings);
BOOL OpenRDPConnectDialog(HINSTANCE hInstance, PRDPSETTINGS pRdpSettings); BOOL OpenRDPConnectDialog(HINSTANCE hInstance, PRDPSETTINGS pRdpSettings);
PRDPSETTINGS LoadRdpSettingsFromFile(LPWSTR lpFile); BOOL LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings, LPWSTR lpFile);
BOOL SaveRdpSettingsToFile(LPWSTR lpFile, PRDPSETTINGS pRdpSettings); BOOL SaveRdpSettingsToFile(LPWSTR lpFile, PRDPSETTINGS pRdpSettings);
INT GetIntegerFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue); INT GetIntegerFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);
LPWSTR GetStringFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue); LPWSTR GetStringFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);

View file

@ -1,15 +1,13 @@
#include <precomp.h> #include <precomp.h>
#define NUM_SETTINGS 6 /* update NUM_SETTINGS in precomp.h */
LPWSTR lpSettings[NUM_SETTINGS] = LPWSTR lpSettings[NUM_SETTINGS] =
{ {
L"screen mode id",
L"desktopwidth", L"desktopwidth",
L"desktopheight", L"desktopheight",
L"session bpp", L"session bpp",
L"full address", L"full address",
L"compression",
}; };
VOID VOID
@ -84,15 +82,15 @@ SetIntegerToSettings(PRDPSETTINGS pRdpSettings,
{ {
if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0) if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
{ {
if (pRdpSettings->pSettings[i].Type == L'i') if (pRdpSettings->pSettings[i].Type == 0)
{ pRdpSettings->pSettings[i].Type = L'i';
pRdpSettings->pSettings[i].Value.i = Value; pRdpSettings->pSettings[i].Value.i = Value;
bRet = TRUE; bRet = TRUE;
break; break;
} }
} }
} }
}
return bRet; return bRet;
} }
@ -113,15 +111,15 @@ SetStringToSettings(PRDPSETTINGS pRdpSettings,
{ {
if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0) if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
{ {
if (pRdpSettings->pSettings[i].Type == L's') if (pRdpSettings->pSettings[i].Type == 0)
{ pRdpSettings->pSettings[i].Type = L's';
wcscpy(pRdpSettings->pSettings[i].Value.s, lpValue); wcscpy(pRdpSettings->pSettings[i].Value.s, lpValue);
bRet = TRUE; bRet = TRUE;
break; break;
} }
} }
} }
}
return bRet; return bRet;
} }
@ -232,89 +230,50 @@ ParseSettings(PRDPSETTINGS pRdpSettings,
LPWSTR lpBuffer) LPWSTR lpBuffer)
{ {
LPWSTR lpStr = lpBuffer; LPWSTR lpStr = lpBuffer;
WCHAR lpKey[MAXKEY]; WCHAR szSeps[] = L":\r\n";
WCHAR lpValue[MAXVALUE]; LPWSTR lpToken;
INT NumSettings = 0; BOOL bFound;
INT s; INT i;
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 */ /* move past unicode byte order */
if (lpStr[0] == 0xFEFF || lpStr[0] == 0xFFFE) if (lpStr[0] == 0xFEFF || lpStr[0] == 0xFFFE)
lpStr += 1; lpStr += 1;
pRdpSettings->pSettings = HeapAlloc(GetProcessHeap(), lpToken = wcstok(lpStr, szSeps);
0, while (lpToken)
sizeof(SETTINGS) * NumSettings);
if (pRdpSettings->pSettings)
{ {
pRdpSettings->NumSettings = NumSettings; bFound = FALSE;
for (s = 0; s < NumSettings; s++) for (i = 0; i < pRdpSettings->NumSettings && !bFound; i++)
{ {
INT i = 0, k; if (wcscmp(lpToken, pRdpSettings->pSettings[i].Key) == 0)
/* get a key */
while (*lpStr != L':')
{ {
lpKey[i++] = *lpStr++; 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);
} }
lpKey[i] = 0; else if (lpToken[0] == L's')
for (k = 0; k < NUM_SETTINGS; k++)
{ {
if (wcscmp(lpSettings[k], lpKey) == 0) pRdpSettings->pSettings[i].Type = lpToken[0];
{ lpToken = wcstok(NULL, szSeps);
wcscpy(pRdpSettings->pSettings[s].Key, lpKey); wcscpy(pRdpSettings->pSettings[i].Value.s, lpToken);
/* 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; bFound = TRUE;
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 */ /* move past the type and value */
while (*lpStr != L'\n') if (!bFound)
{ {
lpStr++; lpToken = wcstok(NULL, szSeps);
} lpToken = wcstok(NULL, szSeps);
lpStr++;
}
} }
/* move to next key */
lpToken = wcstok(NULL, szSeps);
} }
} }
@ -372,7 +331,7 @@ OpenRdpFile(LPWSTR path, BOOL bWrite)
bWrite ? GENERIC_WRITE : GENERIC_READ, bWrite ? GENERIC_WRITE : GENERIC_READ,
0, 0,
NULL, NULL,
bWrite ? OPEN_EXISTING: CREATE_ALWAYS, bWrite ? CREATE_ALWAYS : OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_HIDDEN,
NULL); NULL);
} }
@ -442,17 +401,18 @@ SaveRdpSettingsToFile(LPWSTR lpFile,
} }
PRDPSETTINGS BOOL
LoadRdpSettingsFromFile(LPWSTR lpFile) LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings,
LPWSTR lpFile)
{ {
PRDPSETTINGS pRdpSettings = NULL;
WCHAR pszPath[MAX_PATH]; WCHAR pszPath[MAX_PATH];
HANDLE hFile; HANDLE hFile;
BOOL bRet = FALSE;
/* use default file */ /* use default file */
if (lpFile == NULL) if (lpFile == NULL)
{ {
#ifndef __REACTOS__ #ifndef __REACTOS__ // remove when this is working
HRESULT hr; HRESULT hr;
LPITEMIDLIST lpidl= NULL; LPITEMIDLIST lpidl= NULL;
@ -480,11 +440,6 @@ LoadRdpSettingsFromFile(LPWSTR lpFile)
{ {
LPWSTR lpBuffer = NULL; LPWSTR lpBuffer = NULL;
pRdpSettings = HeapAlloc(GetProcessHeap(),
0,
sizeof(RDPSETTINGS));
if (pRdpSettings)
{
hFile = OpenRdpFile(lpFile, FALSE); hFile = OpenRdpFile(lpFile, FALSE);
if (hFile) if (hFile)
{ {
@ -496,12 +451,41 @@ LoadRdpSettingsFromFile(LPWSTR lpFile)
HeapFree(GetProcessHeap(), HeapFree(GetProcessHeap(),
0, 0,
lpBuffer); lpBuffer);
bRet = TRUE;
} }
CloseRdpFile(hFile); CloseRdpFile(hFile);
} }
} }
return bRet;
} }
return pRdpSettings;
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;
} }

View file

@ -1301,10 +1301,18 @@ wWinMain(HINSTANCE hInstance,
if (WSAStartup(MAKEWORD(2, 0), &d) == 0) if (WSAStartup(MAKEWORD(2, 0), &d) == 0)
{ {
pRdpSettings = LoadRdpSettingsFromFile(NULL); pRdpSettings = HeapAlloc(GetProcessHeap(),
0,
sizeof(RDPSETTINGS));
if (pRdpSettings) if (pRdpSettings)
{ {
pRdpSettings->pSettings = NULL;
pRdpSettings->NumSettings = 0;
if (InitRdpSettings(pRdpSettings))
{
LoadRdpSettingsFromFile(pRdpSettings, NULL);
//mi_process_cl(lpCmdLine) //mi_process_cl(lpCmdLine)
if (OpenRDPConnectDialog(hInstance, if (OpenRDPConnectDialog(hInstance,
pRdpSettings)) pRdpSettings))
@ -1333,6 +1341,7 @@ wWinMain(HINSTANCE hInstance,
HeapFree(GetProcessHeap(), HeapFree(GetProcessHeap(),
0, 0,
pRdpSettings->pSettings); pRdpSettings->pSettings);
}
HeapFree(GetProcessHeap(), HeapFree(GetProcessHeap(),
0, 0,