Esempio n. 1
0
        public RpmReader(string rpmFile)
        {
            _state = StateRead.RPMFILE_NOTFOUND;
            if (File.Exists(rpmFile))
            {
                _fileStream = new FileStream(rpmFile, FileMode.Open, FileAccess.Read);
                _state      = StateRead.RPMFILE_NOT_VALIDATE;

                _headerSection    = new RpmHeaderSection(_fileStream);
                _leadSection      = new RpmLeadSection(_fileStream);
                _signatureSection = new RpmSignatureSection(_fileStream);
                _archiveSection   = new RpmArchiveSection(_fileStream);
            }
            else
            {
                _state = StateRead.RPMFILE_NOTFOUND;
                throw new FileNotFoundException($"File {rpmFile} not found");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// validate a input file
        /// </summary>
        /// <returns></returns>
        public bool Validate()
        {
            if (_state == StateRead.RPMFILE_NOTFOUND || _state == StateRead.RPMFILE_VALIDATE_ERROR)
            {
                return(false);
            }

            if (_state == StateRead.RPMFILE_VALIDATE_SUCCESS)
            {
                return(true);
            }

            _fileStream.Position = 0;

            List <Func <bool> > readers = new List <Func <bool> >();

            readers.Add(ReadLead);
            readers.Add(ReadSignature);
            readers.Add(ReadHeader);
            readers.Add(ReadArchive);

            bool validate = true;

            unchecked
            {
                foreach (var reader in readers)
                {
                    if (!reader())
                    {
                        validate = false;
                        break;
                    }
                }
            }

            _state = validate ? StateRead.RPMFILE_VALIDATE_SUCCESS : StateRead.RPMFILE_VALIDATE_ERROR;
            return(validate);
        }
Esempio n. 3
0
        public RpmReader(string rpmFile)
        {
            _state = StateRead.RPMFILE_NOTFOUND;
            if (File.Exists(rpmFile))
            {
                _fileStream = new FileStream(rpmFile, FileMode.Open, FileAccess.Read);
                _state = StateRead.RPMFILE_NOT_VALIDATE;

                _headerSection = new RpmHeaderSection(_fileStream);
                _leadSection = new RpmLeadSection(_fileStream);
                _signatureSection = new RpmSignatureSection(_fileStream);
                _archiveSection = new RpmArchiveSection(_fileStream);
            }
            else
            {
                _state = StateRead.RPMFILE_NOTFOUND;
                throw new FileNotFoundException($"File {rpmFile} not found");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// validate a input file
        /// </summary>
        /// <returns></returns>
        public bool Validate()
        {
            if (_state == StateRead.RPMFILE_NOTFOUND || _state == StateRead.RPMFILE_VALIDATE_ERROR)
                return false;

            if (_state == StateRead.RPMFILE_VALIDATE_SUCCESS)
                return true;

            _fileStream.Position = 0;

            List<Func<bool>> readers = new List<Func<bool>>();
            readers.Add(ReadLead);
            readers.Add(ReadSignature);
            readers.Add(ReadHeader);
            readers.Add(ReadArchive);

            bool validate = true;
            unchecked
            {
                foreach (var reader in readers)
                {
                    if (!reader())
                    {
                        validate = false;
                        break;
                    }
                }
            }

            _state = validate ? StateRead.RPMFILE_VALIDATE_SUCCESS : StateRead.RPMFILE_VALIDATE_ERROR;
            return validate;
        }