[SYSSETUP]: Code formatting, and exclusively use UNICODE strings.

svn path=/trunk/; revision=71050
This commit is contained in:
Hermès Bélusca-Maïto 2016-03-26 01:43:34 +00:00
parent fcc8dd0c5a
commit 7dc1d07379

View file

@ -28,7 +28,7 @@
#include "precomp.h"
#include <tchar.h>
#include <io.h>
#include <wincon.h>
#include <winnls.h>
#include <winsvc.h>
@ -75,19 +75,16 @@ FatalError(char *pszFmt,...)
static HRESULT
CreateShellLink(
LPCTSTR pszLinkPath,
LPCTSTR pszCmd,
LPCTSTR pszArg,
LPCTSTR pszDir,
LPCTSTR pszIconPath,
int iIconNr,
LPCTSTR pszComment)
LPCWSTR pszLinkPath,
LPCWSTR pszCmd,
LPCWSTR pszArg,
LPCWSTR pszDir,
LPCWSTR pszIconPath,
INT iIconNr,
LPCWSTR pszComment)
{
IShellLink *psl;
IPersistFile *ppf;
#ifndef _UNICODE
WCHAR wszBuf[MAX_PATH];
#endif /* _UNICODE */
HRESULT hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl);
@ -119,14 +116,7 @@ CreateShellLink(
if (SUCCEEDED(hr))
{
#ifdef _UNICODE
hr = ppf->lpVtbl->Save(ppf, pszLinkPath, TRUE);
#else /* _UNICODE */
MultiByteToWideChar(CP_ACP, 0, pszLinkPath, -1, wszBuf, MAX_PATH);
hr = ppf->lpVtbl->Save(ppf, wszBuf, TRUE);
#endif /* _UNICODE */
ppf->lpVtbl->Release(ppf);
}
@ -139,71 +129,69 @@ CreateShellLink(
static BOOL
CreateShortcut(
LPCTSTR pszFolder,
LPCTSTR pszName,
LPCTSTR pszCommand,
LPCTSTR pszDescription,
LPCWSTR pszFolder,
LPCWSTR pszName,
LPCWSTR pszCommand,
LPCWSTR pszDescription,
INT iIconNr,
LPCTSTR pszWorkingDir)
LPCWSTR pszWorkingDir)
{
TCHAR szPath[MAX_PATH];
TCHAR szExeName[MAX_PATH];
TCHAR szWorkingDirBuf[MAX_PATH];
LPTSTR Ptr;
LPTSTR lpFilePart;
WCHAR szPath[MAX_PATH];
WCHAR szExeName[MAX_PATH];
WCHAR szWorkingDirBuf[MAX_PATH];
LPWSTR Ptr;
LPWSTR lpFilePart;
DWORD dwLen;
if (ExpandEnvironmentStrings(pszCommand,
szPath,
sizeof(szPath) / sizeof(szPath[0])) == 0)
if (ExpandEnvironmentStringsW(pszCommand, szPath, ARRAYSIZE(szPath)) == 0)
{
_tcscpy(szPath, pszCommand);
wcscpy(szPath, pszCommand);
}
if ((_taccess(szPath, 0 )) == -1)
if (_waccess(szPath, 0) == -1)
/* Expected error, don't return FALSE */
return TRUE;
dwLen = GetFullPathName(szPath,
sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0]),
dwLen = GetFullPathNameW(szPath,
ARRAYSIZE(szWorkingDirBuf),
szWorkingDirBuf,
&lpFilePart);
if (dwLen != 0 && dwLen <= sizeof(szWorkingDirBuf) / sizeof(szWorkingDirBuf[0]))
if (dwLen != 0 && dwLen <= ARRAYSIZE(szWorkingDirBuf))
{
/* Since those should only be called with (.exe) files,
lpFilePart has not to be NULL */
ASSERT(lpFilePart != NULL);
/* Save the file name */
_tcscpy(szExeName, lpFilePart);
wcscpy(szExeName, lpFilePart);
if (pszWorkingDir == NULL || pszWorkingDir[0] == _T('\0'))
if (pszWorkingDir == NULL || pszWorkingDir[0] == L'\0')
{
/* We're only interested in the path. Cut the file name off.
Also remove the trailing backslash unless the working directory
is only going to be a drive, ie. C:\ */
*(lpFilePart--) = _T('\0');
if (!(lpFilePart - szWorkingDirBuf == 2 && szWorkingDirBuf[1] == _T(':') &&
szWorkingDirBuf[2] == _T('\\')))
*(lpFilePart--) = L'\0';
if (!(lpFilePart - szWorkingDirBuf == 2 && szWorkingDirBuf[1] == L':' &&
szWorkingDirBuf[2] == L'\\'))
{
*lpFilePart = _T('\0');
*lpFilePart = L'\0';
}
pszWorkingDir = szWorkingDirBuf;
}
}
else if (pszWorkingDir && pszWorkingDir[0] == _T('\0'))
else if (pszWorkingDir && pszWorkingDir[0] == L'\0')
{
pszWorkingDir = NULL;
}
_tcscpy(szPath, pszFolder);
wcscpy(szPath, pszFolder);
Ptr = PathAddBackslash(szPath);
_tcscpy(Ptr, pszName);
wcscpy(Ptr, pszName);
// FIXME: we should pass 'command' straight in here, but shell32 doesn't expand it
return SUCCEEDED(CreateShellLink(szPath, szExeName, _T(""), pszWorkingDir, szExeName, iIconNr, pszDescription));
return SUCCEEDED(CreateShellLink(szPath, szExeName, L"", pszWorkingDir, szExeName, iIconNr, pszDescription));
}
@ -226,22 +214,22 @@ static BOOL CreateShortcutsFromSection(HINF hinf, LPWSTR pszSection, LPCWSTR ps
if (dwFieldCount < 4)
continue;
if (!SetupGetStringFieldW(&Context, 1, szCommand, MAX_PATH, NULL))
if (!SetupGetStringFieldW(&Context, 1, szCommand, ARRAYSIZE(szCommand), NULL))
continue;
if (!SetupGetStringFieldW(&Context, 2, szName, MAX_PATH, NULL))
if (!SetupGetStringFieldW(&Context, 2, szName, ARRAYSIZE(szName), NULL))
continue;
if (!SetupGetStringFieldW(&Context, 3, szDescription, MAX_PATH, NULL))
if (!SetupGetStringFieldW(&Context, 3, szDescription, ARRAYSIZE(szDescription), NULL))
continue;
if (!SetupGetIntField(&Context, 4, &iIconNr))
continue;
if (dwFieldCount < 5 || !SetupGetStringFieldW(&Context, 5, szDirectory, MAX_PATH, NULL))
if (dwFieldCount < 5 || !SetupGetStringFieldW(&Context, 5, szDirectory, ARRAYSIZE(szDirectory), NULL))
szDirectory[0] = L'\0';
_tcscat(szName, L".lnk");
wcscat(szName, L".lnk");
CreateShortcut(pszFolder, szName, szCommand, szDescription, iIconNr, szDirectory);
@ -268,13 +256,13 @@ static BOOL CreateShortcuts(HINF hinf, LPCWSTR szSection)
if (SetupGetFieldCount(&Context) < 2)
continue;
if (!SetupGetStringFieldW(&Context, 0, szFolderSection, MAX_PATH, NULL))
if (!SetupGetStringFieldW(&Context, 0, szFolderSection, ARRAYSIZE(szFolderSection), NULL))
continue;
if (!SetupGetIntField(&Context, 1, &csidl))
continue;
if (!SetupGetStringFieldW(&Context, 2, szFolder, MAX_PATH, NULL))
if (!SetupGetStringFieldW(&Context, 2, szFolder, ARRAYSIZE(szFolder), NULL))
continue;
if (FAILED(SHGetFolderPathAndSubDirW(NULL, csidl|CSIDL_FLAG_CREATE, (HANDLE)-1, SHGFP_TYPE_DEFAULT, szFolder, szPath)))
@ -282,7 +270,7 @@ static BOOL CreateShortcuts(HINF hinf, LPCWSTR szSection)
CreateShortcutsFromSection(hinf, szFolderSection, szPath);
}while (SetupFindNextLine(&Context, &Context));
} while (SetupFindNextLine(&Context, &Context));
CoUninitialize();
@ -309,7 +297,7 @@ CreateTempDir(
}
/* Get temp dir */
dwLength = MAX_PATH * sizeof(WCHAR);
dwLength = ARRAYSIZE(szBuffer) * sizeof(WCHAR);
if (RegQueryValueExW(hKey,
VarName,
NULL,
@ -322,9 +310,7 @@ CreateTempDir(
}
/* Expand it */
if (!ExpandEnvironmentStringsW(szBuffer,
szTempDir,
MAX_PATH))
if (!ExpandEnvironmentStringsW(szBuffer, szTempDir, ARRAYSIZE(szTempDir)))
{
FatalError("Error: %lu\n", GetLastError());
goto cleanup;
@ -364,7 +350,7 @@ InstallSysSetupInfDevices(VOID)
if (!SetupGetStringFieldW(&InfContext,
0,
szLineBuffer,
sizeof(szLineBuffer)/sizeof(szLineBuffer[0]),
ARRAYSIZE(szLineBuffer),
&dwLineLength))
{
return FALSE;
@ -402,7 +388,7 @@ InstallSysSetupInfComponents(VOID)
if (!SetupGetStringFieldW(&InfContext,
1, // Get the component name
szNameBuffer,
sizeof(szNameBuffer)/sizeof(szNameBuffer[0]),
ARRAYSIZE(szNameBuffer),
NULL))
{
FatalError("Error while trying to get component name \n");
@ -412,7 +398,7 @@ InstallSysSetupInfComponents(VOID)
if (!SetupGetStringFieldW(&InfContext,
2, // Get the component install section
szSectionBuffer,
sizeof(szSectionBuffer)/sizeof(szSectionBuffer[0]),
ARRAYSIZE(szSectionBuffer),
NULL))
{
FatalError("Error while trying to get component install section \n");
@ -459,7 +445,6 @@ InstallSysSetupInfComponents(VOID)
BOOL
RegisterTypeLibraries (HINF hinf, LPCWSTR szSection)
{
@ -479,7 +464,7 @@ RegisterTypeLibraries (HINF hinf, LPCWSTR szSection)
do
{
/* Get the name of the current type library */
if (!SetupGetStringFieldW(&InfContext, 1, szName, MAX_PATH, NULL))
if (!SetupGetStringFieldW(&InfContext, 1, szName, ARRAYSIZE(szName), NULL))
{
FatalError("SetupGetStringFieldW failed\n");
continue;
@ -496,7 +481,7 @@ RegisterTypeLibraries (HINF hinf, LPCWSTR szSection)
}
p = PathAddBackslash(szPath);
_tcscpy(p, szName);
wcscpy(p, szName);
hmod = LoadLibraryW(szName);
if (hmod == NULL)
@ -507,7 +492,7 @@ RegisterTypeLibraries (HINF hinf, LPCWSTR szSection)
__wine_register_resources(hmod);
}while (SetupFindNextLine(&InfContext, &InfContext));
} while (SetupFindNextLine(&InfContext, &InfContext));
return TRUE;
}
@ -580,7 +565,7 @@ StatusMessageWindowProc(
{
WCHAR szMsg[256];
if (!LoadStringW(hDllInstance, IDS_STATUS_INSTALL_DEV, szMsg, sizeof(szMsg)/sizeof(szMsg[0])))
if (!LoadStringW(hDllInstance, IDS_STATUS_INSTALL_DEV, szMsg, ARRAYSIZE(szMsg)))
return FALSE;
SetDlgItemTextW(hwndDlg, IDC_STATUSLABEL, szMsg);
return TRUE;
@ -597,8 +582,7 @@ ShowStatusMessageThread(
HWND hWnd;
MSG Msg;
hWnd = CreateDialogParam(
hDllInstance,
hWnd = CreateDialogParam(hDllInstance,
MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG),
GetDesktopWindow(),
StatusMessageWindowProc,
@ -664,8 +648,7 @@ IsConsoleBoot(VOID)
BOOL bConsoleBoot = FALSE;
LONG rc;
rc = RegOpenKeyExW(
HKEY_LOCAL_MACHINE,
rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Control",
0,
KEY_QUERY_VALUE,
@ -706,8 +689,7 @@ CommonInstall(VOID)
{
HWND hWnd = NULL;
hSysSetupInf = SetupOpenInfFileW(
L"syssetup.inf",
hSysSetupInf = SetupOpenInfFileW(L"syssetup.inf",
NULL,
INF_STYLE_WIN4,
NULL);
@ -733,14 +715,12 @@ CommonInstall(VOID)
{
HANDLE hThread;
hThread = CreateThread(
NULL,
hThread = CreateThread(NULL,
0,
ShowStatusMessageThread,
(LPVOID)&hWnd,
0,
NULL);
if (hThread)
CloseHandle(hThread);
}
@ -786,7 +766,7 @@ InstallInfSection(
BOOL ret = FALSE;
/* Get Windows directory */
BufferSize = MAX_PATH - 5 - wcslen(InfFile);
BufferSize = ARRAYSIZE(Buffer) - 5 - wcslen(InfFile);
if (GetWindowsDirectoryW(Buffer, BufferSize) > BufferSize)
{
/* Function failed */
@ -820,8 +800,7 @@ InstallInfSection(
}
if (ret && InfService)
{
ret = SetupInstallServicesFromInfSectionW(
hInf, InfService, 0);
ret = SetupInstallServicesFromInfSectionW(hInf, InfService, 0);
}
cleanup:
@ -881,8 +860,7 @@ InstallLiveCD(IN HINSTANCE hInstance)
/* Run the shell */
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
bRes = CreateProcessW(
L"userinit.exe",
bRes = CreateProcessW(L"userinit.exe",
NULL,
NULL,
NULL,
@ -1075,10 +1053,10 @@ InitializeDefaultUserLocale(VOID)
i = 0;
while (LocaleData[i].pValue != NULL)
{
if (GetLocaleInfo(lcid,
if (GetLocaleInfoW(lcid,
LocaleData[i].LCType | LOCALE_NOUSEROVERRIDE,
szBuffer,
sizeof(szBuffer) / sizeof(WCHAR)))
ARRAYSIZE(szBuffer)))
{
RegSetValueExW(hLocaleKey,
LocaleData[i].pValue,
@ -1100,7 +1078,7 @@ DWORD
WINAPI
InstallReactOS(HINSTANCE hInstance)
{
TCHAR szBuffer[MAX_PATH];
WCHAR szBuffer[MAX_PATH];
HANDLE token;
TOKEN_PRIVILEGES privs;
HKEY hKey;
@ -1122,7 +1100,7 @@ InstallReactOS(HINSTANCE hInstance)
InitializeDefaultUserLocale();
if (GetWindowsDirectory(szBuffer, sizeof(szBuffer) / sizeof(TCHAR)))
if (GetWindowsDirectoryW(szBuffer, ARRAYSIZE(szBuffer)))
{
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
@ -1148,7 +1126,7 @@ InstallReactOS(HINSTANCE hInstance)
}
PathAddBackslash(szBuffer);
_tcscat(szBuffer, _T("system"));
wcscat(szBuffer, L"system");
CreateDirectory(szBuffer, NULL);
}
@ -1224,8 +1202,7 @@ InstallReactOS(HINSTANCE hInstance)
FatalError("OpenProcessToken() failed!");
return 0;
}
if (!LookupPrivilegeValue(
NULL,
if (!LookupPrivilegeValue(NULL,
SE_SHUTDOWN_NAME,
&privs.Privileges[0].Luid))
{
@ -1234,8 +1211,7 @@ InstallReactOS(HINSTANCE hInstance)
}
privs.PrivilegeCount = 1;
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (AdjustTokenPrivileges(
token,
if (AdjustTokenPrivileges(token,
FALSE,
&privs,
0,