From 71ec99a021d7945500f6df02f1c58200241e84b1 Mon Sep 17 00:00:00 2001 From: brantje Date: Sun, 7 Aug 2016 13:20:43 +0200 Subject: [PATCH] OS Detection for encrypt lib Fix 32bit check, darwin and linux use the same file Make it a function Check if file exists, if not show error Define file_name first Fix return Check if file exists, if not show error Print info about paths Fix for 32/64bit detection --- pokemongo_bot/__init__.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index c31c1085b3..f60594b8d8 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -28,8 +28,8 @@ from pokemongo_bot.websocket_remote_control import WebsocketRemoteControl from worker_result import WorkerResult from tree_config_builder import ConfigException, MismatchTaskApiVersion, TreeConfigBuilder - - +from sys import platform as _platform +import struct class PokemonGoBot(object): @property def position(self): @@ -591,6 +591,29 @@ def login(self): formatted="Login successful." ) + def get_encryption_lib(self): + file_name = '' + if _platform == "linux" or _platform == "linux2" or _platform == "darwin": + file_name = 'encrypt.so' + elif _platform == "Windows" or _platform == "win32": + # Check if we are on 32 or 64 bit + if sys.maxsize > 2**32: + file_name = 'encrypt_64.dll' + else: + file_name = 'encrypt.dll' + + path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) + full_path = path + '/'+ file_name + + if not os.path.isfile(full_path): + self.logger.error(file_name + ' is not found! Please place it in the bots root directory.') + self.logger.info('Platform: '+ _platform + ' Bot root directory: '+ path) + sys.exit(1) + else: + self.logger.info('Found '+ file_name +'! Platform: ' + _platform + ' Bot root directory: ' + path) + + return full_path + def _setup_api(self): # instantiate pgoapi self.api = ApiWrapper() @@ -602,8 +625,7 @@ def _setup_api(self): # chain subrequests (methods) into one RPC call self._print_character_info() - - self.api.activate_signature("encrypt.so") + self.api.activate_signature(self.get_encryption_lib()) self.logger.info('') self.update_inventory() # send empty map_cells and then our position