static void LoadPreferences()
    {
        s_DocumentationSource = (DocumentationSource)EditorPrefs.GetInt("Thinksquirrel.CameraShakeEditor.DocumentationSource", 0);
        s_DocumentationPath   = EditorPrefs.GetString("Thinksquirrel.CameraShakeEditor.DocumentationPath");
        s_DownloadEveryUpdate = EditorPrefs.GetBool("Thinksquirrel.CameraShakeEditor.DownloadDocsEveryUpdate", false);

        if (string.IsNullOrEmpty(s_DocumentationPath))
        {
            switch (Application.platform)
            {
            case RuntimePlatform.OSXEditor:
                s_DocumentationPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "Thinksquirrel/Camera Shake/Documentation");
                if (!Directory.Exists(s_DocumentationPath))
                {
                    Directory.CreateDirectory(s_DocumentationPath);
                }
                break;

            case RuntimePlatform.WindowsEditor:
                s_DocumentationPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "Thinksquirrel/Camera Shake/Documentation");
                if (!Directory.Exists(s_DocumentationPath))
                {
                    Directory.CreateDirectory(s_DocumentationPath);
                }
                break;
            }
        }

        s_ShortPath   = new DirectoryInfo(s_DocumentationPath).Name;
        s_PrefsLoaded = true;
    }
        //=====================================================================

        /// <summary>
        /// This loads the dialog with the available projects from the given solution file
        /// </summary>
        /// <param name="solutionName">The solution filename to use</param>
        public void LoadSolutionProjectNames(string solutionName)
        {
            lblSolutionName.Text = solutionName;

            foreach (string project in DocumentationSource.ProjectsIn(solutionName).OrderBy(p => p))
            {
                cblProjects.Items.Add(project);
            }
        }
Example #3
0
        //=====================================================================

        /// <summary>
        /// This loads the dialog with the available projects from the given solution file
        /// </summary>
        /// <param name="solutionName">The solution filename to use</param>
        public void LoadSolutionProjectNames(string solutionName)
        {
            lblSolutionName.Text = solutionName;

            foreach (string project in DocumentationSource.ProjectsIn(solutionName).OrderBy(p => p))
            {
                lbProjects.Items.Add(new ProjectItem {
                    ProjectFilename = project
                });
            }
        }
    internal static void DownloadDocumentation(bool fromFirstRunWindow)
    {
        if (fromFirstRunWindow)
        {
            s_DownloadEveryUpdate = true;
            s_DocumentationSource = DocumentationSource.Local;
            EditorPrefs.SetInt("Thinksquirrel.CameraShakeEditor.DocumentationSource", (int)s_DocumentationSource);
            EditorPrefs.SetString("Thinksquirrel.CameraShakeEditor.DocumentationPath", s_DocumentationPath);
            EditorPrefs.SetBool("Thinksquirrel.CameraShakeEditor.DownloadDocsEveryUpdate", s_DownloadEveryUpdate);
        }

        s_ShowProgress            = true;
        s_FinishedInstall         = false;
        s_Progress                = "Downloading documentation...\n";
        s_ProgressColor           = Color.white;
        s_Www                     = new WWW(VersionInfo.ArchiveUrl());
        s_Canceled                = false;
        EditorApplication.update += UpdateProgress;
        EditorApplication.update += UpdateProgressBar;
    }
Example #5
0
        /// <summary>
        /// This method is used to execute the plug-in during the build process
        /// </summary>
        /// <param name="context">The current execution context</param>
        public void Execute(SandcastleBuilder.Utils.BuildComponent.ExecutionContext context)
        {
            Encoding        enc = Encoding.Default;
            Thread          browserThread;
            XmlDocument     sharedContent;
            XPathNavigator  navContent, item;
            XmlCommentsFile comments;
            string          sharedContentFilename, workingPath, content;

            // Copy any XML comments files from the project to the working folder.  Solutions, projects, and
            // assemblies are ignored as they won't be used with this build type.
            if (context.BuildStep == BuildStep.ValidatingDocumentationSources)
            {
                builder.ExecuteBeforeStepPlugIns();

                foreach (DocumentationSource ds in builder.CurrentProject.DocumentationSources)
                {
                    foreach (string commentsName in DocumentationSource.CommentsFiles(ds.SourceFile,
                                                                                      ds.IncludeSubFolders))
                    {
                        workingPath = builder.WorkingFolder + Path.GetFileName(commentsName);

                        // Warn if there is a duplicate and copy the comments file to a unique name to preserve
                        // its content.
                        if (File.Exists(workingPath))
                        {
                            workingPath = builder.WorkingFolder + Guid.NewGuid().ToString("B");

                            builder.ReportWarning("BE0063", "'{0}' matches a previously copied comments " +
                                                  "filename.  The duplicate will be copied to a unique name to preserve the " +
                                                  "comments it contains.", commentsName);
                        }

                        File.Copy(commentsName, workingPath, true);
                        File.SetAttributes(workingPath, FileAttributes.Normal);

                        // Add the file to the XML comments file collection
                        comments = new XmlCommentsFile(workingPath);

                        builder.CommentsFiles.Add(comments);
                        builder.ReportProgress("    {0} -> {1}", commentsName, workingPath);
                    }
                }

                builder.ExecuteAfterStepPlugIns();
                return;
            }

            // Remove the version information items from the shared content file as the AjaxDoc reflection file
            // doesn't contain version information.
            if (context.BuildStep == BuildStep.GenerateSharedContent)
            {
                builder.ReportProgress("Removing version information items from shared content file");

                sharedContentFilename = builder.WorkingFolder + "SHFBContent.xml";

                sharedContent = new XmlDocument();
                sharedContent.Load(sharedContentFilename);
                navContent = sharedContent.CreateNavigator();

                item = navContent.SelectSingleNode("content/item[@id='locationInformation']");

                if (item != null)
                {
                    item.DeleteSelf();
                }

                item = navContent.SelectSingleNode("content/item[@id='assemblyNameAndModule']");

                if (item != null)
                {
                    item.DeleteSelf();
                }

                sharedContent.Save(sharedContentFilename);
                return;
            }

            builder.ReportProgress("Using project '{0}'", projectName);

            if (regenerateFiles)
            {
                // Regenerate the files first.  This is done by starting a thread to invoke the AjaxDoc
                // application via a web browser control.  This is necessary as the browser control needs to run
                // in a thread with a single-threaded apartment state.  We can't just request the page as AjaxDoc
                // has to post back to itself in order to store the generated information.
                builder.ReportProgress("Generating XML comments and reflection information via AjaxDoc");

                browserThread = new Thread(RunBrowser);
                browserThread.SetApartmentState(ApartmentState.STA);

                navCount = 0;
                browserThread.Start();

                if (!browserThread.Join(11000))
                {
                    browserThread.Abort();
                }

                if (!String.IsNullOrEmpty(errorText))
                {
                    throw new BuilderException("ADP0003", "AjaxDoc encountered a scripting error: " + errorText);
                }

                if (commentsFile == null || reflectionFile == null)
                {
                    throw new BuilderException("ADP0004", "Unable to produce comments file and/or reflection file");
                }

                builder.ReportProgress("Generated comments file '{0}' and reflection file '{1}'", commentsFile,
                                       reflectionFile);
            }
            else
            {
                // Use the existing files
                commentsFile   = "Output/" + projectName + ".xml";
                reflectionFile = "Output/" + projectName + ".org";

                builder.ReportProgress("Using existing XML comments file '{0}' and reflection information " +
                                       "file '{1}'", commentsFile, reflectionFile);
            }

            // Allow Before step plug-ins to run
            builder.ExecuteBeforeStepPlugIns();

            // Download the files
            using (WebClient webClient = new WebClient())
            {
                webClient.UseDefaultCredentials = userCreds.UseDefaultCredentials;

                if (!userCreds.UseDefaultCredentials)
                {
                    webClient.Credentials = new NetworkCredential(userCreds.UserName, userCreds.Password);
                }

                webClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

                if (proxyCreds.UseProxyServer)
                {
                    webClient.Proxy = new WebProxy(proxyCreds.ProxyServer, true);

                    if (!proxyCreds.Credentials.UseDefaultCredentials)
                    {
                        webClient.Proxy.Credentials = new NetworkCredential(proxyCreds.Credentials.UserName,
                                                                            proxyCreds.Credentials.Password);
                    }
                }

                // Since there are only two, download them synchronously
                workingPath = builder.WorkingFolder + projectName + ".xml";
                builder.ReportProgress("Downloading {0}", commentsFile);
                webClient.DownloadFile(ajaxDocUrl + commentsFile, workingPath);
                builder.CommentsFiles.Add(new XmlCommentsFile(workingPath));

                builder.ReportProgress("Downloading {0}", reflectionFile);
                webClient.DownloadFile(ajaxDocUrl + reflectionFile, builder.ReflectionInfoFilename);

                builder.ReportProgress("Downloads completed successfully");
            }

            // AjaxDoc 1.1 prefixes all member names with "J#" which causes BuildAssembler's
            // ResolveReferenceLinksComponent component in the Sept 2007 CTP to crash.  As such, we'll strip it
            // out.  I can't see a need for it anyway.
            content = BuildProcess.ReadWithEncoding(workingPath, ref enc);
            content = content.Replace(":J#", ":");

            using (StreamWriter sw = new StreamWriter(workingPath, false, enc))
            {
                sw.Write(content);
            }

            content = BuildProcess.ReadWithEncoding(builder.ReflectionInfoFilename, ref enc);
            content = content.Replace(":J#", ":");

            using (StreamWriter sw = new StreamWriter(builder.ReflectionInfoFilename, false, enc))
            {
                sw.Write(content);
            }

            builder.ReportProgress("Applying visibility settings manually");
            builder.ApplyVisibilityProperties(builder.ReflectionInfoFilename);

            // Don't apply the API filter settings in a partial build
            if (builder.PartialBuildType == PartialBuildType.None && builder.BuildApiFilter.Count != 0)
            {
                builder.ReportProgress("Applying API filter manually");
                builder.ApplyManualApiFilter(builder.BuildApiFilter, builder.ReflectionInfoFilename);
            }

            // Allow After step plug-ins to run
            builder.ExecuteAfterStepPlugIns();
        }
        /// <summary>
        /// This is the method that indexes the comments files
        /// </summary>
        /// <remarks>Rather than a partial build, we'll just index the comments files.</remarks>
        private IndexedCommentsCache IndexComments()
        {
            HashSet <string>     projectDictionary = new HashSet <string>();
            IndexedCommentsCache cache             = new IndexedCommentsCache(100);
            MSBuildProject       projRef;
            string lastSolution = null;

            currentProject.EnsureProjectIsCurrent(false);

            // Index the framework comments based on the framework version in the project
            FrameworkSettings frameworkSettings = FrameworkDictionary.AllFrameworks.GetFrameworkWithRedirect(
                currentProject.FrameworkVersion);

            if (frameworkSettings == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  "Unable to locate information for a framework version or its redirect: {0}",
                                                                  currentProject.FrameworkVersion));
            }

            foreach (var location in frameworkSettings.CommentsFileLocations(currentProject.Language))
            {
                indexTokenSource.Token.ThrowIfCancellationRequested();

                cache.IndexCommentsFiles(Path.GetDirectoryName(location), Path.GetFileName(location),
                                         false, null);
            }

            // Index the comments file documentation sources
            foreach (string file in currentProject.DocumentationSources.CommentsFiles)
            {
                indexTokenSource.Token.ThrowIfCancellationRequested();

                cache.IndexCommentsFiles(Path.GetDirectoryName(file), Path.GetFileName(file), false, null);
            }

            // Also, index the comments files in project documentation sources
            foreach (DocumentationSource ds in currentProject.DocumentationSources)
            {
                foreach (var sourceProject in DocumentationSource.Projects(ds.SourceFile, ds.IncludeSubFolders,
                                                                           !String.IsNullOrEmpty(ds.Configuration) ? ds.Configuration : currentProject.Configuration,
                                                                           !String.IsNullOrEmpty(ds.Platform) ? ds.Platform : currentProject.Platform))
                {
                    indexTokenSource.Token.ThrowIfCancellationRequested();

                    // NOTE: This code should be similar to the code in BuildProcess.ValidateDocumentationSources!

                    // Solutions are followed by the projects that they contain
                    if (sourceProject.ProjectFileName.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
                    {
                        lastSolution = sourceProject.ProjectFileName;
                        continue;
                    }

                    // Ignore projects that we've already seen
                    if (projectDictionary.Add(sourceProject.ProjectFileName))
                    {
                        using (projRef = new MSBuildProject(sourceProject.ProjectFileName))
                        {
                            // Use the project file configuration and platform properties if they are set.  If
                            // not, use the documentation source values.  If they are not set, use the SHFB
                            // project settings.
                            projRef.SetConfiguration(
                                !String.IsNullOrEmpty(sourceProject.Configuration) ? sourceProject.Configuration :
                                !String.IsNullOrEmpty(ds.Configuration) ? ds.Configuration : currentProject.Configuration,
                                !String.IsNullOrEmpty(sourceProject.Platform) ? sourceProject.Platform :
                                !String.IsNullOrEmpty(ds.Platform) ? ds.Platform : currentProject.Platform,
                                currentProject.MSBuildOutDir, false);

                            // Add Visual Studio solution macros if necessary
                            if (lastSolution != null)
                            {
                                projRef.SetSolutionMacros(lastSolution);
                            }

                            if (!String.IsNullOrEmpty(projRef.XmlCommentsFile))
                            {
                                cache.IndexCommentsFiles(Path.GetDirectoryName(projRef.XmlCommentsFile),
                                                         Path.GetFileName(projRef.XmlCommentsFile), false, null);
                            }
                        }
                    }
                }
            }

            return(cache);
        }
Example #7
0
        /// <summary>
        /// This is the thread method that indexes the comments files
        /// </summary>
        /// <remarks>Rather than a partial build, we'll just index the
        /// comments files.</remarks>
        private void IndexComments()
        {
            HashSet <string>            projectDictionary  = new HashSet <string>();
            Collection <string>         frameworkLocations = new Collection <string>();
            Dictionary <string, string> cacheName          = new Dictionary <string, string>();
            IndexedCommentsCache        cache = new IndexedCommentsCache(100);
            MSBuildProject projRef;
            string         path, lastSolution = null;

            try
            {
                BuildProcess.GetFrameworkCommentsFiles(frameworkLocations,
                                                       cacheName, currentProject.Language,
                                                       currentProject.FrameworkVersion);

                // Index the framework comments
                foreach (string location in frameworkLocations)
                {
                    path = Environment.ExpandEnvironmentVariables(location);
                    cache.IndexCommentsFiles(path, null, true, null);
                }

                // Index the comments file documentation sources
                foreach (string file in currentProject.DocumentationSources.CommentsFiles)
                {
                    cache.IndexCommentsFiles(Path.GetDirectoryName(file),
                                             Path.GetFileName(file), false, null);
                }

                // Also, index the comments files in project documentation sources
                foreach (DocumentationSource ds in currentProject.DocumentationSources)
                {
                    foreach (var sourceProject in DocumentationSource.Projects(ds.SourceFile, ds.IncludeSubFolders,
                                                                               !String.IsNullOrEmpty(ds.Configuration) ? ds.Configuration : currentProject.Configuration,
                                                                               !String.IsNullOrEmpty(ds.Platform) ? ds.Platform : currentProject.Platform))
                    {
                        // NOTE: This code should be similar to the code in BuildProcess.ValidateDocumentationSources!

                        // Solutions are followed by the projects that they contain
                        if (sourceProject.ProjectFileName.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
                        {
                            lastSolution = sourceProject.ProjectFileName;
                            continue;
                        }

                        // Ignore projects that we've already seen
                        if (projectDictionary.Add(sourceProject.ProjectFileName))
                        {
                            projRef = new MSBuildProject(sourceProject.ProjectFileName);

                            // Use the project file configuration and platform properties if they are set.  If not,
                            // use the documentation source values.  If they are not set, use the SHFB project settings.
                            projRef.SetConfiguration(
                                !String.IsNullOrEmpty(sourceProject.Configuration) ? sourceProject.Configuration :
                                !String.IsNullOrEmpty(ds.Configuration) ? ds.Configuration : currentProject.Configuration,
                                !String.IsNullOrEmpty(sourceProject.Platform) ? sourceProject.Platform :
                                !String.IsNullOrEmpty(ds.Platform) ? ds.Platform : currentProject.Platform,
                                currentProject.MSBuildOutDir);

                            // Add Visual Studio solution macros if necessary
                            if (lastSolution != null)
                            {
                                projRef.SetSolutionMacros(lastSolution);
                            }

                            if (!String.IsNullOrEmpty(projRef.XmlCommentsFile))
                            {
                                cache.IndexCommentsFiles(Path.GetDirectoryName(projRef.XmlCommentsFile),
                                                         Path.GetFileName(projRef.XmlCommentsFile), false, null);
                            }
                        }
                    }
                }

                this.Invoke(new IndexingCompleted(this.Completed), new object[] { cache });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                this.Invoke(new IndexingFailed(this.Failed), new object[] { ex.Message });
            }
        }
    public static void PreferncesGUI()
    {
        if (!s_PrefsLoaded)
        {
            LoadPreferences();
        }

        s_Label.text    = "Open First-Time Setup";
        s_Label.tooltip = "Opens the Camera Shake first-time setup window.";
        if (GUILayout.Button(s_Label))
        {
            OpenFirstRunWindow();
        }

        // Documentation source
        s_Label.text          = "Documentation Source";
        s_Label.tooltip       = "The source for all documentation links.";
        s_DocumentationSource = (DocumentationSource)EditorGUILayout.EnumPopup(s_Label, s_DocumentationSource);

        if (s_DocumentationSource == DocumentationSource.Local)
        {
            // Documentation path
            s_Label.text    = "Documentation Path";
            s_Label.tooltip = "The path where local documentation should be saved.";
            GUILayout.BeginHorizontal();
            EditorGUILayout.TextField(s_Label, s_ShortPath);
            bool e = GUI.enabled;
            GUI.enabled = !(s_ShowProgress && !s_FinishedInstall);
            if (GUILayout.Button("...", GUILayout.ExpandWidth(false)))
            {
                string newPath = EditorUtility.OpenFolderPanel("Select folder", s_DocumentationPath, string.Empty);

                if (!string.IsNullOrEmpty(newPath))
                {
                    s_DocumentationPath = newPath;
                    s_ShortPath         = new DirectoryInfo(s_DocumentationPath).Name;
                    s_ShowProgress      = false;
                }
            }
            GUI.enabled = e;
            GUILayout.EndHorizontal();

            // Download documentation with every update
            s_Label.text    = "Download with Every Update";
            s_Label.tooltip = "If enabled, documentation will be downloaded with every Camera Shake update.";
            bool downloadEveryUpdate = EditorGUILayout.Toggle(s_Label, s_DownloadEveryUpdate);
            if (downloadEveryUpdate != s_DownloadEveryUpdate)
            {
                s_DownloadEveryUpdate = downloadEveryUpdate;
            }

            Color c = GUI.color;

            // Download documentation
            bool documentationExists = Directory.Exists(Path.Combine(s_DocumentationPath, VersionInfo.version));
            if (!documentationExists)
            {
                GUI.color = Color.red;
            }
            s_Label.text    = documentationExists ? "Update" : "Download";
            s_Label.tooltip = documentationExists ? "Update the local documentation from the server" : "Download local documentation from the server";
            if (GUILayout.Button(s_Label))
            {
                DownloadDocumentation();
            }

            GUI.color = c;

            DisplayDocumentationProgress();

            if (GUI.changed)
            {
                EditorPrefs.SetInt("Thinksquirrel.CameraShakeEditor.DocumentationSource", (int)s_DocumentationSource);
                EditorPrefs.SetString("Thinksquirrel.CameraShakeEditor.DocumentationPath", s_DocumentationPath);
                EditorPrefs.SetBool("Thinksquirrel.CameraShakeEditor.DownloadDocsEveryUpdate", s_DownloadEveryUpdate);
            }
        }
    }
Example #9
0
        static void PreferencesGui()
        {
            if (!s_PreferencesLoaded)
            {
                LoadPreferences();
            }

            // Documentation source
            s_DocumentationSource =
                (DocumentationSource)
                EditorGUILayout.EnumPopup(
                    TempContent("Documentation Source", "The source for all documentation links."),
                    s_DocumentationSource);

            if (s_DocumentationSource != DocumentationSource.Local)
            {
                return;
            }

            // Documentation path
            GUILayout.BeginHorizontal();
            EditorGUILayout.TextField(
                TempContent("Documentation Path", "The path where local documentation should be saved."), s_ShortPath);
            var e = GUI.enabled;

            GUI.enabled = !(s_ShowProgress && !s_FinishedInstall);
            if (GUILayout.Button("...", GUILayout.ExpandWidth(false)))
            {
                var newPath = EditorUtility.OpenFolderPanel("Select folder", s_DocumentationPath, string.Empty);

                if (!string.IsNullOrEmpty(newPath))
                {
                    s_DocumentationPath = newPath;
                    s_ShortPath         = new DirectoryInfo(s_DocumentationPath).Name;
                    s_ShowProgress      = false;
                }
            }
            GUI.enabled = e;
            GUILayout.EndHorizontal();

            // Download documentation with every update
            EditorGUI.BeginChangeCheck();
            var downloadEveryUpdate =
                EditorGUILayout.Toggle(
                    TempContent("Download with Every Update",
                                "If enabled, documentation will be downloaded with every CameraShake update."),
                    s_DownloadEveryUpdate);

            if (EditorGUI.EndChangeCheck() && downloadEveryUpdate != s_DownloadEveryUpdate)
            {
                s_DownloadEveryUpdate = downloadEveryUpdate;
            }

            var c = GUI.color;

            // Download documentation
            var documentationExists = Directory.Exists(Path.Combine(s_DocumentationPath, VersionInfo.version));

            if (!documentationExists)
            {
                GUI.color = Color.red;
            }
            s_Label.text    = documentationExists ? "Update" : "Download";
            s_Label.tooltip = documentationExists
                ? "Update the local documentation from the server"
                : "Download local documentation from the server";
            if (GUILayout.Button(s_Label))
            {
                DownloadDocumentation();
            }

            GUI.color = c;

            DisplayDocumentationProgress();

            if (!GUI.changed)
            {
                return;
            }

            EditorPrefs.SetInt("Thinksquirrel.CShakeEditor.DocumentationSource", (int)s_DocumentationSource);
            EditorPrefs.SetString("Thinksquirrel.CShakeEditor.DocumentationPath", s_DocumentationPath);
            EditorPrefs.SetBool("Thinksquirrel.CShakeEditor.DownloadDocsEveryUpdate", s_DownloadEveryUpdate);
        }