public void SaveLocalDiffZipInfo(string fileName, localDiffZipInfo info) { if (string.IsNullOrEmpty(fileName) || info == null) { return; } try { FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write); try { string str = JsonMapper.ToJson(info); if (!string.IsNullOrEmpty(str)) { byte[] buf = System.Text.Encoding.UTF8.GetBytes(str); if (buf != null && buf.Length > 0) { stream.Write(buf, 0, buf.Length); } } }finally { stream.Close(); stream.Dispose(); } } catch (Exception e) { #if DEBUG Debug.LogError(e.ToString()); #endif } }
public localDiffZipInfo LoadLocalDiffZipInfo(string fileName) { if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) { return(null); } try { FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); try { int size = (int)stream.Length; if (size > 0) { byte[] buf = new byte[size]; stream.Read(buf, 0, size); string str = System.Text.Encoding.UTF8.GetString(buf); localDiffZipInfo info = JsonMapper.ToObject <localDiffZipInfo>(str); return(info); } } finally { stream.Close(); stream.Dispose(); } } catch (Exception e) { #if DEBUG Debug.LogError(e.ToString()); #endif } return(null); }
private void DownloadDiffZip(DiffApkInfo serverInfo, string zipFileName, string jsonFileName, long offset = 0) { var target = ApkUpdateMonitor.GetInstance(); if (offset <= 0) { offset = 0; // 写入localZipInfo到文件 localDiffZipInfo localInfo = new localDiffZipInfo(); localInfo.Name = serverInfo.DiffName; localInfo.Md5 = serverInfo.DiffZipMd5; target.SaveLocalDiffZipInfo(jsonFileName, localInfo); } Clear(); string url = target.Inter.Get_Http_DiffZipUrl(); if (string.IsNullOrEmpty(url)) { target.OnError(ApkUpdateState.CheckLocalNewZip, ApkUpdateError.Get_Server_DiffZip_Url_Error); return; } url = string.Format("{0}/{1}.zip", url, serverInfo.DiffZipMd5); HttpClientFileStream stream = new HttpClientFileStream(zipFileName, offset, 1024 * 4); m_Http = HttpHelper.OpenUrl <HttpClientFileStream>(url, stream, OnHttpEnd); }
internal void SaveLocalDiffZipInfo(string fileName, localDiffZipInfo info) { m_Jsons.SaveLocalDiffZipInfo(fileName, info); }