public virtual BundleManifest Load(string path)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (Regex.IsMatch(path, @"(jar:file:///)|(\.jar)|(\.apk)|(\.obb)|(\.zip)", RegexOptions.IgnoreCase))
            {
                using (ZipFile zip = new ZipFile(this.GetCompressedFileName(path)))
                {
                    string entryName = this.GetCompressedEntryName(path);
                    if (!zip.ContainsEntry(entryName))
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.ErrorFormat("Not found the BundleManifest '{0}'.", path);
                        }
                        return(null);
                    }

                    ZipEntry entry  = zip[entryName];
                    byte[]   buffer = new byte[entry.UncompressedSize];
                    using (Stream input = entry.OpenReader())
                    {
                        input.Read(buffer, 0, buffer.Length);
                    }
                    return(BundleManifest.Parse(Encoding.UTF8.GetString(buffer)));
                }
            }
            return(BundleManifest.Parse(File.ReadAllText(path, Encoding.UTF8)));
#elif UNITY_WEBGL && !UNITY_EDITOR
            throw new NotSupportedException("Because WebGL is single-threaded, this method is not supported,please use LoadAsync instead.");
#else
            return(BundleManifest.Parse(File.ReadAllText(path, Encoding.UTF8)));
#endif
        }
示例#2
0
 public BundleManager(BundleManifest manifest, ILoaderBuilder builder, ITaskExecutor executor)
 {
     this.bundleManifest = manifest;
     this.loaderBuilder  = builder;
     this.executor       = executor != null ? executor : new PriorityTaskExecutor();
     this.loaders        = new Dictionary <string, BundleLoader>();
 }
示例#3
0
        public static void EvictExpiredInStorableDirectory(BundleManifest manifest)
        {
#if !UNITY_WEBGL || UNITY_EDITOR
            Executors.RunAsyncNoReturn(() =>
            {
#endif
                try
                {
                    DirectoryInfo directory = new DirectoryInfo(GetStorableDirectory());
                    if (!directory.Exists)
                        return;

                    List<string> files = new List<string>();
                    FileInfo manifestFileInfo = new FileInfo(GetStorableDirectory() + BundleSetting.ManifestFilename);
                    files.Add(manifestFileInfo.FullName);

                    BundleInfo[] bundleInfos = manifest.GetAllActivated();
                    foreach (BundleInfo bundleInfo in bundleInfos)
                    {
                        string fullname = GetStorableDirectory() + bundleInfo.Filename;
                        FileInfo info = new FileInfo(fullname);
                        if (!info.Exists)
                            continue;

                        files.Add(info.FullName);
                    }

                    foreach (FileInfo info in directory.GetFiles("*", SearchOption.AllDirectories))
                    {
                        try
                        {
                            if (files.Contains(info.FullName))
                                continue;

                            info.Delete();
                        }
                        catch (Exception e)
                        {
                            Debug.LogErrorFormat("Delete file {0}.Error:{1}", info.FullName, e);
                        }
                    }

                    DeleteEmptyDirectory(directory);

                }
                catch (Exception ex)
                {
                    Debug.LogErrorFormat("DeleteExpiredInStorableDirectory exception.Error:{0}", ex);
                }
#if !UNITY_WEBGL || UNITY_EDITOR
            });
#endif
        }
示例#4
0
 public BundleManager(BundleManifest manifest, ILoaderBuilder builder) : this(manifest, builder, null)
 {
 }
        protected virtual IEnumerator DoLoadAsync(IPromise <BundleManifest> promise, string path)
        {
            string absoluteUri = "";

            try
            {
                Uri uri = new Uri(path);
                absoluteUri = uri.AbsoluteUri;
                if (uri.Scheme.Equals("jar") && !absoluteUri.StartsWith("jar:file://"))
                {
                    absoluteUri = absoluteUri.Replace("jar:file:", "jar:file://");
                }
            }
            catch (Exception)
            {
                absoluteUri = path;
            }
#if UNITY_2017_1_OR_NEWER
            using (UnityWebRequest www = new UnityWebRequest(absoluteUri))
            {
                www.downloadHandler = new DownloadHandlerBuffer();
#if UNITY_2018_1_OR_NEWER
                www.SendWebRequest();
#else
                www.Send();
#endif
                while (!www.isDone)
                {
                    yield return(null);
                }

                if (!string.IsNullOrEmpty(www.error))
                {
                    promise.SetException(new Exception(string.Format("Failed to load the Manifest.dat at the address '{0}'.Error:{1}", absoluteUri, www.error)));
                    yield break;
                }

                try
                {
                    string         json     = www.downloadHandler.text;
                    BundleManifest manifest = BundleManifest.Parse(json);
                    promise.SetResult(manifest);
                }
                catch (Exception e)
                {
                    promise.SetException(e);
                }
            }
#else
            using (WWW www = new WWW(absoluteUri))
            {
                yield return(www);

                if (!string.IsNullOrEmpty(www.error))
                {
                    promise.SetException(new Exception(string.Format("Failed to load the Manifest.dat at the address '{0}'.Error:{1}", absoluteUri, www.error)));
                    yield break;
                }

                try
                {
                    string         json     = www.text;
                    BundleManifest manifest = BundleManifest.Parse(json);
                    promise.SetResult(manifest);
                }
                catch (Exception e)
                {
                    promise.SetException(e);
                }
            }
#endif
        }
 public AutoMappingPathInfoParser(BundleManifest manifest)
 {
     this.BundleManifest = manifest;
 }