[commit] r2357 - trunk/SDK/DotNet/CSharpComponentWizard

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Tue Sep 24 15:24:44 CDT 2013


Author: ksmyth
Date: Tue Sep 24 15:24:44 2013
New Revision: 2357

Log:
Better VS1012 support

Modified:
   trunk/SDK/DotNet/CSharpComponentWizard/MainWindow.xaml.cs
   trunk/SDK/DotNet/CSharpComponentWizard/SolutionGenerator.cs

Modified: trunk/SDK/DotNet/CSharpComponentWizard/MainWindow.xaml.cs
==============================================================================
--- trunk/SDK/DotNet/CSharpComponentWizard/MainWindow.xaml.cs	Tue Sep 24 15:23:55 2013	(r2356)
+++ trunk/SDK/DotNet/CSharpComponentWizard/MainWindow.xaml.cs	Tue Sep 24 15:24:44 2013	(r2357)
@@ -18,9 +18,9 @@
         // DEFINES       
         public const string VS2010_REGISTRY_KEYPATH = @"SOFTWARE\Microsoft\VisualStudio\10.0";
         public const string VS2012_REGISTRY_KEYPATH = @"SOFTWARE\Microsoft\VisualStudio\11.0";
-        public const string VS2010_PROJECTFOLDER_REGISTRY_KEYNAME = "VisualStudioProjectsLocation";
-        public const string VS2010_USERPROJECTTEMPLATEPATH_REGISTRY_KEYNAME = "UserProjectTemplatesLocation";
-        public const string VS2010_INSTALLDIR_KEYNAME = "InstallDir";
+        public const string VS_PROJECTFOLDER_REGISTRY_KEYNAME = "VisualStudioProjectsLocation";
+        public const string VS_USERPROJECTTEMPLATEPATH_REGISTRY_KEYNAME = "UserProjectTemplatesLocation";
+        public const string VS_INSTALLDIR_KEYNAME = "InstallDir";
         public const string MSSDK_REGISTRY_KEYPATH = @"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A";
 
         public const string GUIDREGEXP = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$";
@@ -46,9 +46,25 @@
 
             if (type == null || Activator.CreateInstance(type, true) == null)
             {
-                MessageBox.Show(Assembly.GetExecutingAssembly().GetName().Name + " requires Visual Studio 2010 Professional or later. It cannot work with Visual C# Express.", "", MessageBoxButton.OK, MessageBoxImage.Error);
+                MessageBox.Show(Assembly.GetExecutingAssembly().GetName().Name + " requires Visual Studio 2010 or 2012 Professional. It cannot work with Visual C# Express.", "", MessageBoxButton.OK, MessageBoxImage.Error);
                 System.Environment.Exit(11);
             }
+            RegistryKey masterKey = Registry.CurrentUser.OpenSubKey(MainWindow.VS2012_REGISTRY_KEYPATH);
+            if (masterKey == null)
+            {
+                masterKey = Registry.CurrentUser.OpenSubKey(MainWindow.VS2010_REGISTRY_KEYPATH);
+            }
+
+            if (masterKey != null)
+            {
+                SolutionGenerator.ProjectTemplateLocation = masterKey.GetValue(MainWindow.VS_USERPROJECTTEMPLATEPATH_REGISTRY_KEYNAME, "").ToString();
+            }
+            if (string.IsNullOrEmpty(SolutionGenerator.ProjectTemplateLocation))
+            {
+                MessageBox.Show(Assembly.GetExecutingAssembly().GetName().Name + " cannot find Visual Studio registry information. Have you run Visual Studio at least once?", "", MessageBoxButton.OK, MessageBoxImage.Error);
+                System.Environment.Exit(11);
+            }
+
 
             InitializeComponent();
             errorWindow = new ErrorWindow(this);
@@ -93,15 +109,16 @@
             // Generate Guid
             this.txb_Guid.Text = Guid.NewGuid().ToString().ToUpper();
 
-            // Get Visual Studio 2010 Project folder
-            RegistryKey masterKey = Registry.CurrentUser.OpenSubKey(MainWindow.VS2010_REGISTRY_KEYPATH);
+            // Get Visual Studio Project folder
             if (masterKey == null)
             {
                 this.txb_TargetFolder.Text = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
             }
             else
             {
-                this.txb_TargetFolder.Text = masterKey.GetValue(MainWindow.VS2010_PROJECTFOLDER_REGISTRY_KEYNAME).ToString();
+                // this registry value is missing if the user never started devenv.exe
+                this.txb_TargetFolder.Text = masterKey.GetValue(MainWindow.VS_PROJECTFOLDER_REGISTRY_KEYNAME, 
+                    Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)).ToString();
                 masterKey.Close();
             }
             this.txb_TargetFolder.ToolTip = this.txb_TargetFolder.Text;
@@ -731,7 +748,7 @@
                 }
                 else
                 {
-                    DevenvLocation = masterKey.GetValue(MainWindow.VS2010_INSTALLDIR_KEYNAME).ToString();
+                    DevenvLocation = masterKey.GetValue(MainWindow.VS_INSTALLDIR_KEYNAME).ToString();
                 }
                 masterKey.Close();
 
@@ -742,6 +759,8 @@
                 pinfo.FileName = DevenvLocation;
                 pinfo.Verb = "runas"; // Registering needs elevated privileges
                 System.Diagnostics.Process myProc = System.Diagnostics.Process.Start(pinfo);
+
+                this.Close();
             }
             catch (Exception ex)
             {

Modified: trunk/SDK/DotNet/CSharpComponentWizard/SolutionGenerator.cs
==============================================================================
--- trunk/SDK/DotNet/CSharpComponentWizard/SolutionGenerator.cs	Tue Sep 24 15:23:55 2013	(r2356)
+++ trunk/SDK/DotNet/CSharpComponentWizard/SolutionGenerator.cs	Tue Sep 24 15:24:44 2013	(r2357)
@@ -29,7 +29,6 @@
         Independent
     }
 
-    enum VSVersion { VS_2010, VS_2012 };
     public static class SolutionGenerator
     {
         public const string ENTRYPOINTCODE_REPLACESTRING = "$GET_ROOTFOLDER_CODE$";
@@ -60,9 +59,6 @@
             object obj;
             string outputfolder = "";
 
-            VSVersion vsVersion = VSVersion.VS_2010;
-           
-
             try
             {
                 if (SolutionGenerator.SelectedType == CompType.Addon)
@@ -74,12 +70,12 @@
                     SolutionGenerator.TemplateFileName = "CSharpInterpreter.zip";
                 }
 
-                System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
+                // Prefer VS2012
+                System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
 
                 if (type == null)
                 {
-                    type = System.Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
-                    vsVersion = VSVersion.VS_2012;
+                    type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
                 }
 
                 obj = Activator.CreateInstance(type, true);
@@ -94,40 +90,15 @@
                     Directory.Delete(outputfolder, true);
                 }
 
-                // Determine the ProjectTemplateFolder of custom templates
-
-                using (RegistryKey currentUser = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64))
-                {
-
-
-                    RegistryKey masterKey = currentUser.OpenSubKey(MainWindow.VS2012_REGISTRY_KEYPATH);
-                    if (masterKey == null)
-                    {
-                        masterKey = currentUser.OpenSubKey(MainWindow.VS2010_REGISTRY_KEYPATH);
-                    }
-
-                    if (masterKey == null)
-                    {
-
-
-                        throw new Exception("Cannot locate ProjectTemplate folder. Is Visual Studio installed?");
-                    }
-                    else
-                    {
-                        SolutionGenerator.ProjectTemplateLocation = masterKey.GetValue(MainWindow.VS2010_USERPROJECTTEMPLATEPATH_REGISTRY_KEYNAME).ToString();
-                    }
-                    masterKey.Close();
-                }
-
-
                 // Unpack the sufficent template project
                 Stream TemplateStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
                             System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".Templates." + SolutionGenerator.TemplateFileName);
                 FileStream FileWriter = new FileStream(Path.Combine(SolutionGenerator.ProjectTemplateLocation, SolutionGenerator.TemplateFileName), FileMode.Create);
-                byte[] ReadFile = new byte[TemplateStream.Length];
-                TemplateStream.Read(ReadFile, 0, ReadFile.Length);
-                FileWriter.Write(ReadFile, 0, ReadFile.Length);
-                FileWriter.Close();
+                using (TemplateStream)
+                using (FileWriter)
+                {
+                    TemplateStream.CopyTo(FileWriter);
+                }
 
                 sln.Create(outputfolder, solutionName);
 


More information about the gme-commit mailing list