Example #1
0
        /// <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
            {
                var package = AssetSerializer.Load <Package>(filePath, log);
                package.FullPath = filePath;
                package.IsDirty  = false;

                return(package);
            }
            catch (Exception ex)
            {
                log.Error("Error while pre-loading package [{0}]", ex, filePath);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Loads the templates.
        /// </summary>
        /// <param name="log">The log result.</param>
        private void LoadTemplates(ILogger log)
        {
            foreach (var templateDir in TemplateFolders)
            {
                foreach (var filePath in templateDir.Files)
                {
                    try
                    {
                        var file = new FileInfo(filePath);
                        if (!file.Exists)
                        {
                            log.Warning("Template [{0}] does not exist ", file);
                            continue;
                        }

                        var templateDescription = AssetSerializer.Load <TemplateDescription>(file.FullName);
                        templateDescription.FullPath = file.FullName;
                        Templates.Add(templateDescription);
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error while loading template from [{0}]", ex, filePath);
                    }
                }
            }
        }
Example #3
0
 /// <summary>
 /// Gets the package identifier from file.
 /// </summary>
 /// <param name="filePath">The file path.</param>
 /// <returns>Guid.</returns>
 /// <exception cref="System.ArgumentNullException">
 /// log
 /// or
 /// filePath
 /// </exception>
 public static Guid GetPackageIdFromFile(string filePath)
 {
     if (filePath == null)
     {
         throw new ArgumentNullException("filePath");
     }
     return(AssetSerializer.Load <Package>(filePath).Id);
 }
Example #4
0
        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);
        }
Example #5
0
        private static Asset LoadAsset(ILogger log, string assetFullPath, string assetPath, UFile fileUPath, byte[] assetContent)
        {
            var asset = assetContent != null
                ? (Asset)AssetSerializer.Load(new MemoryStream(assetContent), Path.GetExtension(assetFullPath), log)
                : AssetSerializer.Load <Asset>(assetFullPath, log);

            // 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);
        }
Example #6
0
        /// <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);
        }
Example #7
0
        /// <summary>
        /// Loads only the package description but not assets or plugins.
        /// </summary>
        /// <param name="log">The log to receive error messages.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="loadParametersArg">The load parameters argument.</param>
        /// <returns>A package.</returns>
        /// <exception cref="System.ArgumentNullException">log
        /// or
        /// filePath</exception>
        public static Package Load(ILogger log, string filePath, PackageLoadParameters loadParametersArg = null)
        {
            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);
            }

            var loadParameters = loadParametersArg ?? PackageLoadParameters.Default();

            try
            {
                var package = AssetSerializer.Load <Package>(filePath);
                package.FullPath = filePath;
                package.IsDirty  = false;

                // Load assembly references
                if (loadParameters.LoadAssemblyReferences)
                {
                    package.LoadAssemblyReferencesForPackage(log, loadParameters);
                }

                // Load assets
                if (loadParameters.AutoLoadTemporaryAssets)
                {
                    package.LoadTemporaryAssets(log, loadParameters.CancelToken);
                }

                // Convert UPath to absolute
                if (loadParameters.ConvertUPathToAbsolute)
                {
                    var analysis = new PackageAnalysis(package, new PackageAnalysisParameters()
                    {
                        ConvertUPathTo     = UPathType.Absolute,
                        IsProcessingUPaths = true,                        // This is done already by Package.Load
                        SetDirtyFlagOnAssetWhenFixingAbsoluteUFile = true // When loading tag attributes that have an absolute file
                    });
                    analysis.Run(log);
                }

                // Load templates
                package.LoadTemplates(log);

                return(package);
            }
            catch (Exception ex)
            {
                log.Error("Error while pre-loading package [{0}]", ex, filePath);
            }

            return(null);
        }