public static IProgressResult <float> LoadAssetBundle(this ArchiveContainer container, params string[] filenames) { return(EditorExecutors.RunAsync(new Action <IProgressPromise <float> >((promise) => { try { int taskCount = 8; int index = -1; int finishedCount = 0; int count = filenames.Length; CountFinishedEvent countFinishedEvent = new CountFinishedEvent(taskCount); for (int i = 0; i < taskCount; i++) { EditorExecutors.RunAsyncNoReturn(() => { while (true) { int currIndex = Interlocked.Increment(ref index); if (currIndex > count - 1) { break; } try { container.LoadAssetBundle(filenames[currIndex]); } catch (Exception e) { Debug.LogErrorFormat("{0}", e); } finally { Interlocked.Increment(ref finishedCount); } } countFinishedEvent.Set(); }); } while (!countFinishedEvent.Wait(100)) { promise.UpdateProgress((float)finishedCount / count); } promise.SetResult(); } catch (Exception e) { promise.SetException(e); } }))); }
public virtual IProgressResult <float, RedundancyReport> AnalyzeRedundancy() { return(EditorExecutors.RunAsync <float, RedundancyReport>(promise => { try { long totalSize = 0; long redundantSize = 0; long objectTotalCount = 0; List <ObjectInfo> infos = new List <ObjectInfo>(); foreach (var bundle in container.Bundles) { foreach (var archive in bundle.AssetArchives) { totalSize += archive.FileSize; ObjectArchive objectArchive = archive as ObjectArchive; if (objectArchive == null) { continue; } var objectInfos = objectArchive.GetAllObjectInfo(); objectTotalCount += objectInfos.Count; foreach (var info in objectInfos) { if (promise.IsCancellationRequested) { return; } if (info.IsPotentialRedundancy) { infos.Add(info); } } } } Dictionary <IFingerprint, RedundancyInfo> dict = new Dictionary <IFingerprint, RedundancyInfo>(); int count = infos.Count; for (int i = 0; i < infos.Count; i++) { if (promise.IsCancellationRequested) { return; } var info = infos[i]; RedundancyInfo redundancyInfo = null; var fingerprint = info.Fingerprint; if (!dict.TryGetValue(fingerprint, out redundancyInfo)) { redundancyInfo = new RedundancyInfo(info.Name, info.TypeID, info.Size); dict.Add(fingerprint, redundancyInfo); promise.UpdateProgress((float)i / count); } redundancyInfo.AddObjectInfo(info); } List <RedundancyInfo> redundancies = new List <RedundancyInfo>(); foreach (var redundancyInfo in dict.Values) { if (redundancyInfo.Count <= 1) { continue; } redundancies.Add(redundancyInfo); var objectInfos = redundancyInfo.ObjectInfos; for (int i = 1; i < objectInfos.Count; i++) { redundantSize += objectInfos[i].Size; } } promise.SetResult(new RedundancyReport(totalSize, redundantSize, redundancies)); } catch (Exception e) { promise.SetException(e); } })); }
public static IProgressResult <float> LoadAssetBundle(this ArchiveContainer container, string root, IStreamDecryptor decryptor, params BundleInfo[] bundleInfos) { return(EditorExecutors.RunAsync(new Action <IProgressPromise <float> >((promise) => { try { int taskCount = 8; int index = -1; int finishedCount = 0; int count = bundleInfos.Length; CountFinishedEvent countFinishedEvent = new CountFinishedEvent(taskCount); for (int i = 0; i < taskCount; i++) { EditorExecutors.RunAsyncNoReturn(() => { while (true) { int currIndex = Interlocked.Increment(ref index); if (currIndex > count - 1) { break; } try { var bundleInfo = bundleInfos[currIndex]; var path = System.IO.Path.Combine(root, bundleInfo.Filename.Replace("/", @"\")); if (bundleInfo.IsEncrypted) { container.LoadAssetBundle(path, decryptor); } else { container.LoadAssetBundle(path); } } catch (Exception e) { Debug.LogErrorFormat("{0}", e); } finally { Interlocked.Increment(ref finishedCount); } } countFinishedEvent.Set(); }); } while (!countFinishedEvent.Wait(100)) { promise.UpdateProgress((float)finishedCount / count); } promise.SetResult(); } catch (Exception e) { promise.SetException(e); } }))); }