private static Asset LoadAsset(ILogger log, string assetFullPath, string assetPath, UFile fileUPath) { AssetMigration.MigrateAssetIfNeeded(log, assetFullPath); var asset = AssetSerializer.Load <Asset>(assetFullPath); // Set location on source code asset var sourceCodeAsset = asset as SourceCodeAsset; if (sourceCodeAsset != null) { // Use an id generated from the location instead of the default id sourceCodeAsset.Id = SourceCodeAsset.GenerateGuidFromLocation(assetPath); sourceCodeAsset.AbsoluteSourceLocation = fileUPath; } return(asset); }
/// <summary> /// Performs first part of the loading sequence, by deserializing the package but without processing anything yet. /// </summary> /// <param name="log">The log.</param> /// <param name="filePath">The file path.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// log /// or /// filePath /// </exception> internal static Package LoadRaw(ILogger log, string filePath) { if (log == null) { throw new ArgumentNullException("log"); } if (filePath == null) { throw new ArgumentNullException("filePath"); } filePath = FileUtility.GetAbsolutePath(filePath); if (!File.Exists(filePath)) { log.Error("Package file [{0}] was not found", filePath); return(null); } try { bool aliasOccurred; var packageFile = new PackageLoadingAssetFile(filePath, Path.GetDirectoryName(filePath)); AssetMigration.MigrateAssetIfNeeded(log, packageFile); var package = packageFile.AssetContent != null ? (Package)AssetSerializer.Load(new MemoryStream(packageFile.AssetContent), Path.GetExtension(filePath), log, out aliasOccurred) : AssetSerializer.Load <Package>(filePath, log, out aliasOccurred); package.FullPath = filePath; package.IsDirty = packageFile.AssetContent != null || aliasOccurred; return(package); } catch (Exception ex) { log.Error("Error while pre-loading package [{0}]", ex, filePath); } return(null); }
private void LoadAsset(ILogger log, PackageLoadingAssetFile assetFile, LoggerResult loggerResult) { var fileUPath = assetFile.FilePath; var sourceFolder = assetFile.SourceFolder; // Check if asset has been deleted by an upgrader if (assetFile.Deleted) { IsDirty = true; filesToDelete.Add(assetFile.FilePath); } // An exception can occur here, so we make sure that loading a single asset is not going to break // the loop try { AssetMigration.MigrateAssetIfNeeded(log, assetFile); // Try to load only if asset is not already in the package or assetRef.Asset is null var assetPath = fileUPath.MakeRelative(sourceFolder).GetDirectoryAndFileName(); var assetFullPath = fileUPath.FullPath; var assetContent = assetFile.AssetContent; var asset = LoadAsset(log, assetFullPath, assetPath, fileUPath, assetContent); // Create asset item var assetItem = new AssetItem(assetPath, asset, this) { IsDirty = assetContent != null, SourceFolder = sourceFolder.MakeRelative(RootDirectory) }; // Set the modified time to the time loaded from disk if (!assetItem.IsDirty) { assetItem.ModifiedTime = File.GetLastWriteTime(assetFullPath); } // TODO: Let's review that when we rework import process // Not fixing asset import anymore, as it was only meant for upgrade // However, it started to make asset dirty, for ex. when we create a new texture, choose a file and reload the scene later // since there was no importer id and base. //FixAssetImport(assetItem); // Add to temporary assets lock (TemporaryAssets) { TemporaryAssets.Add(assetItem); } } catch (Exception ex) { int row = 1; int column = 1; var yamlException = ex as YamlException; if (yamlException != null) { row = yamlException.Start.Line + 1; column = yamlException.Start.Column; } var module = log.Module; var assetReference = new AssetReference <Asset>(Guid.Empty, fileUPath.FullPath); // TODO: Change this instead of patching LoggerResult.Module, use a proper log message if (loggerResult != null) { loggerResult.Module = "{0}({1},{2})".ToFormat(Path.GetFullPath(fileUPath.FullPath), row, column); } log.Error(this, assetReference, AssetMessageCode.AssetLoadingFailed, ex, fileUPath, ex.Message); if (loggerResult != null) { loggerResult.Module = module; } } }