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

View file

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

View file

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

View file

@ -16,11 +16,10 @@
#define IDC_CONNICON 1017
#define IDC_REMICON 1018
#define IDC_COLORSICON 1019
#define IDC_COLORIMAGE 1020
#define IDB_HEADER 1016
#define IDB_SPECT 1017
#define IDC_COLORIMAGE 1018
#define IDB_HEADER 1100
#define IDB_SPECT 1101
#define IDI_LOGON 2000
#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);
if (mi_process_cl(lpCmdLine))
{
//if (mi_process_cl(lpCmdLine))
//{
if (OpenRDPConnectDialog(hInstance))
{
ui_main();
ret = 0;
}
}
//}
else
mi_show_params();