Index: visual_studio/NativeClientVSAddIn/InstallerResources/install.py |
diff --git a/visual_studio/NativeClientVSAddIn/InstallerResources/install.py b/visual_studio/NativeClientVSAddIn/InstallerResources/install.py |
index 5ce7c666ce3339fca493ea476aa482abf4d19fbd..b367f953c2ab70d66ed38ad558d613ddb676d721 100644 |
--- a/visual_studio/NativeClientVSAddIn/InstallerResources/install.py |
+++ b/visual_studio/NativeClientVSAddIn/InstallerResources/install.py |
@@ -10,15 +10,31 @@ to where Visual Studio can find them. It assumes the current directory |
contains the necessary files to copy. |
""" |
+import create_ppapi_platform |
+import ctypes |
import os |
import platform |
import shutil |
+NACL_PLATFORM_NAME = 'NaCl' |
+PEPPER_PLATFORM_NAME = 'PPAPI' |
+ |
+DEFAULT_ADD_IN_DIRECTORY = os.path.expandvars( |
+ '%USERPROFILE%\\My Documents\\Visual Studio 2010\\Addins') |
+ |
+DEFAULT_MS_BUILD_DIRECTORY = os.path.expandvars('%ProgramFiles(x86)%\\MSBuild') |
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
+ |
def main(): |
if platform.system() != 'Windows': |
raise Exception('Must install to Windows system') |
- # Ensure environment variables are set |
+ # Admin is needed to write to the default platform directory. |
+ if ctypes.windll.shell32.IsUserAnAdmin() != 1: |
+ raise Exception("Not running as administrator. The install script needs " |
+ + "write access to protected Visual Studio directories.") |
+ |
+ # Ensure environment variables are set. |
nacl_sdk_root = os.getenv('NACL_SDK_ROOT', None) |
noelallen1
2012/07/27 00:17:41
This is somewhat dubious... Admin and normal user
tysand
2012/07/28 01:13:11
Good catch, but I've verified that running python
|
chrome_path = os.getenv('CHROME_PATH', None) |
if nacl_sdk_root is None: |
@@ -26,11 +42,74 @@ def main(): |
if chrome_path is None: |
raise Exception('Environment Variable CHROME_PATH is not set') |
- # Copy the necessary files into place |
- add_in_directory = os.path.expandvars( |
- '%USERPROFILE%\My Documents\Visual Studio 2010\Addins') |
- shutil.copy('./NativeClientVSAddIn.AddIn', add_in_directory) |
- shutil.copy('./NativeClientVSAddIn.dll', add_in_directory) |
+ # Ensure add-in directory exists otherwise ask user for correct path. |
+ add_in_directory = DEFAULT_ADD_IN_DIRECTORY |
+ if not os.path.exists(add_in_directory): |
+ print "Could not find Visual Studio add-in directory:" |
+ print add_in_directory |
+ print "Please enter path: " |
+ add_in_directory = raw_input().strip() |
binji
2012/07/26 23:32:17
use command line args instead of raw_input
tysand
2012/07/28 01:13:11
Done.
|
+ if not os.path.exists(add_in_directory): |
+ raise Exception("Add-in directory did not exist") |
+ |
+ # Ensure MS Build directory exists otherwise ask user for correct path. |
+ ms_build_directory = DEFAULT_MS_BUILD_DIRECTORY |
+ if not os.path.exists(ms_build_directory): |
+ print "Could not find MS Build directory:" |
+ print ms_build_directory |
+ print "Please enter path: " |
+ ms_build_directory = raw_input().strip() |
+ if not os.path.exists(ms_build_directory): |
+ raise Exception("MS Build directory did not exist") |
+ |
+ platform_directory = os.path.join( |
+ ms_build_directory, |
+ 'Microsoft.Cpp\\v4.0\\Platforms') |
+ nacl_directory = os.path.join(platform_directory, NACL_PLATFORM_NAME) |
+ pepper_directory = os.path.join(platform_directory, PEPPER_PLATFORM_NAME) |
+ |
+ # Remove existing installation. |
+ if os.path.exists(nacl_directory) or os.path.exists(pepper_directory): |
+ print "Warning: Pre-existing add-in installation will be overwritten." |
+ print "Continue? ((Yes))/((No))" |
+ remove_answer = raw_input().strip() |
+ |
+ if remove_answer.lower() == "yes" or remove_answer.lower() == "y": |
+ if os.path.exists(nacl_directory): |
+ shutil.rmtree(nacl_directory) |
+ if os.path.exists(pepper_directory): |
+ shutil.rmtree(pepper_directory) |
+ else: |
+ raise Exception('User did not allow overwrite of existing install.') |
+ |
+ print "Installing..." |
+ |
+ # Copy the necessary files into place. |
+ shutil.copy( |
binji
2012/07/26 23:32:17
Make sure to clean up copied files if an exception
tysand
2012/07/28 01:13:11
Done.
|
+ os.path.join(SCRIPT_DIR, 'NativeClientVSAddIn.AddIn'), |
+ add_in_directory) |
+ shutil.copy( |
+ os.path.join(SCRIPT_DIR, 'NativeClientVSAddIn.dll'), |
+ add_in_directory) |
+ print "Add-in installed." |
+ |
+ shutil.copytree(os.path.join(SCRIPT_DIR, 'NaCl'), nacl_directory) |
+ print "NaCl platform installed." |
+ |
+ # Ask user before installing PPAPI template. |
+ print "\n" |
+ print "Set up configuration to enable Pepper development with Visual Studio?" |
+ print ("((Yes)) - I want to create and copy relevant files into a" |
+ + " Pepper subdirectory") |
+ print "((No)) - I am not interested or will set up the configuration later" |
+ ppapi_answer = raw_input().strip() |
+ if ppapi_answer.lower() == "yes" or ppapi_answer.lower() == "y": |
+ create_ppapi_platform.CreatePPAPI(ms_build_directory) |
+ print "PPAPI platform installed." |
+ else: |
+ print "Not installing PPAPI platform." |
+ |
+ print "\nInstallation complete!\n" |
if __name__ == '__main__': |
main() |