def first_time_run(): ''' @summary: 第一次运行的工作 ''' Util.info_print('初始化') Util.info_print('创建resources目录', 1) location = locate.get_resources_folder()[:-1] Util.creat_a_folder(location) Util.info_print('创建lib目录', 1) location = locate.get_lib_folder()[:-1] Util.creat_a_folder(location) if Util.is_file_exists(locate.get_mhw_dinput8_file()): Util.info_print('尝试获取 StrackerLoader-dinput8.dll 的 MD5', 2) dinput8_dll_md5 = Util.get_file_MD5(locate.get_mhw_dinput8_file()) else: dinput8_dll_md5 = "" to_install_VC() Util.info_print('创建conf.ini', 1) print('这次输入的信息会记录在conf.ini中,如果需要更改,用记事本修改conf.ini的内容即可') N_name = input('请输入N网账号或邮箱:') N_pwd = input('请输N网密码:') Conf_ini.creat_new_conf_ini(locate.get_conf_file(), dinput8_dll_md5, N_name, N_pwd)
def get_cookies_by_selenium_login(user_name: str, user_password: str): ''' @summary: 通过selenium获取cookies信息,并记录下来,返回 @return: cookies:dict ''' driver = _init_selenium_driver() if not driver: Util.info_print('尝试初始化浏览器失败', 3) return nexus_cookies = _selenium_operations(driver, user_name, user_password) save_cookies_to_file(nexus_cookies) return nexus_cookies
def downloadFile(url, location): ''' @summary: 下载MOD文件 ''' Util.info_print("开始下载\t", 2) download_head = headers.copy() download_head['Host'] = 'cf-files.nexusmods.com' response = requests.get(url, stream=True, verify=False, headers=download_head, cookies=get_cookies_from_file()) with open(location, 'wb')as f: f.write(response.content) Util.info_print("文件已保存为\t" + location, 3) time.sleep(1)
def init_selenium_driver(): try: Util.info_print('尝试初始化chrome浏览器', 3) return init_selenium_chrome_driver() except Exception as e: print(e) try: Util.info_print('尝试初始化IE浏览器', 3) return init_selenium_ie_driver() except Exception as e: print(e) print("初始化浏览器失败") Util.warning_and_exit(1)
def to_install_VC(): ''' @summary: 询问安装VC ''' Util.info_print('需要安装VC吗?', 1) Util.info_print('这个是StrackerLoade的运行库。没有安装这个,但安装了StrackerLoade,会进不了游戏。', 2) Util.info_print('要是你不确定是否已经安装,那么建议安装.', 2) Util.info_print('输入y开始下载安装,输入其他跳过', 2) a = input('->') if a == "y": vc_x64_url = "https://download.visualstudio.microsoft.com/download/pr/3b070396-b7fb-4eee-aa8b-102a23c3e4f4/40EA2955391C9EAE3E35619C4C24B5AAF3D17AEAA6D09424EE9672AA9372AEED/VC_redist.x64.exe" vc_location = locate.get_resources_folder() + 'VCx64.exe' downloadFile(vc_x64_url, vc_location, "download.visualstudio.microsoft.com") Util.run_a_exe(vc_location)
def downloadFile(url, location, dl_host): ''' @summary: 下载MOD文件 ''' Util.info_print("开始下载\t", 2) def formatFloat(num): return '{:.2f}'.format(num) download_head = headers.copy() download_head['Host'] = dl_host with open(location, 'wb')as f: count = 0 count_tmp = 0 time_1 = time.time() response = my_session.get(url, stream=True, headers=download_head, cookies=get_cookies_from_file()) content_length = float(response.headers['content-length']) for chunk in response.iter_content(chunk_size=1): if chunk: f.write(chunk) count += len(chunk) if time.time() - time_1 > 2: p = count / content_length * 100 speed = (count - count_tmp) / 1024 /2 count_tmp = count Util.info_print(formatFloat(p) + '%' + ' Speed: ' + formatFloat(speed) + 'KB/S', 3) time_1 = time.time() Util.info_print("文件已保存为\t" + location, 3) time.sleep(1)
def get_mod_file_page(is_safe_to_spide: bool): ''' @summary: 获取 Stracker\'s Loader 的文件页 @return: 网页:str, 使用了爬虫:bool ''' if is_safe_to_spide: Util.info_print('通过爬虫得到 "Stracker\'s Loader" 文件页', 2) page_html = spider_mod_file_page() is_spider = True else: Util.info_print('由于爬虫等待时间未过,从本地记录中获取', 2) location = locate.get_resources_folder() + 'mod_file_page.html' with open(location, 'r')as f: page_html = f.read() is_spider = False Util.info_print('获取成功', 3) return page_html, is_spider
def _init_selenium_driver(): ''' @summary: 尝试初始化各个不同的webdriver @return: webdriver ''' Util.info_print('尝试初始化浏览器', 3) try: Util.info_print('尝试初始化chrome浏览器', 4) return _init_selenium_chrome_driver() except Exception as e: print("失败", e) try: Util.info_print('尝试初始化火狐浏览器', 4) return _init_selenium_firefox_driver() except Exception as e: print("失败", e) try: Util.info_print('尝试初始化IE浏览器', 4) return _init_selenium_ie_driver() except Exception as e: print("失败", e)
def get_cookies_info(user_name: str, user_pwd: str): ''' @summary: 获取cookies信息 @return: cookies:dict ''' nexus_cookies_location = locate.get_cookies_txt_file() if Util.is_file_exists(nexus_cookies_location): Util.info_print('Nexus_Cookies.json存在', 2) Util.info_print('尝试通过Nexus_Cookies.json获取Cookies信息', 3) my_cookies = get_cookies_from_file() # print(my_cookies) if is_login(my_cookies): Util.info_print('Cookies信息验证成功,', 4) return else: Util.info_print('Cookies信息验证失败,', 4) Util.info_print('尝试通过登录N网记录Cookies信息', 2) my_cookies = get_cookies_by_selenium_login(user_name, user_pwd) if my_cookies is not None: return my_cookies Util.info_print('尝试通过手动输入, 获知Cookies信息', 2) my_cookies = get_cookies_by_input() if is_login(my_cookies): Util.info_print('Cookies信息验证成功,', 4) else: Util.info_print('Cookies信息验证失败,', 4) Util.warning_and_exit(1) return my_cookies
def run(): print("本程序由Recluse制作") print("本程序用于一键更新前置MOD-StrackerLoader") print("本程序不会用于盗号, 偷取信息 等非法操作") print("但由于源码是公开的, 可能存在被魔改成盗号程序的可能。故建议从github获取本程序。") print("github地址:https://github.com/RecluseXU/CheckStrackerLoader") print("B站联系地址:https://www.bilibili.com/video/av91993651") print("输入回车键开始") input('->') init_locate() # 信息获取 if is_first_time_run(): first_time_run() Util.info_print('检查StrackerLoader安装状态', 1) is_installed = Util.is_file_exists(locate.get_mhw_dinput8_file()) Util.info_print('安装状态:\t'+str(is_installed), 2) Util.info_print('尝试获取 conf.ini信息', 1) Util.info_print('读取conf.ini', 2) conf_ini = Conf_ini(locate.get_run_folder()) Util.info_print('尝试获取 Cookies 信息', 1) username, userpwd = conf_ini.get_nexus_account_info() get_cookies_info(username, userpwd) Util.info_print("获取MOD信息") Util.info_print('尝试获取N网 "Stracker\'s Loader" 文件信息页', 1) file_page_html, is_spider = get_mod_file_page(conf_ini.is_safe_to_spide()) if is_spider: # 更新最后一次爬虫的时间信息 conf_ini.set_new_last_spide_time() Util.info_print(r'尝试分析文件页,得到 "Stracker\'s Loader" 最新版信息', 1) last_publish_date, last_download_url = analyze_mod_file_page(file_page_html) Util.info_print("最新版本上传日期\t" + str(last_publish_date), 2) Util.info_print("最新版本下载地址\t" + last_download_url, 2) last_publish_timeStamp = Util.transform_datetime_to_timeStamp(last_publish_date) installed_version_timeStamp = conf_ini.get_installed_SL_upload_date() if is_installed and last_publish_timeStamp == installed_version_timeStamp: Util.info_print("已安装的版本与最新版发布时间一致,无需更新") Util.warning_and_exit() Util.info_print('尝试获取N网 "Stracker\'s Loader" 最新版文件下载页', 1) download_page_html = spider_download_file_page(last_download_url) Util.info_print('尝试分析N网 "Stracker\'s Loader" 最新版文件下载页', 1) file_id, game_id = analyze_download_file_page(download_page_html) Util.info_print('game_id\t'+game_id, 2) Util.info_print('file id\t'+file_id, 2) Util.info_print('尝试获取N网 "Stracker\'s Loader" 最新版文件下载url', 1) download_url, file_type = spider_download_file(file_id, game_id) Util.info_print("最新版文件下载url\t" + download_url, 2) Util.info_print("最新版文件类型\t" + file_type, 2) Util.info_print('尝试下载"Stracker\'s Loader" 最新版文件', 1) dl_loader_location = locate.get_resources_folder() + 'StrackerLoader.' + file_type downloadFile(download_url, dl_loader_location, 'cf-files.nexusmods.com') Util.info_print("信息处理") Util.info_print('尝试解压"Stracker\'s Loader" 文件', 1) if file_type == 'zip': Util.unzip_all(dl_loader_location, locate.get_dl_loader_folder(), '') Util.info_print('尝试获取刚下载的"Stracker\'s Loader" 文件MD5', 1) dl_dll_location = locate.get_dl_loader_folder() + 'dinput8.dll' download_dll_md5 = Util.get_file_MD5(dl_dll_location) Util.info_print('刚下载的"Stracker\'s Loader" dll-MD5:\t'+download_dll_md5, 2) if is_installed and conf_ini.get_installed_mod_ddl_md5() == download_dll_md5: Util.info_print('刚下载的文件MD5 与 已安装的文件MD5一致, 无需更新', 2) else: Util.info_print('尝试覆盖安装', 1) Util.info_print('覆盖安装dinput8.dll', 2) Util.copy_file(dl_dll_location, locate.get_mhw_dinput8_file()) Util.info_print('覆盖安装dinput-config.json', 2) dl_dinputconfig_location = locate.get_dl_loader_folder() + 'dinput-config.json' mhw_dinputconfig_location = locate.get_mhw_folder() + 'dinput-config.json' Util.copy_file(dl_dinputconfig_location, mhw_dinputconfig_location) Util.info_print('更新安装信息', 2) Util.info_print('更新 已安装版本N网作者上传时间信息', 3) conf_ini.set_installed_SL_upload_date(last_publish_date) Util.info_print('更新 已安装版本DLL的MD5 信息', 3) conf_ini.set_installed_mod_ddl_md5(download_dll_md5) locate.save_to_conf_ini_file() print('程序运行完毕\n3DM biss\n') Util.warning_and_exit(0)
def run(): print("本程序由Recluse制作") print("本程序用于一键更新前置MOD-StrackerLoader") print("本程序不会用于盗号, 偷取信息 等非法操作") print("但由于源码是公开的, 可能存在被魔改成盗号程序的可能。故建议从github获取本程序。") print("github地址:https://github.com/RecluseXU/CheckStrackerLoader") print("B站联系地址:https://www.bilibili.com/video/av91993651") print("输入回车键开始") input() Util.info_print('初始化') Util.info_print('创建resources目录', 1) location = Util.get_resources_folder()[:-1] Util.creat_a_folder(location) Util.info_print('创建lib目录', 1) location = Util.get_lib_folder()[:-1] Util.creat_a_folder(location) # 信息获取 Util.info_print("获取本地信息") Util.info_print('尝试获取 MHW 目录', 1) MHW_Install_Address = Util.get_MHW_Install_Address() Util.info_print('MHW 目录:\t' + MHW_Install_Address, 2) Util.info_print('尝试获取当前目录', 1) run_folder_location = Util.get_run_folder() Util.info_print('当前目录:\t' + run_folder_location, 2) Util.info_print('检查StrackerLoader安装状态', 1) is_installed = Util.is_file_exists(MHW_Install_Address + 'dinput8.dll') Util.info_print('安装状态:\t' + str(is_installed), 2) if is_installed: Util.info_print('尝试获取 StrackerLoader-dinput8.dll 的 MD5', 2) dinput8_dll_md5 = Util.get_file_MD5(MHW_Install_Address + 'dinput8.dll') else: dinput8_dll_md5 = "" Util.info_print('尝试获取 conf.ini信息', 1) if not Util.is_file_exists(run_folder_location + 'conf.ini'): Util.info_print('conf.ini不存在,创建conf.ini', 2) print('这次输入的信息会记录在conf.ini中,如果需要更改,用记事本修改conf.ini的内容即可') N_name = input('请输入N网账号或邮箱:') N_pwd = input('请输N网密码:') Conf_ini.creat_new_conf_ini(run_folder_location + 'conf.ini', dinput8_dll_md5, N_name, N_pwd) Util.info_print('读取conf.ini', 2) conf_ini = Conf_ini(run_folder_location) Util.info_print('尝试获取 Cookies 信息', 1) username, userpwd = conf_ini.get_nexus_account_info() get_cookies_info(run_folder_location, username, userpwd) # Util.info_print("获取MOD信息") Util.info_print('尝试获取N网 "Stracker\'s Loader" 文件信息页', 1) file_page_html, is_spider = get_mod_file_page(conf_ini.is_safe_to_spide()) if is_spider: # 更新最后一次爬虫的时间信息 conf_ini.set_new_last_spide_time() Util.info_print(r'尝试分析文件页,得到 "Stracker\'s Loader" 最新版信息', 1) last_publish_date, last_download_url = analyze_mod_file_page( file_page_html) Util.info_print("最新版本上传日期\t" + str(last_publish_date), 2) Util.info_print("最新版本下载地址\t" + last_download_url, 2) last_publish_timeStamp = Util.transform_datetime_to_timeStamp( last_publish_date) installed_version_timeStamp = conf_ini.get_installed_SL_upload_date() if is_installed and last_publish_timeStamp == installed_version_timeStamp: Util.info_print("已安装的版本与最新版发布时间一致,无需更新") Util.warning_and_exit() Util.info_print('尝试获取N网 "Stracker\'s Loader" 最新版文件下载页', 1) download_page_html = spider_download_file_page(last_download_url) Util.info_print('尝试分析N网 "Stracker\'s Loader" 最新版文件下载页', 1) file_id, game_id = analyze_download_file_page(download_page_html) Util.info_print('game_id\t' + game_id, 2) Util.info_print('file id\t' + file_id, 2) Util.info_print('尝试获取N网 "Stracker\'s Loader" 最新版文件下载url', 1) download_url, file_type = spider_download_file(file_id, game_id) Util.info_print("最新版文件下载url\t" + download_url, 2) Util.info_print("最新版文件类型\t" + file_type, 2) Util.info_print('尝试下载"Stracker\'s Loader" 最新版文件', 1) location = Util.get_resources_folder() + 'StrackerLoader.' + file_type downloadFile(download_url, location) Util.info_print("信息处理") Util.info_print('尝试解压"Stracker\'s Loader" 文件', 1) downloaded_mod_location = Util.get_resources_folder( ) + 'StrackerLoader.' + file_type downloaded_mod_unpack_location = Util.get_resources_folder( ) + 'StrackerLoade\\' if file_type == 'zip': Util.unzip_all(downloaded_mod_location, downloaded_mod_unpack_location, '') Util.info_print('尝试获取刚下载的"Stracker\'s Loader" 文件MD5', 1) download_dll_location = Util.get_resources_folder( ) + '\\StrackerLoade\\dinput8.dll' download_dll_md5 = Util.get_file_MD5(download_dll_location) Util.info_print('刚下载的"Stracker\'s Loader" dll-MD5:\t' + download_dll_md5, 2) if is_installed and conf_ini.get_installed_mod_ddl_md5( ) == download_dll_md5: Util.info_print('刚下载MD5 与 已安装MD5一致,无需更新', 2) Util.info_print('更新 已安装版本DLL的MD5 信息', 3) conf_ini.set_installed_mod_ddl_md5(download_dll_md5) Util.info_print('更新 已安装版本N网作者上传时间信息', 3) conf_ini.set_installed_SL_upload_date(last_publish_date) Util.warning_and_exit() Util.info_print('尝试覆盖安装', 1) Util.info_print('覆盖安装dinput8.dll', 2) mhw_ddl_location = MHW_Install_Address + 'dinput8.dll' Util.copy_file(download_dll_location, mhw_ddl_location) Util.info_print('覆盖安装dinput-config.json', 2) download_dinputconfig_location = Util.get_resources_folder( ) + '\\StrackerLoade\\dinput-config.json' mhw_dinputconfig_location = MHW_Install_Address + 'dinput-config.json' Util.copy_file(download_dinputconfig_location, mhw_dinputconfig_location) Util.info_print('更新安装信息', 2) Util.info_print('更新 已安装版本N网作者上传时间信息', 3) conf_ini.set_installed_SL_upload_date(last_publish_date) Util.info_print('更新 已安装版本DLL的MD5 信息', 3) conf_ini.set_installed_mod_ddl_md5(download_dll_md5) print('程序运行完毕\n3DM biss') Util.warning_and_exit(0)
def _selenium_operations(driver: webdriver, user_name: str, user_password: str): # 登录界面 Util.info_print('登录界面', 3) driver.get('https://users.nexusmods.com/auth/sign_in') Util.info_print('请在页面中登录N网账户', 3) Util.info_print('如果设置在conf.ini的账户密码正确,这个过程会自动完成。', 3) Util.info_print('如果不正确,请手动输入账户密码', 3) Util.info_print('每一步操作都设置了一定的的可行时间,超过时间程序就会退出', 3) wait = WebDriverWait(driver, 300) username_inputer = wait.until( presence_of_element_located((By.ID, "user_login"))) userpassword_inputer = wait.until( presence_of_element_located((By.ID, "password"))) commit_button = wait.until( presence_of_element_located((By.XPATH, '//input[@type="submit"]'))) username_inputer.send_keys(user_name) userpassword_inputer.send_keys(user_password) commit_button.click() wait.until(EC.url_changes) # 欢迎界面 index_a = wait.until( EC.presence_of_element_located( (By.XPATH, '//div[@class="links"]/div[@class="left-link"]/a[1]'))) index_a.click() Util.info_print('等待进入首页,请勿操作', 3) # 返回首页后 # Util.info_print('等待从首页中获取cookies', 3) wait.until( EC.presence_of_element_located( (By.CSS_SELECTOR, ".intro > h1:nth-child(1)"))) nexus_cookies_list = driver.get_cookies() driver.quit() nexus_cookies = dict() for cookie in nexus_cookies_list: nexus_cookies[cookie['name']] = cookie['value'] return nexus_cookies
def get_cookies_by_selenium_login(user_name, user_password): ''' @summary: 通过selenium获取cookies信息,并记录下来,返回 @return: cookies:dict ''' driver = init_selenium_driver() # 登录界面 driver.get('https://users.nexusmods.com/auth/sign_in') Util.info_print('请在页面中登录N网账户', 3) Util.info_print('如果设置在conf.ini的账户密码正确,这个过程会自动完成。', 3) Util.info_print('如果不正确,请手动输入账户密码', 3) Util.info_print('每一步操作都设置了30s的可行时间,超过时间程序就会退出', 3) # 登录界面 username_inputer = driver.find_element_by_id("user_login") username_inputer.send_keys(user_name) userpassword_inputer = driver.find_element_by_id("password") userpassword_inputer.send_keys(user_password) commit_button = driver.find_element_by_xpath('//input[@type="submit"]') commit_button.click() while driver.current_url == "https://users.nexusmods.com/auth/sign_in": time.sleep(1) # 欢迎界面 try: index_a = WebDriverWait(driver, 30).until( EC.presence_of_element_located( (By.XPATH, '//div[@class="links"]/div[@class="left-link"]/a[1]'))) index_a.click() finally: Util.info_print('等待进入首页,请勿操作', 3) # 返回首页后 while driver.current_url != "https://www.nexusmods.com/": time.sleep(1) Util.info_print('等待从首页中获取cookies', 3) try: WebDriverWait(driver, 30).until( EC.presence_of_element_located( (By.XPATH, '/html/body/header[1]/div[1]/div[2]/div/div/div[3]/div[2]'))) finally: nexus_cookies_list = driver.get_cookies() nexus_cookies = dict() for cookie in nexus_cookies_list: nexus_cookies[cookie['name']] = cookie['value'] with open(cookies_json_location, 'w', encoding="utf-8") as f: json.dump(nexus_cookies, f) driver.close() return nexus_cookies