예제 #1
0
        /// <summary>
        /// Triggers Duality to (re)load its <see cref="DualityAppData"/>.
        /// </summary>
        public static void LoadAppData()
        {
            string path = AppDataPath;

            if (File.Exists(path))
            {
                try
                {
                    Log.Core.Write("Loading AppData..");
                    Log.Core.PushIndent();
                    using (FileStream str = File.OpenRead(path))
                    {
                        using (var formatter = Formatter.Create(str))
                        {
                            appData = formatter.ReadObject() as DualityAppData ?? new DualityAppData();
                        }
                    }
                    Log.Core.PopIndent();
                }
                catch (Exception)
                {
                    appData = new DualityAppData();
                }
            }
            else
            {
                appData = new DualityAppData();
            }
        }
예제 #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() as 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
파일: DualityApp.cs 프로젝트: undue/duality
		/// <summary>
		/// Triggers Duality to (re)load its <see cref="DualityAppData"/>.
		/// </summary>
		public static void LoadAppData()
		{
			appData = Formatter.TryReadObject<DualityAppData>(AppDataPath) ?? new DualityAppData();
		}
예제 #4
0
 /// <summary>
 /// Triggers Duality to (re)load its <see cref="DualityAppData"/>.
 /// </summary>
 public static void LoadAppData()
 {
     appData = Serializer.TryReadObject <DualityAppData>(AppDataPath) ?? new DualityAppData();
 }
예제 #5
0
		/// <summary>
		/// Triggers Duality to (re)load its <see cref="DualityAppData"/>.
		/// </summary>
		public static void LoadAppData()
		{
			string path = AppDataPath;
			if (File.Exists(path))
			{
				try
				{
					Log.Core.Write("Loading AppData..");
					Log.Core.PushIndent();
					using (FileStream str = File.OpenRead(path))
					{
						using (var formatter = Formatter.Create(str))
						{
							appData = formatter.ReadObject() as DualityAppData ?? new DualityAppData();
						}
					}
					Log.Core.PopIndent();
				}
				catch (Exception)
				{
					appData = new DualityAppData();
				}
			}
			else
				appData = new DualityAppData();
		}