void ApplyDeltaThread() { var delta = new Octodiff.Core.DeltaApplier { SkipHashCheck = m_SkipHashCheck }; using (var basisStream = new FileStream(m_DownloadDir + AssetManager.AssetBundleFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var deltaStream = new FileStream(unzip_dest_path, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var newFileStream = new FileStream(m_DownloadDir + AssetManager.AssetBundleFilename + "_new", FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { try { delta.Apply(basisStream, new Octodiff.Core.BinaryDeltaReader(deltaStream, m_DeltaApplyProgress), newFileStream, m_DeltaApplyProgress); } catch (System.Exception ex) { Debug.LogError(ex); m_DeltaApplyProgress.IsFail = true; deltaStream.Close(); newFileStream.Close(); File.Delete(unzip_dest_path); File.Delete(m_DownloadDir + AssetManager.AssetBundleFilename + "_new"); return; } } try { #if !UNITY_WEBPLAYER File.Delete(unzip_dest_path); File.Delete(m_DownloadDir + AssetManager.AssetBundleFilename); File.Move(m_DownloadDir + AssetManager.AssetBundleFilename + "_new", m_DownloadDir + AssetManager.AssetBundleFilename); #endif } catch (System.Exception ex) { Debug.LogError(ex); m_DeltaApplyProgress.IsFail = true; } m_DeltaApplyProgress.IsSuccess = true; // File.Delete(bundle_filename); }
public int Execute(string[] commandLineArguments) { options.Parse(commandLineArguments); if (string.IsNullOrWhiteSpace(basisFilePath)) throw new OptionException("No basis file was specified", "basis-file"); if (string.IsNullOrWhiteSpace(deltaFilePath)) throw new OptionException("No delta file was specified", "delta-file"); if (string.IsNullOrWhiteSpace(newFilePath)) throw new OptionException("No new file was specified", "new-file"); basisFilePath = Path.GetFullPath(basisFilePath); deltaFilePath = Path.GetFullPath(deltaFilePath); newFilePath = Path.GetFullPath(newFilePath); if (!File.Exists(basisFilePath)) throw new FileNotFoundException("File not found: " + basisFilePath, basisFilePath); if (!File.Exists(deltaFilePath)) throw new FileNotFoundException("File not found: " + deltaFilePath, deltaFilePath); var directory = Path.GetDirectoryName(newFilePath); if (directory != null && !Directory.Exists(directory)) { Directory.CreateDirectory(directory); } var delta = new DeltaApplier { SkipHashCheck = skipHashCheck }; using (var basisStream = new FileStream(basisFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var deltaStream = new FileStream(deltaFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var newFileStream = new FileStream(newFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { delta.Apply(basisStream, new BinaryDeltaReader(deltaStream, progressReporter), newFileStream); } return 0; }