diff --git a/setup/installer/windows/freeze.py b/setup/installer/windows/freeze.py index ee021b559e..01f4c115d6 100644 --- a/setup/installer/windows/freeze.py +++ b/setup/installer/windows/freeze.py @@ -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) diff --git a/setup/installer/windows/portable-installer.cpp b/setup/installer/windows/portable-installer.cpp index 714e9e08b1..3c310a1caf 100644 --- a/setup/installer/windows/portable-installer.cpp +++ b/setup/installer/windows/portable-installer.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -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""; + 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; }