/// <summary> /// 压缩一个数据集到文件 /// </summary> /// <param name="dataSet"></param> /// <param name="destFileName"></param> /// <param name="cry"></param> /// <param name="cryKey"></param> /// <returns></returns> public I3MsgInfo CompressADataSet(DataSet dataSet, string destFileName, bool cry, string cryKey) { #region 初始化临时文件变量 string tmpDir = I3DirectoryUtil.GetAppTmpTmpDir(); string tmpDataSetFile = Path.Combine(tmpDir, "DataSet.tmp"); string tmpRarFile = Path.Combine(tmpDir, I3DateTimeUtil.ConvertDateTimeToLongString(DateTime.Now) + ".tmp"); if ((!I3DirectoryUtil.CreateDirctory(tmpDir).State) || (!I3FileUtil.CheckFileNotExists(tmpDataSetFile)) || (!I3FileUtil.CheckFileNotExists(tmpRarFile))) { return(new I3MsgInfo(false, "")); } #endregion try { #region 数据集保存到临时文件 try { //保存时要写入架构信息,否则字段类型有可能会更改,如Int32更改为String dataSet.WriteXml(tmpDataSetFile, XmlWriteMode.WriteSchema); } catch (Exception ex) { return(new I3MsgInfo(false, "数据集保存到临时文件失败!文件名:" + tmpDataSetFile + "错误信息:" + ex.Message)); } if (!File.Exists(tmpDataSetFile)) { return(new I3MsgInfo(false, "数据集保存到临时文件失败!文件名:" + tmpDataSetFile)); } #endregion #region 数据集临时文件压缩到临时压缩包 I3MsgInfo msg = this.CompressASingleFile(tmpDataSetFile, tmpRarFile); if (!msg.State) { return(msg); } if (!File.Exists(tmpRarFile)) { return(new I3MsgInfo(false, "数据集临时文件压缩失败!文件名:" + tmpDataSetFile)); } #endregion #region 临时压缩包加密到目标文件 if (cry) { return(I3RijnDaelCry.CryFile(tmpRarFile, destFileName, cryKey)); } else { return(I3FileUtil.MoveFile(tmpRarFile, destFileName, true)); } #endregion } finally { #region 除临时文件 I3DirectoryUtil.DeleteDirctory(tmpDir); #endregion } }
public I3MsgInfo UnAllCompressToADir(string sourceRarFileName, string destDir) { I3MsgInfo msg = I3DirectoryUtil.CreateDirctory(destDir); if (!msg.State) { return(msg); } string cmdLine = " X -Y -C- "; if (!string.IsNullOrEmpty(passWord)) { cmdLine = cmdLine + " -p" + I3StringUtil.AppendDoubleQuotes(passWord) + " "; } cmdLine = cmdLine + I3StringUtil.AppendDoubleQuotes(sourceRarFileName) + " " + I3StringUtil.AppendDoubleQuotes(destDir); return(RunCmdLine(cmdLine)); }
protected string getTmpFileName() { string tmpDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tmp"); //MessageBox.Show(tmpDir); if (!I3DirectoryUtil.CreateDirctory(tmpDir).State) { throw new Exception("临时目录创建失败"); } try { I3DirectoryUtil.CheckAndClearDirctory(tmpDir); } catch { } string tmpFileName = Path.Combine(tmpDir, Guid.NewGuid().ToString() + ".xls"); return(tmpFileName); }
/// <summary> /// 从一个被压缩的数据集文件中加载数据集 /// </summary> /// <param name="sourceFileName"></param> /// <param name="dataSet"></param> /// <param name="unCry"></param> /// <param name="unCryKey"></param> /// <returns></returns> public I3MsgInfo UnCompressADataSet(string sourceFileName, DataSet dataSet, bool unCry, string unCryKey) { #region 初始化临时文件变量 string tmpDir = I3DirectoryUtil.GetAppTmpTmpDir(); string tmpDataSetFile = Path.Combine(tmpDir, "DataSet.tmp"); string tmpRarFile = Path.Combine(tmpDir, I3DateTimeUtil.ConvertDateTimeToLongString(DateTime.Now) + ".tmp"); if ((!I3DirectoryUtil.CreateDirctory(tmpDir).State) || (!I3FileUtil.CheckFileNotExists(tmpDataSetFile)) || (!I3FileUtil.CheckFileNotExists(tmpRarFile))) { return(new I3MsgInfo(false, "")); } #endregion I3MsgInfo msg; try { #region 解密到临时压缩文件 if (unCry) { msg = I3RijnDaelCry.UnCryFile(sourceFileName, tmpRarFile, unCryKey); if (!msg.State) { return(msg); } } else { msg = I3FileUtil.MoveFile(sourceFileName, tmpRarFile, false); if (!msg.State) { return(msg); } } if (!File.Exists(tmpRarFile)) { return(new I3MsgInfo(false, "文件解密到临时压缩文件失败!文件名:" + tmpRarFile)); } #endregion #region 解压缩到临时数据集文件 msg = this.UnCompressASingleFile(tmpRarFile, "DataSet.tmp", tmpDataSetFile); if (!msg.State) { return(msg); } if (!File.Exists(tmpDataSetFile)) { return(new I3MsgInfo(false, "临时压缩文件解压到临时数据集文件失败!文件名:" + tmpDataSetFile)); } #endregion #region 从临时数据集文件加载 try { dataSet.ReadXml(tmpDataSetFile); return(I3MsgInfo.Default); } catch (Exception ex) { return(new I3MsgInfo(false, "从临时数据集文件加载数据集失败!错误信息:" + ex.Message, ex)); } #endregion } finally { #region 除临时文件 I3DirectoryUtil.DeleteDirctory(tmpDir); #endregion } }