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); }
public object Load(Stream stream, UFile filePath, ILogger log, bool clearBrokenObjectReferences, out bool aliasOccurred, out AttachedYamlAssetMetadata yamlMetadata) { aliasOccurred = false; var assetFileExtension = filePath.GetFileExtension().ToLowerInvariant(); var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension); var asset = (SourceCodeAsset)Activator.CreateInstance(type); var textAccessor = asset.TextAccessor as 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 yamlMetadata = new AttachedYamlAssetMetadata(); return(asset); }
public void TestWithSimplePathWithExtension() { var assetPath = new UFile("/a/b/c.txt"); Assert.Equal("/a/b", assetPath.GetDirectory()); Assert.Equal("c", assetPath.GetFileNameWithoutExtension()); Assert.Equal(".txt", assetPath.GetFileExtension()); Assert.Equal("/a/b/c", assetPath.GetDirectoryAndFileNameWithoutExtension()); Assert.Equal("/a/b/c.txt", assetPath.FullPath); }
public void TestWithSimplePath() { var assetPath = new UFile("/a/b/c"); Assert.AreEqual("/a/b", assetPath.GetDirectory()); Assert.AreEqual("c", assetPath.GetFileName()); Assert.AreEqual(null, assetPath.GetFileExtension()); Assert.AreEqual("/a/b/c", assetPath.GetDirectoryAndFileName()); Assert.AreEqual("/a/b/c", assetPath.FullPath); }
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())); }
public virtual bool IsSupportingFile(string filePath) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } var file = new UFile(filePath); if (file.GetFileExtension() == null) { return(false); } return(FileUtility.GetFileExtensionsAsSet(SupportedFileExtensions).Contains(file.GetFileExtension())); }
public void TestWithNormalization() { var assetPath = new UFile("/a/b/.././././//c.txt"); Assert.Equal("/a", assetPath.GetDirectory()); Assert.Equal("c", assetPath.GetFileNameWithoutExtension()); Assert.Equal(".txt", assetPath.GetFileExtension()); Assert.Equal("/a/c", assetPath.GetDirectoryAndFileNameWithoutExtension()); Assert.Equal("/a/c.txt", assetPath.FullPath); assetPath = new UFile("../.././././//c.txt"); Assert.Equal("../..", assetPath.GetDirectory()); Assert.Equal("c", assetPath.GetFileNameWithoutExtension()); Assert.Equal(".txt", assetPath.GetFileExtension()); Assert.Equal("../../c", assetPath.GetDirectoryAndFileNameWithoutExtension()); Assert.Equal("../../c.txt", assetPath.FullPath); assetPath = new UFile("a/../../../c.txt"); Assert.Equal("../../c.txt", assetPath.FullPath); }
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); }
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); }