MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Load

Method Load

Source/Tools/Flax.Build/ProjectInfo.cs:428–498  ·  view source on GitHub ↗

Loads the project from the specified file. The path. The loaded project.

(string path)

Source from the content-addressed store, hash-verified

426 /// <param name="path">The path.</param>
427 /// <returns>The loaded project.</returns>
428 public static ProjectInfo Load(string path)
429 {
430 // Try to reuse loaded file
431 path = Utilities.RemovePathRelativeParts(path);
432 if (_projectsCache == null)
433 _projectsCache = new List<ProjectInfo>();
434 for (int i = 0; i < _projectsCache.Count; i++)
435 {
436 if (_projectsCache[i].ProjectPath == path)
437 return _projectsCache[i];
438 }
439
440 try
441 {
442 // Load
443 Log.Verbose("Loading project file from \"" + path + "\"...");
444 var contents = File.ReadAllText(path);
445 var project = JsonSerializer.Deserialize<ProjectInfo>(contents.AsSpan(), JsonOptions);
446 project.ProjectPath = path;
447 project.ProjectFolderPath = Path.GetDirectoryName(path);
448
449 // Process project data
450 if (string.IsNullOrEmpty(project.Name))
451 throw new Exception("Missing project name.");
452 if (project.Version == null)
453 project.Version = new Version(1, 0);
454 if (project.Version.Revision == 0)
455 project.Version = new Version(project.Version.Major, project.Version.Minor, project.Version.Build);
456 if (project.Version.Build == 0 && project.Version.Revision == -1)
457 project.Version = new Version(project.Version.Major, project.Version.Minor);
458 foreach (var reference in project.References)
459 {
460 string referencePath;
461 if (reference.Name.StartsWith("$(EnginePath)"))
462 {
463 // Relative to engine root
464 referencePath = Path.Combine(Globals.EngineRoot, reference.Name.Substring(14));
465 }
466 else if (reference.Name.StartsWith("$(ProjectPath)"))
467 {
468 // Relative to project root
469 referencePath = Path.Combine(project.ProjectFolderPath, reference.Name.Substring(15));
470 }
471 else if (Path.IsPathRooted(reference.Name))
472 {
473 // Relative to workspace
474 referencePath = Path.Combine(Environment.CurrentDirectory, reference.Name);
475 }
476 else
477 {
478 // Absolute
479 referencePath = reference.Name;
480 }
481 referencePath = Utilities.RemovePathRelativeParts(referencePath);
482
483 // Load referenced project
484 reference.Project = Load(referencePath);
485 }

Callers 1

MainMethod · 0.45

Calls 9

VerboseMethod · 0.80
ReadAllTextMethod · 0.80
GetDirectoryNameMethod · 0.80
SubstringMethod · 0.80
LoadFunction · 0.50
StartsWithMethod · 0.45
AddMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected