mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Portable installer: Error out if calibre.exe is running
This commit is contained in:
parent
e5e5da661e
commit
95b52a2059
@ -385,7 +385,7 @@ class Win32Freeze(Command, WixMixIn):
|
||||
zf = self.a(self.j('dist', 'calibre-portable-%s.zip.lz'%VERSION))
|
||||
usz = os.path.getsize(zf)
|
||||
def cc(src, obj):
|
||||
cflags = '/c /EHsc /MT /W4 /Ox /nologo /D_UNICODE /DUNICODE'.split()
|
||||
cflags = '/c /EHsc /MT /W4 /Ox /nologo /D_UNICODE /DUNICODE /DPSAPI_VERSION=1'.split()
|
||||
cflags.append(r'/I%s\include'%LZMA)
|
||||
cflags.append('/DUNCOMPRESSED_SIZE=%d'%usz)
|
||||
if self.newer(obj, [src]):
|
||||
@ -414,7 +414,7 @@ class Win32Freeze(Command, WixMixIn):
|
||||
desc='Calibre Portable Installer', extra_data=zf,
|
||||
product_description='Calibre Portable Installer'),
|
||||
xobj, obj, 'User32.lib', 'Shell32.lib', 'easylzma_s.lib',
|
||||
'Ole32.lib', 'Shlwapi.lib', 'Kernel32.lib']
|
||||
'Ole32.lib', 'Shlwapi.lib', 'Kernel32.lib', 'Psapi.lib']
|
||||
self.run_builder(cmd)
|
||||
|
||||
os.remove(zf)
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <Shlobj.h>
|
||||
#include <Shlwapi.h>
|
||||
#include <Shellapi.h>
|
||||
#include <Psapi.h>
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
@ -433,6 +434,39 @@ static BOOL move_program() {
|
||||
}
|
||||
// }}}
|
||||
|
||||
static BOOL ensure_not_running(LPCWSTR dest) {
|
||||
DWORD processes[4096], needed, num;
|
||||
unsigned int i;
|
||||
WCHAR name[4*MAX_PATH] = L"<unknown>";
|
||||
HANDLE h;
|
||||
DWORD len;
|
||||
LPWSTR fname = NULL;
|
||||
|
||||
if ( !EnumProcesses( processes, sizeof(processes), &needed ) ) {
|
||||
return true;
|
||||
}
|
||||
num = needed / sizeof(DWORD);
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
if (processes[i] == 0) continue;
|
||||
h = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, processes[i] );
|
||||
if (h != NULL) {
|
||||
len = GetProcessImageFileNameW(h, name, 4*MAX_PATH);
|
||||
CloseHandle(h);
|
||||
if (len != 0) {
|
||||
name[len] = 0;
|
||||
fname = PathFindFileName(name);
|
||||
if (wcscmp(fname, L"calibre.exe") == 0) {
|
||||
show_error(L"Calibre appears to be running on your computer. Please quit it before trying to install Calibre Portable.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void launch_calibre() {
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
@ -517,6 +551,10 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (existing) {
|
||||
if (!ensure_not_running(fdest)) goto end;
|
||||
}
|
||||
|
||||
// Make a temp dir to unpack into
|
||||
if (!SetCurrentDirectoryW(fdest)) { show_detailed_error(L"Failed to change to unzip directory: ", fdest, 0); goto end; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user