mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 08:03:01 +00:00
- 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:
parent
ed7a5c7e25
commit
096ed8b631
4 changed files with 143 additions and 170 deletions
|
@ -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)
|
||||||
{
|
{
|
||||||
SendDlgItemMessageW(pInfo->hDisplayPage,
|
pos = index;
|
||||||
IDC_GEOSLIDER,
|
|
||||||
TBM_SETPOS,
|
|
||||||
TRUE,
|
|
||||||
index);
|
|
||||||
break;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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,12 +82,12 @@ 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;
|
|
||||||
bRet = TRUE;
|
pRdpSettings->pSettings[i].Value.i = Value;
|
||||||
break;
|
bRet = TRUE;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,12 +111,12 @@ 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);
|
|
||||||
bRet = TRUE;
|
wcscpy(pRdpSettings->pSettings[i].Value.s, lpValue);
|
||||||
break;
|
bRet = TRUE;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
/* move past unicode byte order */
|
||||||
|
if (lpStr[0] == 0xFEFF || lpStr[0] == 0xFFFE)
|
||||||
|
lpStr += 1;
|
||||||
|
|
||||||
|
lpToken = wcstok(lpStr, szSeps);
|
||||||
|
while (lpToken)
|
||||||
{
|
{
|
||||||
/* get number of settings */
|
bFound = FALSE;
|
||||||
while (*lpStr)
|
|
||||||
|
for (i = 0; i < pRdpSettings->NumSettings && !bFound; i++)
|
||||||
{
|
{
|
||||||
if (*lpStr == L'\n')
|
if (wcscmp(lpToken, pRdpSettings->pSettings[i].Key) == 0)
|
||||||
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;
|
lpToken = wcstok(NULL, szSeps);
|
||||||
|
if (lpToken[0] == L'i')
|
||||||
/* get a key */
|
|
||||||
while (*lpStr != L':')
|
|
||||||
{
|
{
|
||||||
lpKey[i++] = *lpStr++;
|
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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
bFound = TRUE;
|
||||||
/* move onto next setting */
|
|
||||||
while (*lpStr != L'\n')
|
|
||||||
{
|
|
||||||
lpStr++;
|
|
||||||
}
|
|
||||||
lpStr++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 @@ 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,28 +440,52 @@ LoadRdpSettingsFromFile(LPWSTR lpFile)
|
||||||
{
|
{
|
||||||
LPWSTR lpBuffer = NULL;
|
LPWSTR lpBuffer = NULL;
|
||||||
|
|
||||||
pRdpSettings = HeapAlloc(GetProcessHeap(),
|
hFile = OpenRdpFile(lpFile, FALSE);
|
||||||
0,
|
if (hFile)
|
||||||
sizeof(RDPSETTINGS));
|
|
||||||
if (pRdpSettings)
|
|
||||||
{
|
{
|
||||||
hFile = OpenRdpFile(lpFile, FALSE);
|
lpBuffer = ReadRdpFile(hFile);
|
||||||
if (hFile)
|
if (lpBuffer)
|
||||||
{
|
{
|
||||||
lpBuffer = ReadRdpFile(hFile);
|
ParseSettings(pRdpSettings, lpBuffer);
|
||||||
if (lpBuffer)
|
|
||||||
{
|
|
||||||
ParseSettings(pRdpSettings, lpBuffer);
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(),
|
HeapFree(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
lpBuffer);
|
lpBuffer);
|
||||||
}
|
|
||||||
|
bRet = TRUE;
|
||||||
CloseRdpFile(hFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CloseRdpFile(hFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pRdpSettings;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1301,39 +1301,48 @@ 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)
|
||||||
{
|
{
|
||||||
//mi_process_cl(lpCmdLine)
|
pRdpSettings->pSettings = NULL;
|
||||||
if (OpenRDPConnectDialog(hInstance,
|
pRdpSettings->NumSettings = 0;
|
||||||
pRdpSettings))
|
|
||||||
|
if (InitRdpSettings(pRdpSettings))
|
||||||
{
|
{
|
||||||
char szValue[MAXVALUE];
|
LoadRdpSettingsFromFile(pRdpSettings, NULL);
|
||||||
|
|
||||||
uni_to_str(szValue, GetStringFromSettings(pRdpSettings, L"full address"));
|
//mi_process_cl(lpCmdLine)
|
||||||
|
if (OpenRDPConnectDialog(hInstance,
|
||||||
|
pRdpSettings))
|
||||||
|
{
|
||||||
|
char szValue[MAXVALUE];
|
||||||
|
|
||||||
strcpy(g_servername, szValue);
|
uni_to_str(szValue, GetStringFromSettings(pRdpSettings, L"full address"));
|
||||||
//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();
|
strcpy(g_servername, szValue);
|
||||||
ret = 0;
|
//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(),
|
HeapFree(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
pRdpSettings);
|
pRdpSettings);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue