/// <summary> /// 以字节流的形式载入资源 /// </summary> private IEnumerator LoadBundleAsync(string bundleName, string bundleVersion, BundleLoadMethod method, bool saveBundle = false) { string bundlePath; var container = new BundleContainer(); switch (method) { case BundleLoadMethod.File_StreamingBundle: bundlePath = @Path.Combine(Application.streamingAssetsPath, bundleName); break; case BundleLoadMethod.File_LocalBundle: bundlePath = pather.GetLocalBundlePath(bundleName, bundleVersion); break; default: bundlePath = pather.GetServeBundlePath(bundleName, bundleVersion); break; } yield return(ExecuteLoadBundleAsync(bundlePath, method, container)); onLoadEveryComplete(container.assetBundle); if (saveBundle && container.bytes != null) { var filePath = pather.GetLocalBundlePath(bundleName, bundleVersion); FileUtil.CreateFile(filePath, container.bytes); } }
public override Response ProcessRequest(NancyContext context) { if (!context.Request.Url.Path.StartsWith(HandlerRoot, StringComparison.InvariantCultureIgnoreCase)) { return(null); } var path = Regex.Match(string.Concat("~", context.Request.Url.Path.Remove(0, HandlerRoot.Length)), @"^[^\?]*").Value; var bundles = BundleContainer.FindBundlesContainingPath(path).ToList(); if (bundles == null) { //if (Logger != null) // Logger.Error("AssetRouteHandler.ProcessRequest : Bundle not found for path '{0}'", context.Request.Url.Path); return(null); } IAsset asset; Bundle bundle; if (!bundles.TryGetAssetByPath(path, out asset, out bundle)) { //if (Logger != null) // Logger.Error("AssetRouteHandler.ProcessRequest : Asset not found for path '{0}'", context.Request.Url.Path); return(null); } var response = new StreamResponse(asset.OpenStream, bundle.ContentType); //if (Logger != null) // Logger.Trace("AssetRouteHandler.ProcessRequest : Returned response for '{0}'", context.Request.Url.Path); return(response); }
CassetteApplication CreateApplication(Action <BundleCollection> configure, string sourceDirectory = "assets", bool isDebuggingEnabled = false) { var container = new Mock <ICassetteApplicationContainer <ICassetteApplication> >(); var settings = new CassetteSettings("") { CacheDirectory = new IsolatedStorageDirectory(storage), SourceDirectory = new FileSystemDirectory(Path.GetFullPath(sourceDirectory)), UrlGenerator = new UrlGenerator(new VirtualDirectoryPrepender("/"), "_cassette"), IsDebuggingEnabled = isDebuggingEnabled }; var bundles = new BundleCollection(settings); configure(bundles); foreach (var bundle in bundles) { bundle.Process(settings); } var bundleContainer = new BundleContainer(bundles); var application = new CassetteApplication( bundleContainer, settings, () => httpContext.Object ); container.Setup(c => c.Application).Returns(() => application); new RouteInstaller(container.Object, "_cassette").InstallRoutes(routes); return(application); }
public void Read(BinaryReader br = null, long?Offset = null) { if (_bundle == null) { if (Offset.HasValue) { br.BaseStream.Seek(Offset.Value, SeekOrigin.Begin); _bundle = new BundleContainer(br); } else if (br == null) { _bundle = new BundleContainer(Name); } else { _bundle = new BundleContainer(br); } } }
public override IBundleContainer Create(IEnumerable <Bundle> unprocessedBundles, CassetteSettings settings) { // The bundles may get altered, so force the evaluation of the enumerator first. var bundlesArray = unprocessedBundles.ToArray(); var externalBundles = CreateExternalBundlesFromReferences(bundlesArray, settings); if (cache.InitializeBundlesFromCacheIfUpToDate(bundlesArray)) { return(new BundleContainer(bundlesArray.Concat(externalBundles))); } else { ProcessAllBundles(bundlesArray, settings); var container = new BundleContainer(bundlesArray.Concat(externalBundles)); cache.SaveBundleContainer(container); cache.InitializeBundlesFromCacheIfUpToDate(bundlesArray); return(container); } }
public override IBundleContainer Create(IEnumerable<Bundle> unprocessedBundles, CassetteSettings settings) { // The bundles may get altered, so force the evaluation of the enumerator first. var bundlesArray = unprocessedBundles.ToArray(); var externalBundles = CreateExternalBundlesFromReferences(bundlesArray, settings); if (cache.InitializeBundlesFromCacheIfUpToDate(bundlesArray)) { return new BundleContainer(bundlesArray.Concat(externalBundles)); } else { ProcessAllBundles(bundlesArray, settings); var container = new BundleContainer(bundlesArray.Concat(externalBundles)); cache.SaveBundleContainer(container); cache.InitializeBundlesFromCacheIfUpToDate(bundlesArray); return container; } }
public void CanSaveBundleWherePathIsJustATilde() { var bundle = new TestableBundle("~"); bundle.Assets.Add(StubAsset().Object); using (var source = new TempDirectory()) using (var cache = new TempDirectory()) { var container = new BundleContainer(new[] { bundle }); var settings = new CassetteSettings("") { SourceDirectory = new FileSystemDirectory(source), CacheDirectory = new FileSystemDirectory(cache) }; settings.BundleCache.SaveBundleContainer(container); File.Exists(Path.Combine(cache, ".bundle")).ShouldBeTrue(); } }
public override Response ProcessRequest(NancyContext context) { if (!context.Request.Url.Path.StartsWith(HandlerRoot, StringComparison.InvariantCultureIgnoreCase)) { return(null); } var path = Regex.Replace(string.Concat("~", context.Request.Url.Path.Remove(0, HandlerRoot.Length)), @"_[^_]+$", ""); var bundles = BundleContainer.FindBundlesContainingPath(path).ToList(); if (bundles == null || bundles.Count != 1) { //if (Logger != null) Logger.Error("BundleRouteHandler.ProcessRequest : Bundle not found for path '{0}'", context.Request.Url.Path); return(null); } /* TODO : Caching * var actualETag = string.Concat( "\"", module.Assets[0].Hash.ToHexString(), "\""); * var givenETag = context.Request.Headers["If-None-Match"]; * if (givenETag == actualETag) * { * SendNotModified(actualETag); * } * * CacheLongTime(actualETag); * * var encoding = request.Headers["Accept-Encoding"]; * response.Filter = EncodeStreamAndAppendResponseHeaders(response.Filter, encoding); */ var response = new StreamResponse(() => bundles[0].Assets[0].OpenStream(), bundles[0].ContentType); //if (Logger != null) Logger.Trace("BundleRouteHandler.ProcessRequest : Returned response for '{0}'", context.Request.Url.Path); return(response); }
CassetteApplication CreateApplication(Action<BundleCollection> configure, string sourceDirectory = "assets", bool isDebuggingEnabled = false) { var container = new Mock<ICassetteApplicationContainer<ICassetteApplication>>(); var settings = new CassetteSettings("") { CacheDirectory = new IsolatedStorageDirectory(storage), SourceDirectory = new FileSystemDirectory(Path.GetFullPath(sourceDirectory)), UrlGenerator = new UrlGenerator(new VirtualDirectoryPrepender("/"), "_cassette"), IsDebuggingEnabled = isDebuggingEnabled }; var bundles = new BundleCollection(settings); configure(bundles); foreach (var bundle in bundles) { bundle.Process(settings); } var bundleContainer = new BundleContainer(bundles); var application = new CassetteApplication( bundleContainer, settings, () => httpContext.Object ); container.Setup(c => c.Application).Returns(() => application); new RouteInstaller(container.Object, "_cassette").InstallRoutes(routes); return application; }
public void Read() { _bundle = new BundleContainer(Name); }
/// <summary> /// 读取字节 /// 1.File.ReadAllBytes(path) /// 2.WWW /// </summary> /// <param name="path">路径</param> /// <param name="streamMethod">形式</param> /// <param name="cotiner">字节容器</param> /// <returns></returns> private IEnumerator ExecuteLoadBundleAsync(string path, BundleLoadMethod streamMethod, BundleContainer container) { // Debug.Log(streamMethod); switch (streamMethod) { case BundleLoadMethod.WWW_LoadBundleAndBytes: { var webBbLoadRequest = UnityWebRequest.Get(path); yield return(webBbLoadRequest.SendWebRequest()); container.bytes = webBbLoadRequest.downloadHandler.data; var bundleCreationRequest = AssetBundle.LoadFromMemoryAsync(container.bytes); yield return(bundleCreationRequest); container.assetBundle = bundleCreationRequest.assetBundle; break; } case BundleLoadMethod.WWW_LoadBytes: { var webBytesLoadRequest = UnityWebRequest.Get(path); yield return(webBytesLoadRequest.SendWebRequest()); container.bytes = webBytesLoadRequest.downloadHandler.data; break; } case BundleLoadMethod.WWW_LoadBundle: { var webBundleRequest = UnityWebRequestAssetBundle.GetAssetBundle(path); yield return(webBundleRequest.SendWebRequest()); container.assetBundle = DownloadHandlerAssetBundle.GetContent(webBundleRequest); break; } case BundleLoadMethod.File_LocalBundle: { var fileBundleRequest = AssetBundle.LoadFromFileAsync(path); yield return(fileBundleRequest); container.assetBundle = fileBundleRequest.assetBundle; break; } case BundleLoadMethod.File_StreamingBundle: { var fileBundleRequest = AssetBundle.LoadFromFileAsync(path); yield return(fileBundleRequest); container.assetBundle = fileBundleRequest.assetBundle; break; } case BundleLoadMethod.File_Bytes: break; default: yield break; } }