private System.Collections.IEnumerable async_PerformBatchAction(ProcessingBigTaskDialog.WorkerInterface state) { BatchActionTaskData data = state.Data as BatchActionTaskData; // Retrieve files to perform action on List <string> files = Resource.GetResourceFiles(data.FolderPath); state.Progress += 0.05f; yield return(null); // Perform action on files foreach (string file in files) { state.StateDesc = file; yield return(null); MetaFormatHelper.FilePerformAction(file, data.Action); state.Progress += 0.9f / files.Count; yield return(null); } // Assure reloading the modified resources if (PathHelper.IsPathLocatedIn(data.FolderPath, ".")) { string dataPath = PathHelper.MakeFilePathRelative(data.FolderPath); ContentProvider.RemoveContentTree(dataPath); } state.Progress += 0.05f; }
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")); }