public DateTime GetUpdateDate(string strFileName)
        {
            strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName);
            if (string.IsNullOrEmpty(strFileName))
            {
                throw new ArgumentNullException(strFileName);
            }
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);

            zipConn.Open();
            SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null;
            DateTime updateTime = DateTime.MinValue;

            foreach (var v in zipConn.ZipTarget.Entries)
            {
                if (v.IsDirectory)
                {
                    continue;
                }
                if (string.Compare(v.Key, strFileName, true) == 0)
                {
                    findFile   = v;
                    updateTime = v.LastModifiedTime ?? DateTime.MinValue;
                    break;
                }
            }

            return(updateTime);
        }
        public void AddFile(string strFileName, byte[] fileData, DateTime date)
        {
            strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName);
            if (string.IsNullOrEmpty(strFileName))
            {
                throw new ArgumentNullException(strFileName);
            }
            string firstDir         = "";
            string childDirFileName = "";

            firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName);
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);//获取存储位置

            zipConn.Open();
            //_checkTopChildDirZipPath(firstDir);//检测ZIP,并创建
            FileEntryInfo file = new FileEntryInfo();

            file.FileDir        = firstDir;
            file.FileName       = childDirFileName;
            file.FileLen        = fileData.Length;
            file.FileUpdateTime = file.DateTimeToStr(date);
            //
            zipConn.AddFile(file, fileData);
            if (m_InUpdateState)
            {
                m_InUpdateConnZips.Add(zipConn);
            }
            else
            {
                zipConn.Save();
            }
        }
        public Stream OpenFileAsStream(string strFileName)
        {
            strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName);
            if (string.IsNullOrEmpty(strFileName))
            {
                throw new ArgumentNullException(strFileName);
            }
            string firstDir         = "";
            string childDirFileName = "";

            firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName);
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);//获取存储位置

            zipConn.Open();
            SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null;
            foreach (var v in zipConn.ZipTarget.Entries)
            {
                if (v.IsDirectory)
                {
                    continue;
                }
                if (string.Compare(v.Key, childDirFileName, true) == 0)
                {
                    findFile = v;
                    break;
                }
            }
            if (findFile != null)
            {
                return(zipConn.GetUnCompressStream(findFile));
            }
            return(null);
        }
        public void UpdateFile(string strFileName, byte[] fileData, DateTime date)
        {
            strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName);
            if (string.IsNullOrEmpty(strFileName))
            {
                throw new ArgumentNullException(strFileName);
            }
            string firstDir         = "";
            string childDirFileName = "";

            firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName);
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);//获取存储位置
            //_checkTopChildDirZipPath(firstDir);//检测ZIP,并创建
            FileEntryInfo file = new FileEntryInfo();

            file.FileDir        = firstDir;
            file.FileName       = childDirFileName;
            file.FileLen        = fileData.Length;
            file.FileUpdateTime = file.DateTimeToStr(date);
            //
            zipConn.Open();
            SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null;
            foreach (var ze in zipConn.ZipTarget.Entries)
            {
                if (ze.IsDirectory)
                {
                    continue;
                }
                if (string.Compare(ze.Key, file.FileName, true) == 0)
                {
                    findFile = ze;
                    break;
                }
            }
            //
            if (findFile != null)
            {
                zipConn.ZipTarget.RemoveEntry(findFile);
                //findFile.Close();//删除老的
            }
            //修改文件
            AddFile(strFileName, fileData, date);
            if (m_InUpdateState)
            {
                m_InUpdateConnZips.Add(zipConn);
            }
            else
            {
                zipConn.Save();
            }
        }
        /// <summary>
        /// 目录不能为空
        /// </summary>
        /// <param name="strDir"></param>
        /// <param name="fileNames"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public int GetFiles(string strDir, out List <string> fileNames, out int totalSize)
        {
            //
            strDir = FileEntryInfo.GetDirPathToLowerNorm_STC(strDir);
            if (string.IsNullOrEmpty(strDir))
            {
                throw new ArgumentNullException(strDir);
            }
            strDir    = strDir + "/";//补充
            fileNames = new List <string>();
            totalSize = 0;
            string firstDir         = "";
            string childDirFileName = "";

            //string strFileName= Path.Combine(strDir, "checkfiledata.zip");
            firstDir = FileEntryInfo.GetFirstDir_STC(strDir, out childDirFileName);
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strDir);

            zipConn.Open();
            //
            List <SharpCompress.Archive.Zip.ZipArchiveEntry> filesInDir = new List <SharpCompress.Archive.Zip.ZipArchiveEntry>();
            bool all = string.IsNullOrEmpty(childDirFileName);

            //ToDo:查找里面的所有文件
            foreach (var ze in zipConn.ZipTarget.Entries)
            {
                if (!ze.IsDirectory)
                {
                    if (all)
                    {
                        filesInDir.Add(ze);
                    }
                    else if (ze.Key.ToLower().StartsWith(firstDir))
                    {
                        filesInDir.Add(ze);
                    }
                }
            }
            foreach (var v in filesInDir)
            {
                fileNames.Add(v.Key);
                totalSize += (int)v.Size;
                //v.Close();
            }
            //
            int count = filesInDir.Count;

            return(count);
        }
        public void DelFile(string strFileName)
        {
            strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName);
            if (string.IsNullOrEmpty(strFileName))
            {
                return;
            }
            string firstDir         = "";
            string childDirFileName = "";

            firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName);
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);

            zipConn.Open();
            SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null;
            foreach (var v in zipConn.ZipTarget.Entries)
            {
                if (v.IsDirectory)
                {
                    continue;
                }
                if (string.Compare(v.Key, childDirFileName, true) == 0)
                {
                    findFile = v;
                    break;
                }
            }
            if (findFile != null)
            {
                zipConn.ZipTarget.RemoveEntry(findFile);
                //findFile.Close();
            }
            if (m_InUpdateState)
            {
                m_InUpdateConnZips.Add(zipConn);
            }
            else
            {
                zipConn.Save();
            }
        }
        public bool FileExists(string strFileName)
        {
            strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName);
            if (string.IsNullOrEmpty(strFileName))
            {
                return(false);
            }
            string firstDir         = "";
            string childDirFileName = "";

            firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName);
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);

            zipConn.Open();
            SharpCompress.Archive.Zip.ZipArchiveEntry findFile = null;
            foreach (var v in zipConn.ZipTarget.Entries)
            {
                if (v.IsDirectory)
                {
                    continue;
                }
                if (string.Compare(v.Key, childDirFileName, true) == 0)
                {
                    findFile = v;
                    break;
                }
            }
            bool find = false;

            if (findFile != null)
            {
                //findFile.Close();
                find = true;
            }

            return(find);
        }
        /// <summary>
        /// 传进来的必须是目录,注意:会中断 m_InUpdateState状态
        /// </summary>
        /// <param name="strDir"></param>
        public void DelDir(string strDir)
        {
            //删除DIR
            strDir = FileEntryInfo.GetDirPathToLowerNorm_STC(strDir);
            if (string.IsNullOrEmpty(strDir))
            {
                return;            //不能删除所有?
            }
            strDir = strDir + "/"; //补充
            string firstDir = "";
            string childFirstDirFileName = "";
            string secendDir             = "";

            //string childSecendDirFileName = "";
            firstDir = FileEntryInfo.GetFirstDir_STC(strDir, out childFirstDirFileName);
            if (!string.IsNullOrEmpty(childFirstDirFileName))
            {
                //有子目录
                int index = childFirstDirFileName.IndexOf('/');
                if (index != -1)
                {
                    secendDir = childFirstDirFileName.Substring(0, index);
                }
                else
                {
                    secendDir = childFirstDirFileName;
                }
            }
            //第2层目录为空,说明删除的是顶层DIR
            if (string.IsNullOrEmpty(secendDir))
            {
                //删除目录---这一块一执行就被删除了,需要注意
                string realPath = Path.Combine(this.RootDir_FileTable, firstDir);
                string zip      = Path.Combine(realPath, FileDataDBName);
                if (File.Exists(zip))
                {
                    DiskZip_ConnectInfo zipConn = _checkFileDataZip(firstDir + "/checkdir.zip");
                    zipConn.Close();
                    File.Delete(zip);
                }
                if (Directory.Exists(realPath))
                {
                    Directory.Delete(realPath, true);
                }
                if (m_FileDataZips.ContainsKey(zip))
                {
                    m_FileDataZips.Remove(zip);
                }
            }
            else
            {
                //场景中的机器人/VPL文件列表
                secendDir = secendDir + "/";
                //删除压缩包内的文件
                DiskZip_ConnectInfo zipConn = _checkFileDataZip(strDir + "/checkfiledata.zip");
                zipConn.Open();
                List <SharpCompress.Archive.Zip.ZipArchiveEntry> olddirs = new List <SharpCompress.Archive.Zip.ZipArchiveEntry>();

                foreach (var ze in zipConn.ZipTarget.Entries)
                {
                    //if (ze.IsDirectory) {
                    if (ze.Key.ToLower().StartsWith(secendDir))
                    {
                        olddirs.Add(ze);
                    }
                    //}
                }
                //删除目录以及其中的文件
                for (int i = olddirs.Count - 1; i >= 0; i--)
                {
                    zipConn.ZipTarget.RemoveEntry(olddirs[i]);
                    //olddirs[i].Close();
                }
                if (m_InUpdateState)
                {
                    m_InUpdateConnZips.Add(zipConn);
                }
                else
                {
                    zipConn.Save();
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="strNewFile"></param>
        public void RenameFile(string strFileName, string strNewFile)
        {
            strFileName = FileEntryInfo.GetDirPathToLowerNorm_STC(strFileName);
            strNewFile  = FileEntryInfo.GetDirPathToLowerNorm_STC(strNewFile);
            if (string.IsNullOrEmpty(strFileName) || string.IsNullOrEmpty(strNewFile))
            {
                return;                                                                       //名称不能为空
            }
            if (string.Compare(strFileName, strNewFile) == 0)
            {
                return;                                              //没有修改
            }
            string firstDir         = "";
            string childDirFileName = "";

            firstDir = FileEntryInfo.GetFirstDir_STC(strFileName, out childDirFileName);
            DiskZip_ConnectInfo zipConn = _checkFileDataZip(strFileName);//获取存储位置

            zipConn.Open();
            SharpCompress.Archive.Zip.ZipArchiveEntry findfile = null;

            foreach (var ze in zipConn.ZipTarget.Entries)
            {
                if (ze.IsDirectory)
                {
                    continue;
                }
                if (string.Compare(ze.Key, childDirFileName, true) == 0)
                {
                    findfile = ze;
                    break;
                }
            }
            if (findfile != null)
            {
                MemoryStream ms = zipConn.GetUnCompressStream(findfile);
                zipConn.ZipTarget.RemoveEntry(findfile);
                //findfile.Close();
                //
                string firstDir2         = "";
                string childDirFileName2 = "";
                firstDir2 = FileEntryInfo.GetFirstDir_STC(strNewFile, out childDirFileName2);
                DiskZip_ConnectInfo zipConn2 = _checkFileDataZip(strNewFile);//获取存储位置
                zipConn2.Open();
                zipConn2.ZipTarget.AddEntry(strNewFile, ms, true, ms.Length, findfile.LastModifiedTime);
                if (m_InUpdateState)
                {
                    m_InUpdateConnZips.Add(zipConn);
                    if (string.Compare(firstDir2, firstDir) != 0)
                    {
                        m_InUpdateConnZips.Add(zipConn2);
                    }
                }
                else
                {
                    zipConn.Save();
                    if (string.Compare(firstDir2, firstDir) != 0)
                    {
                        zipConn2.Save();
                    }
                }
            }
        }