ExtractTo() публичный Метод

public ExtractTo ( string dir ) : void
dir string
Результат void
Пример #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, typeof(XmlSerializer));

                // 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"));
        }
Пример #2
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 srcFile = Path.Combine(DualityApp.PluginDirectory, Path.GetFileName(dstFile));
                    if (File.Exists(srcFile))
                    {
                        File.Copy(srcFile, 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 for further operations
            string oldPath = Environment.CurrentDirectory;

            Environment.CurrentDirectory = projFolder;

            // Initialize content
            if (Directory.Exists(DualityApp.DataDirectory))
            {
                // Read content source code data (needed to rename classes / namespaces)
                string oldRootNamespaceNameCore;
                string newRootNamespaceNameCore;
                DualityEditorApp.ReadPluginSourceCodeContentData(out oldRootNamespaceNameCore, out newRootNamespaceNameCore);

                // Rename classes / namespaces
                List <string> resFiles = Resource.GetResourceFiles();
                foreach (string resFile in resFiles)
                {
                    MetaFormatHelper.FilePerformAction(resFile, d => d.ReplaceTypeStrings(oldRootNamespaceNameCore, newRootNamespaceNameCore));
                }
            }

            // Initialize AppData
            DualityAppData data;

            if (File.Exists(DualityApp.AppDataPath))
            {
                try
                {
                    using (FileStream str = File.OpenRead(DualityApp.AppDataPath))
                        using (var formatter = Formatter.Create(str))
                        {
                            data = formatter.ReadObject <DualityAppData>() ?? new DualityAppData();
                        }
                }
                catch (Exception) { data = new DualityAppData(); }
            }
            else
            {
                data = new DualityAppData();
            }
            data.AppName    = projName;
            data.AuthorName = Environment.UserName;
            data.Version    = 0;
            using (FileStream str = File.Open(DualityApp.AppDataPath, FileMode.Create))
                using (var formatter = Formatter.Create(str, FormattingMethod.Binary))
                {
                    formatter.WriteObject(data);
                }

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

            // Compile plugins
            var buildProperties = new Dictionary <string, string>();

            buildProperties["Configuration"] = "Release";
            var buildRequest    = new BuildRequestData(EditorHelper.SourceCodeSolutionFile, buildProperties, null, new string[] { "Build" }, null);
            var buildParameters = new BuildParameters();
            var buildResult     = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);

            Environment.CurrentDirectory = oldPath;
            return(Path.Combine(projFolder, "DualityEditor.exe"));
        }
Пример #3
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");
        }
Пример #4
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 srcFile = Path.Combine(DualityApp.PluginDirectory, Path.GetFileName(dstFile));
                    if (File.Exists(srcFile)) File.Copy(srcFile, 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 for further operations
            string oldPath = Environment.CurrentDirectory;
            Environment.CurrentDirectory = projFolder;

            // Initialize content
            if (Directory.Exists(DualityApp.DataDirectory))
            {
                // Read content source code data (needed to rename classes / namespaces)
                string oldRootNamespaceNameCore;
                string newRootNamespaceNameCore;
                DualityEditorApp.ReadPluginSourceCodeContentData(out oldRootNamespaceNameCore, out newRootNamespaceNameCore);

                // Rename classes / namespaces
                List<string> resFiles = Resource.GetResourceFiles();
                foreach (string resFile in resFiles)
                {
                    MetaFormatHelper.FilePerformAction(resFile, d => d.ReplaceTypeStrings(oldRootNamespaceNameCore, newRootNamespaceNameCore));
                }
            }

            // Initialize AppData
            DualityAppData data;
            if (File.Exists(DualityApp.AppDataPath))
            {
                try
                {
                    using (FileStream str = File.OpenRead(DualityApp.AppDataPath))
                    using (var formatter = Formatter.Create(str))
                    {
                        data = formatter.ReadObject<DualityAppData>() ?? new DualityAppData();
                    }
                }
                catch (Exception) { data = new DualityAppData(); }
            }
            else
            {
                data = new DualityAppData();
            }
            data.AppName = projName;
            data.AuthorName = Environment.UserName;
            data.Version = 0;
            using (FileStream str = File.Open(DualityApp.AppDataPath, FileMode.Create))
            using (var formatter = Formatter.Create(str, FormattingMethod.Binary))
            {
                formatter.WriteObject(data);
            }

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

            // Compile plugins
            var buildProperties = new Dictionary<string, string>();
            buildProperties["Configuration"] = "Release";
            var buildRequest = new BuildRequestData(EditorHelper.SourceCodeSolutionFile, buildProperties, null, new string[] { "Build" }, null);
            var buildParameters = new BuildParameters();
            var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);

            Environment.CurrentDirectory = oldPath;
            return Path.Combine(projFolder, "DualityEditor.exe");
        }