Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CommonAnalysis.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 using SiliconStudio.Core.IO;
7 
8 namespace SiliconStudio.Assets.Analysis
9 {
10  internal class CommonAnalysis
11  {
12  internal static void UpdatePaths(IFileSynchronizable parentFileSync, IEnumerable<AssetReferenceLink> paths, AssetAnalysisParameters parameters)
13  {
14  if (parameters == null) throw new ArgumentNullException("parameters");
15 
16  var fileDirectory = parentFileSync.FullPath.GetParent();
17 
18  foreach (var assetReferenceLink in paths)
19  {
20  var currentLocation = (UPath)assetReferenceLink.Reference;
21 
22  // If we need to skip an attribute
23  var upathAttribute = assetReferenceLink.Path.GetCustomAttribute<UPathAttribute>();
24  if (upathAttribute != null && upathAttribute.RelativeTo == UPathRelativeTo.None)
25  {
26  continue;
27  }
28 
29  UPath newLocation = null;
30 
31  var uFile = currentLocation as UFile;
32  if (uFile != null)
33  {
34  var previousLocationOnDisk = UPath.Combine(fileDirectory, uFile);
35 
36  // If UseRelativeForUFile is used, then turn
37  newLocation = parameters.ConvertUPathTo == UPathType.Relative ? previousLocationOnDisk.MakeRelative(fileDirectory) : previousLocationOnDisk;
38  }
39  else
40  {
41  var uDirectory = (UDirectory)currentLocation;
42 
43  var previousDirectoryOnDisk = UPath.Combine(fileDirectory, uDirectory);
44 
45  // If UseRelativeForUFile is used, then turn
46  newLocation = parameters.ConvertUPathTo == UPathType.Relative ? previousDirectoryOnDisk.MakeRelative(fileDirectory) : previousDirectoryOnDisk;
47  }
48 
49  // Only update location that are actually different
50  if (currentLocation != newLocation)
51  {
52  assetReferenceLink.UpdateReference(null, newLocation != null ? newLocation.FullPath : null);
53  if (parameters.SetDirtyFlagOnAssetWhenFixingUFile)
54  {
55  parentFileSync.IsDirty = true;
56  }
57  }
58 
59  // Set dirty flag on asset if the uFile was previously absolute and
60  // SetDirtyFlagOnAssetWhenFixingAbsoluteUFile = true
61  if ((currentLocation.IsAbsolute && parameters.ConvertUPathTo == UPathType.Absolute && parameters.SetDirtyFlagOnAssetWhenFixingAbsoluteUFile))
62  {
63  parentFileSync.IsDirty = true;
64  }
65  }
66  }
67  }
68 }
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
Definition: UDirectory.cs:13
UPathType
Describes if a UPath is relative or absolute.
Definition: UPathType.cs:8
Base class that describes a uniform path and provides method to manipulate them. Concrete class are U...
Definition: UPath.cs:21
UPathRelativeTo
Enum UPathRelativeTo
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13