Beispiel #1
0
        /// <summary>
        /// 解压缩字符串
        /// </summary>
        /// <param name="source"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string UnCryString(string source, string key)
        {
            string tmpStr = I3MD5.MD5String(key);

            byte[] keyBytes = Encoding.ASCII.GetBytes(tmpStr);                                //32*8
            byte[] ivBytes  = Encoding.ASCII.GetBytes(I3StringUtil.SubString(tmpStr, 0, 16)); //16*8

            return(I3CryWeb.Decrypt(source, "Rijndael", keyBytes, ivBytes));
        }
Beispiel #2
0
        /// <summary>
        /// 解压单个文件 到 指定文件
        /// 注意:单个文件的文件名,要指定在rar文件中的相对路径
        /// </summary>
        /// <param name="sourceRarFileName"></param>
        /// <param name="sourceFileName"></param>
        /// <param name="destFileName"></param>
        /// <returns></returns>
        public I3MsgInfo UnCompressASingleFile(string sourceRarFileName, string sourceFileName, string destFileName)
        {
            #region 先删除目的文件
            if (!I3FileUtil.CheckFileNotExists(destFileName))
            {
                return(new I3MsgInfo(false, ""));
            }
            #endregion

            #region 获取临时目录与临时文件名
            string tmpDir      = I3DirectoryUtil.GetAppTmpTmpDir();
            string tmpFileName = Path.Combine(tmpDir, Path.GetFileName(sourceFileName));
            #endregion

            I3MsgInfo msg = I3DirectoryUtil.CreateDirectoryByFileName(tmpFileName);
            #region 创建临时目录
            if (!msg.State)
            {
                return(msg);
            }
            #endregion

            try
            {
                #region 生成命令行参数
                string cmdLine;
                cmdLine = " E -Y ";
                if (!string.IsNullOrEmpty(passWord))
                {
                    cmdLine = cmdLine + " -p" + I3StringUtil.AppendDoubleQuotes(passWord) + " ";
                }
                cmdLine = cmdLine + I3StringUtil.AppendDoubleQuotes(sourceRarFileName) + " "
                          + I3StringUtil.AppendDoubleQuotes(sourceFileName) + " "
                          + I3StringUtil.AppendDoubleQuotes(tmpDir);
                #endregion

                //执行
                msg = RunCmdLine(cmdLine);
                if (!msg.State)
                {
                    return(msg);
                }

                //检查临时文件
                if (!File.Exists(tmpFileName))
                {
                    return(new I3MsgInfo(false, "未知错误,临时文件未生成!文件名:" + tmpFileName));
                }

                //移动
                return(I3FileUtil.MoveFile(tmpFileName, destFileName, true));
            }
            finally
            {
                I3DirectoryUtil.DeleteDirctory(tmpDir);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 从文件名和文件流得到一个Entry
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileStream"></param>
        /// <returns></returns>
        private ZipEntry GetEntry(string aFileName, string aFullName)
        {
            ZipEntry zipEntry = new ZipEntry(aFileName);

            zipEntry.DateTime = DateTime.Now;

            //目录
            if (I3StringUtil.SubString(aFileName, aFileName.Length - 1).Equals("/"))
            {
                zipEntry.Size = 0;
                //zipEntry.Crc = 0;

                return(zipEntry);
            }

            using (FileStream fileStream = File.Open(aFullName, FileMode.Open))
            {
                zipEntry.Size = fileStream.Length;

                /*Crc32 crc = new Crc32();
                 * byte[] buffer = new byte[4096];
                 * crc.Reset();
                 * fileStream.Position = 0;
                 *
                 * while (true)
                 * {
                 *  long pos = fileStream.Position;
                 *  int size = fileStream.Read(buffer, 0, buffer.Length);
                 *  if (size == 0)
                 *      break;
                 *  if (size < buffer.Length)
                 *  {
                 *      buffer = new byte[size];
                 *      fileStream.Position = pos;
                 *      fileStream.Read(buffer, 0, buffer.Length);
                 *  }
                 *  crc.Update(buffer);
                 *  Application.DoEvents();
                 * }
                 *
                 * zipEntry.Crc = crc.Value;*/
                return(zipEntry);
            }
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        /// <summary>
        /// 加密流
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static I3MsgInfo CryStream(Stream source, Stream dest, string key)
        {
            try
            {
                string             tmpStr   = I3MD5.MD5String(key);
                byte[]             keyBytes = Encoding.ASCII.GetBytes(tmpStr);                                //32*8
                byte[]             ivBytes  = Encoding.ASCII.GetBytes(I3StringUtil.SubString(tmpStr, 0, 16)); //16*8
                SymmetricAlgorithm sym      = SymmetricAlgorithm.Create("Rijndael");
                sym.Key = keyBytes;
                sym.IV  = ivBytes;

                I3CryWeb cry = new I3CryWeb();
                cry.EncryptData(source, dest, sym, null, null, null);

                return(I3MsgInfo.Default);
            }
            catch (Exception ex)
            {
                return(new I3MsgInfo(false, ex.Message, ex));
            }
        }
Beispiel #6
0
        public string ToString2()
        {
            string result = "";

            foreach (I3SearchItem item in Items)
            {
                if (string.IsNullOrEmpty(item.SearchString.Trim()))
                {
                    continue;
                }

                result = result + item.LookString + ",";
            }

            if (result.Length > 0)
            {
                result = I3StringUtil.SubString(result, 0, result.Length - 1);
            }

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// 压缩单个文件
        /// </summary>
        /// <param name="sourceFileName"></param>
        /// <param name="destFileName"></param>
        /// <returns></returns>
        public I3MsgInfo CompressASingleFile(string sourceFileName, string destFileName)
        {
            #region 先删除目的文件
            if (!I3FileUtil.CheckFileNotExists(destFileName))
            {
                return(new I3MsgInfo(false, "目标文件删除失败"));
            }
            #endregion

            #region 生成命令行参数
            string cmdLine;
            cmdLine = " A -ep -Y ";
            if (!string.IsNullOrEmpty(passWord))
            {
                cmdLine = cmdLine + " -p" + I3StringUtil.AppendDoubleQuotes(passWord) + " ";
            }
            cmdLine = cmdLine + I3StringUtil.AppendDoubleQuotes(destFileName) + " " + I3StringUtil.AppendDoubleQuotes(sourceFileName);
            #endregion

            return(RunCmdLine(cmdLine));
        }
Beispiel #8
0
        /// <summary>
        /// 压缩整个目录,包含子目录和文件
        /// </summary>
        /// <param name="aDir"></param>
        /// <param name="destFileName"></param>
        /// <returns></returns>
        public I3MsgInfo CompressADir(string aDir, string destFileName)
        {
            #region 先删除目的文件
            if (!I3FileUtil.CheckFileNotExists(destFileName))
            {
                return(new I3MsgInfo(false, ""));
            }
            #endregion

            if (!string.IsNullOrEmpty(aDir))
            {
                aDir = I3DirectoryUtil.CheckDirctoryLastChar(aDir);
                aDir = aDir + "*";
            }
            string cmdLine = " a -ep1 -r -Y ";
            if (!string.IsNullOrEmpty(passWord))
            {
                cmdLine = cmdLine + " -p" + I3StringUtil.AppendDoubleQuotes(passWord) + " ";
            }
            cmdLine = cmdLine + I3StringUtil.AppendDoubleQuotes(destFileName) + " " + I3StringUtil.AppendDoubleQuotes(aDir);

            return(RunCmdLine(cmdLine));
        }
        private void TfrmGetSymbol_Load(object sender, EventArgs e)
        {
            busy = true;

            try
            {
                nameList = new ArrayList();
                textList = new ArrayList();

                #region 读取数据,并检查数据正确性
                try
                {
                    dataSet.ReadXml(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Symbol.set"));
                }
                catch (Exception ex)
                {
                    I3MessageHelper.ShowError(ex.Message, ex);
                    return;
                }

                if (dataSet.Tables.Count == 0)
                {
                    return;
                }
                if (dataSet.Tables[0].Columns.Count == 0)
                {
                    return;
                }
                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return;
                }
                #endregion

                #region 写入默认数据

                /*dataSet.Tables[0].Columns[0].ColumnName = "数学序号";
                 * dataSet.Tables[0].Columns[1].ColumnName = "数学符号";
                 * dataSet.Tables[0].Columns[2].ColumnName = "单位符号";
                 * dataSet.Tables[0].Columns[3].ColumnName = "特殊符号";
                 * dataSet.Tables[0].Rows[0][0] = "①②③④⑤⑥⑦⑧⑨⑩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ";
                 * dataSet.Tables[0].Rows[0][1] = "×÷≠≤≥≮≯±∽≈≌⊕⊙∈∏∑∝∞∫∮";
                 * dataSet.Tables[0].Rows[0][2] = "℃℉﹪‰¥№㎡23㎝㎞㏎㎎㎏㏄";
                 * dataSet.Tables[0].Rows[0][3] = "Ф★☆○☉◎●▲△▼▽■□♀♂《》「」『』〖〗【】";
                 * dataSet.WriteXml(AppDomain.CurrentDomain.BaseDirectory + @"\Symbol.set");*/
                #endregion

                #region 将数据保存到动态数组中
                for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
                {
                    nameList.Add(dataSet.Tables[0].Columns[i].ColumnName);
                    textList.Add(dataSet.Tables[0].Rows[0][i].ToString());
                }
                cbbSymbolStyle.DataSource = nameList;
                #endregion

                #region 增加20列
                for (int i = 0; i < 20; i++)
                {
                    DataColumn newColumn = new DataColumn("col" + (i + 1).ToString(), typeof(string));
                    newDataTable.Columns.Add(newColumn);

                    I3TextColumn textColumn = new I3TextColumn();
                    textColumn.Width    = Convert.ToInt32(this.i3Table.Width / 20);
                    textColumn.Sortable = false;
                    textColumn.Editable = false;
                    this.i3ColumnModel.Columns.Add(textColumn);
                }
                #endregion

                #region 得到完全字符串
                string s = "";
                for (int i = 0; i < textList.Count; i++)
                {
                    s = s + textList[i].ToString();
                }
                #endregion

                #region 得到行数,并生成DataRow
                int rowcount = s.Length / 20;
                if (s.Length % 20 > 0)
                {
                    rowcount++;
                }
                for (int i = 0; i < rowcount; i++)
                {
                    DataRow newRow = newDataTable.NewRow();
                    newDataTable.Rows.Add(newRow);
                }
                #endregion

                #region 给每行每列赋值
                int row, col;
                for (int i = 0; i < s.Length; i++)
                {
                    row = (i + 1) / 20; //整除
                    col = (i + 1) % 20; //求余
                    if (col == 0)
                    {
                        row--;
                        col += 20;
                    }
                    col--;
                    newDataTable.Rows[row].BeginEdit();
                    newDataTable.Rows[row][col] = I3StringUtil.SubString(s, i, 1);
                    newDataTable.Rows[row].EndEdit();
                }
                foreach (DataRow dataRow in newDataTable.Rows)
                {
                    I3Row i3Row = new I3Row();
                    this.i3TableModel.Rows.Add(i3Row);
                    foreach (DataColumn column in newDataTable.Columns)
                    {
                        I3Cell i3Cell = new I3Cell(dataRow[column].ToString());
                        i3Row.Cells.Add(i3Cell);
                    }
                }
                #endregion

                this.i3TableModel.Selections.SelectCell(0, 0);
            }
            finally
            {
                busy = false;
            }
        }
Beispiel #10
0
        /// <summary>
        /// 解压所有文件到指定的目录
        ///
        /// checkFileIsNormal:解压时,是否在fileInfoList中检查其状态为normal,为normal时才解压
        /// 此功能用于更换或者删除文件时,同时,为normal状态的fileinfo.fullName将被更新,指示现在被解压到了哪里
        ///
        /// </summary>
        /// <param name="aNewPath"></param>
        /// <returns></returns>
        public I3MsgInfo UnCompressAllFile(string aNewPath, bool checkFileIsNormal)
        {
            if (!fileExists)
            {
                return(I3MsgInfo.Default);
            }

            I3MsgInfo msg;

            #region 定义变量
            string         message             = "";
            ZipInputStream inputStream         = null;
            int            normalFileCount     = GetNormalFileCount();
            long           totalNormalFileSize = GetTotalNormalFileSize(); //所有需要解压的文件的字节数
            long           passFileSize        = 0;                        //已经解压掉的文件的字节数
            long           totalPosition       = 0;                        //总共解压到的字节数
            #endregion

            try
            {
                inputStream = new ZipInputStream(File.OpenRead(fileName));
                if (!string.IsNullOrEmpty(passWord))
                {
                    inputStream.Password = passWord;
                }
                ZipEntry theEntry;

                int fileindex = 0;
                while ((theEntry = inputStream.GetNextEntry()) != null)
                {
                    I3SharpZipFileInfo normalInfo = null;
                    #region 检查文件是否为normal状态
                    if (checkFileIsNormal)
                    {
                        bool isNormal = false;
                        foreach (I3SharpZipFileInfo info in fileInfoList)
                        {
                            if (info.FileName.Equals(theEntry.Name))
                            {
                                isNormal   = info.Mode == I3SZFileInfoMode.szimNormal;
                                normalInfo = info;
                                break;
                            }
                        }

                        if (!isNormal)
                        {
                            continue;
                        }
                    }
                    #endregion
                    #region 获取目的文件名,并生成目录 normalInfo不为空时,更新FullName
                    string aNewFileName = Path.Combine(aNewPath, theEntry.Name);
                    if (normalInfo != null)
                    {
                        normalInfo.FullName = aNewFileName;
                    }
                    msg = I3DirectoryUtil.CreateDirectoryByFileName(aNewFileName);
                    if (!msg.State)
                    {
                        return(msg);
                    }
                    #endregion
                    #region 发送文件个数进度信息
                    message = "正在解压文件" + theEntry.Name + "到" + aNewFileName;
                    fileindex++;
                    OnMutiFileProcessReport(normalFileCount, fileindex, message);
                    #endregion
                    #region 如果是目录则不需要解压  文件大小为0且文件名最后一个字符是/表示是目录
                    if ((theEntry.Size.Equals(0) && (I3StringUtil.SubString(theEntry.Name, theEntry.Name.Length - 1).Equals("/"))))
                    {
                        continue;
                    }
                    #endregion

                    #region 定义单个文件的变量
                    FileStream streamWriter = null;
                    #endregion
                    try
                    {
                        #region 解压
                        streamWriter = File.Create(aNewFileName);

                        byte[] data     = new byte[blockSize];
                        long   longsize = 0;
                        while (true)
                        {
                            int size = inputStream.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                                longsize += size;
                                OnSingleFileProcessReport(theEntry.Size, longsize, message);
                                totalPosition = passFileSize + longsize;
                                OnTotalBytesProcessReport(totalNormalFileSize, totalPosition, message);
                            }
                            else
                            {
                                break;
                            }
                        }
                        passFileSize += longsize;
                        #endregion
                    }
                    finally
                    {
                        #region 释放单个文件的变量
                        if (streamWriter != null)
                        {
                            streamWriter.Close();
                        }
                        #endregion
                    }
                }

                return(I3MsgInfo.Default);
            }
            #region 错误处理
            catch (Exception ex)
            {
                return(new I3MsgInfo(false, ex.Message, ex));
            }
            #endregion
            #region 释放inputStream
            finally
            {
                if (inputStream != null)
                {
                    inputStream.Close();
                }
            }
            #endregion
        }
Beispiel #11
0
        /// <summary>
        /// 根据文件信息从压缩包中获取单个文件,需要指定FullName
        /// </summary>
        /// <param name="aFileInfo"></param>
        /// <returns></returns>
        public I3MsgInfo UnCompressSingleFile(I3SharpZipFileInfo aFileInfo)
        {
            #region 检查文件名与上级目录
            if (string.IsNullOrEmpty(aFileInfo.FullName))
            {
                return(new I3MsgInfo(false, "未设置目的路径!"));
            }
            I3MsgInfo msg = I3DirectoryUtil.CreateDirectoryByFileName(aFileInfo.FullName);
            if (!msg.State)
            {
                return(msg);
            }
            string message = "正在解压文件" + aFileInfo.FileName + "到" + aFileInfo.FullName;
            #endregion
            #region 检查是否是目录  文件大小为0且文件名最后一个字符是/表示是目录
            if ((aFileInfo.FileSize.Equals(0) && (I3StringUtil.SubString(aFileInfo.FileName, aFileInfo.FileName.Length - 1).Equals("/"))))
            {
                return(I3MsgInfo.Default);
            }
            #endregion

            bool           result      = false;
            ZipInputStream inputStream = null;
            try
            {
                inputStream = new ZipInputStream(File.OpenRead(fileName));
                if (!string.IsNullOrEmpty(passWord))
                {
                    inputStream.Password = passWord;
                }
                ZipEntry theEntry;

                while ((theEntry = inputStream.GetNextEntry()) != null)
                {
                    #region 判断文件名是否为要解压的文件
                    if (!theEntry.Name.Equals(aFileInfo.FileName))
                    {
                        continue;
                    }
                    #endregion

                    #region 定义单个文件的变量
                    FileStream streamWriter = null;
                    #endregion
                    try
                    {
                        #region 解压
                        streamWriter = File.Create(aFileInfo.FullName);

                        byte[] data     = new byte[blockSize];
                        long   longsize = 0;
                        while (true)
                        {
                            int size = inputStream.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                streamWriter.Write(data, 0, size);
                                longsize += size;
                                OnSingleFileProcessReport(aFileInfo.FileSize, longsize, message);
                            }
                            else
                            {
                                break;
                            }
                        }
                        #endregion
                    }
                    finally
                    {
                        #region 释放单个文件的变量
                        if (streamWriter != null)
                        {
                            streamWriter.Close();
                        }
                        #endregion
                    }
                    result = true;
                }
            }
            #region 错误处理
            catch (Exception ex)
            {
                return(new I3MsgInfo(false, ex.Message, ex));
            }
            #endregion
            #region 释放inputStream
            finally
            {
                if (inputStream != null)
                {
                    inputStream.Close();
                }
            }
            #endregion

            return(new I3MsgInfo(result, ""));
        }