Esempio n. 1
0
        void _checkDBFilePath(string path, string _dbfileName)
        {
            //创建目录与文件 第1层,第2层的文件保存方式
            string rootDir = path;

            if (!Directory.Exists(rootDir))
            {
                FileEntryInfo.CheckDirectory_STC(rootDir);
            }
            string dbname = Path.Combine(rootDir, _dbfileName);
            //创建根目录 下保存的文件对象位置
            bool fileExist = File.Exists(dbname);//存在文件就直接打开,否则创建

            //conn = new SQLiteConnection(dbname, fileExist ? SQLiteOpenFlags.ReadWrite : (SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create));
            if (fileExist)
            {
                //检测是否为压缩文件
                using (FileStream fst = new FileStream(dbname, FileMode.Open, FileAccess.Read)) {
                    fileExist = SharpCompress.Archive.Zip.ZipArchive.IsZipFile(fst);//非压缩文件
                    //压缩文件系统 没必要一直处于打开状态吧 用完销毁
                }
            }
            if (!fileExist)
            {
                using (SharpCompress.Archive.Zip.ZipArchive con = SharpCompress.Archive.Zip.ZipArchive.Create()) {
                    using (FileStream fst = new FileStream(dbname, FileMode.Create, FileAccess.Write)) {
                        con.SaveTo(fst, new SharpCompress.Common.CompressionInfo());//保存完毕
                    }
                }
            }
        }
Esempio n. 2
0
        private void Save()
        {
            if (mode == ZipArchiveMode.Create)
            {
                zipFile.SaveTo(stream, CompressionType.Deflate, entryNameEncoding ?? Encoding.UTF8);
            }
            else
            {
                using (var newZip = new MemoryStream())
                {
                    zipFile.SaveTo(newZip, CompressionType.Deflate, entryNameEncoding ?? Encoding.UTF8);

                    stream.SetLength(0);
                    stream.Position = 0;
                    newZip.Position = 0;
                    newZip.CopyTo(stream);
                }
            }
        }
Esempio n. 3
0
        private void Save()
        {
            using (var newZip = new MemoryStream()) {
                zipFile.SaveTo(newZip, CompressionType.Deflate);

                stream.SetLength(0);
                stream.Position = 0;
                newZip.Position = 0;
                newZip.CopyTo(stream);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 根据文件名,取得存储数据的zip
        /// </summary>
        /// <param name="strFileName">相对与table根目录的路径</param>
        /// <returns></returns>
        DiskZip_ConnectInfo _checkFileDataZip(string strFileName)
        {
            string zipDataPath = _getFileDataZipPath(strFileName);
            bool   fileExist   = File.Exists(zipDataPath);

            if (!fileExist)
            {
                FileEntryInfo.CheckDirectory_STC(Path.GetDirectoryName(zipDataPath));
                using (SharpCompress.Archive.Zip.ZipArchive con = SharpCompress.Archive.Zip.ZipArchive.Create()) {
                    using (FileStream fst = new FileStream(zipDataPath, FileMode.Create, FileAccess.Write)) {
                        con.SaveTo(fst, new SharpCompress.Common.CompressionInfo());//保存完毕
                    }
                }
            }
            if (!m_FileDataZips.ContainsKey(zipDataPath))
            {
                //创建
                if (fileExist)
                {
                    //检测是否为压缩文件
                    using (FileStream fst = new FileStream(zipDataPath, FileMode.Open, FileAccess.Read)) {
                        fileExist = SharpCompress.Archive.Zip.ZipArchive.IsZipFile(fst);//非压缩文件
                        //压缩文件系统 没必要一直处于打开状态吧 用完销毁
                    }
                }
                if (!fileExist)
                {
                    FileEntryInfo.CheckDirectory_STC(Path.GetDirectoryName(zipDataPath));
                    using (SharpCompress.Archive.Zip.ZipArchive con = SharpCompress.Archive.Zip.ZipArchive.Create()) {
                        using (FileStream fst = new FileStream(zipDataPath, FileMode.Create, FileAccess.Write)) {
                            con.SaveTo(fst, new SharpCompress.Common.CompressionInfo());//保存完毕
                        }
                    }
                }

                DiskZip_ConnectInfo dc = new DiskZip_ConnectInfo();
                dc.ConnString = zipDataPath;
                m_FileDataZips.Add(zipDataPath, dc);
            }
            return(m_FileDataZips[zipDataPath]);
        }
        /// <summary>
        /// 检测压缩文件是否存在,如果不存在则创建文件并加入表中,返回连接.z文件对象
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        internal DiskReadZip_ConnectInfo CheckConnection(string tableName)
        {
            if (!m_Conns.ContainsKey(tableName))
            {
                //创建
                string dbname    = _GetTableFileFullPath(tableName);
                bool   fileExist = File.Exists(dbname);//存在文件就直接打开,否则创建
                //conn = new SQLiteConnection(dbname, fileExist ? SQLiteOpenFlags.ReadWrite : (SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create));
                if (fileExist)
                {
                    //检测是否为压缩文件
                    using (FileStream fst = new FileStream(dbname, FileMode.Open, FileAccess.Read)) {
                        fileExist = SharpCompress.Archive.Zip.ZipArchive.IsZipFile(fst);//非压缩文件
                        //压缩文件系统 没必要一直处于打开状态吧 用完销毁
                    }
                }
                if (!fileExist)
                {
                    using (SharpCompress.Archive.Zip.ZipArchive con = SharpCompress.Archive.Zip.ZipArchive.Create()) {
                        using (FileStream fst = new FileStream(dbname, FileMode.Create, FileAccess.Write)) {
                            con.SaveTo(fst, new SharpCompress.Common.CompressionInfo());//保存完毕
                        }
                    }
                }
                //
                //FileStream fs = new FileStream(dbname, FileMode.Open, FileAccess.ReadWrite);
                //conn =  SharpCompress.Archive.Zip.ZipArchive.Open(fs);
                DiskReadZip_ConnectInfo ci = new DiskReadZip_ConnectInfo();
                ci.ConnString = dbname;
                ci.Name       = tableName;
                m_Conns.Add(tableName, ci);//添加在数据表中
                //
            }

            //打开,用的时候再打开吧
            //m_Conns[tableName].Open();

            return(m_Conns[tableName]);
        }