/// <summary> /// DES解密后解压 /// </summary> /// <param name="hexStringKey"></param> /// <param name="encryptSource"></param> /// <returns></returns> public static byte[] UnDelphiDesAndUnZip(string hexStringKey, byte[] encryptSource) { string hexStringIV = StringEncode.ByteArrayToHexString(DefaultDesIV); byte[] desResult = DelphiDesDecryptToArray(hexStringKey, hexStringIV, encryptSource); return(ZipCompress.DeCompress(desResult)); }
// byte[] = byte[] /// <summary> /// 3DES解密后Zip解压缩,密钥长度必需是24字节 /// </summary> /// <param name="hexStringKey">密钥串</param> /// <param name="encryptSource"></param> /// <returns></returns> public static byte[] Un3DesAndUnZip(string hexStringKey, byte[] encryptSource) { byte[] desResult = Cryptography.TripleDesDecrypt(hexStringKey, encryptSource); return(ZipCompress.DeCompress(desResult)); }
/// <summary> /// 替换程序 /// </summary> public void Replace() { string fileName = ServiceFileInfoPath + @"\" + this.FileName; //是压缩包 if (this.IsZip) { if (!System.IO.Directory.Exists(TempZipPath)) { System.IO.Directory.CreateDirectory(TempZipPath); } if (!System.IO.Directory.Exists(TempBakPath)) { System.IO.Directory.CreateDirectory(TempBakPath); } //Zip包解压缩,并且替换目标文件 Message?.Invoke("正在解压..."); if (ZipCompress == null) { ZipCompress = new GZipCompress(); } ZipCompress.DirPath = TempZipPath; ZipCompress.ZipFileName = fileName; ZipCompress.Message = Message; ZipCompress.DeCompress(); System.Threading.Thread.Sleep(100); //复制文件到安装目录 var tempFiles = System.IO.Directory.GetFiles(TempZipPath, "*", System.IO.SearchOption.AllDirectories); foreach (string f in tempFiles) { Message?.Invoke("正在替换文件" + f + "..."); string workPath = System.IO.Path.GetFullPath(LocalFileInfoPath + @"\" + f.Substring(TempZipPath.Length, f.Length - TempZipPath.Length - System.IO.Path.GetFileName(f).Length)); if (!System.IO.Directory.Exists(workPath)) { System.IO.Directory.CreateDirectory(workPath); } string strOldFilename = System.IO.Path.GetFullPath(workPath + @"\" + System.IO.Path.GetFileName(f)); string strOldBakFilename = System.IO.Path.GetFullPath(workPath.Replace(LocalFileInfoPath, TempBakPath) + @"\" + System.IO.Path.GetFileName(f)); if (System.IO.File.Exists(strOldFilename)) { if (System.IO.File.Exists(strOldBakFilename + ".bak")) { System.IO.File.Delete(strOldBakFilename + ".bak"); } try { System.IO.File.Move(strOldFilename, strOldBakFilename + ".bak"); } catch (Exception ex) { ex.ToString(); } } try { System.IO.File.Copy(f, System.IO.Path.GetFullPath(workPath + @"\" + System.IO.Path.GetFileName(f)), true); } catch (Exception ex) { ex.ToString(); } } System.Threading.Thread.Sleep(100); Message?.Invoke("正在清理..."); System.IO.File.Delete(fileName); System.IO.File.Delete(ServiceFileInfoPath + @"\" + FileInfoName); System.IO.Directory.Delete(TempZipPath, true); System.IO.Directory.Delete(ServiceFileInfoPath, true); //var fileBaks = System.IO.Directory.GetFiles(LocalFileInfoPath, "*.bak", System.IO.SearchOption.AllDirectories); var fileBaks = System.IO.Directory.GetFiles(TempBakPath, "*.bak", System.IO.SearchOption.AllDirectories); foreach (var fileBak in fileBaks) { try { System.IO.File.Delete(fileBak); } catch (Exception ex) { ex.ToString(); } } System.Threading.Thread.Sleep(100); //var dev = @"cmd.exe"; //System.Diagnostics.Process.Start(dev); } else //是安装包 { System.Diagnostics.Process.Start(fileName); } }