Fixes updatecheck on Windows Vista to correctly attempt to execute its Install functionality even in the case of UAC.

cusax-fix
Lyubomir Marinov 17 years ago
parent e310300318
commit df9062d893

@ -345,8 +345,8 @@
depends="clean-install-windows,version">
<!--
This versionupdate.properties isn't of interest to be MSI but is
necessary for the site
This versionupdate.properties file isn't of interest to the MSI but
is necessary for the site.
-->
<propertyfile file="${windows.app.dir}/versionupdate.properties">
<entry key="last_version" value="${sip-communicator.version}" />
@ -357,7 +357,7 @@
<!--
Prepare for the execution of heat.exe (which is part of the
preparation for the execution of candle.exe)
preparation for the execution of candle.exe).
-->
<property name="light.dir" value="${windows.app.dir}/tmp/light" />
@ -367,7 +367,7 @@
<include name="run.bat" />
<include name="run.exe" />
<include name="sc-logo.ico" />
<include name="updater.exe" />
<include name="up2date.exe" />
</fileset>
</copy>
<mkdir dir="${light.dir}/lib" />
@ -413,8 +413,8 @@
</copy>
<!--
This versionupdate.properties is the only of interest to the MSI
i.e. it gets installed on the user machine.
This versionupdate.properties file is the only of interest to the
MSI i.e. it gets installed on the user machine.
-->
<copy
file="${inst.resrc}/windows/versionupdate.properties"

@ -0,0 +1,195 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
#include <windows.h>
#include <shellapi.h> /* ShellExecute */
#include <stdlib.h>
#include <string.h>
#include <tchar.h> /* _istspace */
#ifndef ERROR_ELEVATION_REQUIRED
#define ERROR_ELEVATION_REQUIRED 740
#endif
#ifndef _tcsncicmp
#ifdef _UNICODE
#define _tcsncicmp _wcsnicmp
#else
#define _tcsncicmp _strnicmp
#endif
#endif
DWORD up2date_createProcess(LPCTSTR);
DWORD up2date_displayError(DWORD error);
LPTSTR up2date_getAllowElevation(LPTSTR, BOOL *);
DWORD up2date_getExePath(LPTSTR, DWORD);
LPTSTR up2date_skipWhitespace(LPTSTR);
LPTSTR up2date_str2tstr(LPCSTR);
int WINAPI
WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine, int cmdShow) {
LPTSTR commandLine;
commandLine = up2date_str2tstr(cmdLine);
if (commandLine) {
BOOL allowElevation;
LPTSTR noAllowElevationCommandLine;
DWORD error;
allowElevation = FALSE;
noAllowElevationCommandLine
= up2date_getAllowElevation(commandLine, &allowElevation);
error = up2date_createProcess(noAllowElevationCommandLine);
if ((ERROR_ELEVATION_REQUIRED == error) && allowElevation) {
TCHAR exePath[MAX_PATH + 1];
if (!up2date_getExePath(exePath, MAX_PATH + 1)) {
ShellExecute(NULL, TEXT("runas"), exePath,
noAllowElevationCommandLine, NULL, SW_SHOWDEFAULT);
}
} else if (error)
up2date_displayError(error);
if (((LPVOID) commandLine) != ((LPVOID) cmdLine))
free(commandLine);
}
return 0;
}
DWORD
up2date_createProcess(LPCTSTR commandLine) {
LPWSTR *argv;
int argc;
DWORD error;
argv = CommandLineToArgvW(commandLine, &argc);
if (argv) {
switch (argc) {
case 2:
if (!SetEnvironmentVariable(
TEXT("SIP_COMMUNICATOR_AUTOUPDATE_INSTALLDIR"),
*(argv + 1))) {
error = GetLastError();
break;
}
case 1: {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
error
= CreateProcess(NULL, *argv, NULL, NULL, FALSE, 0, NULL,
NULL, &si, &pi)
? 0
: GetLastError();
}
break;
default:
error = 0;
break;
}
LocalFree((HLOCAL) argv);
} else
error = GetLastError();
return error;
}
DWORD
up2date_displayError(DWORD error) {
LPTSTR message;
DWORD ret;
if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
0,
error,
0,
(LPTSTR) &message,
0,
NULL)) {
TCHAR caption[MAX_PATH + 1];
MessageBox(
NULL,
message,
up2date_getExePath(caption, MAX_PATH + 1) ? NULL : caption,
MB_ICONERROR);
LocalFree((HLOCAL) message);
ret = 0;
} else
ret = GetLastError();
return ret;
}
LPTSTR
up2date_getAllowElevation(LPTSTR commandLine, BOOL *allowElevation) {
LPCTSTR argName = TEXT("--allow-elevation");
size_t argNameLength = _tcslen(argName);
BOOL argValue;
commandLine = up2date_skipWhitespace(commandLine);
if (0 == _tcsncicmp(commandLine, argName, argNameLength)) {
argValue = TRUE;
commandLine
= up2date_skipWhitespace(commandLine + argNameLength);
} else
argValue = FALSE;
if (allowElevation)
*allowElevation = argValue;
return commandLine;
}
DWORD
up2date_getExePath(LPTSTR exePath, DWORD exePathSize) {
return
GetModuleFileName(NULL, (LPTSTR) exePath, exePathSize)
? 0
: GetLastError();
}
LPTSTR
up2date_skipWhitespace(LPTSTR str) {
TCHAR ch;
while ((ch = *str) && _istspace(ch))
++str;
return str;
}
LPTSTR
up2date_str2tstr(LPCSTR str) {
LPTSTR tstr;
#ifdef UNICODE
int tstrSize;
tstrSize =
MultiByteToWideChar(CP_THREAD_ACP, 0, str, -1, NULL, 0);
if (tstrSize) {
tstr = (LPTSTR) malloc(tstrSize * sizeof(TCHAR));
if (tstr) {
tstrSize
= MultiByteToWideChar(CP_THREAD_ACP, 0, str, -1, tstr, tstrSize);
if (!tstrSize) {
free(tstr);
tstr = NULL;
}
} else
tstr = NULL;
} else
tstr = NULL;
#else
tstr = str;
#endif
return tstr;
}

@ -1,37 +0,0 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
#include <windows.h>
#include <stdio.h>
int main(int argc, char **argv)
{
// Local variables
PROCESS_INFORMATION pi;
STARTUPINFO si;
// Argument count
if (argc != 2)
return EXIT_FAILURE;
// Initialize
memset(&si,0,sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
// Execute
if(!CreateProcess(NULL, argv[1], NULL, NULL, FALSE, 0, NULL,NULL,&si,&pi)) {
// Failed
//cout << "Could not run the program." << endl;
char msg[255];
DWORD dwError = GetLastError();
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,dwError,0,msg,sizeof(msg),0);
printf("Could not start installer %s\n", msg);
return EXIT_FAILURE;
}
// Finished
return EXIT_SUCCESS;
}

@ -546,12 +546,11 @@ public void run()
= new ProcessBuilder(
new String[]
{
workingDir + File.separator + "updater.exe",
temp.getCanonicalPath()
workingDir + File.separator + "up2date.exe",
"--allow-elevation",
temp.getCanonicalPath(),
workingDir
});
processBuilder.environment().put(
"SIP_COMMUNICATOR_AUTOUPDATE_INSTALLDIR",
workingDir);
processBuilder.start();
getUIService().beginShutdown();

Loading…
Cancel
Save