/// <summary> /// http 请求 /// </summary> /// <param name="url">请求url</param> /// <param name="method">请求类型 /// <param name="contentType">request content_type</param> /// <param name="queryDictionary">query集合</param> /// <param name="bodyDictionary">body集合</param> /// <returns></returns> public async Task <string> SendAndReadAsStringAsync(string url, HttpMethod method, string contentType = "application/x-www-form-urlencoded", int timeOut = 30, SortedDictionary <string, string> queryDictionary = null, SortedDictionary <string, string> bodyDictionary = null, SortedDictionary <string, string> headerDictionary = null, bool isGzip = false) { var _response = await GetResponse(url, method, contentType, timeOut, queryDictionary, bodyDictionary, headerDictionary, isGzip); if (_response.StatusCode != System.Net.HttpStatusCode.OK) { var _errMsg = $"请求:{_response.RequestMessage.ToString()}失败,状态码:{(int)_response.StatusCode},内容:{await _response.Content.ReadAsStringAsync()}"; this.AppendDebugLog(_errMsg); return(_errMsg); } if (!isGzip) { return(await _response.Content.ReadAsStringAsync()); } else { var _result = await _response.Content.ReadAsByteArrayAsync(); return(Encoding.UTF8.GetString(ZipHelper.Decompress(_result))); } }
public void ZipHelperSerialization() { string testPath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\CompressTestFolder"); var compressedItem = ZipHelper.Compress( "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市"); int size = compressedItem.CompressedSize; File.WriteAllBytes( Path.Combine(testPath, "SerializedCompressed.comp"), Encoding.Unicode.GetBytes(compressedItem.ToString())); var decompressedItem = CompressedItem.FromXml( Encoding.Unicode.GetString( File.ReadAllBytes( Path.Combine( testPath, "SerializedCompressed.comp")))); Assert.AreEqual(size, decompressedItem.CompressedSize); string decompressedData = ZipHelper.Decompress(decompressedItem); Assert.AreEqual( "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市", decompressedData); File.Delete(Path.Combine(testPath, "SerializedCompressed.comp")); }
public static void DecompressAssetBundleZip() { if (!File.Exists(ZipABPath + "/" + AssetBundleZipFileName)) { return; } EditorUtility.ClearProgressBar(); bool deCompressState = true; float deCompressProgress = 0f; ZipHelper.Decompress(ZipABPath + "/" + AssetBundleZipFileName, Application.dataPath + "/StreamingAssets/AssetBundle", (progress) => { deCompressProgress = progress; if (deCompressProgress >= 1) { deCompressState = false; } }); while (deCompressState) { EditorUtility.DisplayProgressBar("解压AssetBundle", "解压AssetBundle文件", deCompressProgress); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public void ZipHelperCompressionTest() { var compressedItem = ZipHelper.Compress("Hello World"); string decompressedData = ZipHelper.Decompress(compressedItem); Assert.AreEqual("Hello World", decompressedData); Assert.AreNotEqual("Hello world", decompressedData); }
/// <summary> /// 解压文件 /// </summary> public void DeCompressFile() { byte[] rawData1 = File.ReadAllBytes(datfile); byte[] outData1 = ZipHelper.Decompress(rawData1); File.WriteAllBytes(filename, outData1); byte[] rawData2 = File.ReadAllBytes(datfile_new); byte[] outData2 = ZipHelper.Decompress(rawData2); File.WriteAllBytes(filename_new, outData2); }
public void ZipHelperExtendedUnicodeCompressionTest() { var compressedItem = ZipHelper.Compress( "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市"); string decompressedData = ZipHelper.Decompress(compressedItem); Assert.AreEqual( "普選正式選票2008年11月4日,星期二伊利諾州芝加哥市", decompressedData); }
void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Cancelled) { this.StatusMessage = "更新被取消"; this.PursueEnable = true; base.RaisePropertyChanged(() => StatusMessage); return; } if (e.Error is WebException) { this.StatusMessage = "请检测您的网络或防火墙设置!"; this.PursueEnable = true; base.RaisePropertyChanged(() => StatusMessage); return; } // 更新 this.StatusMessage = "正在更新"; Task.Run(() => { string erroMessage = string.Empty; var isTrue = ZipHelper.Decompress(_tempPath, _filePath, out erroMessage); if (!isTrue) { LogManager.Logger.Warn(erroMessage); MessageBox.Show(erroMessage); return; } var servicePath = Path.Combine(_tempPath, "ServiceUpdate.xml"); servicePath.SaveToXml <ServiceUpdate>(_serviceUpdate); var clientPath = Path.Combine(_tempPath, "ClientUpdate.xml"); clientPath.SaveToXml <ClientUpdate>(CacheManager.Instance.Version); this.PursueEnable = true; System.Threading.Thread.Sleep(1000); Process process = new Process(); process.StartInfo.FileName = _tempPath + "\\Update.exe"; process.StartInfo.WorkingDirectory = _tempPath; process.Start(); GalaSoft.MvvmLight.Threading.DispatcherHelper.CheckBeginInvokeOnUI(() => { System.Environment.Exit(-2); }); }); }
public static void DecompressTest() { string targetPath = "E:/myProject/LonelyFramework/AssetBundleServer/FenBao/Win/version_1/"; string zipFileName = "E:/myProject/LonelyFramework/AssetBundleServer/FenBao/Win/version_1/Package1_11111.zip"; UpdateStageResult updateStageResult = new UpdateStageResult(); DownLoadFileResultInfo info = new DownLoadFileResultInfo(); List <AssetDataInfo> list = new List <AssetDataInfo>(); ZipHelper.Decompress( zipFileName, targetPath); Debug.Log("解压成功!"); }
private void Run(ushort nOpcode, byte[] rMessageBytes) { int nOffset = 0; bool bIsCompressed = (nOpcode & 0x8000) > 0; // opcode最高位表示是否压缩 if (bIsCompressed) // 最高位为1,表示有压缩,需要解压缩 { rMessageBytes = ZipHelper.Decompress(rMessageBytes, 2, rMessageBytes.Length - 2); nOffset = 0; } else { nOffset = 2; } nOpcode &= 0x7fff; this.RunDecompressedBytes(nOpcode, rMessageBytes, nOffset); }
public static void CompressTest() { string packPath = "E:/myProject/LonelyFramework/Assets/PersistentAssets/dataconfig"; long size = 0; string md51 = FileUtils.GetFileMD5(packPath, ref size); string localPath = AssetsCommon.LocalAssetPath; string zipFileName = string.Format("{0}/{1}", localPath, "Package1_0.zip"); List <AssetDataInfo> assetNames = ZipHelper.Decompress( zipFileName, localPath); Debug.Log(md51); Debug.Log("压缩成功!"); }
/// <summary> /// Handles the file in case of a zip File /// </summary> /// <param name="file">The File</param> /// <param name="fileName">Name of the zip file.</param> /// <returns>Returns true if the code should continue, false when the processing stops here</returns> protected virtual bool HandleZipFile(byte[] file, string fileName) { try { var stream = new MemoryStream(file); ZipHelper.Decompress(stream, fileName, TransactionConfigurationHelper.TemporaryPath); var files = Directory.GetFiles(TransactionConfigurationHelper.TemporaryPath); foreach (var tempFile in files) { File.Move(tempFile, Path.Combine(TransactionConfigurationHelper.InboxPath, new FileInfo(tempFile).Name)); } } catch (Exception ex) { FxLog.Debug(GetType(), ex.GetCombinedMessages()); throw; } return(false); }
IEnumerator CopyUnZipBundle() { string filename = "bundleassets_" + version + ".zip"; string url = BundleConfig.StreamingAssetPath + filename; WWW www = new WWW(url); yield return(www); if (string.IsNullOrEmpty(www.error) == false) { EDebug.Log("copy versionfile from streamingasset to persistentdatapath error:" + www.error); yield break; } string destUrl = BundleConfig.PersistentDataPath + filename; File.WriteAllBytes(destUrl, www.bytes); ZipHelper.Decompress(destUrl, BundleConfig.PersistentDataPath, null); yield return(null); }
/// <summary> /// 通过dat(压缩)文件装载数据 /// </summary> /// <param name="dt">数据表</param> /// <param name="filename">压缩文件路径</param> private void loadZipData(DataTable dt, string filename) { byte[] rawData = File.ReadAllBytes(filename); byte[] outData = ZipHelper.Decompress(rawData); MemoryStream mm = new MemoryStream(outData); using (StreamReader sr = new StreamReader(mm)) { string line = ""; while ((line = sr.ReadLine()) != null) { if (line.Trim() == "") { continue; } try { string[] cols = line.Split('\t'); dt.Rows.Add(new string[] { cols[0], cols[1] }); } catch { } } } }
// 开始解压缩 public void StartDecompress() { UpdateStageResult.DownLoad.IsEnable = false; UpdateStageResult.Compression.IsEnable = true; UpdateStageResult.Compression.ClearAll(); var deItr = _decompress_queue.GetEnumerator(); while (deItr.MoveNext()) { UpdateStageResult.Compression.TotalSize += deItr.Current.TotalSize; UpdateStageResult.Compression.FileCount++; } deItr.Dispose(); string localPath = AssetsCommon.LocalAssetPath; if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } AssetDownInfo[] tempDatas = new AssetDownInfo[_decompress_queue.Count]; for (int i = 0; i < tempDatas.Length; i++) { int index = _decompress_queue[i].Index; tempDatas[index] = _decompress_queue[i]; } for (int i = 0; i < tempDatas.Length; i++) { AssetDownInfo downInfo = tempDatas[i]; string zipFileName = string.Format("{0}/{1}", localPath, downInfo.AssetName); List <AssetDataInfo> assetNames = ZipHelper.Decompress( zipFileName, localPath); AssetDataInfo dataInfo = downInfo.ToAssetDataInfo(); dataInfo.IsCompressed = true; UpdateStageResult.Compression.CurrentCount++; FileManifestManager.UpdateLocalFenBaoData(dataInfo); for (int j = 0; j < assetNames.Count; j++) { FileManifestManager.UpdateLocalABData(assetNames[j]); } if (File.Exists(zipFileName)) { File.Delete(zipFileName); } } UpdateStageResult.Compression.IsEnable = false; if (_owner.IsDownLoadAllVersion) { FileManifestManager.WriteFenBaoDataByServer(); } else { FileManifestManager.WriteFenBaoDataByCurrent(); } FileManifestManager.WriteABDataByCurrent(); }
private IEnumerator unZip(List <DownLoadFile> list) { if (!verInfo.IsReleaseVer) { LuaInterface.Debugger.Log(string.Format("--unZip--listcount: {0}", list.Count)); } if (!checkFiles(list)) { //文件校验失败,重新下载 showMsg("取消", delegate { closeMessageBox(); Application.Quit(); }, "文件校验失败,是否重新下载", "确定", delegate { closeMessageBox(); if (versionReqCor != null) { StopCoroutine(versionReqCor); versionReqCor = StartCoroutine(versionReq()); } }); yield break; } yield return(null); if (slider != null) { slider.gameObject.SetActive(true); } for (int i = 0; i < list.Count; i++) { if (!downSizeLab.gameObject.activeSelf) { downSizeLab.gameObject.SetActive(true); downSizeLab.text = string.Format("正在解压:{0}/{1}", i, list.Count); yield return(new WaitForSeconds(0.5f)); } string gzipFileUrl = list[i].localFile; if (File.Exists(gzipFileUrl)) { string[] arraytemp = gzipFileUrl.Split('/'); string gzipFileName = arraytemp[arraytemp.Length - 1]; string gzipFilePath = gzipFileUrl.Replace(gzipFileName, ""); ZipResult zipResult = new ZipResult(); ZipHelper.Decompress(string.Format("{0}{1}", gzipFilePath, gzipFileName), gzipFilePath, ref zipResult); if (zipResult.Errors) { if (!verInfo.IsReleaseVer) { LuaInterface.Debugger.LogError("解压结果:失败" + i); } //重新下包。。。 showMsg("取消", delegate { closeMessageBox(); Application.Quit(); }, "解压失败,是否重新解压文件", "确定", delegate { closeMessageBox(); if (unZipCor != null) { StopCoroutine(unZipCor); } unZipCor = StartCoroutine(unZip(list)); }); yield break; } if (downSizeLab != null) { downSizeLab.text = string.Format("正在解压:{0}/{1}", (i + 1), list.Count); yield return(null); if (!verInfo.IsReleaseVer) { LuaInterface.Debugger.Log(string.Format("--->:{0}, {1}", downSizeLab.gameObject.activeSelf, downSizeLab.text)); } } //删除patch压缩包 if (File.Exists(gzipFileUrl)) { File.Delete(gzipFileUrl); } } } verInfo = FileUtils.GetCurrentVerNo(); VersionInfoData.CurrentVersionInfo = verInfo; if (currentVerNoLab != null) { currentVerNoLab.text = string.Format("当前资源版本 {0}", verInfo.VersionNum); } if (downSizeLab != null) { downSizeLab.gameObject.SetActive(false); } if (slider != null) { slider.gameObject.SetActive(false); } if (startGameCor != null) { StopCoroutine(startGameCor); } startGameCor = StartCoroutine(startGame()); }
public static void Decompress(FileInfo fileToDecompress) { ZipHelper.Decompress(fileToDecompress); }