Beispiel #1
0
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="strFilePath"></param>
        /// <param name="bCacheInMemory"></param>
        /// <returns></returns>
        public bool Open(string strFilePath, bool bCacheInMemory)
        {
            if (string.IsNullOrEmpty(strFilePath) == true)
            {
                return(false);
            }
            if (File.Exists(strFilePath) == false)
            {
                return(false);
            }

            CloseIfOpened();

            m_fileStream = File.Open(strFilePath, FileMode.Open, FileAccess.Read);
            if (m_fileStream == null || m_fileStream.CanRead == false || m_fileStream.Length > cnMaxFileLength)
            {
                return(false);
            }

            Int64 n64FileLength = m_fileStream.Length;

            if (n64FileLength > cnMaxFileLength || n64FileLength < 0)
            {
                return(false);
            }

            if (bCacheInMemory == true)
            {
                m_tFileStatue = TBTFileStatus.enCached;
                if (n64FileLength > 0)
                {
                    m_CacheByteArray = new Byte[n64FileLength];
                    m_fileStream.Read(m_CacheByteArray, 0, (Int32)n64FileLength);
                }
                m_fileStream.Close();
                m_fileStream = null;
            }
            else
            {
                m_tFileStatue    = TBTFileStatus.enOpenHandle;
                m_CacheByteArray = null;
            }

            return(true);
        }
Beispiel #2
0
 /// <summary>
 /// 关闭
 /// </summary>
 /// <returns></returns>
 public bool CloseIfOpened()
 {
     if (m_tFileStatue == TBTFileStatus.enClosed)
     {
         return(true);
     }
     if (m_tFileStatue == TBTFileStatus.enOpenHandle && m_fileStream != null)
     {
         m_tFileStatue = TBTFileStatus.enClosed;
         m_fileStream.Close();
         return(true);
     }
     if (m_tFileStatue == TBTFileStatus.enCached)
     {
         m_tFileStatue    = TBTFileStatus.enClosed;
         m_CacheByteArray = null;
         return(true);
     }
     return(false);
 }
Beispiel #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CBTFileReader()
 {
     m_tFileStatue = TBTFileStatus.enCached;
 }