本文整理汇总了C#中SiliconStudio.Core.IO.UFile.GetFileExtension方法的典型用法代码示例。如果您正苦于以下问题:C# UFile.GetFileExtension方法的具体用法?C# UFile.GetFileExtension怎么用?C# UFile.GetFileExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiliconStudio.Core.IO.UFile
的用法示例。
在下文中一共展示了UFile.GetFileExtension方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsSupportingFile
public static bool IsSupportingFile(this IAssetImporter importer, UFile file)
{
if (file == null) throw new ArgumentNullException("file");
if (file.GetFileExtension() == null) return false;
return FileUtility.GetFileExtensionsAsSet(importer.SupportedFileExtensions).Contains(file.GetFileExtension());
}
示例2: IsSupportingFile
public virtual bool IsSupportingFile(string filePath)
{
if (filePath == null) throw new ArgumentNullException("filePath");
var file = new UFile(filePath);
if (file.GetFileExtension() == null) return false;
return FileUtility.GetFileExtensionsAsSet(SupportedFileExtensions).Contains(file.GetFileExtension());
}
示例3: Load
public object Load(Stream stream, UFile filePath, ILogger log, out bool aliasOccurred, out Dictionary<YamlAssetPath, OverrideType> overrides)
{
aliasOccurred = false;
var assetFileExtension = filePath.GetFileExtension().ToLowerInvariant();
var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension);
var asset = (SourceCodeAsset)Activator.CreateInstance(type);
var textAccessor = asset.TextAccessor as SourceCodeAsset.DefaultTextAccessor;
if (textAccessor != null)
{
// Don't load the file if we have the file path
textAccessor.FilePath = filePath;
// Set the assets text if it loaded from an in-memory version
// TODO: Propagate dirtiness?
if (stream is MemoryStream)
{
var reader = new StreamReader(stream, Encoding.UTF8);
textAccessor.Set(reader.ReadToEnd());
}
}
// No override in source code assets
overrides = new Dictionary<YamlAssetPath, OverrideType>();
return asset;
}
示例4: ListAssetFiles
private static List<Tuple<UFile, UDirectory>> ListAssetFiles(ILogger log, Package package, CancellationToken? cancelToken)
{
var listFiles = new List<Tuple<UFile, UDirectory>>();
// TODO Check how to handle refresh correctly as a public API
if (package.RootDirectory == null)
{
throw new InvalidOperationException("Package RootDirectory is null");
}
if (!Directory.Exists(package.RootDirectory))
{
throw new InvalidOperationException("Package RootDirectory [{0}] does not exist".ToFormat(package.RootDirectory));
}
// Iterate on each source folders
foreach (var sourceFolder in package.GetDistinctAssetFolderPaths())
{
// Lookup all files
foreach (var directory in FileUtility.EnumerateDirectories(sourceFolder, SearchDirection.Down))
{
var files = directory.GetFiles();
foreach (var filePath in files)
{
// Don't load package via this method
if (filePath.FullName.EndsWith(PackageFileExtension))
{
continue;
}
// Make an absolute path from the root of this package
var fileUPath = new UFile(filePath.FullName);
if (fileUPath.GetFileExtension() == null)
{
continue;
}
// If this kind of file an asset file?
if (!AssetRegistry.IsAssetFileExtension(fileUPath.GetFileExtension()))
{
continue;
}
listFiles.Add(new Tuple<UFile, UDirectory>(fileUPath, sourceFolder));
}
}
}
return listFiles;
}
示例5: 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);
//.........这里部分代码省略.........
示例6: ListAssetFiles
public static List<PackageLoadingAssetFile> ListAssetFiles(ILogger log, Package package, CancellationToken? cancelToken)
{
var listFiles = new List<PackageLoadingAssetFile>();
// TODO Check how to handle refresh correctly as a public API
if (package.RootDirectory == null)
{
throw new InvalidOperationException("Package RootDirectory is null");
}
if (!Directory.Exists(package.RootDirectory))
{
return listFiles;
}
var sharedProfile = package.Profiles.FindSharedProfile();
var hasProject = sharedProfile != null && sharedProfile.ProjectReferences.Count > 0;
// Iterate on each source folders
foreach (var sourceFolder in package.GetDistinctAssetFolderPaths())
{
// Lookup all files
foreach (var directory in FileUtility.EnumerateDirectories(sourceFolder, SearchDirection.Down))
{
var files = directory.GetFiles();
foreach (var filePath in files)
{
// Don't load package via this method
if (filePath.FullName.EndsWith(PackageFileExtension))
{
continue;
}
// Make an absolute path from the root of this package
var fileUPath = new UFile(filePath.FullName);
if (fileUPath.GetFileExtension() == null)
{
continue;
}
// If this kind of file an asset file?
var ext = fileUPath.GetFileExtension();
//make sure to add default shaders in this case, since we don't have a csproj for them
if (AssetRegistry.IsProjectCodeGeneratorAssetFileExtension(ext) && !hasProject)
{
listFiles.Add(new PackageLoadingAssetFile(fileUPath, sourceFolder));
continue;
}
if (!AssetRegistry.IsAssetFileExtension(ext) || AssetRegistry.IsProjectSourceCodeAssetFileExtension(ext)) //project source code assets follow the csproj pipeline
{
continue;
}
listFiles.Add(new PackageLoadingAssetFile(fileUPath, sourceFolder));
}
}
}
//find also assets in the csproj
FindCodeAssetsInProject(listFiles, package);
return listFiles;
}
示例7: TestWithNormalization
public void TestWithNormalization()
{
var assetPath = new UFile("/a/b/.././././//c.txt");
Assert.AreEqual("/a", assetPath.GetDirectory());
Assert.AreEqual("c", assetPath.GetFileName());
Assert.AreEqual(".txt", assetPath.GetFileExtension());
Assert.AreEqual("/a/c", assetPath.GetDirectoryAndFileName());
Assert.AreEqual("/a/c.txt", assetPath.FullPath);
assetPath = new UFile("../.././././//c.txt");
Assert.AreEqual("../..", assetPath.GetDirectory());
Assert.AreEqual("c", assetPath.GetFileName());
Assert.AreEqual(".txt", assetPath.GetFileExtension());
Assert.AreEqual("../../c", assetPath.GetDirectoryAndFileName());
Assert.AreEqual("../../c.txt", assetPath.FullPath);
assetPath = new UFile("a/../../../c.txt");
Assert.AreEqual("../../c.txt", assetPath.FullPath);
}
示例8: TestWithSimplePathWithExtension
public void TestWithSimplePathWithExtension()
{
var assetPath = new UFile("/a/b/c.txt");
Assert.AreEqual("/a/b", assetPath.GetDirectory());
Assert.AreEqual("c", assetPath.GetFileName());
Assert.AreEqual(".txt", assetPath.GetFileExtension());
Assert.AreEqual("/a/b/c", assetPath.GetDirectoryAndFileName());
Assert.AreEqual("/a/b/c.txt", assetPath.FullPath);
}