Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import string | 6 import string |
| 7 import win32api | 7 import win32api |
| 8 import win32com.client | 8 import win32com.client |
| 9 from win32com.shell import shell, shellcon | 9 from win32com.shell import shell, shellcon |
| 10 | 10 |
| 11 | 11 |
| 12 def GetProductName(file_path): | |
| 13 """Returns the product name of the given file. | |
| 14 | |
| 15 Args: | |
| 16 file_path: The absolute or relative path to the file. | |
| 17 | |
| 18 Returns: | |
| 19 A string representing the product name of the file, or None if the product | |
| 20 name was not found. | |
| 21 """ | |
| 22 language_and_codepage_pairs = win32api.GetFileVersionInfo( | |
| 23 file_path, '\\VarFileInfo\\Translation') | |
| 24 if not language_and_codepage_pairs: | |
| 25 return None | |
| 26 subblock = ('\\StringFileInfo\\%04x%04x\\ProductName' % | |
|
robertshield
2013/08/29 19:01:07
nit: subblock -> product_name_entry
sukolsak
2013/08/30 02:59:29
Done.
| |
| 27 language_and_codepage_pairs[0]) | |
| 28 return win32api.GetFileVersionInfo(file_path, subblock) | |
|
gab
2013/08/29 12:31:06
I find it weird to have to inspect the mini_instal
robertshield
2013/08/29 19:01:07
I actually kind of like the approach taken here in
| |
| 29 | |
| 30 | |
| 12 def ResolvePath(path): | 31 def ResolvePath(path): |
| 13 """Resolves variables in a file path, and returns the resolved path. | 32 """Resolves variables in a file path, and returns the resolved path. |
| 14 | 33 |
| 15 This method resolves only variables defined below. It does not resolve | 34 This method resolves only variables defined below. It does not resolve |
| 16 environment variables. Any dollar signs that are not part of variables must be | 35 environment variables. Any dollar signs that are not part of variables must be |
| 17 escaped with $$, otherwise a KeyError or a ValueError will be raised. | 36 escaped with $$, otherwise a KeyError or a ValueError will be raised. |
| 18 | 37 |
| 19 Args: | 38 Args: |
| 20 path: An absolute or relative path. | 39 path: An absolute or relative path. |
| 21 | 40 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 34 root key, of Chrome for Google Update. | 53 root key, of Chrome for Google Update. |
| 35 """ | 54 """ |
| 36 program_files_path = shell.SHGetFolderPath(0, shellcon.CSIDL_PROGRAM_FILES, | 55 program_files_path = shell.SHGetFolderPath(0, shellcon.CSIDL_PROGRAM_FILES, |
| 37 None, 0) | 56 None, 0) |
| 38 local_appdata_path = shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, | 57 local_appdata_path = shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, |
| 39 None, 0) | 58 None, 0) |
| 40 # TODO(sukolsak): Copy the mini_installer.exe from the build output into here. | 59 # TODO(sukolsak): Copy the mini_installer.exe from the build output into here. |
| 41 mini_installer_path = os.path.abspath('mini_installer.exe') | 60 mini_installer_path = os.path.abspath('mini_installer.exe') |
| 42 mini_installer_file_version = win32com.client.Dispatch( | 61 mini_installer_file_version = win32com.client.Dispatch( |
| 43 'Scripting.FileSystemObject').GetFileVersion(mini_installer_path) | 62 'Scripting.FileSystemObject').GetFileVersion(mini_installer_path) |
| 44 # TODO(sukolsak): Check whether this is Chrome or Chromium. | 63 mini_installer_product_name = GetProductName(mini_installer_path) |
| 45 is_chrome = True | 64 if mini_installer_product_name == 'Google Chrome': |
| 46 if is_chrome: | |
| 47 chrome_short_name = 'Chrome' | 65 chrome_short_name = 'Chrome' |
| 48 chrome_long_name = 'Google Chrome' | 66 chrome_long_name = 'Google Chrome' |
| 49 chrome_dir = 'Google\\Chrome' | 67 chrome_dir = 'Google\\Chrome' |
| 50 chrome_update_registry_subkey = ('Software\\Google\\Update\\Clients\\' | 68 chrome_update_registry_subkey = ('Software\\Google\\Update\\Clients\\' |
| 51 '{8A69D345-D564-463c-AFF1-A69D9E530F96}') | 69 '{8A69D345-D564-463c-AFF1-A69D9E530F96}') |
| 52 else: | 70 elif mini_installer_product_name == 'Chromium': |
| 53 chrome_short_name = 'Chromium' | 71 chrome_short_name = 'Chromium' |
| 54 chrome_long_name = 'Chromium' | 72 chrome_long_name = 'Chromium' |
| 55 chrome_dir = 'Chromium' | 73 chrome_dir = 'Chromium' |
| 56 chrome_update_registry_subkey = 'Software\\Chromium' | 74 chrome_update_registry_subkey = 'Software\\Chromium' |
| 75 else: | |
| 76 raise KeyError("Unknown mini_installer's product name '%s'" % | |
|
grt (UTC plus 2)
2013/08/30 02:39:59
nit: "mini_installer's" -> "mini_installer"
sukolsak
2013/08/30 02:59:29
Done.
| |
| 77 mini_installer_product_name) | |
|
robertshield
2013/08/29 19:01:07
This has the side benefit of breaking if mini_inst
| |
| 57 | 78 |
| 58 variable_mapping = { | 79 variable_mapping = { |
| 59 'PROGRAM_FILES': program_files_path, | 80 'PROGRAM_FILES': program_files_path, |
| 60 'LOCAL_APPDATA': local_appdata_path, | 81 'LOCAL_APPDATA': local_appdata_path, |
| 61 'MINI_INSTALLER': mini_installer_path, | 82 'MINI_INSTALLER': mini_installer_path, |
| 62 'MINI_INSTALLER_FILE_VERSION': mini_installer_file_version, | 83 'MINI_INSTALLER_FILE_VERSION': mini_installer_file_version, |
| 63 'CHROME_SHORT_NAME': chrome_short_name, | 84 'CHROME_SHORT_NAME': chrome_short_name, |
| 64 'CHROME_LONG_NAME': chrome_long_name, | 85 'CHROME_LONG_NAME': chrome_long_name, |
| 65 'CHROME_DIR': chrome_dir, | 86 'CHROME_DIR': chrome_dir, |
| 66 'CHROME_UPDATE_REGISTRY_SUBKEY': chrome_update_registry_subkey, | 87 'CHROME_UPDATE_REGISTRY_SUBKEY': chrome_update_registry_subkey, |
| 67 } | 88 } |
| 68 return string.Template(path).substitute(variable_mapping) | 89 return string.Template(path).substitute(variable_mapping) |
| OLD | NEW |