From e87a34d32ed7cbde702b60950908e218b64781b8 Mon Sep 17 00:00:00 2001 From: Li Fanxi Date: Wed, 15 Dec 2010 23:34:46 +0800 Subject: [PATCH] [Device] Add Mac OS support --- src/calibre/devices/bambook/driver.py | 2 +- src/calibre/devices/bambook/libbambookcore.py | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/calibre/devices/bambook/driver.py b/src/calibre/devices/bambook/driver.py index a0cbd66bb5..a687d3b88d 100644 --- a/src/calibre/devices/bambook/driver.py +++ b/src/calibre/devices/bambook/driver.py @@ -22,7 +22,7 @@ class BAMBOOK(DeviceConfig, DevicePlugin): name = 'Bambook Device Interface' description = _('Communicate with the Sanda Bambook eBook reader.') author = _('Li Fanxi') - supported_platforms = ['windows', 'linux'] + supported_platforms = ['windows', 'linux', 'osx'] log_packets = False booklist_class = BookList diff --git a/src/calibre/devices/bambook/libbambookcore.py b/src/calibre/devices/bambook/libbambookcore.py index fcd4bf0361..9bae22b83f 100644 --- a/src/calibre/devices/bambook/libbambookcore.py +++ b/src/calibre/devices/bambook/libbambookcore.py @@ -8,19 +8,35 @@ __docformat__ = 'restructuredtext en' Sanda library wrapper ''' -import ctypes, uuid, hashlib +import ctypes, uuid, hashlib, os, sys from threading import Event, Lock -from calibre.constants import iswindows, islinux - +from calibre.constants import iswindows, islinux, isosx +from calibre import load_library + try: + _lib_name = 'libBambookCore' + cdll = ctypes.cdll if iswindows: - text_encoding = 'mbcs' - lib_handle = ctypes.cdll.BambookCore - elif islinux: - text_encoding = 'utf-8' - lib_handle = ctypes.CDLL('libBambookCore.so') + _lib_name = 'BambookCore' + cdll = ctypes.windll + else: + if hasattr(sys, 'frozen') and iswindows: + lp = os.path.join(os.path.dirname(sys.executable), 'DLLs', 'BambookCore.dll') + lib_handle = cdll.LoadLibrary(lp) + elif hasattr(sys, 'frozen_path'): + lp = os.path.join(sys.frozen_path, 'lib', 'libBambookCore.so') + lib_handle = cdll.LoadLibrary(lp) + else: + lib_handle = load_library(_lib_name, cdll) except: lib_handle = None + +if iswindows: + text_encoding = 'mbcs' +elif islinux: + text_encoding = 'utf-8' +elif isosx: + text_encoding = 'utf-8' # Constant DEFAULT_BAMBOOK_IP = '192.168.250.2'