private static bool TryGetVisualStudioVersion(string externalEditor, out VisualStudioVersion vsVersion)
        {
            switch (UnityVSSupport.ProductVersion(externalEditor).Major)
            {
            case 9:
                vsVersion = VisualStudioVersion.VisualStudio2008;
                return(true);

            case 10:
                vsVersion = VisualStudioVersion.VisualStudio2010;
                return(true);

            case 11:
                vsVersion = VisualStudioVersion.VisualStudio2012;
                return(true);

            case 12:
                vsVersion = VisualStudioVersion.VisualStudio2013;
                return(true);

            case 14:
                vsVersion = VisualStudioVersion.VisualStudio2015;
                return(true);

            case 15:
                vsVersion = VisualStudioVersion.VisualStudio15;
                return(true);
            }
            vsVersion = VisualStudioVersion.Invalid;
            return(false);
        }
Example #2
0
        private static bool IsVisualStudio(string externalEditor, out VisualStudioVersion vsVersion)
        {
            bool result;

            if (string.IsNullOrEmpty(externalEditor))
            {
                vsVersion = VisualStudioVersion.Invalid;
                result    = false;
            }
            else
            {
                KeyValuePair <VisualStudioVersion, string>[] array = (from kvp in SyncVS.InstalledVisualStudios
                                                                      where Paths.AreEqual(kvp.Value, externalEditor, true)
                                                                      select kvp).ToArray <KeyValuePair <VisualStudioVersion, string> >();
                if (array.Length > 0)
                {
                    vsVersion = array[0].Key;
                    result    = true;
                }
                else
                {
                    if (externalEditor.EndsWith("devenv.exe", StringComparison.OrdinalIgnoreCase))
                    {
                        if (UnityVSSupport.TryGetVisualStudioVersion(externalEditor, out vsVersion))
                        {
                            result = true;
                            return(result);
                        }
                    }
                    vsVersion = VisualStudioVersion.Invalid;
                    result    = false;
                }
            }
            return(result);
        }
Example #3
0
        private static string CalculateAboutWindowLabel()
        {
            string result;

            if (!UnityVSSupport.IsUnityVSEnabled())
            {
                result = "";
            }
            else
            {
                Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.Location == UnityVSSupport.s_UnityVSBridgeToLoad);
                if (assembly == null)
                {
                    result = "";
                }
                else
                {
                    StringBuilder stringBuilder = new StringBuilder("Microsoft Visual Studio Tools for Unity ");
                    stringBuilder.Append(assembly.GetName().Version);
                    stringBuilder.Append(" enabled");
                    result = stringBuilder.ToString();
                }
            }
            return(result);
        }
Example #4
0
 public static void Initialize(string editorPath)
 {
     if (Application.platform == RuntimePlatform.WindowsEditor)
     {
         string text = editorPath ?? EditorPrefs.GetString("kScriptsDefaultApp");
         if (text.EndsWith("UnityVS.OpenFile.exe"))
         {
             text = SyncVS.FindBestVisualStudio();
             if (text != null)
             {
                 EditorPrefs.SetString("kScriptsDefaultApp", text);
             }
         }
         VisualStudioVersion version;
         if (UnityVSSupport.IsVisualStudio(text, out version))
         {
             UnityVSSupport.m_ShouldUnityVSBeActive = true;
             string vstuBridgeAssembly = UnityVSSupport.GetVstuBridgeAssembly(version);
             if (vstuBridgeAssembly == null)
             {
                 Console.WriteLine("Unable to find bridge dll in registry for Microsoft Visual Studio Tools for Unity for " + text);
             }
             else if (!File.Exists(vstuBridgeAssembly))
             {
                 Console.WriteLine("Unable to find bridge dll on disk for Microsoft Visual Studio Tools for Unity for " + vstuBridgeAssembly);
             }
             else
             {
                 UnityVSSupport.s_UnityVSBridgeToLoad = vstuBridgeAssembly;
                 InternalEditorUtility.SetupCustomDll(Path.GetFileNameWithoutExtension(vstuBridgeAssembly), vstuBridgeAssembly);
             }
         }
     }
 }
Example #5
0
        private static void InitializeVisualStudio(string externalEditor)
        {
            if (externalEditor.EndsWith("UnityVS.OpenFile.exe"))
            {
                externalEditor = SyncVS.FindBestVisualStudio();
                if (externalEditor != null)
                {
                    ScriptEditorUtility.SetExternalScriptEditor(externalEditor);
                }
            }
            VisualStudioVersion version;

            if (UnityVSSupport.IsVisualStudio(externalEditor, out version))
            {
                UnityVSSupport.m_ShouldUnityVSBeActive = true;
                string vstuBridgeAssembly = UnityVSSupport.GetVstuBridgeAssembly(version);
                if (vstuBridgeAssembly == null)
                {
                    Console.WriteLine("Unable to find bridge dll in registry for Microsoft Visual Studio Tools for Unity for " + externalEditor);
                }
                else if (!File.Exists(vstuBridgeAssembly))
                {
                    Console.WriteLine("Unable to find bridge dll on disk for Microsoft Visual Studio Tools for Unity for " + vstuBridgeAssembly);
                }
                else
                {
                    UnityVSSupport.s_UnityVSBridgeToLoad = vstuBridgeAssembly;
                    InternalEditorUtility.RegisterPrecompiledAssembly(Path.GetFileNameWithoutExtension(vstuBridgeAssembly), vstuBridgeAssembly);
                }
            }
        }
Example #6
0
        private static string GetVstuBridgeAssembly(VisualStudioVersion version)
        {
            string result;

            try
            {
                string vsTargetYear = string.Empty;
                switch (version)
                {
                case VisualStudioVersion.VisualStudio2010:
                    vsTargetYear = "2010";
                    break;

                case VisualStudioVersion.VisualStudio2012:
                    vsTargetYear = "2012";
                    break;

                case VisualStudioVersion.VisualStudio2013:
                    vsTargetYear = "2013";
                    break;

                case VisualStudioVersion.VisualStudio2015:
                    vsTargetYear = "2015";
                    break;
                }
                result = (UnityVSSupport.GetVstuBridgePathFromRegistry(vsTargetYear, true) ?? UnityVSSupport.GetVstuBridgePathFromRegistry(vsTargetYear, false));
            }
            catch (Exception)
            {
                result = null;
            }
            return(result);
        }
Example #7
0
 public static void ScriptEditorChanged(string editorPath)
 {
     if (Application.platform == RuntimePlatform.WindowsEditor)
     {
         UnityVSSupport.Initialize(editorPath);
         InternalEditorUtility.RequestScriptReload();
     }
 }
 public static string GetAboutWindowLabel()
 {
     if (UnityVSSupport.s_AboutLabel != null)
     {
         return(UnityVSSupport.s_AboutLabel);
     }
     UnityVSSupport.s_AboutLabel = UnityVSSupport.CalculateAboutWindowLabel();
     return(UnityVSSupport.s_AboutLabel);
 }
Example #9
0
        public static void Initialize(string editorPath)
        {
            string externalEditor = editorPath ?? ScriptEditorUtility.GetExternalScriptEditor();

            if (Application.platform == RuntimePlatform.OSXEditor)
            {
                UnityVSSupport.InitializeVSForMac(externalEditor);
            }
            else if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                UnityVSSupport.InitializeVisualStudio(externalEditor);
            }
        }
        public static void Initialize(string editorPath)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            UnityVSSupport.\u003CInitialize\u003Ec__AnonStoreyC4 initializeCAnonStoreyC4 = new UnityVSSupport.\u003CInitialize\u003Ec__AnonStoreyC4();
            if (Application.platform != RuntimePlatform.WindowsEditor)
            {
                return;
            }
            // ISSUE: reference to a compiler-generated field
            initializeCAnonStoreyC4.externalEditor = editorPath ?? EditorPrefs.GetString("kScriptsDefaultApp");
            // ISSUE: reference to a compiler-generated field
            if (initializeCAnonStoreyC4.externalEditor.EndsWith("UnityVS.OpenFile.exe"))
            {
                // ISSUE: reference to a compiler-generated field
                initializeCAnonStoreyC4.externalEditor = SyncVS.FindBestVisualStudio();
                // ISSUE: reference to a compiler-generated field
                if (initializeCAnonStoreyC4.externalEditor != null)
                {
                    // ISSUE: reference to a compiler-generated field
                    EditorPrefs.SetString("kScriptsDefaultApp", initializeCAnonStoreyC4.externalEditor);
                }
            }
            // ISSUE: reference to a compiler-generated method
            KeyValuePair <VisualStudioVersion, string>[] array = SyncVS.InstalledVisualStudios.Where <KeyValuePair <VisualStudioVersion, string> >(new Func <KeyValuePair <VisualStudioVersion, string>, bool>(initializeCAnonStoreyC4.\u003C\u003Em__237)).ToArray <KeyValuePair <VisualStudioVersion, string> >();
            bool flag = array.Length > 0;

            UnityVSSupport.m_ShouldUnityVSBeActive = flag;
            if (!flag)
            {
                return;
            }
            string vstuBridgeAssembly = UnityVSSupport.GetVstuBridgeAssembly(array[0].Key);

            if (vstuBridgeAssembly == null)
            {
                // ISSUE: reference to a compiler-generated field
                Console.WriteLine("Unable to find bridge dll in registry for Microsoft Visual Studio Tools for Unity for " + initializeCAnonStoreyC4.externalEditor);
            }
            else if (!File.Exists(vstuBridgeAssembly))
            {
                Console.WriteLine("Unable to find bridge dll on disk for Microsoft Visual Studio Tools for Unity for " + vstuBridgeAssembly);
            }
            else
            {
                UnityVSSupport.s_LoadedUnityVS = vstuBridgeAssembly;
                InternalEditorUtility.SetupCustomDll(Path.GetFileNameWithoutExtension(vstuBridgeAssembly), vstuBridgeAssembly);
            }
        }
Example #11
0
        public static string GetAboutWindowLabel()
        {
            string result;

            if (UnityVSSupport.s_AboutLabel != null)
            {
                result = UnityVSSupport.s_AboutLabel;
            }
            else
            {
                UnityVSSupport.s_AboutLabel = UnityVSSupport.CalculateAboutWindowLabel();
                result = UnityVSSupport.s_AboutLabel;
            }
            return(result);
        }
Example #12
0
        private static void InitializeVSForMac(string externalEditor)
        {
            Version vsfmVersion;

            if (UnityVSSupport.IsVSForMac(externalEditor, out vsfmVersion))
            {
                UnityVSSupport.m_ShouldUnityVSBeActive = true;
                string vSForMacBridgeAssembly = UnityVSSupport.GetVSForMacBridgeAssembly(externalEditor, vsfmVersion);
                if (string.IsNullOrEmpty(vSForMacBridgeAssembly) || !File.Exists(vSForMacBridgeAssembly))
                {
                    Console.WriteLine("Unable to find Tools for Unity bridge dll for Visual Studio for Mac " + externalEditor);
                }
                else
                {
                    UnityVSSupport.s_UnityVSBridgeToLoad = vSForMacBridgeAssembly;
                    InternalEditorUtility.RegisterPrecompiledAssembly(Path.GetFileNameWithoutExtension(vSForMacBridgeAssembly), vSForMacBridgeAssembly);
                }
            }
        }
Example #13
0
        public static void Initialize(string editorPath)
        {
            if (Application.platform != RuntimePlatform.WindowsEditor)
            {
                return;
            }
            string externalEditor = editorPath ?? EditorPrefs.GetString("kScriptsDefaultApp");

            if (externalEditor.EndsWith("UnityVS.OpenFile.exe"))
            {
                externalEditor = SyncVS.FindBestVisualStudio();
                if (externalEditor != null)
                {
                    EditorPrefs.SetString("kScriptsDefaultApp", externalEditor);
                }
            }
            KeyValuePair <VisualStudioVersion, string>[] array = (from kvp in SyncVS.InstalledVisualStudios
                                                                  where Paths.AreEqual(kvp.Value, externalEditor, true)
                                                                  select kvp).ToArray <KeyValuePair <VisualStudioVersion, string> >();
            bool flag = array.Length > 0;

            UnityVSSupport.m_ShouldUnityVSBeActive = flag;
            if (!flag)
            {
                return;
            }
            string vstuBridgeAssembly = UnityVSSupport.GetVstuBridgeAssembly(array[0].Key);

            if (vstuBridgeAssembly == null)
            {
                Console.WriteLine("Unable to find bridge dll in registry for Microsoft Visual Studio Tools for Unity for " + externalEditor);
                return;
            }
            if (!File.Exists(vstuBridgeAssembly))
            {
                Console.WriteLine("Unable to find bridge dll on disk for Microsoft Visual Studio Tools for Unity for " + vstuBridgeAssembly);
                return;
            }
            UnityVSSupport.s_LoadedUnityVS = vstuBridgeAssembly;
            InternalEditorUtility.SetupCustomDll(Path.GetFileNameWithoutExtension(vstuBridgeAssembly), vstuBridgeAssembly);
        }
 public static void OnGeneratedCSProjectFiles()
 {
     if (UnityVSSupport.IsUnityVSEnabled())
     {
         try
         {
             string   currentDirectory = Directory.GetCurrentDirectory();
             string[] files            = Directory.GetFiles(currentDirectory, string.Format("*{0}", SolutionSynchronizer.GetProjectExtension(ScriptingLanguage.CSharp)), SearchOption.TopDirectoryOnly);
             string[] array            = files;
             for (int i = 0; i < array.Length; i++)
             {
                 string text        = array[i];
                 string projectFile = text.Substring(currentDirectory.Length + 1);
                 SolutionPostProcessor.ReplacePathsInProjectFile(projectFile, currentDirectory);
             }
         }
         catch (Exception ex)
         {
             Debug.LogWarning("Post processing of CS project files failed, reason: " + ex.Message);
         }
     }
 }
Example #15
0
        /// <summary>
        /// Callback from AssetPostprocessor which is called after CSProj file(s) are generated.
        /// </summary>
        public static void OnGeneratedCSProjectFiles()
        {
            if (!UnityVSSupport.IsUnityVSEnabled())
            {
                return;
            }

            try
            {
                var projectDir   = Directory.GetCurrentDirectory();
                var projectFiles = Directory.GetFiles(projectDir, string.Format("*{0}", SolutionSynchronizer.GetProjectExtension(ScriptingLanguage.CSharp)), SearchOption.TopDirectoryOnly);
                foreach (string projectFile in projectFiles)
                {
                    var file = projectFile.Substring(projectDir.Length + 1);
                    ReplacePathsInProjectFile(file, projectDir);
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogWarning("Post processing of CS project files failed, reason: " + e.Message);
            }
        }
Example #16
0
        private static bool IsVSForMac(string externalEditor, out Version vsfmVersion)
        {
            vsfmVersion = null;
            bool result;

            if (!externalEditor.ToLower().EndsWith("visual studio.app"))
            {
                result = false;
            }
            else
            {
                try
                {
                    result = UnityVSSupport.GetVSForMacVersion(externalEditor, out vsfmVersion);
                }
                catch (Exception arg)
                {
                    Console.WriteLine("Failed to read Visual Studio for Mac information: {0}", arg);
                    result = false;
                }
            }
            return(result);
        }
Example #17
0
 public static void Initialize()
 {
     UnityVSSupport.Initialize(null);
 }
Example #18
0
 public static bool IsUnityVSEnabled()
 {
     if (!UnityVSSupport.s_IsUnityVSEnabled.HasValue)
     {
         bool arg_49_0;
         if (UnityVSSupport.m_ShouldUnityVSBeActive)
         {
             arg_49_0 = AppDomain.CurrentDomain.GetAssemblies().Any((Assembly a) => UnityVSSupport.GetAssemblyLocation(a) == UnityVSSupport.s_UnityVSBridgeToLoad);
         }
         else
         {
             arg_49_0 = false;
         }
         UnityVSSupport.s_IsUnityVSEnabled = new bool?(arg_49_0);
     }
     return(UnityVSSupport.s_IsUnityVSEnabled.Value);
 }