2016-04-09 21:40:32 +00:00
|
|
|
/*
|
2017-09-08 20:19:51 +00:00
|
|
|
* PROJECT: ReactOS Compatibility Layer Shell Extension
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* PURPOSE: CLayerUIPropPage implementation
|
2018-02-06 18:32:51 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2018 Mark Jansen (mark.jansen@reactos.org)
|
2016-04-09 21:40:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
2016-08-23 19:37:31 +00:00
|
|
|
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <shellapi.h>
|
2017-04-22 17:11:52 +00:00
|
|
|
#include <shellutils.h>
|
2016-08-23 19:37:31 +00:00
|
|
|
#include <strsafe.h>
|
|
|
|
#include <apphelp.h>
|
2016-04-09 21:40:32 +00:00
|
|
|
#include <windowsx.h>
|
|
|
|
#include <sfc.h>
|
|
|
|
|
|
|
|
const GUID CLSID_CLayerUIPropPage = { 0x513D916F, 0x2A8E, 0x4F51, { 0xAE, 0xAB, 0x0C, 0xBC, 0x76, 0xFB, 0x1A, 0xF8 } };
|
|
|
|
#define ACP_WNDPROP L"{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}.Prop"
|
|
|
|
|
|
|
|
#define GPLK_USER 1
|
|
|
|
#define GPLK_MACHINE 2
|
|
|
|
#define MAX_LAYER_LENGTH 256
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const PCWSTR Display;
|
|
|
|
const PCWSTR Name;
|
|
|
|
} g_CompatModes[] = {
|
|
|
|
{ L"Windows 95", L"WIN95" },
|
2016-07-21 17:29:41 +00:00
|
|
|
{ L"Windows 98/ME", L"WIN98" },
|
2016-04-09 21:40:32 +00:00
|
|
|
{ L"Windows NT 4.0 (SP5)", L"NT4SP5" },
|
|
|
|
{ L"Windows 2000", L"WIN2000" },
|
|
|
|
{ L"Windows XP (SP2)", L"WINXPSP2" },
|
|
|
|
{ L"Windows XP (SP3)", L"WINXPSP3" },
|
|
|
|
{ L"Windows Server 2003 (SP1)", L"WINSRV03SP1" },
|
|
|
|
{ L"Windows Server 2008 (SP1)", L"WINSRV08SP1" },
|
|
|
|
{ L"Windows Vista", L"VISTARTM" },
|
|
|
|
{ L"Windows Vista (SP1)", L"VISTASP1" },
|
|
|
|
{ L"Windows Vista (SP2)", L"VISTASP2" },
|
|
|
|
{ L"Windows 7", L"WIN7RTM" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const PCWSTR Name;
|
|
|
|
DWORD Id;
|
|
|
|
} g_Layers[] = {
|
2017-04-22 17:11:52 +00:00
|
|
|
{ L"256COLOR", IDC_CHKRUNIN256COLORS },
|
|
|
|
{ L"640X480", IDC_CHKRUNIN640480RES },
|
|
|
|
{ L"DISABLETHEMES", IDC_CHKDISABLEVISUALTHEMES },
|
|
|
|
#if 0
|
|
|
|
{ L"DISABLEDWM", IDC_??, TRUE },
|
|
|
|
{ L"HIGHDPIAWARE", IDC_??, TRUE },
|
|
|
|
{ L"RUNASADMIN", IDC_??, TRUE },
|
|
|
|
#endif
|
|
|
|
{ NULL, 0 }
|
2016-04-09 21:40:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WCHAR* g_AllowedExtensions[] = {
|
|
|
|
L".exe",
|
|
|
|
L".msi",
|
|
|
|
L".pif",
|
|
|
|
L".bat",
|
|
|
|
L".cmd",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2018-01-27 16:41:58 +00:00
|
|
|
BOOL IsBuiltinLayer(PCWSTR Name)
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
for (n = 0; g_Layers[n].Name; ++n)
|
|
|
|
{
|
|
|
|
if (!wcsicmp(g_Layers[n].Name, Name))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; g_CompatModes[n].Name; ++n)
|
|
|
|
{
|
|
|
|
if (!wcsicmp(g_CompatModes[n].Name, Name))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-04-22 17:11:52 +00:00
|
|
|
|
|
|
|
void ACDBG_FN(PCSTR FunctionName, PCWSTR Format, ...)
|
|
|
|
{
|
|
|
|
WCHAR Buffer[512];
|
|
|
|
WCHAR* Current = Buffer;
|
|
|
|
size_t Length = _countof(Buffer);
|
|
|
|
|
|
|
|
StringCchPrintfExW(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, L"[%-20S] ", FunctionName);
|
|
|
|
va_list ArgList;
|
|
|
|
va_start(ArgList, Format);
|
|
|
|
StringCchVPrintfExW(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, Format, ArgList);
|
|
|
|
va_end(ArgList);
|
|
|
|
OutputDebugStringW(Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ACDBG(fmt, ...) ACDBG_FN(__FUNCTION__, fmt, ##__VA_ARGS__ )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CLayerUIPropPage::CLayerUIPropPage()
|
|
|
|
: m_IsSfcProtected(FALSE)
|
|
|
|
, m_AllowPermLayer(FALSE)
|
|
|
|
, m_LayerQueryFlags(GPLK_USER) /* TODO: When do we read from HKLM? */
|
|
|
|
, m_RegistryOSMode(0)
|
|
|
|
, m_OSMode(0)
|
|
|
|
, m_RegistryEnabledLayers(0)
|
|
|
|
, m_EnabledLayers(0)
|
|
|
|
{
|
2018-01-27 17:10:50 +00:00
|
|
|
CComBSTR title;
|
|
|
|
title.LoadString(g_hModule, IDS_COMPAT_TITLE);
|
|
|
|
m_psp.pszTitle = title.Detach();
|
|
|
|
m_psp.dwFlags |= PSP_USETITLE;
|
2017-04-22 17:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CLayerUIPropPage::~CLayerUIPropPage()
|
|
|
|
{
|
2018-01-27 17:10:50 +00:00
|
|
|
CComBSTR title;
|
|
|
|
title.Attach((BSTR)m_psp.pszTitle);
|
2017-04-22 17:11:52 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
HRESULT CLayerUIPropPage::InitFile(PCWSTR Filename)
|
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
CString ExpandedFilename;
|
|
|
|
DWORD dwRequired = ExpandEnvironmentStringsW(Filename, NULL, 0);
|
|
|
|
if (dwRequired > 0)
|
|
|
|
{
|
|
|
|
LPWSTR Buffer = ExpandedFilename.GetBuffer(dwRequired);
|
|
|
|
DWORD dwReturned = ExpandEnvironmentStringsW(Filename, Buffer, dwRequired);
|
|
|
|
if (dwRequired == dwReturned)
|
|
|
|
{
|
|
|
|
ExpandedFilename.ReleaseBufferSetLength(dwReturned - 1);
|
|
|
|
ACDBG(L"Expanded '%s' => '%s'\r\n", Filename, (PCWSTR)ExpandedFilename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ExpandedFilename.ReleaseBufferSetLength(0);
|
|
|
|
ExpandedFilename = Filename;
|
|
|
|
ACDBG(L"Failed during expansion '%s'\r\n", Filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ACDBG(L"Failed to expand '%s'\r\n", Filename);
|
|
|
|
ExpandedFilename = Filename;
|
|
|
|
}
|
|
|
|
PCWSTR pwszExt = PathFindExtensionW(ExpandedFilename);
|
2016-04-09 21:40:32 +00:00
|
|
|
if (!pwszExt)
|
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
ACDBG(L"Failed to find an extension: '%s'\r\n", (PCWSTR)ExpandedFilename);
|
2016-04-09 21:40:32 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if (!wcsicmp(pwszExt, L".lnk"))
|
|
|
|
{
|
|
|
|
WCHAR Buffer[MAX_PATH];
|
2017-04-22 17:11:52 +00:00
|
|
|
if (!GetExeFromLnk(ExpandedFilename, Buffer, _countof(Buffer)))
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
ACDBG(L"Failed to read link target from: '%s'\r\n", (PCWSTR)ExpandedFilename);
|
2016-04-09 21:40:32 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-04-22 17:11:52 +00:00
|
|
|
if (!wcsicmp(Buffer, ExpandedFilename))
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
ACDBG(L"Link redirects to itself: '%s'\r\n", (PCWSTR)ExpandedFilename);
|
2016-04-09 21:40:32 +00:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
return InitFile(Buffer);
|
|
|
|
}
|
2017-08-15 12:37:25 +00:00
|
|
|
|
|
|
|
CString tmp;
|
|
|
|
if (tmp.GetEnvironmentVariable(L"SystemRoot"))
|
|
|
|
{
|
|
|
|
tmp += L"\\System32";
|
|
|
|
if (ExpandedFilename.GetLength() >= tmp.GetLength() &&
|
|
|
|
ExpandedFilename.Left(tmp.GetLength()).MakeLower() == tmp.MakeLower())
|
|
|
|
{
|
|
|
|
ACDBG(L"Ignoring System32: %s\r\n", (PCWSTR)ExpandedFilename);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
tmp.GetEnvironmentVariable(L"SystemRoot");
|
|
|
|
tmp += L"\\WinSxs";
|
|
|
|
if (ExpandedFilename.GetLength() >= tmp.GetLength() &&
|
|
|
|
ExpandedFilename.Left(tmp.GetLength()).MakeLower() == tmp.MakeLower())
|
|
|
|
{
|
|
|
|
ACDBG(L"Ignoring WinSxs: %s\r\n", (PCWSTR)ExpandedFilename);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
for (size_t n = 0; g_AllowedExtensions[n]; ++n)
|
|
|
|
{
|
|
|
|
if (!wcsicmp(g_AllowedExtensions[n], pwszExt))
|
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
m_Filename = ExpandedFilename;
|
|
|
|
ACDBG(L"Got: %s\r\n", (PCWSTR)ExpandedFilename);
|
2016-04-09 21:40:32 +00:00
|
|
|
m_IsSfcProtected = SfcIsFileProtected(NULL, m_Filename);
|
2017-04-22 17:11:52 +00:00
|
|
|
m_AllowPermLayer = AllowPermLayer(ExpandedFilename);
|
2016-04-09 21:40:32 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ACDBG(L"Extension not included: '%s'\r\n", pwszExt);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2017-04-22 17:11:52 +00:00
|
|
|
static BOOL GetLayerInfo(PCWSTR Filename, DWORD QueryFlags, PDWORD OSMode, PDWORD Enabledlayers, CSimpleArray<CString>& customLayers)
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
|
|
|
WCHAR wszLayers[MAX_LAYER_LENGTH] = { 0 };
|
|
|
|
DWORD dwBytes = sizeof(wszLayers);
|
2017-04-22 17:11:52 +00:00
|
|
|
|
|
|
|
*OSMode = *Enabledlayers = 0;
|
|
|
|
customLayers.RemoveAll();
|
2016-04-09 21:40:32 +00:00
|
|
|
if (!SdbGetPermLayerKeys(Filename, wszLayers, &dwBytes, QueryFlags))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (PWCHAR Layer = wcstok(wszLayers, L" "); Layer; Layer = wcstok(NULL, L" "))
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
for (n = 0; g_Layers[n].Name; ++n)
|
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
if (!wcsicmp(g_Layers[n].Name, Layer))
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
|
|
|
*Enabledlayers |= (1<<n);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-04-22 17:11:52 +00:00
|
|
|
/* Did we find it? */
|
|
|
|
if (g_Layers[n].Name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (n = 0; g_CompatModes[n].Name; ++n)
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
if (!wcsicmp(g_CompatModes[n].Name, Layer))
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
*OSMode = n+1;
|
|
|
|
break;
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-22 17:11:52 +00:00
|
|
|
/* Did we find it? */
|
|
|
|
if (g_CompatModes[n].Name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Must be a 'custom' layer */
|
|
|
|
customLayers.Add(Layer);
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
int CLayerUIPropPage::OnSetActive()
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
if (!GetLayerInfo(m_Filename, m_LayerQueryFlags, &m_RegistryOSMode, &m_RegistryEnabledLayers, m_RegistryCustomLayers))
|
2016-04-09 21:40:32 +00:00
|
|
|
m_RegistryOSMode = m_RegistryEnabledLayers = 0;
|
|
|
|
|
|
|
|
for (size_t n = 0; g_Layers[n].Name; ++n)
|
2017-10-23 15:56:57 +00:00
|
|
|
CheckDlgButton(g_Layers[n].Id, (m_RegistryEnabledLayers & (1<<n)) ? BST_CHECKED : BST_UNCHECKED);
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
CheckDlgButton(IDC_CHKRUNCOMPATIBILITY, m_RegistryOSMode ? BST_CHECKED : BST_UNCHECKED);
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
if (m_RegistryOSMode)
|
2017-10-23 15:56:57 +00:00
|
|
|
ComboBox_SetCurSel(GetDlgItem(IDC_COMPATIBILITYMODE), m_RegistryOSMode-1);
|
2017-04-22 17:11:52 +00:00
|
|
|
|
|
|
|
m_CustomLayers = m_RegistryCustomLayers;
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
UpdateControls();
|
|
|
|
|
|
|
|
return 0;
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 17:11:52 +00:00
|
|
|
|
|
|
|
static BOOL ArrayEquals(const CSimpleArray<CString>& lhs, const CSimpleArray<CString>& rhs)
|
|
|
|
{
|
|
|
|
if (lhs.GetSize() != rhs.GetSize())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (int n = 0; n < lhs.GetSize(); ++n)
|
|
|
|
{
|
|
|
|
if (lhs[n] != rhs[n])
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CLayerUIPropPage::HasChanges() const
|
|
|
|
{
|
|
|
|
if (m_RegistryEnabledLayers != m_EnabledLayers)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (m_RegistryOSMode != m_OSMode)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!ArrayEquals(m_RegistryCustomLayers, m_CustomLayers))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
int CLayerUIPropPage::OnApply()
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
if (HasChanges())
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
|
|
|
BOOL bMachine = m_LayerQueryFlags == GPLK_MACHINE;
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
for (size_t n = 0; g_CompatModes[n].Name; ++n)
|
|
|
|
SetPermLayerState(m_Filename, g_CompatModes[n].Name, 0, bMachine, (n+1) == m_OSMode);
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
for (size_t n = 0; g_Layers[n].Name; ++n)
|
|
|
|
{
|
2017-04-22 17:11:52 +00:00
|
|
|
SetPermLayerState(m_Filename, g_Layers[n].Name, 0, bMachine, ((1<<n) & m_EnabledLayers) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable all old values */
|
|
|
|
for (int j = 0; j < m_RegistryCustomLayers.GetSize(); j++)
|
|
|
|
{
|
|
|
|
SetPermLayerState(m_Filename, m_RegistryCustomLayers[j].GetString(), 0, bMachine, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable all new values */
|
|
|
|
for (int j = 0; j < m_CustomLayers.GetSize(); j++)
|
|
|
|
{
|
|
|
|
SetPermLayerState(m_Filename, m_CustomLayers[j].GetString(), 0, bMachine, TRUE);
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
2017-04-22 17:11:52 +00:00
|
|
|
|
|
|
|
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATHW, (PCWSTR)m_Filename, NULL);
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
2017-10-23 15:56:57 +00:00
|
|
|
|
|
|
|
return PSNRET_NOERROR;
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
LRESULT CLayerUIPropPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
HWND cboMode = GetDlgItem(IDC_COMPATIBILITYMODE);
|
2016-04-09 21:40:32 +00:00
|
|
|
for (size_t n = 0; g_CompatModes[n].Display; ++n)
|
|
|
|
ComboBox_AddString(cboMode, g_CompatModes[n].Display);
|
|
|
|
ComboBox_SetCurSel(cboMode, 5);
|
|
|
|
|
|
|
|
CComBSTR explanation;
|
|
|
|
if (!m_AllowPermLayer)
|
|
|
|
{
|
|
|
|
explanation.LoadString(g_hModule, IDS_FAILED_NETWORK);
|
2017-10-23 15:56:57 +00:00
|
|
|
DisableControls();
|
2016-04-09 21:40:32 +00:00
|
|
|
ACDBG(L"AllowPermLayer returned FALSE\r\n");
|
|
|
|
}
|
|
|
|
else if (m_IsSfcProtected)
|
|
|
|
{
|
|
|
|
explanation.LoadString(g_hModule, IDS_FAILED_PROTECTED);
|
2017-10-23 15:56:57 +00:00
|
|
|
DisableControls();
|
2016-04-09 21:40:32 +00:00
|
|
|
ACDBG(L"Protected OS file\r\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-10-23 15:56:57 +00:00
|
|
|
SetDlgItemTextW(IDC_EXPLANATION, explanation);
|
2016-04-09 21:40:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
INT_PTR CLayerUIPropPage::DisableControls()
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
::EnableWindow(GetDlgItem(IDC_COMPATIBILITYMODE), 0);
|
|
|
|
::EnableWindow(GetDlgItem(IDC_CHKRUNCOMPATIBILITY), 0);
|
2016-04-09 21:40:32 +00:00
|
|
|
for (size_t n = 0; g_Layers[n].Name; ++n)
|
2017-10-23 15:56:57 +00:00
|
|
|
::EnableWindow(GetDlgItem(g_Layers[n].Id), 0);
|
|
|
|
::EnableWindow(GetDlgItem(IDC_EDITCOMPATIBILITYMODES), 0);
|
2016-04-09 21:40:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
void CLayerUIPropPage::UpdateControls()
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
|
|
|
m_OSMode = 0, m_EnabledLayers = 0;
|
2017-10-23 15:56:57 +00:00
|
|
|
BOOL ModeEnabled = IsDlgButtonChecked(IDC_CHKRUNCOMPATIBILITY);
|
2016-04-09 21:40:32 +00:00
|
|
|
if (ModeEnabled)
|
2017-10-23 15:56:57 +00:00
|
|
|
m_OSMode = ComboBox_GetCurSel(GetDlgItem(IDC_COMPATIBILITYMODE))+1;
|
|
|
|
::EnableWindow(GetDlgItem(IDC_COMPATIBILITYMODE), ModeEnabled);
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
for (size_t n = 0; g_Layers[n].Name; ++n)
|
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
m_EnabledLayers |= IsDlgButtonChecked(g_Layers[n].Id) ? (1<<n) : 0;
|
|
|
|
::ShowWindow(GetDlgItem(g_Layers[n].Id), SW_SHOW);
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2018-01-29 16:57:19 +00:00
|
|
|
CStringW customLayers;
|
|
|
|
for (int j = 0; j < m_CustomLayers.GetSize(); ++j)
|
|
|
|
{
|
|
|
|
if (j > 0)
|
|
|
|
customLayers += L", ";
|
|
|
|
customLayers += m_CustomLayers[j];
|
|
|
|
}
|
|
|
|
SetDlgItemTextW(IDC_ENABLED_LAYERS, customLayers);
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
SetModified(HasChanges());
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
LRESULT CLayerUIPropPage::OnCtrlCommand(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
UpdateControls();
|
|
|
|
return 0;
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
LRESULT CLayerUIPropPage::OnEditModes(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
|
2016-04-09 21:40:32 +00:00
|
|
|
{
|
2018-01-27 17:10:50 +00:00
|
|
|
if (DialogBoxParamW(g_hModule, MAKEINTRESOURCEW(IDD_EDITCOMPATIBILITYMODES), m_hWnd, EditModesProc, (LPARAM)this) == IDOK)
|
2017-10-23 15:56:57 +00:00
|
|
|
UpdateControls();
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-09 21:40:32 +00:00
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
LRESULT CLayerUIPropPage::OnClickNotify(INT uCode, LPNMHDR hdr, BOOL& bHandled)
|
|
|
|
{
|
|
|
|
if (hdr->idFrom == IDC_INFOLINK)
|
|
|
|
ShellExecute(NULL, L"open", L"https://www.reactos.org/forum/viewforum.php?f=4", NULL, NULL, SW_SHOW);
|
|
|
|
return 0;
|
2016-04-09 21:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 17:11:52 +00:00
|
|
|
static void ListboxChanged(HWND hWnd)
|
|
|
|
{
|
|
|
|
int Sel = ListBox_GetCurSel(GetDlgItem(hWnd, IDC_COMPATIBILITYMODE));
|
|
|
|
EnableWindow(GetDlgItem(hWnd, IDC_EDIT), Sel >= 0);
|
|
|
|
EnableWindow(GetDlgItem(hWnd, IDC_DELETE), Sel >= 0);
|
|
|
|
}
|
|
|
|
|
2017-07-16 13:47:16 +00:00
|
|
|
static void OnAdd(HWND hWnd)
|
|
|
|
{
|
|
|
|
HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
|
|
|
|
|
|
|
|
int Length = ComboBox_GetTextLength(Combo);
|
|
|
|
CComBSTR Str(Length);
|
|
|
|
ComboBox_GetText(Combo, Str, Length+1);
|
|
|
|
HWND List = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
|
|
|
|
int Index = ListBox_FindStringExact(List, -1, Str);
|
|
|
|
if (Index == LB_ERR)
|
|
|
|
Index = ListBox_AddString(List, Str);
|
|
|
|
ListBox_SetCurSel(List, Index);
|
|
|
|
ListboxChanged(hWnd);
|
2017-07-30 12:46:53 +00:00
|
|
|
ComboBox_SetCurSel(Combo, -1);
|
2017-07-16 13:47:16 +00:00
|
|
|
SetFocus(Combo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL ComboHasData(HWND hWnd)
|
|
|
|
{
|
|
|
|
HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
|
|
|
|
if (ComboBox_GetCurSel(Combo) >= 0)
|
|
|
|
return TRUE;
|
|
|
|
ULONG Len = ComboBox_GetTextLength(Combo);
|
|
|
|
return Len > 0;
|
|
|
|
}
|
|
|
|
|
2017-04-22 17:11:52 +00:00
|
|
|
INT_PTR CALLBACK CLayerUIPropPage::EditModesProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
CLayerUIPropPage* page = NULL;
|
2017-07-16 13:47:16 +00:00
|
|
|
|
2017-04-22 17:11:52 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
page = (CLayerUIPropPage*)lParam;
|
|
|
|
page->AddRef();
|
2017-10-23 15:56:57 +00:00
|
|
|
::SetProp(hWnd, ACP_WNDPROP, page);
|
2017-04-22 17:11:52 +00:00
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
HWND Combo = ::GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
|
2017-07-16 13:47:16 +00:00
|
|
|
CComObject<CLayerStringList> pList;
|
|
|
|
|
|
|
|
while (TRUE)
|
2017-04-22 17:11:52 +00:00
|
|
|
{
|
2017-09-22 19:42:08 +00:00
|
|
|
CComHeapPtr<OLECHAR> str;
|
2017-07-16 13:47:16 +00:00
|
|
|
HRESULT hr = pList.Next(1, &str, NULL);
|
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
ComboBox_AddString(Combo, str);
|
2017-04-22 17:11:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
|
2017-04-22 17:11:52 +00:00
|
|
|
for (int n = 0; n < page->m_CustomLayers.GetSize(); ++n)
|
|
|
|
{
|
|
|
|
const WCHAR* Str = page->m_CustomLayers[n].GetString();
|
|
|
|
int Index = ListBox_FindStringExact(List, -1, Str);
|
|
|
|
if (Index == LB_ERR)
|
|
|
|
Index = ListBox_AddString(List, Str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_ENDSESSION:
|
|
|
|
case WM_DESTROY:
|
2017-10-23 15:56:57 +00:00
|
|
|
page = (CLayerUIPropPage*)::GetProp(hWnd, ACP_WNDPROP);
|
|
|
|
::RemoveProp(hWnd, ACP_WNDPROP);
|
2017-04-22 17:11:52 +00:00
|
|
|
page->Release();
|
|
|
|
break;
|
2017-07-16 13:47:16 +00:00
|
|
|
|
2017-04-22 17:11:52 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDC_ADD:
|
2017-07-16 13:47:16 +00:00
|
|
|
OnAdd(hWnd);
|
2017-04-22 17:11:52 +00:00
|
|
|
break;
|
|
|
|
case IDC_EDIT:
|
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
|
2017-04-22 17:11:52 +00:00
|
|
|
int Cur = ListBox_GetCurSel(List);
|
|
|
|
int Length = ListBox_GetTextLen(List, Cur);
|
|
|
|
CComBSTR Str(Length);
|
|
|
|
ListBox_GetText(List, Cur, Str);
|
|
|
|
ListBox_DeleteString(List, Cur);
|
2017-10-23 15:56:57 +00:00
|
|
|
HWND Combo = ::GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
|
2017-07-30 12:46:53 +00:00
|
|
|
ComboBox_SetCurSel(Combo, -1);
|
2017-10-23 15:56:57 +00:00
|
|
|
::SetWindowText(Combo,Str);
|
2017-04-22 17:11:52 +00:00
|
|
|
ListboxChanged(hWnd);
|
2017-07-16 13:47:16 +00:00
|
|
|
ComboBox_SetEditSel(Combo, 30000, 30000);
|
2017-10-23 15:56:57 +00:00
|
|
|
::SetFocus(Combo);
|
2017-04-22 17:11:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_DELETE:
|
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
|
2017-04-22 17:11:52 +00:00
|
|
|
ListBox_DeleteString(List, ListBox_GetCurSel(List));
|
|
|
|
ListboxChanged(hWnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDC_COMPATIBILITYMODE:
|
|
|
|
ListboxChanged(hWnd);
|
|
|
|
break;
|
|
|
|
case IDC_NEWCOMPATIBILITYMODE:
|
2017-07-16 13:47:16 +00:00
|
|
|
{
|
2017-10-23 15:56:57 +00:00
|
|
|
::EnableWindow(::GetDlgItem(hWnd, IDC_ADD), ComboHasData(hWnd));
|
2017-07-16 13:47:16 +00:00
|
|
|
}
|
2017-04-22 17:11:52 +00:00
|
|
|
break;
|
|
|
|
case IDOK:
|
|
|
|
/* Copy from list! */
|
|
|
|
{
|
2017-07-16 13:47:16 +00:00
|
|
|
if (ComboHasData(hWnd))
|
|
|
|
{
|
|
|
|
CComBSTR question, title;
|
2018-01-27 17:10:50 +00:00
|
|
|
title.LoadString(g_hModule, IDS_COMPAT_TITLE);
|
2017-07-16 13:47:16 +00:00
|
|
|
question.LoadString(g_hModule, IDS_YOU_DID_NOT_ADD);
|
2017-10-23 15:56:57 +00:00
|
|
|
int result = ::MessageBoxW(hWnd, question, title, MB_YESNOCANCEL | MB_ICONQUESTION);
|
2017-07-16 13:47:16 +00:00
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case IDYES:
|
|
|
|
OnAdd(hWnd);
|
|
|
|
break;
|
|
|
|
case IDNO:
|
|
|
|
break;
|
|
|
|
case IDCANCEL:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
page = (CLayerUIPropPage*)::GetProp(hWnd, ACP_WNDPROP);
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2017-10-23 15:56:57 +00:00
|
|
|
HWND List = ::GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
|
2017-04-22 17:11:52 +00:00
|
|
|
int Count = ListBox_GetCount(List);
|
|
|
|
page->m_CustomLayers.RemoveAll();
|
|
|
|
for (int Cur = 0; Cur < Count; ++Cur)
|
|
|
|
{
|
|
|
|
int Length = ListBox_GetTextLen(List, Cur);
|
|
|
|
CString Str;
|
|
|
|
LPWSTR Buffer = Str.GetBuffer(Length + 1);
|
|
|
|
ListBox_GetText(List, Cur, Buffer);
|
|
|
|
Str.ReleaseBuffer(Length);
|
|
|
|
page->m_CustomLayers.Add(Str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Fall trough */
|
|
|
|
case IDCANCEL:
|
2017-10-23 15:56:57 +00:00
|
|
|
::EndDialog(hWnd, LOWORD(wParam));
|
2017-04-22 17:11:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_CLOSE:
|
2017-10-23 15:56:57 +00:00
|
|
|
::EndDialog(hWnd, IDCANCEL);
|
2017-04-22 17:11:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-01 11:37:44 +00:00
|
|
|
static BOOL DisableShellext()
|
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
LSTATUS ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\AppCompat", 0, KEY_QUERY_VALUE, &hkey);
|
|
|
|
BOOL Disable = FALSE;
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DWORD dwValue = 0;
|
|
|
|
DWORD type, size = sizeof(dwValue);
|
|
|
|
ret = RegQueryValueExW(hkey, L"DisableEngine", NULL, &type, (PBYTE)&dwValue, &size);
|
|
|
|
if (ret == ERROR_SUCCESS && type == REG_DWORD)
|
|
|
|
{
|
|
|
|
Disable = !!dwValue;
|
|
|
|
}
|
|
|
|
if (!Disable)
|
|
|
|
{
|
|
|
|
size = sizeof(dwValue);
|
|
|
|
ret = RegQueryValueExW(hkey, L"DisablePropPage", NULL, &type, (PBYTE)&dwValue, &size);
|
|
|
|
if (ret == ERROR_SUCCESS && type == REG_DWORD)
|
|
|
|
{
|
|
|
|
Disable = !!dwValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
return Disable;
|
|
|
|
}
|
2017-04-22 17:11:52 +00:00
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
STDMETHODIMP CLayerUIPropPage::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hkeyProgID)
|
|
|
|
{
|
|
|
|
FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
|
|
|
STGMEDIUM stg;
|
2017-07-01 11:37:44 +00:00
|
|
|
|
|
|
|
if (DisableShellext())
|
|
|
|
return E_ACCESSDENIED;
|
|
|
|
|
2016-04-09 21:40:32 +00:00
|
|
|
HRESULT hr = pDataObj->GetData(&etc, &stg);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ACDBG(L"Failed to retrieve Data from pDataObj.\r\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
hr = E_FAIL;
|
|
|
|
HDROP hdrop = (HDROP)GlobalLock(stg.hGlobal);
|
|
|
|
if (hdrop)
|
|
|
|
{
|
|
|
|
UINT uNumFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, NULL, 0);
|
|
|
|
if (uNumFiles == 1)
|
|
|
|
{
|
|
|
|
WCHAR szFile[MAX_PATH * 2];
|
|
|
|
if (DragQueryFileW(hdrop, 0, szFile, _countof(szFile)))
|
|
|
|
{
|
|
|
|
this->AddRef();
|
|
|
|
hr = InitFile(szFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ACDBG(L"Failed to query the file.\r\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ACDBG(L"Invalid number of files: %d\r\n", uNumFiles);
|
|
|
|
}
|
|
|
|
GlobalUnlock(stg.hGlobal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ACDBG(L"Could not lock stg.hGlobal\r\n");
|
|
|
|
}
|
|
|
|
ReleaseStgMedium(&stg);
|
|
|
|
return hr;
|
|
|
|
}
|