コード例 #1
0
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):
        info_print("110")
        info_print("111")
        my_cookies = get_cookies_from_file()
        # print(my_cookies)
        if is_login(my_cookies):
            info_print("112")
            return
        else:
            info_print("113")

    info_print("114")
    my_cookies = get_cookies_by_selenium_login(user_name, user_pwd)
    if my_cookies is not None:
        return my_cookies

    info_print("115")
    my_cookies = get_cookies_by_input()
    if is_login(my_cookies):
        info_print("116")
    else:
        info_print("117")
        Util.warning_and_exit(1)
    return my_cookies
コード例 #2
0
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
コード例 #3
0
def analyze_download_file_page(html: str):
    '''
    @summary: 解析 MOD 的下载页
    @return: file_id, game_id
    '''
    try:
        file_id = re.search(r"const file_id = \d+", html).group()[16:]
        game_id = re.search(r"const game_id = \d+", html).group()[16:]
        return file_id, game_id

    except Exception as e:
        print("失败", e)
        Util.warning_and_exit(1)
コード例 #4
0
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)
コード例 #5
0
def spider_download_file_page(download_page_url):
    '''
    @summary: 爬虫得到 MOD 的文件页
    @return: 下载页html:str
    '''
    try:
        response = my_session.get(url=download_page_url, headers=headers)
        download_page_html = response.content.decode()

        location = locate.get_resources_folder() + "mod_download_page.html"
        with open(location, 'w', encoding='utf-8')as f:
            f.write(download_page_html)
        headers['Referer'] = download_page_url
        return download_page_html
    except Exception as e:
        print("失败", e)
        Util.warning_and_exit(1)
コード例 #6
0
def analyze_mod_file_page(html: str):
    '''
    @summary: 解析得到 MOD 的文件页,得到一些数据保存到配置中,并返回下载页数据
    @return: 最新版发布的时间, 最新版下载的URL
    '''
    try:
        xpath_data = etree.HTML(html)
        a = xpath_data.xpath('//*[@id="file-expander-header-9908"]//div[@class="stat"]/text()')
        a = a[0].strip()
        last_publish_date = datetime.datetime.strptime(a, r"%d %b %Y, %I:%M%p")

        a = xpath_data.xpath('//*[@id="file-expander-header-9908"]')[0]
        last_download_url = a.xpath('..//a[@class="btn inline-flex"]/@href')[1]

        return last_publish_date, last_download_url
    except Exception as e:
        print("失败", e)
        Util.warning_and_exit(1)
コード例 #7
0
def get_cookies_by_input():
    '''
    @summary: 让用户手工输入cookies信息
    @return: cookies:dict
    '''
    a = input("尝试手动获取Cookies信息?(输入y代表尝试,输入其他东西代表不尝试并退出)\n")
    if a == "y":
        cookes_dict = dict()
        try:
            cookies_str = input("请输入手动获取的cookies:")
            for cookie in cookies_str.split(';'):
                cookie_one_list = cookie.split('=')
                cookes_dict[cookie_one_list[0]] = cookie_one_list[1]
            save_cookies_to_file(cookes_dict)
            return cookes_dict
        except Exception as e:
            print("失败", e)
    Util.warning_and_exit(1)
コード例 #8
0
def spider_mod_file_page():
    '''
    @summary: 爬虫得到 MOD 的文件页
    @return: session
    '''
    try:
        response = my_session.get(
            url="https://www.nexusmods.com/monsterhunterworld/mods/1982?tab=files",
            headers=headers)
        file_page_html = response.content.decode()
        # print(file_page_html)
        location = locate.get_resources_folder() + 'mod_file_page.html'
        with open(location, 'w', encoding='utf-8')as f:
            f.write(file_page_html)
        headers['Referer'] = "https://www.nexusmods.com/monsterhunterworld/mods/1982?tab=files"
        return file_page_html
    except Exception as e:
        print("失败", e)
        Util.warning_and_exit(1)
コード例 #9
0
def get_cookies_by_input():
    '''
    @summary: 让用户手工输入cookies信息
    @return: cookies:dict
    '''
    _info_print('Coo_11')
    a = input()
    if a == "y":
        cookes_dict = dict()
        try:
            _info_print('Coo_12')
            cookies_str = input()
            for cookie in cookies_str.split(';'):
                cookie_one_list = cookie.split('=')
                cookes_dict[cookie_one_list[0]] = cookie_one_list[1]
            save_cookies_to_file(cookes_dict)
            return cookes_dict
        except Exception as e:
            print("失败", e)
    Util.warning_and_exit(1)
コード例 #10
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('->')

    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)
コード例 #11
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)
コード例 #12
0
def run():
    info_print('000')
    info_print('001')
    info_print('002')
    info_print('003')
    info_print('004')
    info_print('005')
    info_print('006')
    info_print('007')
    input('->')

    init_inject_func()
    init_locate()

    # 信息获取
    is_first_time = is_first_time_run()
    if is_first_time:
        first_time_run()

    info_print('107')
    info_print('108')
    conf_ini = Conf_ini(locate.get_run_folder())

    info_print('109')
    username, userpwd = conf_ini.get_nexus_account_info()
    get_cookies_info(username, userpwd)

    info_print('200')
    info_print('201')
    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()

    info_print('204_1')
    last_publish_date, last_download_url = analyze_mod_file_page(
        file_page_html)
    info_print('205')
    print("\t\t\t" + str(last_publish_date))
    info_print('206')
    print("\t\t\t" + last_download_url)
    last_publish_timeStamp = Util.transform_datetime_to_timeStamp(
        last_publish_date)
    installed_version_timeStamp = conf_ini.get_installed_SL_upload_date()
    if last_publish_timeStamp == installed_version_timeStamp:
        info_print('207')
        Util.warning_and_exit()

    info_print('208')
    download_page_html = spider_download_file_page(last_download_url)
    info_print('209')
    file_id, game_id = analyze_download_file_page(download_page_html)
    print('\t\tgame_id\t' + game_id, 2)
    print('\t\tfile id\t' + file_id, 2)

    info_print('210')
    download_url, file_type = spider_download_file(file_id, game_id)
    info_print('211')
    print("\t\t\t" + download_url)
    info_print('212')
    print("\t\t\t" + file_type)

    info_print('213')
    dl_loader_location = locate.get_resources_folder(
    ) + 'StrackerLoader.' + file_type
    downloadFile(download_url, dl_loader_location, 'cf-files.nexusmods.com')
    # 英文化!!!!!!!!
    #
    info_print('215')
    if file_type == 'zip':
        Util.unzip_all(dl_loader_location, locate.get_dl_loader_folder(), '')
    else:
        info_print('216')
        print('\t\t' + file_type)
        info_print('217')
        Util.warning_and_exit(1)

    info_print('218')
    old_mod_file_list = conf_ini.get_mod_file_list()
    if len(old_mod_file_list) > 0:
        info_print('219')
        for _file in old_mod_file_list:
            print('\t\t\t' + _file)
            if Util.is_file_exists(locate.get_mhw_folder() + _file):
                Util.delete_file(locate.get_mhw_folder() + _file)
            else:
                info_print('220')

    info_print('221')
    sl_file_list = Util.get_file_list_in_folder(locate.get_dl_loader_folder())
    info_print('222')
    print('\t\t\t' + str(sl_file_list))

    info_print('223')
    for _file in sl_file_list:
        print('\t\t' + _file)
        Util.copy_file(locate.get_dl_loader_folder() + _file,
                       locate.get_mhw_folder() + _file)

    info_print('224')
    info_print('225')
    conf_ini.set_installed_SL_upload_date(last_publish_date)
    info_print('226')
    conf_ini.set_mod_file_list(sl_file_list)

    locate.save_to_conf_ini_file()
    info_print('227')

    if is_first_time:
        to_install_VC()

    print('3DM biss')
    Util.warning_and_exit(0)