Beispiel #1
0
        public static string CreateNewProject(string projName, string projFolder, ProjectTemplateInfo template)
        {
            // Create project folder
            projFolder = Path.Combine(projFolder, projName);
            if (!Directory.Exists(projFolder))
            {
                Directory.CreateDirectory(projFolder);
            }

            // Extract template
            if (template.SpecialTag == ProjectTemplateInfo.SpecialInfo.None)
            {
                template.ExtractTo(projFolder);

                // Update main directory
                foreach (string srcFile in Directory.GetFiles(Environment.CurrentDirectory, "*", SearchOption.TopDirectoryOnly))
                {
                    if (Path.GetFileName(srcFile) == "appdata.dat")
                    {
                        continue;
                    }
                    if (Path.GetFileName(srcFile) == "defaultuserdata.dat")
                    {
                        continue;
                    }
                    string dstFile = Path.Combine(projFolder, Path.GetFileName(srcFile));
                    File.Copy(srcFile, dstFile, true);
                }

                // Update plugin directory
                foreach (string dstFile in Directory.GetFiles(Path.Combine(projFolder, DualityApp.PluginDirectory), "*", SearchOption.AllDirectories))
                {
                    string srcFileWorking = Path.Combine(DualityApp.PluginDirectory, Path.GetFileName(dstFile));
                    string srcFileExec    = Path.Combine(PathHelper.ExecutingAssemblyDir, DualityApp.PluginDirectory, Path.GetFileName(dstFile));
                    if (File.Exists(srcFileWorking))
                    {
                        File.Copy(srcFileWorking, dstFile, true);
                    }
                    else if (File.Exists(srcFileExec))
                    {
                        File.Copy(srcFileExec, dstFile, true);
                    }
                }
            }
            else if (template.SpecialTag == ProjectTemplateInfo.SpecialInfo.Current)
            {
                DualityEditorApp.SaveAllProjectData();
                PathHelper.CopyDirectory(Environment.CurrentDirectory, projFolder, true, delegate(string path)
                {
                    bool isDir      = Directory.Exists(path);
                    string fullPath = Path.GetFullPath(path);
                    if (isDir)
                    {
                        return(fullPath != Path.GetFullPath(EditorHelper.BackupDirectory));
                    }
                    else
                    {
                        return(true);
                    }
                });
            }
            else
            {
                PathHelper.CopyDirectory(Environment.CurrentDirectory, projFolder, true, delegate(string path)
                {
                    bool isDir      = Directory.Exists(path);
                    string fullPath = Path.GetFullPath(path);
                    if (isDir)
                    {
                        return
                        (fullPath != Path.GetFullPath(DualityApp.DataDirectory) &&
                         fullPath != Path.GetFullPath(EditorHelper.SourceDirectory) &&
                         fullPath != Path.GetFullPath(EditorHelper.BackupDirectory));
                    }
                    else
                    {
                        string fileName = Path.GetFileName(fullPath);
                        return(fileName != "appdata.dat" && fileName != "defaultuserdata.dat" && fileName != "designtimedata.dat");
                    }
                });
            }

            // Adjust current directory and perform init operations in the new project folder
            string oldPath = Environment.CurrentDirectory;

            Environment.CurrentDirectory = projFolder;
            try
            {
                // Initialize AppData
                DualityAppData data;
                data            = Serializer.TryReadObject <DualityAppData>(DualityApp.AppDataPath) ?? new DualityAppData();
                data.AppName    = projName;
                data.AuthorName = Environment.UserName;
                data.Version    = 0;
                Serializer.WriteObject(data, DualityApp.AppDataPath, SerializeMethod.Xml);

                // Read content source code data (needed to rename classes / namespaces)
                string oldRootNamespaceNameCore;
                string newRootNamespaceNameCore;
                DualityEditorApp.ReadPluginSourceCodeContentData(out oldRootNamespaceNameCore, out newRootNamespaceNameCore);

                // Initialize source code
                DualityEditorApp.InitPluginSourceCode();                 // Force re-init to update namespaces, etc.
                DualityEditorApp.UpdatePluginSourceCode();

                // Add SerializeErrorHandler class to handle renamed Types
                if (Directory.Exists(DualityApp.DataDirectory))
                {
                    // Add error handler source file to project
                    XDocument coreProject         = XDocument.Load(SourceCodeProjectCorePluginFile);
                    string    relErrorHandlerPath = PathHelper.MakeFilePathRelative(
                        SourceCodeErrorHandlerFile,
                        Path.GetDirectoryName(SourceCodeProjectCorePluginFile));
                    if (!coreProject.Descendants("Compile", true).Any(c => string.Equals(c.GetAttributeValue("Include"), relErrorHandlerPath)))
                    {
                        XElement compileElement    = coreProject.Descendants("Compile", true).FirstOrDefault();
                        XElement newCompileElement = new XElement(
                            XName.Get("Compile", compileElement.Name.NamespaceName),
                            new XAttribute("Include", relErrorHandlerPath));
                        compileElement.AddAfterSelf(newCompileElement);
                    }
                    coreProject.Save(SourceCodeProjectCorePluginFile);

                    // Generate and save error handler source code
                    File.WriteAllText(
                        EditorHelper.SourceCodeErrorHandlerFile,
                        EditorHelper.GenerateErrorHandlersSrcFile(oldRootNamespaceNameCore, newRootNamespaceNameCore));
                }

                // Compile plugins
                BuildHelper.BuildSolutionFile(EditorHelper.SourceCodeSolutionFile, "Release");
            }
            finally
            {
                Environment.CurrentDirectory = oldPath;
            }
            return(Path.Combine(projFolder, "DualityEditor.exe"));
        }
Beispiel #2
0
        private static void UpdateHelpStack()
        {
            needStackUpdate = false;

            foreach (Form f in EditorHelper.GetZSortedAppWindows())
            {
                if (!f.Visible)
                {
                    continue;
                }
                if (!new Rectangle(f.Location, f.Size).Contains(Cursor.Position))
                {
                    continue;
                }

                Point localPos = f.PointToClient(Cursor.Position);
                hoveredControl = f.GetChildAtPointDeep(localPos, GetChildAtPointSkip.Invisible | GetChildAtPointSkip.Transparent);
                break;
            }

            Control  c;
            HelpInfo help;

            // Get rid of disposed Controls
            c = hoveredHelpProvider as Control;
            if (c == null || c.IsDisposed)
            {
                hoveredHelpProvider = null;
                hoveredHelpCaptured = false;
            }

            // An IHelpProvider has captured the mouse: Ask what to do with it.
            if (hoveredHelpCaptured)
            {
                help = hoveredHelpProvider.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);

                // Update provider's help info
                stack.UpdateFromProvider(hoveredHelpProvider, help);

                // If still in charge: Return early.
                if (hoveredHelpCaptured)
                {
                    return;
                }
            }

            // No IHelpProvider in charge: Find one that provides help
            help = null;
            IHelpProvider lastHelpProvider = hoveredHelpProvider;

            foreach (IHelpProvider hp in hoveredControl.GetControlAncestors <IHelpProvider>())
            {
                c    = hp as Control;
                help = hp.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);
                hoveredHelpProvider = hp;
                if (help != null || hoveredHelpCaptured)
                {
                    break;
                }
            }

            // Update help system based on the result.
            if (lastHelpProvider != hoveredHelpProvider)
            {
                stack.UpdateFromProvider(lastHelpProvider, hoveredHelpProvider, help);
            }
            else if (hoveredHelpProvider != null)
            {
                stack.UpdateFromProvider(hoveredHelpProvider, help);
            }
        }
Beispiel #3
0
        private static void UpdateHelpStack()
        {
            needStackUpdate = false;

            // Retrieving all windows in a z-sorted way is a "time consuming" (~ 0.05ms) and API-heavy
            // query, and we don't need to be that accurate. Don't do it every time. Once a second is enough.
            bool updateGlobalWindows =
                globalWindows == null ||
                (DateTime.Now - lastGlobalWindowUpdate).TotalMilliseconds > 1000 ||
                globalWindows.Any(f => f.IsDisposed);

            if (updateGlobalWindows)
            {
                lastGlobalWindowUpdate = DateTime.Now;
                globalWindows          = EditorHelper.GetZSortedAppWindows();
            }

            // Iterate through our list of windows to find the one we're hovering
            foreach (Form form in globalWindows)
            {
                if (!form.Visible)
                {
                    continue;
                }
                if (!new Rectangle(form.Location, form.Size).Contains(Cursor.Position))
                {
                    continue;
                }

                Point localPos = form.PointToClient(Cursor.Position);
                hoveredControl = form.GetChildAtPointDeep(localPos, GetChildAtPointSkip.Invisible | GetChildAtPointSkip.Transparent);
                break;
            }

            Control  c;
            HelpInfo help;

            // Get rid of disposed Controls
            c = hoveredHelpProvider as Control;
            if (c == null || c.IsDisposed)
            {
                hoveredHelpProvider = null;
                hoveredHelpCaptured = false;
            }

            // An IHelpProvider has captured the mouse: Ask what to do with it.
            if (hoveredHelpCaptured)
            {
                help = hoveredHelpProvider.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);

                // Update provider's help info
                stack.UpdateFromProvider(hoveredHelpProvider, help);

                // If still in charge: Return early.
                if (hoveredHelpCaptured)
                {
                    return;
                }
            }

            // No IHelpProvider in charge: Find one that provides help
            help = null;
            IHelpProvider lastHelpProvider = hoveredHelpProvider;

            foreach (IHelpProvider hp in hoveredControl.GetControlAncestors <IHelpProvider>())
            {
                c    = hp as Control;
                help = hp.ProvideHoverHelp(c.PointToClient(Cursor.Position), ref hoveredHelpCaptured);
                hoveredHelpProvider = hp;
                if (help != null || hoveredHelpCaptured)
                {
                    break;
                }
            }

            // Update help system based on the result.
            if (lastHelpProvider != hoveredHelpProvider)
            {
                stack.UpdateFromProvider(lastHelpProvider, hoveredHelpProvider, help);
            }
            else if (hoveredHelpProvider != null)
            {
                stack.UpdateFromProvider(hoveredHelpProvider, help);
            }
        }