calibre portable: Add launchers for standalone viewer and editor

This commit is contained in:
Kovid Goyal 2020-07-19 15:14:56 +05:30
parent 9d31105ad0
commit 1b9318e01b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 40 additions and 20 deletions

View File

@ -313,14 +313,16 @@ def extract_pyd_modules(env, site_packages_dir):
def embed_resources(env, module, desc=None, extra_data=None, product_description=None): def embed_resources(env, module, desc=None, extra_data=None, product_description=None):
icon_base = j(env.src_root, 'icons') icon_base = j(env.src_root, 'icons')
icon_map = {'calibre': 'library', 'ebook-viewer': 'viewer', 'ebook-edit': 'ebook-edit', icon_map = {
'lrfviewer': 'viewer', 'calibre-portable': 'library'} 'calibre': 'library', 'ebook-viewer': 'viewer', 'ebook-edit': 'ebook-edit',
'lrfviewer': 'viewer',
}
file_type = 'DLL' if module.endswith('.dll') else 'APP' file_type = 'DLL' if module.endswith('.dll') else 'APP'
with open(env.rc_template, 'rb') as f: with open(env.rc_template, 'rb') as f:
template = f.read().decode('utf-8') template = f.read().decode('utf-8')
bname = b(module) bname = b(module)
internal_name = os.path.splitext(bname)[0] internal_name = os.path.splitext(bname)[0]
icon = icon_map.get(internal_name, 'command-prompt') icon = icon_map.get(internal_name.replace('-portable', ''), 'command-prompt')
if internal_name.startswith('calibre-portable-'): if internal_name.startswith('calibre-portable-'):
icon = 'install' icon = 'install'
icon = j(icon_base, icon + '.ico') icon = j(icon_base, icon + '.ico')
@ -415,18 +417,23 @@ def build_portable(env):
obj = j(env.obj_dir, b(src) + '.obj') obj = j(env.obj_dir, b(src) + '.obj')
cflags = '/c /EHsc /MT /W3 /Ox /nologo /D_UNICODE /DUNICODE'.split() cflags = '/c /EHsc /MT /W3 /Ox /nologo /D_UNICODE /DUNICODE'.split()
printf('Compiling', obj) for exe_name in ('calibre.exe', 'ebook-viewer.exe', 'ebook-edit.exe'):
cmd = [CL] + cflags + ['/Fo' + obj, '/Tc' + src] exe = j(base, exe_name.replace('.exe', '-portable.exe'))
printf('Compiling', exe)
cmd = [CL] + cflags + ['/DEXE_NAME="%s"' % exe_name, '/Fo' + obj, '/Tc' + src]
run_compiler(env, *cmd) run_compiler(env, *cmd)
exe = j(base, 'calibre-portable.exe')
printf('Linking', exe) printf('Linking', exe)
desc = {
'calibre.exe': 'Calibre Portable',
'ebook-viewer.exe': 'Calibre Portable Viewer',
'ebook-edit.exe': 'Calibre Portable Editor'
}[exe_name]
cmd = [LINK] + [ cmd = [LINK] + [
'/INCREMENTAL:NO', '/MACHINE:' + machine, '/INCREMENTAL:NO', '/MACHINE:' + machine,
'/LIBPATH:' + env.obj_dir, '/SUBSYSTEM:WINDOWS', '/LIBPATH:' + env.obj_dir, '/SUBSYSTEM:WINDOWS',
'/RELEASE', '/RELEASE',
'/ENTRY:wWinMainCRTStartup', '/ENTRY:wWinMainCRTStartup',
'/OUT:' + exe, embed_resources(env, exe, desc='Calibre Portable', product_description='Calibre Portable'), '/OUT:' + exe, embed_resources(env, exe, desc=desc, product_description=desc),
obj, 'User32.lib'] obj, 'User32.lib']
run(*cmd) run(*cmd)

View File

@ -407,6 +407,16 @@ static BOOL move_program() {
show_last_error(L"Failed to move calibre-portable.exe, make sure calibre is not running"); show_last_error(L"Failed to move calibre-portable.exe, make sure calibre is not running");
return false; return false;
} }
if (MoveFileEx(L"Calibre Portable\\ebook-viewer-portable.exe",
L"..\\ebook-viewer-portable.exe", MOVEFILE_REPLACE_EXISTING) == 0) {
show_last_error(L"Failed to move ebook-viewer-portable.exe, make sure calibre is not running");
return false;
}
if (MoveFileEx(L"Calibre Portable\\ebook-edit-portable.exe",
L"..\\ebook-edit-portable.exe", MOVEFILE_REPLACE_EXISTING) == 0) {
show_last_error(L"Failed to move ebook-edit-portable.exe, make sure calibre is not running");
return false;
}
if (directory_exists(L"..\\Calibre")) { if (directory_exists(L"..\\Calibre")) {
if (!rmtree(L"..\\Calibre")) { if (!rmtree(L"..\\Calibre")) {

View File

@ -148,7 +148,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
exe = (LPTSTR)calloc(BUFSIZE, sizeof(TCHAR)); exe = (LPTSTR)calloc(BUFSIZE, sizeof(TCHAR));
_sntprintf_s(config_dir, BUFSIZE, _TRUNCATE, _T("%sCalibre Settings"), app_dir); _sntprintf_s(config_dir, BUFSIZE, _TRUNCATE, _T("%sCalibre Settings"), app_dir);
_sntprintf_s(exe, BUFSIZE, _TRUNCATE, _T("%sCalibre\\calibre.exe"), app_dir); _sntprintf_s(exe, BUFSIZE, _TRUNCATE, _T("%sCalibre\\%s"), app_dir, _T(EXE_NAME));
launch_calibre(exe, config_dir); launch_calibre(exe, config_dir);

View File

@ -331,8 +331,11 @@ def decode(cfi, doc):
node = q node = q
cfi = cfi.substr(r[0].length) cfi = cfi.substr(r[0].length)
else: else:
if target:
error = "No matching child found for CFI: " + cfi error = "No matching child found for CFI: " + cfi
break break
else:
cfi = cfi.substr(r[0].length)
else if cfi[0] is '!': # Indirection else if cfi[0] is '!': # Indirection
if node.contentDocument: if node.contentDocument:
node = node.contentDocument node = node.contentDocument