예제 #1
0
        /// <summary>
        /// Write default editor values to registry for Visual Studio 2013 and above. Uses the VSIX
        /// install path.
        /// </summary>
        public void WriteVsixRegistryValues(Vsix vsixInstance)
        {
            if (vsixInstance.Dte != null)
            {
                var basePath = string.Format(registryBasePath, vsixInstance.Dte.Version)
#if DEBUG
                               + @"Exp"
#endif
                ;
                WriteRegistryValues(basePath, vsixInstance.PkgInstallPath);
            }
        }
예제 #2
0
        public static string GetString(string name, Vsix vsixInstance)
        {
            var sys = GetLoader(vsixInstance.Dte.LocaleID);

            if (sys == null)
            {
                return(null);
            }

            string result;

            try {
                result = sys.resources.GetString(name, Culture);
            } catch (Exception) {
                result = sys.resources.GetString(name, defaultCultureInfo);
            }

            return(result);
        }
예제 #3
0
파일: Vsix.cs 프로젝트: freall/vstools
        protected override async Task InitializeAsync(
            CancellationToken cancellationToken,
            IProgress <ServiceProgressData> progress)
#endif
        {
            try
            {
                var timeInitBegin = initTimer.Elapsed;
                VsServiceProvider.Instance = instance = this;
                QtProject.ProjectTracker   = this;

#if !VS2013
                ///////////////////////////////////////////////////////////////////////////////////
                // Switch to main (UI) thread
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                var timeUiThreadBegin = initTimer.Elapsed;
#endif

                if ((Dte = VsServiceProvider.GetService <DTE>()) == null)
                {
                    throw new Exception("Unable to get service: DTE");
                }

                VsShellSettings.Manager = new ShellSettingsManager(this as IServiceProvider);

                eventHandler = new DteEventsHandler(Dte);
                DefaultEditorsClient.Initialize(eventHandler);
                DefaultEditorsClient.Instance.Listen();

                Qml.Debug.Launcher.Initialize();
                QtMainMenu.Initialize(this);
                QtSolutionContextMenu.Initialize(this);
                QtProjectContextMenu.Initialize(this);
                QtItemContextMenu.Initialize(this);
                DefaultEditorsHandler.Initialize(Dte);
                QtHelpMenu.Initialize(this);

                if (!string.IsNullOrEmpty(VsShell.InstallRootDir))
                {
                    HelperFunctions.VCPath = Path.Combine(VsShell.InstallRootDir, "VC");
                }

#if !VS2013
                ///////////////////////////////////////////////////////////////////////////////////
                // Switch to background thread
                await TaskScheduler.Default;
                var timeUiThreadEnd = initTimer.Elapsed;
#endif

                var vm    = QtVersionManager.The(initDone);
                var error = string.Empty;
                if (vm.HasInvalidVersions(out error))
                {
                    Messages.PaneMessageSafe(Dte, error, 5000);
                }

                // determine the package installation directory
                var uri = new Uri(System.Reflection.Assembly
                                  .GetExecutingAssembly().EscapedCodeBase);
                PkgInstallPath = Path.GetDirectoryName(
                    Uri.UnescapeDataString(uri.AbsolutePath)) + @"\";

                var QtMsBuildDefault = Path.Combine(
                    Environment.GetEnvironmentVariable("LocalAppData"), "QtMsBuild");
                try {
                    var qtMsBuildDefaultUri = new Uri(QtMsBuildDefault + "\\");
                    var qtMsBuildVsixPath   = Path.Combine(PkgInstallPath, "QtMsBuild");
                    var qtMsBuildVsixUri    = new Uri(qtMsBuildVsixPath + "\\");
                    if (qtMsBuildVsixUri != qtMsBuildDefaultUri)
                    {
                        var qtMsBuildVsixFiles = Directory
                                                 .GetFiles(qtMsBuildVsixPath, "*", SearchOption.AllDirectories)
                                                 .Select(x => qtMsBuildVsixUri.MakeRelativeUri(new Uri(x)));
                        foreach (var qtMsBuildFile in qtMsBuildVsixFiles)
                        {
                            var sourcePath     = new Uri(qtMsBuildVsixUri, qtMsBuildFile).LocalPath;
                            var targetPath     = new Uri(qtMsBuildDefaultUri, qtMsBuildFile).LocalPath;
                            var targetPathTemp = targetPath + ".tmp";
                            Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                            File.Copy(sourcePath, targetPathTemp, overwrite: true);
                            if (File.Exists(targetPath))
                            {
                                File.Replace(targetPathTemp, targetPath, null);
                            }
                            else
                            {
                                File.Move(targetPathTemp, targetPath);
                            }
                        }
                    }
                } catch {
                    QtMsBuildDefault = Path.Combine(PkgInstallPath, "QtMsBuild");
                }

                var QtMsBuildPath = Environment.GetEnvironmentVariable("QtMsBuild");
                if (string.IsNullOrEmpty(QtMsBuildPath))
                {
                    Environment.SetEnvironmentVariable(
                        "QtMsBuild", QtMsBuildDefault,
                        EnvironmentVariableTarget.User);

                    Environment.SetEnvironmentVariable(
                        "QtMsBuild", QtMsBuildDefault,
                        EnvironmentVariableTarget.Process);
                }

                CopyTextMateLanguageFiles();
                UpdateDefaultEditors(Mode.Startup);
                CopyNatvisFile();

                var modules = QtModules.Instance.GetAvailableModuleInformation();
                foreach (var module in modules)
                {
                    if (!string.IsNullOrEmpty(module.ResourceName))
                    {
                        var translatedName = SR.GetString(module.ResourceName, this);
                        if (!string.IsNullOrEmpty(translatedName))
                        {
                            module.Name = translatedName;
                        }
                    }
                }

                Messages.PaneMessageSafe(Dte, string.Format("\r\n"
                                                            + "== Qt Visual Studio Tools version {0}\r\n"
                                                            + "\r\n"
                                                            + "   Initialized in: {1:0.##} msecs\r\n"
#if !VS2013
                                                            + "   Main (UI) thread: {2:0.##} msecs\r\n"
#endif
                                                            , Version.USER_VERSION
                                                            , (initTimer.Elapsed - timeInitBegin).TotalMilliseconds
#if !VS2013
                                                            , (timeUiThreadEnd - timeUiThreadBegin).TotalMilliseconds
#endif
                                                            ), 5000);
            }
            catch (Exception e)
            {
                Messages.PaneMessageSafe(Dte,
                                         e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace, 5000);
            }
            finally
            {
                initDone.Set();
                initTimer.Stop();
            }
        }