本文整理汇总了C#中SiliconStudio.Core.IO.UFile.MakeRelative方法的典型用法代码示例。如果您正苦于以下问题:C# UFile.MakeRelative方法的具体用法?C# UFile.MakeRelative怎么用?C# UFile.MakeRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiliconStudio.Core.IO.UFile
的用法示例。
在下文中一共展示了UFile.MakeRelative方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddExitingProject
/// <summary>
/// Adds an exiting project to this package.
/// </summary>
/// <param name="pathToMsproj">The path to msproj.</param>
/// <param name="logger">The logger.</param>
public void AddExitingProject(UFile pathToMsproj, LoggerResult logger)
{
if (pathToMsproj == null) throw new ArgumentNullException("pathToMsproj");
if (logger == null) throw new ArgumentNullException("logger");
if (!pathToMsproj.IsAbsolute) throw new ArgumentException("Expecting relative path", "pathToMsproj");
try
{
// Load a project without specifying a platform to make sure we get the correct platform type
var msProject = VSProjectHelper.LoadProject(pathToMsproj, platform: "NoPlatform");
var projectType = VSProjectHelper.GetProjectTypeFromProject(msProject);
if (!projectType.HasValue)
{
logger.Error("This project is not a project created with the editor");
}
else
{
var platformType = VSProjectHelper.GetPlatformTypeFromProject(msProject) ?? PlatformType.Shared;
var projectReference = new ProjectReference()
{
Id = VSProjectHelper.GetProjectGuid(msProject),
Location = pathToMsproj.MakeRelative(RootDirectory),
Type = projectType.Value
};
// Add the ProjectReference only for the compatible profiles (same platform or no platform)
foreach (var profile in Profiles.Where(profile => platformType == profile.Platform))
{
profile.ProjectReferences.Add(projectReference);
}
}
}
catch (Exception ex)
{
logger.Error("Unexpected exception while loading project [{0}]", ex, pathToMsproj);
}
}
示例2: TestMakeRelativeWithDrive
public void TestMakeRelativeWithDrive()
{
UPath assetPath2 = null;
UPath newAssetPath2 = null;
var dir1 = new UDirectory("C:/a/b/c");
// Test direct relative
assetPath2 = new UFile("C:/a/b/c/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("test.txt", newAssetPath2.FullPath);
// Test direct relative + subdir
assetPath2 = new UFile("C:/a/b/c/test/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("test/test.txt", newAssetPath2.FullPath);
// Test relative 1
assetPath2 = new UFile("C:/a/b/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../test.txt", newAssetPath2.FullPath);
// Test relative 2
assetPath2 = new UFile("C:/a/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../../test.txt", newAssetPath2.FullPath);
// Test relative 3
assetPath2 = new UFile("C:/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);
// Test already relative
assetPath2 = new UFile("../test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../test.txt", newAssetPath2.FullPath);
// Test no path in common
assetPath2 = new UFile("E:/e/f/g/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("E:/e/f/g/test.txt", newAssetPath2.FullPath);
// Test no root path single file
assetPath2 = new UFile("E:/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("E:/test.txt", newAssetPath2.FullPath);
}
示例3: RunChangeWatcher
/// <summary>
/// This method is running in a separate thread and process file events received from <see cref="Core.IO.DirectoryWatcher"/>
/// in order to generate the appropriate list of <see cref="AssetFileChangedEvent"/>.
/// </summary>
private void RunChangeWatcher()
{
// Only check every minute
while (true)
{
if (threadWatcherEvent.WaitOne(TrackingSleepTime))
break;
// Use a working copy in order to limit the locking
fileEventsWorkingCopy.Clear();
lock (fileEvents)
{
fileEventsWorkingCopy.AddRange(fileEvents);
fileEvents.Clear();
}
if (fileEventsWorkingCopy.Count == 0 || isTrackingPaused)
continue;
var assetEvents = new List<AssetFileChangedEvent>();
// If this an asset belonging to a package
lock (ThisLock)
{
var packages = Packages;
// File event
foreach (var fileEvent in fileEventsWorkingCopy)
{
var file = new UFile(fileEvent.FullPath);
// When the session is being saved, we should not process events are they are false-positive alerts
// So we just skip the file
if (assetsBeingSaved.Contains(file.FullPath))
{
continue;
}
// 1) Check if this is related to imported assets
// Asset imports are handled slightly differently as we need to compute the
// hash of the source file
if (mapInputDependencyToAssets.ContainsKey(file.FullPath))
{
// Prepare the hash of the import file in advance for later re-import
FileVersionManager.Instance.ComputeFileHashAsync(file.FullPath, SourceImportFileHashCallback, tokenSourceForImportHash.Token);
continue;
}
// 2) else check that the file is a supported extension
if (!AssetRegistry.IsAssetFileExtension(file.GetFileExtension()))
{
continue;
}
// Find the parent package of the file that has been updated
UDirectory parentPackagePath = null;
Package parentPackage = null;
foreach (var package in packages)
{
var rootDirectory = package.RootDirectory;
if (rootDirectory == null)
continue;
if (rootDirectory.Contains(file) && (parentPackagePath == null || parentPackagePath.FullPath.Length < rootDirectory.FullPath.Length))
{
parentPackagePath = rootDirectory;
parentPackage = package;
}
}
// If we found a parent package, create an associated asset event
if (parentPackage != null)
{
var relativeLocation = file.MakeRelative(parentPackagePath);
var item = parentPackage.Assets.Find(relativeLocation);
AssetFileChangedEvent evt = null;
switch (fileEvent.ChangeType)
{
case FileEventChangeType.Created:
evt = new AssetFileChangedEvent(parentPackage, AssetFileChangedType.Added, relativeLocation);
break;
case FileEventChangeType.Deleted:
evt = new AssetFileChangedEvent(parentPackage, AssetFileChangedType.Deleted, relativeLocation);
break;
case FileEventChangeType.Changed:
evt = new AssetFileChangedEvent(parentPackage, AssetFileChangedType.Updated, relativeLocation);
break;
}
if (evt != null)
{
if (item != null)
{
evt.AssetId = item.Id;
}
assetEvents.Add(evt);
//.........这里部分代码省略.........
示例4: TestMakeRelative
public void TestMakeRelative()
{
UPath assetPath2 = null;
UPath newAssetPath2 = null;
var dir1 = new UDirectory("/a/b/c");
var assetDir2 = new UDirectory("/a/b/c");
newAssetPath2 = dir1.MakeRelative(assetDir2);
Assert.AreEqual(".", newAssetPath2.FullPath);
var assetDir3 = new UDirectory("/a/b");
newAssetPath2 = dir1.MakeRelative(assetDir3);
Assert.AreEqual("c", newAssetPath2.FullPath);
var assetDir4 = new UDirectory("/a/b/c/d");
newAssetPath2 = dir1.MakeRelative(assetDir4);
Assert.AreEqual("..", newAssetPath2.FullPath);
// Test direct relative
assetPath2 = new UFile("/a/b/c/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("test.txt", newAssetPath2.FullPath);
// Test direct relative + subdir
assetPath2 = new UFile("/a/b/c/test/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("test/test.txt", newAssetPath2.FullPath);
// Test relative 1
assetPath2 = new UFile("/a/b/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../test.txt", newAssetPath2.FullPath);
// Test relative 2
assetPath2 = new UFile("/a/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../../test.txt", newAssetPath2.FullPath);
// Test relative 3
assetPath2 = new UFile("/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);
// Test already relative
assetPath2 = new UFile("../test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../test.txt", newAssetPath2.FullPath);
// Test only root path in common
assetPath2 = new UFile("/e/f/g/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../../../e/f/g/test.txt", newAssetPath2.FullPath);
// Test only root path in common with single file
assetPath2 = new UFile("/test.txt");
newAssetPath2 = assetPath2.MakeRelative(dir1);
Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);
}