- fix various bugs in the .rdp parser

- add code to allow querying of key value pairs

svn path=/trunk/; revision=30226
This commit is contained in:
Ged Murphy 2007-11-06 20:36:31 +00:00
parent 1723012d87
commit 12f6b06910
6 changed files with 181 additions and 69 deletions

View file

@ -22,8 +22,10 @@
#include <commctrl.h> #include <commctrl.h>
#include <stdio.h> #include <stdio.h>
#include <tchar.h> #include <tchar.h>
#include <todo.h>
#include "resource.h" #include "resource.h"
#define MAX_KEY_NAME 255 #define MAX_KEY_NAME 255
/* As slider control can't contain user data, we have to keep an /* As slider control can't contain user data, we have to keep an
@ -62,6 +64,7 @@ typedef struct _DISPLAY_DEVICE_ENTRY
typedef struct _INFO typedef struct _INFO
{ {
PRDPSETTINGS pRdpSettings;
PDISPLAY_DEVICE_ENTRY DisplayDeviceList; PDISPLAY_DEVICE_ENTRY DisplayDeviceList;
PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice; PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice;
HWND hSelf; HWND hSelf;
@ -206,11 +209,11 @@ GeneralOnInit(PINFO pInfo)
} }
pInfo->hConn = LoadImage(hInst, pInfo->hConn = LoadImage(hInst,
MAKEINTRESOURCE(IDI_CONN), MAKEINTRESOURCE(IDI_CONN),
IMAGE_ICON, IMAGE_ICON,
32, 32,
32, 32,
LR_DEFAULTCOLOR); LR_DEFAULTCOLOR);
if (pInfo->hConn) if (pInfo->hConn)
{ {
SendDlgItemMessage(pInfo->hGeneralPage, SendDlgItemMessage(pInfo->hGeneralPage,
@ -221,6 +224,10 @@ GeneralOnInit(PINFO pInfo)
} }
FillServerAddesssCombo(pInfo); FillServerAddesssCombo(pInfo);
/* add address */
//GetStringFromSettings(pInfo->pRdpSettings, L"full address");
} }
@ -240,6 +247,18 @@ GeneralDlgProc(HWND hDlg,
GeneralOnInit(pInfo); GeneralOnInit(pInfo);
return TRUE; return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_SAVE:
break;
}
break;
}
case WM_CLOSE: case WM_CLOSE:
{ {
if (pInfo->hLogon) if (pInfo->hLogon)
@ -789,7 +808,7 @@ OnMainCreate(HWND hwnd)
BOOL bRet = FALSE; BOOL bRet = FALSE;
pInfo = HeapAlloc(GetProcessHeap(), pInfo = HeapAlloc(GetProcessHeap(),
0, HEAP_ZERO_MEMORY,
sizeof(INFO)); sizeof(INFO));
if (pInfo) if (pInfo)
{ {
@ -797,12 +816,17 @@ OnMainCreate(HWND hwnd)
GWLP_USERDATA, GWLP_USERDATA,
(LONG_PTR)pInfo); (LONG_PTR)pInfo);
pInfo->hHeader = LoadImage(hInst, /* read the default .rdp file */
MAKEINTRESOURCE(IDB_HEADER), pInfo->pRdpSettings = LoadRdpSettingsFromFile(NULL);
IMAGE_BITMAP, if (!pInfo->pRdpSettings)
0, return FALSE;
0,
LR_DEFAULTCOLOR); pInfo->hHeader = (HBITMAP)LoadImage(hInst,
MAKEINTRESOURCE(IDB_HEADER),
IMAGE_BITMAP,
0,
0,
LR_DEFAULTCOLOR);
if (pInfo->hHeader) if (pInfo->hHeader)
{ {
GetObject(pInfo->hHeader, sizeof(BITMAP), &pInfo->headerbitmap); GetObject(pInfo->hHeader, sizeof(BITMAP), &pInfo->headerbitmap);
@ -840,8 +864,6 @@ OnMainCreate(HWND hwnd)
} }
OnTabWndSelChange(pInfo); OnTabWndSelChange(pInfo);
bRet = TRUE;
} }
} }
@ -888,7 +910,6 @@ DlgProc(HWND hDlg,
switch(LOWORD(wParam)) switch(LOWORD(wParam))
{ {
break;
} }
break; break;
@ -943,9 +964,25 @@ DlgProc(HWND hDlg,
case WM_CLOSE: case WM_CLOSE:
{ {
if (pInfo) if (pInfo)
{
if (pInfo->pRdpSettings)
{
if (pInfo->pRdpSettings->pSettings)
{
HeapFree(GetProcessHeap(),
0,
pInfo->pRdpSettings->pSettings);
}
HeapFree(GetProcessHeap(),
0,
pInfo->pRdpSettings);
}
HeapFree(GetProcessHeap(), HeapFree(GetProcessHeap(),
0, 0,
pInfo); pInfo);
}
EndDialog(hDlg, 0); EndDialog(hDlg, 0);
} }

View file

@ -633,6 +633,10 @@
Name="Header Files" Name="Header Files"
Filter="h;hpp;hxx;hm;inl" Filter="h;hpp;hxx;hm;inl"
> >
<File
RelativePath=".\todo.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"

View file

@ -1,23 +1,10 @@
#include <windows.h> #include <windows.h>
#include <commctrl.h>
#include <stdio.h> #include <stdio.h>
#include <tchar.h> #include <tchar.h>
#include <shlobj.h> #include <shlobj.h>
#include <todo.h>
#include "resource.h" #include "resource.h"
#define MAXKEY 256
#define MAXVALUE 256
typedef struct _Settings
{
WCHAR Key[MAXKEY];
WCHAR Type; // holds 'i' or 's'
union {
INT i;
WCHAR s[MAXVALUE];
} Value;
} SETTINGS, *PSETTINGS;
#define NUM_SETTINGS 6 #define NUM_SETTINGS 6
LPWSTR lpSettings[NUM_SETTINGS] = LPWSTR lpSettings[NUM_SETTINGS] =
{ {
@ -30,6 +17,61 @@ LPWSTR lpSettings[NUM_SETTINGS] =
}; };
INT
GetIntegerFromSettings(PRDPSETTINGS pRdpSettings,
LPWSTR lpKey)
{
INT Value = -1;
if (pRdpSettings)
{
INT i;
for (i = 0; i < pRdpSettings->NumSettings; i++)
{
if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
{
if (pRdpSettings->pSettings[i].Type == L'i')
{
Value = pRdpSettings->pSettings[i].Value.i;
break;
}
}
}
}
return Value;
}
LPWSTR
GetStringFromSettings(PRDPSETTINGS pRdpSettings,
LPWSTR lpKey)
{
LPWSTR lpValue = NULL;
if (pRdpSettings)
{
INT i;
for (i = 0; i < pRdpSettings->NumSettings; i++)
{
if (wcscmp(pRdpSettings->pSettings[i].Key, lpKey) == 0)
{
if (pRdpSettings->pSettings[i].Type == L's')
{
lpValue = pRdpSettings->pSettings[i].Value.s;
break;
}
}
}
}
return lpValue;
}
static BOOL static BOOL
WriteRdpFile(HANDLE hFile, WriteRdpFile(HANDLE hFile,
PSETTINGS pSettings) PSETTINGS pSettings)
@ -38,15 +80,15 @@ WriteRdpFile(HANDLE hFile,
} }
static PSETTINGS static VOID
ParseSettings(LPWSTR lpBuffer) ParseSettings(PRDPSETTINGS pRdpSettings,
LPWSTR lpBuffer)
{ {
PSETTINGS pSettings;
LPWSTR lpStr = lpBuffer; LPWSTR lpStr = lpBuffer;
WCHAR lpKey[MAXKEY]; WCHAR lpKey[MAXKEY];
WCHAR lpValue[MAXVALUE]; WCHAR lpValue[MAXVALUE];
INT NumSettings = 0; INT NumSettings = 0;
INT s; INT s, structsize;
if (lpStr) if (lpStr)
{ {
@ -60,17 +102,19 @@ ParseSettings(LPWSTR lpBuffer)
lpStr = lpBuffer; lpStr = lpBuffer;
if (NumSettings == 0) if (NumSettings == 0)
return NULL; 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;
pSettings = HeapAlloc(GetProcessHeap(), pRdpSettings->pSettings = HeapAlloc(GetProcessHeap(),
0, 0,
sizeof(SETTINGS) * NumSettings); sizeof(SETTINGS) * NumSettings);
if (pSettings) if (pRdpSettings->pSettings)
{ {
pRdpSettings->NumSettings = NumSettings;
for (s = 0; s < NumSettings; s++) for (s = 0; s < NumSettings; s++)
{ {
INT i = 0, k, temp; INT i = 0, k, temp;
@ -86,12 +130,12 @@ ParseSettings(LPWSTR lpBuffer)
{ {
if (wcscmp(lpSettings[k], lpKey) == 0) if (wcscmp(lpSettings[k], lpKey) == 0)
{ {
wcscpy(pSettings[s].Key, lpKey); wcscpy(pRdpSettings->pSettings[s].Key, lpKey);
/* get the type */ /* get the type */
lpStr++; lpStr++;
if (*lpStr == L'i' || *lpStr == L's') if (*lpStr == L'i' || *lpStr == L's')
pSettings[s].Type = *lpStr; pRdpSettings->pSettings[s].Type = *lpStr;
lpStr += 2; lpStr += 2;
@ -103,18 +147,16 @@ ParseSettings(LPWSTR lpBuffer)
} }
lpValue[i] = 0; lpValue[i] = 0;
if (pSettings[s].Type == L'i') if (pRdpSettings->pSettings[s].Type == L'i')
{ {
pSettings[s].Value.i = _wtoi(lpValue); pRdpSettings->pSettings[s].Value.i = _wtoi(lpValue);
pSettings[s].Value.s[0] = 0;
} }
else if (pSettings[s].Type == L's') else if (pRdpSettings->pSettings[s].Type == L's')
{ {
pSettings[s].Value.i = 0; wcscpy(pRdpSettings->pSettings[s].Value.s, lpValue);
wcscpy(pSettings[s].Value.s, lpValue);
} }
else else
pSettings[s].Type = 0; pRdpSettings->pSettings[s].Type = 0;
} }
} }
@ -127,10 +169,9 @@ ParseSettings(LPWSTR lpBuffer)
} }
} }
} }
return pSettings;
} }
static LPWSTR static LPWSTR
ReadRdpFile(HANDLE hFile) ReadRdpFile(HANDLE hFile)
{ {
@ -172,6 +213,7 @@ ReadRdpFile(HANDLE hFile)
return lpBuffer; return lpBuffer;
} }
static HANDLE static HANDLE
OpenRdpFile(LPWSTR path, BOOL bWrite) OpenRdpFile(LPWSTR path, BOOL bWrite)
{ {
@ -200,10 +242,10 @@ CloseRdpFile(HANDLE hFile)
} }
PSETTINGS PRDPSETTINGS
LoadRdpSettingsFromFile(LPWSTR lpFile) LoadRdpSettingsFromFile(LPWSTR lpFile)
{ {
PSETTINGS pSettings = NULL; PRDPSETTINGS pRdpSettings;
WCHAR pszPath[MAX_PATH]; WCHAR pszPath[MAX_PATH];
HANDLE hFile; HANDLE hFile;
@ -224,6 +266,7 @@ LoadRdpSettingsFromFile(LPWSTR lpFile)
{ {
wcscat(pszPath, L"\\Default.rdp"); wcscat(pszPath, L"\\Default.rdp");
lpFile = pszPath; lpFile = pszPath;
CoTaskMemFree(lpidl);
} }
} }
} }
@ -232,22 +275,28 @@ LoadRdpSettingsFromFile(LPWSTR lpFile)
{ {
LPWSTR lpBuffer = NULL; LPWSTR lpBuffer = NULL;
hFile = OpenRdpFile(lpFile, FALSE); pRdpSettings = HeapAlloc(GetProcessHeap(),
if (hFile) 0,
sizeof(RDPSETTINGS));
if (pRdpSettings)
{ {
lpBuffer = ReadRdpFile(hFile); hFile = OpenRdpFile(lpFile, FALSE);
if (lpBuffer) if (hFile)
{ {
pSettings = ParseSettings(lpBuffer); lpBuffer = ReadRdpFile(hFile);
if (lpBuffer)
{
ParseSettings(pRdpSettings, lpBuffer);
HeapFree(GetProcessHeap(), HeapFree(GetProcessHeap(),
0, 0,
lpBuffer); lpBuffer);
}
CloseRdpFile(hFile);
} }
CloseRdpFile(hFile);
} }
} }
return pSettings; return pRdpSettings;
} }

View file

@ -16,11 +16,10 @@
#define IDC_CONNICON 1017 #define IDC_CONNICON 1017
#define IDC_REMICON 1018 #define IDC_REMICON 1018
#define IDC_COLORSICON 1019 #define IDC_COLORSICON 1019
#define IDC_COLORIMAGE 1020
#define IDB_HEADER 1016 #define IDB_HEADER 1100
#define IDB_SPECT 1017 #define IDB_SPECT 1101
#define IDC_COLORIMAGE 1018
#define IDI_LOGON 2000 #define IDI_LOGON 2000
#define IDI_CONN 2001 #define IDI_CONN 2001

View file

@ -0,0 +1,23 @@
#define MAXKEY 256
#define MAXVALUE 256
typedef struct _SETTINGS
{
WCHAR Key[MAXKEY];
WCHAR Type; // holds 'i' or 's'
union {
INT i;
WCHAR s[MAXVALUE];
} Value;
} SETTINGS, *PSETTINGS;
typedef struct _RDPSETTINGS
{
PSETTINGS pSettings;
INT NumSettings;
} RDPSETTINGS, *PRDPSETTINGS;
PRDPSETTINGS LoadRdpSettingsFromFile(LPWSTR lpFile);
INT GetIntegerFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);
LPWSTR GetStringFromSettings(PRDPSETTINGS pSettings, LPWSTR lpValue);

View file

@ -1338,14 +1338,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
WSAStartup(MAKEWORD(2, 0), &d); WSAStartup(MAKEWORD(2, 0), &d);
if (mi_process_cl(lpCmdLine)) //if (mi_process_cl(lpCmdLine))
{ //{
if (OpenRDPConnectDialog(hInstance)) if (OpenRDPConnectDialog(hInstance))
{ {
ui_main(); ui_main();
ret = 0; ret = 0;
} }
} //}
else else
mi_show_params(); mi_show_params();