mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 20:50:29 +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];
|
||||
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 @@ FillResolutionsAndColors(PINFO pInfo)
|
|||
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)
|
||||
{
|
||||
pos = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* set slider position */
|
||||
SendDlgItemMessageW(pInfo->hDisplayPage,
|
||||
IDC_GEOSLIDER,
|
||||
TBM_SETPOS,
|
||||
TRUE,
|
||||
index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
pos);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
OnResolutionChanged(pInfo, pos);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#define MAXKEY 256
|
||||
#define MAXVALUE 256
|
||||
|
||||
#define NUM_SETTINGS 4
|
||||
extern LPWSTR lpSettings[];
|
||||
|
||||
typedef struct _SETTINGS
|
||||
|
@ -90,8 +90,9 @@ typedef struct _INFO
|
|||
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);
|
||||
|
|
|
@ -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,15 +82,15 @@ SetIntegerToSettings(PRDPSETTINGS pRdpSettings,
|
|||
{
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
@ -113,15 +111,15 @@ SetStringToSettings(PRDPSETTINGS pRdpSettings,
|
|||
{
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
@ -232,89 +230,50 @@ ParseSettings(PRDPSETTINGS pRdpSettings,
|
|||
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;
|
||||
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;
|
||||
|
||||
pRdpSettings->pSettings = HeapAlloc(GetProcessHeap(),
|
||||
0,
|
||||
sizeof(SETTINGS) * NumSettings);
|
||||
if (pRdpSettings->pSettings)
|
||||
lpToken = wcstok(lpStr, szSeps);
|
||||
while (lpToken)
|
||||
{
|
||||
pRdpSettings->NumSettings = NumSettings;
|
||||
bFound = FALSE;
|
||||
|
||||
for (s = 0; s < NumSettings; s++)
|
||||
for (i = 0; i < pRdpSettings->NumSettings && !bFound; i++)
|
||||
{
|
||||
INT i = 0, k;
|
||||
|
||||
/* get a key */
|
||||
while (*lpStr != L':')
|
||||
if (wcscmp(lpToken, pRdpSettings->pSettings[i].Key) == 0)
|
||||
{
|
||||
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;
|
||||
|
||||
for (k = 0; k < NUM_SETTINGS; k++)
|
||||
else if (lpToken[0] == L's')
|
||||
{
|
||||
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++;
|
||||
pRdpSettings->pSettings[i].Type = lpToken[0];
|
||||
lpToken = wcstok(NULL, szSeps);
|
||||
wcscpy(pRdpSettings->pSettings[i].Value.s, lpToken);
|
||||
}
|
||||
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')
|
||||
/* move past the type and value */
|
||||
if (!bFound)
|
||||
{
|
||||
lpStr++;
|
||||
}
|
||||
lpStr++;
|
||||
}
|
||||
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,
|
||||
0,
|
||||
NULL,
|
||||
bWrite ? OPEN_EXISTING: CREATE_ALWAYS,
|
||||
bWrite ? CREATE_ALWAYS : OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_HIDDEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -442,17 +401,18 @@ SaveRdpSettingsToFile(LPWSTR lpFile,
|
|||
}
|
||||
|
||||
|
||||
PRDPSETTINGS
|
||||
LoadRdpSettingsFromFile(LPWSTR lpFile)
|
||||
BOOL
|
||||
LoadRdpSettingsFromFile(PRDPSETTINGS pRdpSettings,
|
||||
LPWSTR lpFile)
|
||||
{
|
||||
PRDPSETTINGS pRdpSettings = NULL;
|
||||
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,11 +440,6 @@ LoadRdpSettingsFromFile(LPWSTR lpFile)
|
|||
{
|
||||
LPWSTR lpBuffer = NULL;
|
||||
|
||||
pRdpSettings = HeapAlloc(GetProcessHeap(),
|
||||
0,
|
||||
sizeof(RDPSETTINGS));
|
||||
if (pRdpSettings)
|
||||
{
|
||||
hFile = OpenRdpFile(lpFile, FALSE);
|
||||
if (hFile)
|
||||
{
|
||||
|
@ -496,12 +451,41 @@ LoadRdpSettingsFromFile(LPWSTR lpFile)
|
|||
HeapFree(GetProcessHeap(),
|
||||
0,
|
||||
lpBuffer);
|
||||
|
||||
bRet = TRUE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1301,10 +1301,18 @@ wWinMain(HINSTANCE hInstance,
|
|||
|
||||
if (WSAStartup(MAKEWORD(2, 0), &d) == 0)
|
||||
{
|
||||
pRdpSettings = LoadRdpSettingsFromFile(NULL);
|
||||
|
||||
pRdpSettings = HeapAlloc(GetProcessHeap(),
|
||||
0,
|
||||
sizeof(RDPSETTINGS));
|
||||
if (pRdpSettings)
|
||||
{
|
||||
pRdpSettings->pSettings = NULL;
|
||||
pRdpSettings->NumSettings = 0;
|
||||
|
||||
if (InitRdpSettings(pRdpSettings))
|
||||
{
|
||||
LoadRdpSettingsFromFile(pRdpSettings, NULL);
|
||||
|
||||
//mi_process_cl(lpCmdLine)
|
||||
if (OpenRDPConnectDialog(hInstance,
|
||||
pRdpSettings))
|
||||
|
@ -1333,6 +1341,7 @@ wWinMain(HINSTANCE hInstance,
|
|||
HeapFree(GetProcessHeap(),
|
||||
0,
|
||||
pRdpSettings->pSettings);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(),
|
||||
0,
|
||||
|
|
Loading…
Reference in a new issue