Beispiel #1
0
        protected override bool read(BinaryReader source, MetaDataIO.ReadTagParams readTagParams)
        {
            bool      result = true;
            PSFHeader header = new PSFHeader();
            PSFTag    tag    = new PSFTag();

            header.Reset();
            tag.Reset();
            resetData();

            isValid = readHeader(source, ref header);
            if (!isValid)
            {
                throw new Exception("Not a PSF file");
            }

            if (source.BaseStream.Length > HEADER_LENGTH + header.CompressedProgramLength + header.ReservedAreaLength)
            {
                source.BaseStream.Seek((long)(4 + header.CompressedProgramLength + header.ReservedAreaLength), SeekOrigin.Current);

                if (!readTag(source, ref tag, readTagParams))
                {
                    throw new Exception("Not a PSF tag");
                }

                tagExists = true;
            }

            bitrate = (sizeInfo.FileSize - tag.size) * 8 / duration;

            return(result);
        }
Beispiel #2
0
        // === PUBLIC METHODS ===

        public bool ReadFromFile(String fileName)
        {
            bool      result = true;
            PSFHeader header = new PSFHeader();
            PSFTag    tag    = new PSFTag();

            FResetData();

            header.Reset();
            tag.Reset();

            FileStream   fs     = null;
            BinaryReader source = null;

            try
            {
                fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                fs.Lock(0, fs.Length);
                source = new BinaryReader(fs);

                if (!readHeader(ref source, ref header))
                {
                    throw new Exception("Not a PSF file");
                }

                if (fs.Length > HEADER_LENGTH + header.CompressedProgramLength + header.ReservedAreaLength)
                {
                    fs.Seek((long)(4 + header.CompressedProgramLength + header.ReservedAreaLength), SeekOrigin.Current);

                    if (!readTag(ref source, ref tag))
                    {
                        throw new Exception("Not a PSF tag");
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.StackTrace);
                //LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
                result = false;
            }

            if (fs != null)
            {
                fs.Unlock(0, fs.Length);
                fs.Close();
            }

            if (tag.tags.ContainsKey(TAG_GAME))
            {
                FAlbum = (String)tag.tags[TAG_GAME];
            }
            if (tag.tags.ContainsKey(TAG_ARTIST))
            {
                FArtist = (String)tag.tags[TAG_ARTIST];
            }
            if (tag.tags.ContainsKey(TAG_COMMENT))
            {
                FComment = (String)tag.tags[TAG_COMMENT];
            }
            if (tag.tags.ContainsKey(TAG_TITLE))
            {
                FTitle = (String)tag.tags[TAG_TITLE];
            }
            if (tag.tags.ContainsKey(TAG_YEAR))
            {
                FYear = (String)tag.tags[TAG_YEAR];
            }
            if (tag.tags.ContainsKey(TAG_LENGTH))
            {
                FDuration = parsePSFDuration((String)tag.tags[TAG_LENGTH]);
            }
            if (tag.tags.ContainsKey(TAG_FADE))
            {
                FDuration += parsePSFDuration((String)tag.tags[TAG_FADE]);
            }

            return(result);
        }
Beispiel #3
0
		// === PUBLIC METHODS ===

		public bool ReadFromFile(String fileName)
		{
			bool result = true;
			PSFHeader header = new PSFHeader();
			PSFTag tag = new PSFTag();

			FResetData();
			
			header.Reset();
			tag.Reset();

			FileStream fs = null;
			BinaryReader source = null;

			try
			{
				fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
				fs.Lock(0,fs.Length);
				source = new BinaryReader(fs);

				if ( !readHeader(ref source, ref header) ) throw new Exception("Not a PSF file");

				if (fs.Length > HEADER_LENGTH+header.CompressedProgramLength+header.ReservedAreaLength)
				{
					fs.Seek((long)(4+header.CompressedProgramLength+header.ReservedAreaLength),SeekOrigin.Current);
				
					if ( !readTag(ref source,ref tag) ) throw new Exception("Not a PSF tag");
				} 
			}
			catch (Exception e) 
			{
				System.Console.WriteLine(e.StackTrace);
				//LogDelegator.GetLogDelegate()(Log.LV_ERROR, e.Message);
				result = false;
			}

			if (fs != null)
			{
				fs.Unlock(0,fs.Length);
				fs.Close();
			}

			if (tag.tags.ContainsKey(TAG_GAME)) FAlbum = (String)tag.tags[TAG_GAME];
			if (tag.tags.ContainsKey(TAG_ARTIST)) FArtist = (String)tag.tags[TAG_ARTIST];
			if (tag.tags.ContainsKey(TAG_COMMENT)) FComment = (String)tag.tags[TAG_COMMENT];
			if (tag.tags.ContainsKey(TAG_TITLE)) FTitle = (String)tag.tags[TAG_TITLE];
			if (tag.tags.ContainsKey(TAG_YEAR)) FYear = (String)tag.tags[TAG_YEAR];
			if (tag.tags.ContainsKey(TAG_LENGTH)) 
			{
				FDuration = parsePSFDuration( (String)tag.tags[TAG_LENGTH] );				
			}
			if (tag.tags.ContainsKey(TAG_FADE)) 
			{
				FDuration += parsePSFDuration( (String)tag.tags[TAG_FADE] );				
			}

			return result;
		}