コード例 #1
0
ファイル: helper.py プロジェクト: sykuang/skcom
def install_vcredist():
    """
    安裝 Visual C++ 2010 x64 Redistributable 10.0.40219.325
    """
    DEBUG_MODE = False

    # 下載與安裝 (安裝程式會自動切換系統管理員身分)
    if not DEBUG_MODE:
        url = 'https://download.microsoft.com/download/1/6/5/' + \
              '165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe'
        # 如果下載失敗, 會觸發 NetworkException
        vcexe = download_file(url, check_dir('~/.skcom'))
    else:
        vcexe = '~/.skcom/vcredist_x64.exe'

    # 如果拒絕安裝, 會觸發 ShellException "(1) 存取被拒。"
    cmd = [vcexe, 'setup', '/passive']
    win_exec(cmd)

    # 移除安裝包, 暫不處理檔案系統例外
    if not DEBUG_MODE:
        os.remove(vcexe)

    # 版本檢查
    expected_ver = version.parse('10.0.40219.325')
    current_ver = verof_vcredist()
    if current_ver != expected_ver:
        raise InstallationException('Visual C++ 2010 可轉發套件', expected_ver)

    return current_ver
コード例 #2
0
ファイル: helper.py プロジェクト: virus-warnning/skcom
def install_vcredist():
    """
    安裝 Visual C++ 2010 Redistributable 10.0.40219.325
    """
    # pylint: disable=invalid-name
    DEBUG_MODE = False

    # 下載 (失敗會觸發 NetworkException)
    (width, _) = platform.architecture()
    url = 'https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/'
    if width == '32bit':
        url += 'vcredist_x86.exe'
    else:
        url += 'vcredist_x64.exe'
    vcexe = download_file(url, check_dir('~/.skcom'))

    # 安裝 (安裝程式會自動切換系統管理員身分)
    # https://www.microsoft.com/en-US/download/details.aspx?id=26999
    cmd = [vcexe, 'setup', '/passive']
    powershell_start(cmd, True)

    # 移除安裝包, 暫不處理檔案系統例外
    if not DEBUG_MODE:
        os.remove(vcexe)

    # 版本檢查
    expected_ver = version.parse('10.0.40219.325')
    current_ver = verof_vcredist()
    if current_ver != expected_ver:
        raise InstallationException('Visual C++ 2010 可轉發套件', expected_ver)

    return current_ver
コード例 #3
0
ファイル: helper.py プロジェクト: virus-warnning/skcom
def install_skcom(install_ver):
    """
    安裝群益 API 元件
    """
    url = 'https://www.capital.com.tw/Service2/download/api_zip/CapitalAPI_%s.zip' % install_ver

    # 建立元件目錄
    # 暫不處理檔案系統例外
    com_path = check_dir(r'~\.skcom\lib')

    # 下載
    # 如果下載失敗, 會觸發 NetworkException
    file_path = download_file(url, com_path)

    # 解壓縮
    # 只解壓縮 64-bits DLL 檔案, 其他非必要檔案不處理
    # 讀檔時需要用 CP437 編碼處理檔名, 寫檔時需要用 CP950 處理檔名
    # 暫不處理解壓縮例外
    (width, _) = platform.architecture()
    if width == '32bit':
        pattern = r'元件/x86/.+\.dll$'
    else:
        pattern = r'元件/x64/.+\.dll$'
    with zipfile.ZipFile(file_path, 'r') as archive:
        for name437 in archive.namelist():
            name950 = name437.encode('cp437').decode('cp950')
            if re.search(pattern, name950):
                dest_path = r'%s\%s' % (com_path, name950.split('/')[-1])
                with archive.open(name437, 'r') as cmpf, \
                     open(dest_path, 'wb') as extf:
                    extf.write(cmpf.read())

    # 註冊元件
    # TODO: 使用者拒絕提供系統管理員權限時, 會觸發 ShellException,
    #       但是登錄檔依然能寫入成功, 原因需要再調查
    cmd = ['regsvr32', '/s', r'%s\SKCOM.dll' % com_path]
    powershell_start(cmd, admin_priv=True)

    # 版本檢查
    expected_ver = version.parse(install_ver)
    current_ver = verof_skcom()
    if current_ver != expected_ver:
        raise InstallationException('群益 API COM 元件', expected_ver)

    return current_ver