public void LoadAssetBundle(string filePath) { using (BundleFile bundle = new BundleFile(this, filePath, OnRequestDependency)) { bundle.Load(filePath); } }
private string GetRelativePath(HttpServerUtilityBase server, BundleFile bundleFile, string filePath) { var relativeBundlePath = bundleFile.IncludedVirtualPath.Remove(bundleFile.IncludedVirtualPath.IndexOf(@"\")); var bundlePath = server.MapPath(relativeBundlePath); return(FileToolkit.PathDifference(filePath, bundlePath)); }
internal void ReadAssetBundle(Stream stream, string filePath, Action <string> requestDependencyCallback) { using (BundleFile bundle = new BundleFile(this, filePath, requestDependencyCallback)) { bundle.Read(stream); } }
public void Process(BundleContext context, BundleResponse response) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (response == null) { throw new ArgumentNullException(nameof(response)); } try { foreach (string inputFile in context.InputBundleFiles) { BundleFile bundleFile = new BundleFile(context.Parent); bundleFile.VirtualPath = $"/{RemoveFirstOccurenceSpecialCharacters(inputFile, EStartPoint.FromStart, new char[] { '/', '\\', '~' })}"; bundleFile.PhysicalPath = context.FileProvider.GetFileInfo(bundleFile.VirtualPath).PhysicalPath; response.BundleFiles.Add(bundleFile.VirtualPath, bundleFile); } } catch (Exception ex) { response.TransformationErrors.Append($"Error: {ex.Message}<br />Error details: {ex.StackTrace}").Append("<br />"); throw; } }
public void ReadBundleFile(SmartStream stream, string bundlePath) { using (BundleFile bundle = BundleFile.Read(stream, bundlePath)) { AddBundleFile(bundle); } }
/// <summary>Process a asset</summary> /// <param name="assetVirtualPath">Virtual path of asset</param> /// <param name="bundleVirtualPath">Virtual path of bundle</param> /// <returns>Processed asset</returns> private IAsset ProcessAsset(string assetVirtualPath, string bundleVirtualPath) { BundleFile bundleFile = (BundleFile)null; ITransformer transformer = (ITransformer)null; if (!string.IsNullOrWhiteSpace(bundleVirtualPath)) { Bundle bundleByVirtualPath = this.GetBundleByVirtualPath(bundleVirtualPath); bundleFile = bundleByVirtualPath != null?this.GetBundleFileByVirtualPath(bundleByVirtualPath, assetVirtualPath) : throw new HttpException(500, string.Format(BundleTransformer.Core.Resources.Strings.AssetHandler_BundleNotFound, (object)bundleVirtualPath)); if (bundleFile == null) { throw new HttpException(500, string.Format(BundleTransformer.Core.Resources.Strings.AssetHandler_BundleFileNotFound, (object)assetVirtualPath, (object)bundleVirtualPath)); } transformer = this.GetTransformer(bundleByVirtualPath); if (transformer == null) { throw new HttpException(500, string.Format(BundleTransformer.Core.Resources.Strings.AssetHandler_TransformerNotFound, (object)bundleVirtualPath)); } } IAsset asset = (IAsset) new Asset(assetVirtualPath, bundleFile); if (!this.IsStaticAsset) { asset = this.TranslateAsset(asset, transformer, BundleTransformerContext.Current.IsDebugMode); } if (transformer != null) { asset = this.PostProcessAsset(asset, transformer); } return(asset); }
/// <summary> /// Returns content from a bundle file /// </summary> protected static string GetContent(BundleFile file) { using (var sr = new StreamReader(file.VirtualFile.Open())) { return(sr.ReadToEnd()); } }
public void LoadBundleFile(string bundlePath) { using (BundleFile bundle = BundleFile.Load(bundlePath)) { AddBundleFile(bundle); } }
/// <summary> /// Constructs a instance of Asset /// </summary> /// <param name="virtualPath">Virtual path to asset file</param> /// <param name="bundleFile">Bundle file</param> /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param> public Asset(string virtualPath, BundleFile bundleFile, IVirtualFileSystemWrapper virtualFileSystemWrapper) : this(virtualPath, bundleFile, virtualFileSystemWrapper, BundleTransformerContext.Current.Styles.FileExtensionMappings, BundleTransformerContext.Current.Scripts.FileExtensionMappings) { }
public BundleFileProvider(string bundleFile, bool readOnly = true, bool useCombinedStream = false) { _bundleFilename = bundleFile; _fileStream = File.Open(bundleFile, FileMode.Open, readOnly ? FileAccess.Read : FileAccess.ReadWrite); _bundleFile = new BundleFile(_fileStream); UseCombinedStream = useCombinedStream; }
private static void ReadFumen(string fileName) { ScrObj scoreObj = null; using (var fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bundle = new BundleFile(fileStream, false)) { foreach (var assetFile in bundle.AssetFiles) { foreach (var preloadData in assetFile.PreloadDataList) { if (preloadData.KnownType == KnownClassID.MonoBehaviour) { var behaviour = preloadData.LoadAsMonoBehaviour(true); if (behaviour.Name.Contains("fumen")) { behaviour = preloadData.LoadAsMonoBehaviour(false); var serializer = new MonoBehaviourSerializer(); CodeTimer.Time($"Deserialize scrobj to {typeof(ScrObj).Name}", 10, () => { var _ = serializer.Deserialize <ScrObj>(behaviour); }); scoreObj = serializer.Deserialize <ScrObj>(behaviour); break; } } } } } } if (scoreObj != null) { Console.WriteLine("Total notes: {0}", scoreObj.NoteEvents.Length); } }
/// <summary> /// Gets a bundle file by virtual path /// </summary> /// <param name="bundle">Bundle</param> /// <param name="virtualPath">Virtual path</param> /// <returns>Bundle</returns> protected virtual BundleFile GetBundleFileByVirtualPath(Bundle bundle, string virtualPath) { BundleFile file = null; string url = _virtualFileSystemWrapper.ToAbsolutePath(virtualPath); url = UrlHelpers.ProcessBackSlashes(url); url = RemoveAdditionalFileExtension(url); var bundleContext = new BundleContext(_context, BundleTable.Bundles, bundle.Path); IEnumerable <BundleFile> bundleFiles = bundle.EnumerateFiles(bundleContext); foreach (BundleFile bundleFile in bundleFiles) { string bundleFileUrl = _virtualFileSystemWrapper.ToAbsolutePath(bundleFile.VirtualFile.VirtualPath); bundleFileUrl = UrlHelpers.ProcessBackSlashes(bundleFileUrl); bundleFileUrl = RemoveAdditionalFileExtension(bundleFileUrl); if (string.Equals(bundleFileUrl, url, StringComparison.OrdinalIgnoreCase)) { file = bundleFile; break; } } return(file); }
public static ScenarioObject Load([NotNull] string path) { ScenarioObject result = null; using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bundle = new BundleFile(fileStream, false)) { foreach (var asset in bundle.AssetFiles) { foreach (var preloadData in asset.PreloadDataList) { if (preloadData.KnownType != KnownClassID.MonoBehaviour) { continue; } var behaviour = preloadData.LoadAsMonoBehaviour(true); if (!behaviour.Name.EndsWith("scenario_sobj")) { continue; } behaviour = preloadData.LoadAsMonoBehaviour(false); var serializer = new MonoBehaviourSerializer(); result = serializer.Deserialize <ScenarioObject>(behaviour); break; } } } } return(result); }
private static string GetJavascriptEncodedContent(BundleFile bundleFile) { using (var streamReader = new StreamReader(BundleTable.VirtualPathProvider.GetFile(bundleFile.IncludedVirtualPath).Open())) { return HttpUtility.JavaScriptStringEncode(streamReader.ReadToEnd().Trim()); } }
protected override IHtmlContent RenderAssetTag(BundleFile file) { var script = new TagBuilder("script"); script.Attributes.Add(SourceAttributeName, file.Path); return(script); }
public static Mesh LoadHeadMesh([NotNull] string filePath) { var meshList = new List <Mesh>(); using (var fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bundle = new BundleFile(fileStream, false)) { foreach (var assetFile in bundle.AssetFiles) { foreach (var preloadData in assetFile.PreloadDataList) { if (preloadData.KnownType != KnownClassID.Mesh) { continue; } var mesh = preloadData.LoadAsMesh(); meshList.Add(mesh); } } } } var compositeMesh = CompositeMesh.FromMeshes(meshList); return(compositeMesh); }
/// <summary> /// Constructs a instance of Asset /// </summary> /// <param name="virtualPath">Virtual path to asset file</param> /// <param name="bundleFile">Bundle file</param> /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param> /// <param name="styleFileExtensionMappings">Style file extension mappings</param> /// <param name="scriptFileExtensionMappings">Script file extension mappings</param> public Asset(string virtualPath, BundleFile bundleFile, IVirtualFileSystemWrapper virtualFileSystemWrapper, FileExtensionMappingCollection styleFileExtensionMappings, FileExtensionMappingCollection scriptFileExtensionMappings) { _virtualFileSystemWrapper = virtualFileSystemWrapper; _styleFileExtensionMappings = styleFileExtensionMappings; _scriptFileExtensionMappings = scriptFileExtensionMappings; if (bundleFile != null) { _includedVirtualPath = bundleFile.IncludedVirtualPath; _transforms = bundleFile.Transforms; } else { _includedVirtualPath = string.Empty; _transforms = new List <IItemTransform>(); } _assetTypeCode = Constants.AssetTypeCode.Unknown; _isStylesheet = false; _isScript = false; _content = null; VirtualPath = virtualPath; VirtualPathDependencies = new List <string>(); OriginalAssets = new List <IAsset>(); Combined = false; Minified = false; RelativePathsResolved = false; }
public List <string> GetFilePaths(BundleFile bundle) { MemoryReader reader = new(bundle.GetContent(Offset, Size).Span); var templates = BuildPathTemplates(ref reader); return(BuildFilePaths(ref reader, templates)); }
static public AssetBundle LoadBundle(BundleFile _bundle) { if (!loadedBundles.ContainsKey(_bundle)) { loadedBundles[_bundle] = AssetBundle.LoadFromFile(_bundle.fullPath); } return(loadedBundles[_bundle]); }
static public void UnloadBundle(BundleFile _bundle) { if (loadedBundles.ContainsKey(_bundle)) { loadedBundles[_bundle].Unload(true); loadedBundles.Remove(_bundle); } }
public void ReadAssetBundle(Stream stream, string filePath) { using (BundleFile bundle = new BundleFile(this, filePath, OnRequestDependency)) { bundle.Read(stream); AddBundleFile(bundle); } }
static void DumpBundleFileInfo(BundleFile bundleFile, StreamWriter sw) { sw.WriteLine("BundleFile"); var metadata = bundleFile.Metadata; var header = bundleFile.Header; sw.WriteLine(" TODO"); }
public void ReadAssetBundle(Stream stream, string filePath) { using (BundleFile bundle = new BundleFile()) { bundle.Read(stream); ProcessSerializedFileData(bundle.FileData, filePath); } }
public void LoadAssetBundle(string filePath) { using (BundleFile bundle = new BundleFile()) { bundle.Load(filePath); ProcessSerializedFileData(bundle.FileData, filePath); } }
private static void ExecuteCommand(FileInfo bundleFile) { var bundle = new BundleFile(bundleFile.FullName); Console.WriteLine($"Name: {bundle.Name}"); Console.WriteLine($"Blocks: {bundle.BlockCount}"); Console.WriteLine($"Compressed size: {bundle.CompressedSize} bytes"); Console.WriteLine($"Uncompressed size: {bundle.UncompressedSize} bytes"); }
public string GetName(BundleFile bundleFile) { var name = bundleFile.VirtualFile.VirtualPath; if (_removeLeadingSlash && name.StartsWith("/")) { return name.Substring(1); } return name; }
private string Read(BundleFile file) { FileInfo fileInfo = new FileInfo(HttpContext.Current.Server.MapPath(@file.IncludedVirtualPath)); using (var reader = fileInfo.OpenText()) { return(reader.ReadToEnd()); } }
private string Read(BundleFile file) { using (var s = file.VirtualFile.Open()) { using (var r = new StreamReader(s)) { return(r.ReadToEnd()); } } }
private string Read(BundleFile file) { using (var s = file.VirtualFile.Open()) { using (var r = new StreamReader(s)) { return r.ReadToEnd(); } } }
public string GetName(BundleFile bundleFile) { var name = bundleFile.VirtualFile.VirtualPath; if (_removeLeadingSlash && name.StartsWith("/")) { return(name.Substring(1)); } return(name); }
static string RetrieveFileContent(BundleFile current) { using (var stream = current.VirtualFile.Open()) { using (var reader = new StreamReader(stream)) { return reader.ReadToEnd(); } } }
private void AddBundleFile(BundleFile bundle) { foreach (SerializedFile file in bundle.SerializedFiles) { AddSerializedFile(file); } foreach (ResourcesFile resource in bundle.ResourceFiles) { m_resources.Add(resource); } }
private static string GetFileHeader(string appPath, BundleFile file, string fileHeaderFormat) { if (!string.IsNullOrEmpty(fileHeaderFormat)) { var appRelativePath = new object[1]; appRelativePath[0] = ConvertToAppRelativePath(file.VirtualFile.Name, appPath); return(string.Concat(string.Format(CultureInfo.InvariantCulture, fileHeaderFormat, appRelativePath), "\r\n")); } return(string.Empty); }
static BundleFile GetBundleFile(string _textLine) { string[] text = _textLine.Split('%'); if (text[0].Length > 1) { BundleFile x = new BundleFile(); x.fileName = text[1]; x.version = text[3]; return(x); } return(null); }
private static string TransformUrl(BundleContext context, string cssRelativeUrl, BundleFile cssFileInfo) { if (cssRelativeUrl.StartsWith("http://") || cssRelativeUrl.StartsWith("https://") || cssRelativeUrl.StartsWith("/") || cssRelativeUrl.StartsWith("data:image")) { return cssRelativeUrl; } var cssFilePath = context.HttpContext.Server.MapPath(cssFileInfo.IncludedVirtualPath); Debug.Assert(cssFileInfo.VirtualFile.Name != null); var cssFileDirectory = cssFilePath.Substring(0, cssFilePath.Length - cssFileInfo.VirtualFile.Name.Length); var path = GetPathWithIllegalCharacters(cssFileDirectory, cssRelativeUrl); return RelativeFromAbsolutePath(context.HttpContext, path); }
/// <summary> /// Constructs a instance of Asset /// </summary> /// <param name="virtualPath">Virtual path to asset file</param> /// <param name="bundleFile">Bundle file</param> /// <param name="virtualFileSystemWrapper">Virtual file system wrapper</param> /// <param name="styleFileExtensionMappings">Style file extension mappings</param> /// <param name="scriptFileExtensionMappings">Script file extension mappings</param> public Asset(string virtualPath, BundleFile bundleFile, IVirtualFileSystemWrapper virtualFileSystemWrapper, FileExtensionMappingCollection styleFileExtensionMappings, FileExtensionMappingCollection scriptFileExtensionMappings) { _virtualFileSystemWrapper = virtualFileSystemWrapper; _styleFileExtensionMappings = styleFileExtensionMappings; _scriptFileExtensionMappings = scriptFileExtensionMappings; if (bundleFile != null) { _includedVirtualPath = bundleFile.IncludedVirtualPath; _transforms = bundleFile.Transforms; } else { _includedVirtualPath = string.Empty; _transforms = new List<IItemTransform>(); } _assetTypeCode = Constants.AssetTypeCode.Unknown; _isStylesheet = false; _isScript = false; _content = null; VirtualPath = virtualPath; VirtualPathDependencies = new List<string>(); OriginalAssets = new List<IAsset>(); Combined = false; Minified = false; RelativePathsResolved = false; }
private static string GetBundleText(BundleFile bundleFile) { return string.Format("$templateCache.put(\"{0}\", \"{1}\");", GetTemplatePath(bundleFile), GetJavascriptEncodedContent(bundleFile)); }
private static string GetTemplatePath(BundleFile bundleFile) { return VirtualPathUtility.ToAbsolute(bundleFile.IncludedVirtualPath); }
private void Add(BundleFile bf) { if (bf == null) return; if (!_filesInCorrectOrder.Contains(bf) && bf.VirtualFile != null) { if (!bf.VirtualFile.Name.Contains(@"_References")) _filesInCorrectOrder.Add(bf); } }
/// <summary> /// Constructs a instance of Asset /// </summary> /// <param name="virtualPath">Virtual path to asset file</param> /// <param name="bundleFile">Bundle file</param> public Asset(string virtualPath, BundleFile bundleFile) : this(virtualPath, bundleFile, BundleTransformerContext.Current.FileSystem.GetVirtualFileSystemWrapper()) { }
public string Read(BundleFile bundleFile) { var contentRaw = File.ReadAllText(HttpContext.Current.Server.MapPath(bundleFile.VirtualFile.VirtualPath)); return contentRaw.Replace(Environment.NewLine, "\\n").Replace("'", "\\'"); }
private string GetRelativePath(HttpServerUtilityBase server, BundleFile bundleFile, string filePath) { var relativeBundlePath = bundleFile.IncludedVirtualPath.Remove(bundleFile.IncludedVirtualPath.IndexOf(@"\")); var bundlePath = server.MapPath(relativeBundlePath); return FileToolkit.PathDifference(filePath, bundlePath); }
public OrderedBundleFile(int order, BundleFile file) { Order = order; File = file; }