Loads the project from the specified file. The path. The loaded project.
(string path)
| 231 | /// <param name="path">The path.</param> |
| 232 | /// <returns>The loaded project.</returns> |
| 233 | public static ProjectInfo Load(string path) |
| 234 | { |
| 235 | // Try to reuse loaded file |
| 236 | path = StringUtils.RemovePathRelativeParts(path); |
| 237 | if (_projectsCache == null) |
| 238 | _projectsCache = new List<ProjectInfo>(); |
| 239 | for (int i = 0; i < _projectsCache.Count; i++) |
| 240 | { |
| 241 | if (_projectsCache[i].ProjectPath == path) |
| 242 | return _projectsCache[i]; |
| 243 | } |
| 244 | |
| 245 | Profiler.BeginEvent(path); |
| 246 | try |
| 247 | { |
| 248 | // Load |
| 249 | var contents = File.ReadAllText(path); |
| 250 | var project = JsonConvert.DeserializeObject<ProjectInfo>(contents, new JsonSerializerSettings() { Converters = new[] { new FlaxVersionConverter() } }); |
| 251 | project.ProjectPath = path; |
| 252 | project.ProjectFolderPath = StringUtils.NormalizePath(Path.GetDirectoryName(path)); |
| 253 | |
| 254 | // Process project data |
| 255 | if (string.IsNullOrEmpty(project.Name)) |
| 256 | throw new Exception("Missing project name."); |
| 257 | if (project.Version == null) |
| 258 | project.Version = new Version(1, 0); |
| 259 | if (project.Version.Revision == 0) |
| 260 | project.Version = new Version(project.Version.Major, project.Version.Minor, project.Version.Build); |
| 261 | if (project.Version.Build == 0 && project.Version.Revision == -1) |
| 262 | project.Version = new Version(project.Version.Major, project.Version.Minor); |
| 263 | foreach (var reference in project.References) |
| 264 | { |
| 265 | string referencePath; |
| 266 | if (reference.Name.StartsWith("$(EnginePath)")) |
| 267 | { |
| 268 | // Relative to engine root |
| 269 | referencePath = Path.Combine(Globals.StartupFolder, reference.Name.Substring(14)); |
| 270 | } |
| 271 | else if (reference.Name.StartsWith("$(ProjectPath)")) |
| 272 | { |
| 273 | // Relative to project root |
| 274 | referencePath = Path.Combine(project.ProjectFolderPath, reference.Name.Substring(15)); |
| 275 | } |
| 276 | else if (Path.IsPathRooted(reference.Name)) |
| 277 | { |
| 278 | // Relative to workspace |
| 279 | referencePath = Path.Combine(Environment.CurrentDirectory, reference.Name); |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | // Absolute |
| 284 | referencePath = reference.Name; |
| 285 | } |
| 286 | |
| 287 | // Load referenced project |
| 288 | reference.Project = Load(referencePath); |
| 289 | } |
| 290 |
nothing calls this directly
no test coverage detected