Ejemplo n.º 1
0
def cra_3dmax(install_dir: str, program_name: str) -> None:
    """ 激活3dmax2014及CAD2014
    :param program_name: 程序名称 CAD2014 OR 3DMAX2014
    :param install_dir: 用户程序安装路径
    :return: None
    """
    program_name_dict = {
        "3DMAX2014": ['3ds Max 2014', '3dsmax'],
        "CAD2014": ['AutoCAD 2014', 'acad']
    }

    program_path = join(install_dir, program_name,
                        program_name_dict[program_name][0],
                        program_name_dict[program_name][1])  # 启动文件所在路径
    program_temp = Application().start(program_path +
                                       str(" /Language=CHS"))  # 以中文语言打开程序
    while True:
        try:
            Application().connect(title='Autodesk 许可')
        except:
            pass
        else:
            break

    sleep_time = [5, 1, 1, 1, 1]  # 各图片的等待时间
    grayscale = [True, False, True, True, True]  # 各图片是否使用灰度搜索
    skewing = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]  # x、y坐标偏移

    if install_from_png(app_name=program_name,
                        confidence=0.8,
                        sleep_time_list=sleep_time,
                        grayscale_list=grayscale,
                        skewing_list=skewing,
                        png_file_name="_shot1"):  # 点击同意协议一直到复制申请号的界面

        sleep_time = [2, 1]  # 各图片的等待时间
        grayscale = [True, True]  # 各图片是否使用灰度搜索
        skewing = [[200, 0], [0, 0]]  # x、y坐标偏移
        coordinate_list = install_from_png(app_name=program_name,
                                           confidence=0.8,
                                           sleep_time_list=sleep_time,
                                           grayscale_list=grayscale,
                                           skewing_list=skewing,
                                           png_file_name="_shot2",
                                           coordinate=True)
        if len(coordinate_list) == 2:
            _extracted_from_cra_3dmax_32(coordinate_list, program_name,
                                         program_temp)
Ejemplo n.º 2
0
    def auto_install(self):
        choose = self.choose
        start_time = (strftime("%H:%M", localtime()))  # 获取运行程序时的开始时间
        failure = []  # 保存安装失败的软件名称
        menu = load_menu()  # 读取安装目录下的menu.txt获取需要安装的文件
        menu_change = menu.copy()

        for each in menu:

            labelframe1 = tk.LabelFrame(self.root, text=f'安装进度(第{menu.index(each) + 1}个,共{len(menu)}个)', height=80,
                                        width=300)  # 信息区
            labelframe1.grid(row=1, column=0, columnspan=10, padx=10, pady=10)
            labelframe1.propagate(0)  # 使组件大小不变,此时width才起作用
            tk.Label(labelframe1, text=f"正在安装{format_menu(each.split())[0]}...", font=(', 11')).pack(fill="both",
                                                                                                     expand="yes")

            if each == 'QQ':
                main_window = ["腾讯QQ安装向导", "win32", "QQ"]
                step = {0: ["自定义选项", 'click', 15],
                        1: ["添加到快速启动栏", 'click', 6],
                        2: ["开机自动启动", 'click', 6],
                        3: ['', 'edit', 6],
                        4: ["立即安装", 'click', 6],
                        5: ["完成安装", 'click', 40]}

                program = Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', 'QQ', 'QQ.exe'))

                if install(main_window=main_window[0], window_backend=main_window[1], step=step,
                           program=program, install_path=join(choose, each), edit_value=3):
                    kill_program(main_window[2])
                    # 安装成功修改menu文件
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))  # 安装失败记录安装失败程序

            if each == 'Wechat':
                main_window = ["微信安装向导", "uia", "微信"]
                step = {0: ["更多选项", 'click', 40],
                        1: ["程序安装目录", 'edit', 6],
                        2: ["安装微信", 'click', 6],
                        3: ['开始使用', 'click', 40]}

                program = Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', 'wechat', 'wechat.exe'))

                if install(main_window=main_window[0], window_backend=main_window[1], step=step, program=program,
                           install_path=join(choose, each)):
                    kill_program(main_window[2])
                    # 安装成功修改menu文件
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))  # 安装失败记录安装失败程序

            if each == 'Dtalk':
                main_window = ["钉钉 安装", "win32"]
                step = {0: ["下一步(&N) >", 'click', 50],
                        1: ["", 'edit', 6],
                        2: ["下一步(&N) >", 'click', 6],
                        3: ["运行 钉钉(&R)", 'click', 40],
                        4: ["完成(&F)", 'click', 6]}

                program = Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', 'Dtalk', 'Dtalk.exe'))

                if install(main_window=main_window[0], window_backend=main_window[1], step=step,
                           program=program, install_path=join(choose, each), edit_value=1):
                    # 安装成功修改menu文件
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))  # 安装失败记录安装失败程序

            if each == 'Winrar':
                main_window = ["WinRAR 5.91", "win32", 10]
                step = {0: ["", "Edit", 'edit', 6],
                        1: ["安装", "Button", 'click', 6]}

                program = Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', 'Winrar', 'Winrar.exe'))
                sleep(2)
                if install(main_window=main_window[0], window_backend=main_window[1], step=step, program=program,
                           install_path=join(choose, each), edit_value=0, special=True):
                    time = 6
                    while time >= 0:
                        try:
                            temp = Application().connect(title="WinRAR 简体中文版安装")
                        except:
                            sleep(1)
                            time -= 1
                        else:  # 未抛出异常时说明程序成功链接
                            for button in ["确定", "完成"]:
                                temp2 = temp.window(title='WinRAR 简体中文版安装').child_window(title=button).wait('ready',
                                                                                                            timeout=30)
                                temp2.click()
                            break
                    # 安装成功修改menu文件
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))  # 安装失败记录安装失败程序

            if each == 'LMsoft':
                main_window = 'uia'
                step = {0: ["原创工具", 'click', 10],
                        1: ["流氓软件免疫", 'click', 5],
                        2: ["一键免疫", 'click', 8],
                        3: ["确定", 'click', 3],
                        4: ["确定", 'click', 10]
                        }
                sleep_time = [1, 5, 2, 5, 2]
                program = Application(backend=main_window).start(
                    join(getcwd(), 'app_pkg', each, each))

                if install_from_topwindow(window_backend=main_window, step=step, program=program,
                                          install_path=join(choose, each), sleep_time=sleep_time):
                    program.kill()
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))

            if each in ['VCRedist', 'DX', 'NF3']:
                main_window = "win32"
                step = {0: ["确定", 'click', 10],
                        1: ["是(&Y)", 'click', 10]}
                sleep_time = [1, 0]
                program = Application(backend=main_window).start(
                    join(getcwd(), 'app_pkg', each, each))

                if install_from_topwindow(window_backend=main_window, step=step, program=program,
                                          install_path=join(choose, each), sleep_time=sleep_time):
                    ok_dict = {'DX': 'DirectX 9.0c 安装完成!程序即将退出',
                               'VCRedist': 'Visual C++ 运行库 安装完成!程序即将退出',
                               'NF3': '.Net Framework 安装完成!程序即将退出'}
                    # 安装成功修改menu文件
                    txt_change(prom_name=each, menu_change=menu_change)
                    time = 60
                    while time >= 0:
                        try:
                            if program.window(title_re='信息').child_window(title=ok_dict[each]).exists():
                                break
                        except:
                            sleep(1)
                            time -= 1
                    program.window(title_re='信息').child_window(
                        title=ok_dict[each]).wait('ready', timeout=80)
                    program.window(title_re='信息').child_window(
                        title="确定").click_input()
                else:
                    failure.extend(format_menu(each.split()))  # 安装失败记录安装失败程序

            if each == 'OFFICE2013':
                main_window = [
                    "Microsoft Office Professional Plus 2013", "uia"]
                step = {0: ["我接受此协议的条款", "CheckBox", 'click', 20],
                        1: ["继续", "Button", 'click', 6],
                        2: ["自定义", "Button", 'click', 6],
                        3: ["Microsoft Access", "MenuItem", 'click', 6],
                        4: ["不可用", "Button", 'click', 6],
                        5: ["Microsoft InfoPath", "MenuItem", 'click', 6],
                        6: ["不可用", "Button", 'click', 6],
                        7: ["Microsoft Lync", "MenuItem", 'click', 6],
                        8: ["不可用", "Button", 'click', 6],
                        9: ["Microsoft OneNote", "MenuItem", 'click', 6],
                        10: ["不可用", "Button", 'click', 6],
                        11: ["Microsoft Outlook", "MenuItem", 'click', 6],
                        12: ["不可用", "Button", 'click', 6],
                        13: ["Microsoft Publisher", "MenuItem", 'click', 6],
                        14: ["不可用", "Button", 'click', 6],
                        15: ["Microsoft SkyDrive Pro", "MenuItem", 'click', 6],
                        16: ["不可用", "Button", 'click', 6],
                        17: ["Microsoft Visio Viewer", "MenuItem", 'click', 6],
                        18: ["不可用", "Button", 'click', 6],
                        19: ["文件位置", "TabItem", 'click', 6],
                        20: ["", "Edit", 'edit', 10],
                        21: ["立即安装", "Button", 'click', 6]}

                program = Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', 'OFFICE2013', 'setup.exe'))

                if install(main_window=main_window[0], window_backend=main_window[1], step=step, program=program,
                           install_path=join(choose, each), edit_value=20, special=True):
                    program.window(title_re='Microsoft Office Professional Plus 2013').child_window(title="继续联机",
                                                                                                    control_type="Button"
                                                                                                    ).wait('ready',
                                                                                                           timeout=600)
                    program.window(title_re='Microsoft Office Professional Plus 2013')[
                        '关闭Button'].click_input()
                    # 安装成功修改menu文件
                    txt_change(prom_name=each, menu_change=menu_change)
                    office_crack(choose)  # 激活office
                else:
                    failure.extend(format_menu(each.split()))  # 安装失败记录安装失败程序

            if each == "WPS":
                sleep_time = [5, 1, 1, 1]  # 各图片的等待时间
                grayscale = [True, True, True, False]  # 各图片是否使用灰度搜索
                skewing = [[0, 0], [0, 0], [-200, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", 'WPS',
                                         'wpssetup_k56008174_281235.exe'))  # 打开指定的安装程序

                png_file_name = "_shot" if system_info() == "10" else "_shot_win7"
                result = install_from_png(app_name=each, edit_index=2, png_file_name=png_file_name,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))

            if each == '360drv':
                main_window = ["欢迎使用 360驱动大师", "uia"]
                step = {0: ["已经阅读并同意", 'CheckBox', 'click', 10],
                        1: ["", 'Edit', 'edit', 6],
                        2: ["安装完成后打开360驱动大师", 'CheckBox', 'click', 6],
                        3: ["立即安装", 'Button', 'click', 6]}

                sleep_time = [3]  # 各图片的等待时间
                grayscale = [True]  # 各图片是否使用灰度搜索
                skewing = [[0, 0]]  # x、y坐标偏移

                program = Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', each, each))

                result = install_from_png(app_name=each, confidence=0.8, install_path=choose,
                                          sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing)  # 第一个按钮获取不到用png图片匹配
                if result:
                    if install(main_window=main_window[0], window_backend=main_window[1], step=step,
                               program=program, install_path=join(choose, each), edit_value=1,
                               special=True):  # 图片匹配成功后再用pywinauto控制
                        txt_change(prom_name=each, menu_change=menu_change)
                    else:
                        # 安装失败记录安装失败程序
                        failure.extend(format_menu(each.split()))
                else:
                    failure.extend(format_menu(each.split()))

            if each == "Chrome":
                program = Application(backend='win32').start(
                    join(getcwd(), 'app_pkg', each, each))
                txt_change(prom_name=each, menu_change=menu_change)
                while True:
                    if not program.is_process_running():
                        break
                kill_program("欢迎使用 Chrome - Google Chrome")

            if each == "2345explorer":
                sleep_time = [5, 1]  # 各图片的等待时间
                grayscale = [False, False]  # 各图片是否使用灰度搜索
                skewing = [[300, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", each,
                                         '2345explorer_k56008174.exe'))  # 打开指定的安装程序
                result = install_from_png(app_name=each, edit_index=0,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                    kill_program(title=['2345网址导航-开创中国百年品牌(已创建11年整) - 2345加速浏览器 10.14', '网络不稳定或断网 - 2345加速浏览器 10.14'],
                                 time=30)
                else:
                    failure.extend(format_menu(each.split()))

            if each == "TXvideo":
                main_window = ["腾讯视频 2020 安装程序 ", "win32"]
                step = {0: ["自定义安装", 'click', 30],
                        1: ["开机自动启动", 'click', 6],
                        2: ["", 'edit', 6],
                        3: ["立即安装", 'click', 8],
                        4: ["立即体验", 'click', 90]}

                program = Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', each, each))

                if install(main_window=main_window[0], window_backend=main_window[1], step=step, program=program,
                           install_path=join(choose, each), edit_value=2):
                    # 安装成功修改menu文件
                    txt_change(prom_name=each, menu_change=menu_change)
                    kill_program(title='腾讯视频')
                else:
                    failure.extend(format_menu(each.split()))  # 安装失败记录安装失败程序

            if each == "IQIYI":
                main_window = ["爱奇艺 安装向导", "win32"]
                step = {0: ["阅读并同意", 'click', 30],
                        1: ["", 'edit', 6],
                        2: ["立即安装", 'click', 6],
                        3: ["完成", 'click', 90]}

                Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', each, 'iqiyi_k56008174_107328.exe'))
                time = 5
                while time >= 0:
                    try:
                        program = Application(backend=main_window[1]).connect(
                            title_re=main_window[0])  # 直接打开的程序对象不能直接使用需要重新链接
                    except:
                        sleep(1)
                        time -= 1
                    else:
                        if install(main_window=main_window[0], window_backend=main_window[1], step=step,
                                   program=program,
                                   install_path=join(choose, each), edit_value=1):
                            # 安装成功修改menu文件
                            txt_change(prom_name=each, menu_change=menu_change)
                        else:
                            # 安装失败记录安装失败程序
                            failure.extend(format_menu(each.split()))
                        break

            if each == "PSCS3":
                main_window = ["安装 - Adobe Photoshop CS3 Extended", "win32"]
                step = {0: ["下一步(&N) >", "TButton", 'click', 10],
                        1: [r"C:\Program Files (x86)\Adobe\Adobe Photoshop CS3", "TEdit", 'edit', 6],
                        2: ["下一步(&N) >", "TButton", 'click', 6],
                        3: ["下一步(&N) >", "TButton", 'click', 6],
                        4: ["安装(&I)", "TButton", 'click', 6],
                        5: ["完成(&F)", "TButton", 'click', 60]}

                Application(backend=main_window[1]).start(
                    join(getcwd(), 'app_pkg', each, each))
                time = 5
                while time >= 0:
                    try:
                        program = Application(backend=main_window[1]).connect(
                            title='安装')  # 直接打开的程序对象不能直接使用需要重新链接
                    except:
                        sleep(1)
                        time -= 1
                    else:
                        if install(main_window=main_window[0], window_backend=main_window[1], step=step,
                                   program=program,
                                   install_path=join(choose, each), edit_value=100, special=True):
                            # 安装成功修改menu文件
                            txt_change(prom_name=each, menu_change=menu_change)
                        else:
                            # 安装失败记录安装失败程序
                            failure.extend(format_menu(each.split()))
                        break

            if each == "PSCC2018":  # PSCC2018打开自动安装不需要任何按钮
                if "PSCS3" in menu:  # 防止装完PSCS3马上打开程序报错
                    sleep(5)
                ps_path = join(getcwd(), "app_pkg", each, 'Set-up')
                copy(ps_path)
                hotkey('win', 'r')
                hotkey('ctrl', 'v')
                hotkey('enter')
                time = 10
                while time >= 0:
                    try:
                        ps_cc = Application().connect(path=paste())
                    except:
                        sleep(1)
                        time -= 1
                    else:
                        break

                while True:
                    if not ps_cc.is_process_running():
                        break
                    else:
                        sleep(2)
                txt_change(prom_name=each, menu_change=menu_change)
                kill_program(title='Adobe Photoshop CC 2018')
                ps_crack()

            if each == "PRCC2018":  # PRCC2018打开自动安装不需要任何按钮
                pr_path = join(getcwd(), "app_pkg", each, 'Set-up')
                copy(pr_path)
                hotkey('win', 'r')
                hotkey('ctrl', 'v')
                hotkey('enter')
                time = 10
                while time >= 0:
                    try:
                        pr_cc = Application().connect(path=paste())
                    except:
                        sleep(1)
                        time -= 1
                    else:
                        break

                while True:
                    if not pr_cc.is_process_running():
                        break
                    else:
                        sleep(2)
                txt_change(prom_name=each, menu_change=menu_change)
                kill_program(title='Adobe Premiere Pro CC 2018')
                pr_crack()

            if each == "163music":
                sleep_time = [5, 1, 1, 1, 1, 5]  # 各图片的等待时间
                grayscale = [True, True, True, True, True, True]  # 各图片是否使用灰度搜索
                skewing = [[0, 0], [0, 0], [0, 0],
                           [-230, 0], [0, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", each, each))  # 打开指定的安装程序

                result = install_from_png(app_name=each, edit_index=3,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                    time = 5
                    while time >= 0:
                        try:
                            Application(backend='uia').connect(title='网易云音乐')
                        except:
                            sleep(1)
                            time -= 1
                        else:
                            system('taskkill /IM cloudmusic.exe /F')
                            sleep(3)
                            break
                else:
                    failure.extend(format_menu(each.split()))

            if each == "QQmusic":
                sleep_time = [5, 1, 1, 1, 5]  # 各图片的等待时间
                grayscale = [True, True, True, True, True]  # 各图片是否使用灰度搜索
                skewing = [[0, 0], [0, 0], [-230, 0],
                           [0, 0], [0, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", each, 'QQMusic_YQQFullStack'))  # 打开指定的安装程序

                result = install_from_png(app_name=each, edit_index=2,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                    kill_program(title='QQ音乐', backend='uia')
                else:
                    failure.extend(format_menu(each.split()))

            if each == "Kugou":
                sleep_time = [5, 1, 1, 1, 1, 1, 10]  # 各图片的等待时间
                grayscale = [True, True, True, True,
                             True, True, True]  # 各图片是否使用灰度搜索
                skewing = [[0, 0], [-250, 0], [0, 0], [0, 0],
                           [0, 0], [0, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", each,
                                         'kugou_k56008174_306395'))  # 打开指定的安装程序

                result = install_from_png(app_name=each, edit_index=1,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                    kill_program(title='酷狗音乐', backend='uia')
                else:
                    failure.extend(format_menu(each.split()))

            if each == "Xunlei":
                sleep_time = [3, 3]  # 各图片的等待时间
                grayscale = [True, True]  # 各图片是否使用灰度搜索
                skewing = [[-50, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", each, each))  # 打开指定的安装程序

                result = install_from_png(app_name=each, edit_index=0,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                    kill_program(title='迅雷', backend='uia')
                else:
                    failure.extend(format_menu(each.split()))

            if each == "SougouPY":
                sleep_time = [5, 1, 1, 1, 1, 8]  # 各图片的等待时间
                grayscale = [True, True, True, True, True, True]  # 各图片是否使用灰度搜索
                skewing = [[0, 0], [0, 0], [0, 0], [
                    70, 0], [0, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", each, each))  # 打开指定的安装程序

                result = install_from_png(app_name=each, edit_index=3,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))

            if each == "2345pinyin":
                sleep_time = [5, 1, 1, 10]  # 各图片的等待时间
                grayscale = [False, True, True, True]  # 各图片是否使用灰度搜索
                skewing = [[50, 0], [0, 0], [0, 0], [0, 0]]  # x、y坐标偏移

                Application().start(join(getcwd(), "app_pkg", each,
                                         '2345pinyin_k56008174.exe'))  # 打开指定的安装程序

                result = install_from_png(app_name=each, edit_index=0,
                                          confidence=0.8, install_path=choose, sleep_time_list=sleep_time,
                                          grayscale_list=grayscale, skewing_list=skewing, paste_identi=True)  # 采用全图片匹配
                if result:
                    txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))

            if each == "3DMAX2014":
                step = {0: ["ListBox3", 'click', 30],
                        1: ["我接受Button", 'click', 6],
                        2: ["下一步Button", 'click', 6],
                        3: ["序列号:Edit", '666', 'edit', 6],
                        4: ["Edit2", '69696969', 'edit', 6],
                        5: ["产品密钥:Edit5", '128F1', 'edit', 6],
                        6: ["下一步Button", 'click', 6],
                        7: ["安装路径:Edit", join(choose, each), 'edit', 6],
                        8: ["安装Button", 'click', 6]}

                setup_path = join(getcwd(), "app_pkg", each, "Setup.exe")
                copy(setup_path)
                hotkey('win', 'r')
                hotkey('ctrl', 'v')
                hotkey('enter')

                time = 20
                while time >= 0:
                    try:
                        program = Application().connect(title="Autodesk 3ds Max 2014")
                    except:
                        sleep(1)
                        time -= 1
                    else:
                        break
                if simple_install(window_backend='win32', step=step, program=program):
                    while True:
                        try:
                            temp = Application().connect(title_re='文件正在使用')
                            if temp.top_window().window(title='忽略(&I)').exists():
                                temp.top_window()['忽略(&I)'].click_input()
                        except:
                            pass

                        if program.top_window().child_window(title="完成").exists():
                            program.top_window().child_window(title="完成").wait("ready", timeout=10)
                            program.top_window()['完成'].click_input()
                            txt_change(prom_name=each, menu_change=menu_change)
                            break
                        else:
                            sleep(3)
                    cra_3dmax(choose, each)
                else:
                    failure.extend(format_menu(each.split()))

            if each == "CAD2014":
                step = {0: ["ListBox3", 'click', 30],
                        1: ["我接受Button", 'click', 6],
                        2: ["下一步Button", 'click', 6],
                        3: ["序列号:Edit", '666', 'edit', 6],
                        4: ["Edit2", '69696969', 'edit', 6],
                        5: ["产品密钥:Edit5", '001F1', 'edit', 6],
                        6: ["下一步Button", 'click', 6],
                        7: ["安装路径:Edit", join(choose, each), 'edit', 6],
                        8: ["安装Button", 'click', 6]}

                setup_path = join(getcwd(), "app_pkg", each, "Setup.exe")
                copy(setup_path)
                hotkey('win', 'r')
                hotkey('ctrl', 'v')
                hotkey('enter')

                time = 20
                while time >= 0:
                    try:
                        program = Application().connect(title="Autodesk® AutoCAD® 2014")
                    except:
                        sleep(1)
                        time -= 1
                    else:
                        break
                if simple_install(window_backend='win32', step=step, program=program):
                    while True:
                        try:
                            temp = Application().connect(title_re='文件正在使用')
                            if temp.top_window().window(title='忽略(&I)').exists():
                                temp.top_window()['忽略(&I)'].click_input()
                        except:
                            pass

                        if program.top_window().child_window(title="完成").exists():
                            program.top_window().child_window(title="完成").wait("ready", timeout=10)
                            program.top_window()['完成'].click_input()
                            txt_change(prom_name=each, menu_change=menu_change)
                            break
                        else:
                            sleep(3)
                    cra_3dmax(choose, each)
                else:
                    failure.extend(format_menu(each.split()))

            if each == "CAD2007":
                program = Application().start(join(getcwd(), "app_pkg", each, 'setup'))
                if program.top_window()['确定Button'].wait("ready", timeout=10) and program.top_window()[
                        '确定Button'].exists():
                    sleep(1)
                    program.top_window()['确定Button'].click_input()
                time = 10
                while time >= 0:
                    try:
                        program = Application().connect(title="AutoCAD 2007 安装")
                    except:
                        sleep(1)
                        time -= 1
                    else:
                        break
                step = {0: ["Button2", 'click', 10],
                        1: ["RadioButton2", 'click', 6],
                        2: ["Button0", 'click', 6],
                        3: ["Edit1", '000', 'edit', 6],
                        4: ["Edit2", '00000000', 'edit', 6],
                        5: ["Button1", 'click', 6],
                        6: ["Edit1", "admin", 'edit', 6],
                        7: ["Edit2", "admin", 'edit', 6],
                        8: ["Edit3", "admin", 'edit', 6],
                        9: ["Edit4", "admin", 'edit', 6],
                        10: ["Edit5", "admin", 'edit', 6],
                        11: ["Button1", "click", 6],
                        12: ["Button1", "click", 6],
                        13: ["Button1", "click", 6],
                        14: ["Edit", join(choose, each), 'edit', 6],
                        15: ["Button1", "click", 6],
                        16: ["Button1", "click", 6],
                        17: ["Button1", "click", 6]}
                sleep_time = [1, 0, 1, 0, 0, 1, 1,
                              0, 0, 0, 0, 1, 3, 3, 0, 3, 3, 3]
                if simple_install(window_backend="win32", step=step, program=program, sleep_time=sleep_time):
                    sleep(5)
                    try:
                        Application().connect(title="AutoCAD 2007 安装程序")
                    except:
                        failure.extend(format_menu(each.split()))
                        break
                    sleep(2)
                    time = 300
                    while time >= 0:
                        try:
                            program = Application().connect(title="AutoCAD 2007 安装程序")
                            if program.top_window()['完成(&F)'].exists():
                                break
                        except:
                            sleep(1)
                            time -= 1
                    step = {0: ["CheckBox", 'click', 8],
                            1: ["Button1", 'click', 6]}
                    simple_install(window_backend="win32",
                                   step=step, program=program)
                    txt_change(prom_name=each, menu_change=menu_change)
                    cad2007_cra(choose)
                else:
                    failure.extend(format_menu(each.split()))

            if each == "T20":
                program = Application().start(join(getcwd(), "app_pkg", each, 'setup'))
                time = 20
                while time >= 0:
                    if program.top_window()["我接受许可证协议中的条款((&A)RadioButton"].exists():
                        break
                    sleep(1)
                    time -= 1

                step = {0: ["我接受许可证协议中的条款((&A)RadioButton", 'click', 10],
                        1: ["下一步(&N) >Button", 'click', 6],
                        2: ["浏览(&R)...Button", 'click', 6],
                        3: ["路径(&P):Edit", join(choose, each), 'edit', 6],
                        4: ["确定Button", 'click', 6],
                        5: ["下一步(&N) >Button", 'click', 6],
                        6: ["下一步(&N) >Button", 'click', 6]}
                sleep_time = [0, 2, 1, 0, 0.5, 0.5, 0]
                if simple_install(window_backend="win32", step=step, program=program, sleep_time=sleep_time):
                    time = 60
                    while time >= 0:
                        try:
                            if program.top_window()['InstallShield Wizard 完成'].exists():
                                break
                        except:
                            sleep(1)
                            time -= 1
                    step = {0: ["完成Button", 'click', 10]}
                    if simple_install(window_backend="win32", step=step, program=program):
                        t20_cra(choose)
                        txt_change(prom_name=each, menu_change=menu_change)
                else:
                    failure.extend(format_menu(each.split()))

        end_time = strftime("%H:%M", localtime())  # 获取程序安装结束时的时间
        menu = format_menu(menu)
        labelframe1 = tk.LabelFrame(
            self.root, text="", height=80, width=300)  # 信息区
        labelframe1.grid(row=1, column=0, columnspan=10, padx=10, pady=10)
        labelframe1.propagate(0)  # 使组件大小不变,此时width才起作用
        if len(failure) != 0:
            tk.Label(labelframe1,
                     text=f"程序安装完毕,用时{running_time(start_time, end_time)}分钟,共选择了{len(menu)}个软件,\n安装失败的软件为:{','.join(failure)}",
                     font=(', 8')).pack(fill="both", expand="yes")
        else:
            tk.Label(labelframe1,
                     text=f"程序安装完毕,用时{running_time(start_time, end_time)}分钟,共选择了{len(menu)}个软件",
                     font=(', 10')).pack(fill="both", expand="yes")
Ejemplo n.º 3
0
def cra_3dmax(install_dir: str, program_name: str):
    """ 激活3dmax2014及CAD2014
    :param program_name: 程序名称 CAD2014 OR 3DMAX2014
    :param install_dir: 用户程序安装路径
    :return:
    """
    program_name_dict = {
        "3DMAX2014": ['3ds Max 2014', '3dsmax'],
        "CAD2014": ['AutoCAD 2014', 'acad']
    }

    program_path = join(install_dir, program_name,
                        program_name_dict[program_name][0],
                        program_name_dict[program_name][1])  # 启动文件所在路径
    program_temp = Application().start(program_path +
                                       str(" /Language=CHS"))  # 以中文语言打开程序
    while True:
        try:
            Application().connect(title='Autodesk 许可')
        except:
            pass
        else:
            break

    sleep_time = [5, 1, 1, 1, 1]  # 各图片的等待时间
    grayscale = [True, False, True, True, True]  # 各图片是否使用灰度搜索
    skewing = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]  # x、y坐标偏移

    if install_from_png(app_name=program_name,
                        confidence=0.8,
                        sleep_time_list=sleep_time,
                        grayscale_list=grayscale,
                        skewing_list=skewing,
                        png_file_name="_shot1"):  # 点击同意协议一直到复制申请号的界面

        sleep_time = [2, 1]  # 各图片的等待时间
        grayscale = [True, True]  # 各图片是否使用灰度搜索
        skewing = [[200, 0], [0, 0]]  # x、y坐标偏移
        coordinate_list = install_from_png(app_name=program_name,
                                           confidence=0.8,
                                           sleep_time_list=sleep_time,
                                           grayscale_list=grayscale,
                                           skewing_list=skewing,
                                           png_file_name="_shot2",
                                           coordinate=True)
        if len(coordinate_list) == 2:
            button1 = coordinate_list[0]  # 申请号坐标
            button2 = coordinate_list[1]  # 我具有激活码坐标
            tripleClick(button1[0], button1[1])
            hotkey('ctrl', 'c')  # 复制申请号

            key_soft = Application().start(
                join(getcwd(), 'app_pkg', program_name, 'crack',
                     'xf-adsk64'))  # 打开注册机
            step = {
                0: ["Request :Edit", paste(), 'edit', 10],  # 将申请号粘贴
                1: ["CButton", 'click', 6],  # 按下注册机patch按钮
                2: ["确定Button", 'click', 6],  # 按下弹出窗口的确定按钮
                3: ["GButton", 'click', 6]
            }  # 按下注册机Gen按钮获得激活码

            if simple_install(window_backend='win32',
                              step=step,
                              program=key_soft):
                while True:  # 判断生成的激活码是否正确
                    dict_temp = key_soft.top_window()._ctrl_identifiers()
                    for each in dict_temp.keys():  # 通过按钮便签值获取激活码
                        if 'Activation :Edit' in dict_temp[each]:
                            temp = str(each)
                    key = temp.split("'")[1]
                    if len(key) == 57:
                        copy(key)
                        break
                    else:
                        key_soft.top_window()['GButton'].click_input()

                key_soft.top_window()['QQButton'].click_input()  # 按下注册机Quit按钮
                click(button2[0], button2[1])  # 按下我具有激活码坐标
                sleep(1)
                hotkey('ctrl', 'v')  # 粘贴激活码
                sleep(1)

                for _ in range(5):
                    hotkey('tab')
                    sleep(.5)
                hotkey('enter')
                sleep(2)
                hotkey('enter')
                sleep(5)
                program_temp.kill()