public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName) { using (var zipStream = new ZipInputStream(FileEx.OpenRead(sourceArchiveFileName))) { ZipEntry theEntry; byte[] data = new byte[BufferSize]; while ((theEntry = zipStream.GetNextEntry()) != null) { var fileName = Path.GetFileName(theEntry.Name); if (string.IsNullOrEmpty(fileName)) { continue; } string file = Path.Combine(destinationDirectoryName, theEntry.Name); DirectoryEx.CreateDirectory(Directory.GetParent(file)); using (FileStream fileStream = File.Create(file)) { while (true) { var size = zipStream.Read(data, 0, data.Length); if (size <= 0) { break; } fileStream.Write(data, 0, size); } } } } }
void BuildiOS() { var oldTarget = EditorUserBuildSettings.activeBuildTarget; DirectoryEx.CreateDirectory(OutputDir); var app = BuildPlayer(GetIOSBuildTarget(), BuildOptions.None, "Assets/Level1.unity"); var appDataDir = Path.Combine(app, "Data"); var assetbundle = BuildStreamedSceneAssetBundle(GetIOSBuildTarget(), "Assets/Level2.unity"); if (!AssetBundlePatch.IsSupport(assetbundle)) { Debug.LogError("AssetBundlePatch.IsSupport failed!!!!"); return; } EditorUserBuildSettings.SwitchActiveBuildTarget(oldTarget); var diff = Path.Combine(OutputDir, Updater.Diff); var ret = AssetBundlePatch.Diff(appDataDir, null, assetbundle, diff); if (!ret) { Debug.LogError("AssetBundlePatch.Diff failed!!!!"); return; } // Real environment, you need to place this file on http server var diffZip = Path.Combine(appDataDir, "Raw"); diffZip = Path.Combine(diffZip, Updater.DiffZip); ZipFile.CreateFromDirectory(new string[] { diff }, diffZip); var sb = new StringBuilder(); sb.AppendLine(DateTime.Now.ToString()); sb.AppendLine(string.Format("Assetbundle size:{0}", GetFileSizeString(assetbundle))); sb.AppendLine(string.Format("Diff size:{0}", GetFileSizeString(diff))); sb.AppendLine(string.Format("Diff zip size:{0}", GetFileSizeString(diffZip))); DebugInfo = sb.ToString(); }
void ProcessNextEntry() { while (true) { var theEntry = ZipStream.GetNextEntry(); if (theEntry == null) { CurState = State.Succeed; return; } var fileName = Path.GetFileName(theEntry.Name); if (string.IsNullOrEmpty(fileName)) { continue; } string file = Path.Combine(DestinationDirectoryName, theEntry.Name); DirectoryEx.CreateDirectory(Directory.GetParent(file)); WriteFileStream = File.OpenWrite(file); return; } }