/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="HeaderExtensionObject" /> by reading the contents
		///    from a specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langref="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The object read from disk does not have the correct GUID
		///    or contents.
		/// </exception>
		public HeaderExtensionObject (Asf.File file, long position)
			: base (file, position)
		{
			if (!Guid.Equals (Asf.Guid.AsfHeaderExtensionObject))
				throw new CorruptFileException (
					"Object GUID incorrect.");
			
			if (file.ReadGuid () != Asf.Guid.AsfReserved1)
				throw new CorruptFileException (
					"Reserved1 GUID expected.");
			
			if (file.ReadWord () != 6)
				throw new CorruptFileException (
					"Invalid reserved WORD. Expected '6'.");
			
			uint size_remaining = file.ReadDWord ();
			position += 0x170 / 8;
			
			while (size_remaining > 0) {
				Object obj = file.ReadObject (position);
				position += (long) obj.OriginalSize;
				size_remaining -= (uint) obj.OriginalSize;
				children.Add (obj);
			}
		}
Example #2
0
 public SnowFlake(Vector2 positionInWorld, Vector2 direction, float velocity, Asf texture)
     : base(positionInWorld, velocity, texture)
 {
     _direction = direction;
     if (_direction != Vector2.Zero)
     {
         _direction.Normalize();
     }
 }
Example #3
0
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="PaddingObject" /> by reading the contents from a
		///    specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The object read from disk does not have the correct GUID
		///    or smaller than the minimum size.
		/// </exception>
		public PaddingObject (Asf.File file, long position)
			: base (file, position)
		{
			if (!Guid.Equals (Asf.Guid.AsfPaddingObject))
				throw new CorruptFileException (
					"Object GUID incorrect.");
			
			if (OriginalSize < 24)
				throw new CorruptFileException (
					"Object size too small.");
			
			size = OriginalSize;
		}
Example #4
0
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="Object" /> by reading the contents from a
		///    specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		protected Object (Asf.File file, long position)
		{
			if (file == null)
				throw new ArgumentNullException ("file");
			
			if (position < 0 ||
				position > file.Length - 24)
				throw new ArgumentOutOfRangeException (
					"position");
			
			file.Seek (position);
			id = file.ReadGuid ();
			size = file.ReadQWord ();
		}
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="ExtendedContentDescriptionObject" /> by reading the contents
		///    from a specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langref="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The object read from disk does not have the correct GUID
		///    or smaller than the minimum size.
		/// </exception>
		public ExtendedContentDescriptionObject (Asf.File file,
		                                         long position)
			: base (file, position)
		{
			if (!Guid.Equals (
				Asf.Guid.AsfExtendedContentDescriptionObject))
				throw new CorruptFileException (
					"Object GUID incorrect.");
			
			if (OriginalSize < 26)
				throw new CorruptFileException (
					"Object size too small.");
			
			ushort count = file.ReadWord ();
			
			for (ushort i = 0; i < count; i ++)
				AddDescriptor (new ContentDescriptor (file));
		}
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="MetadataLibraryObject" /> by reading the contents
		///    from a specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langref="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The object read from disk does not have the correct GUID
		///    or smaller than the minimum size.
		/// </exception>
		public MetadataLibraryObject (Asf.File file, long position)
			: base (file, position)
		{
			if (!Guid.Equals (Asf.Guid.AsfMetadataLibraryObject))
				throw new CorruptFileException (
					"Object GUID incorrect.");
			
			if (OriginalSize < 26)
				throw new CorruptFileException (
					"Object size too small.");
			
			ushort count = file.ReadWord ();
			
			for (ushort i = 0; i < count; i ++) {
				DescriptionRecord rec = new DescriptionRecord (
					file);
				AddRecord (rec);
			}
		}
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="HeaderObject" /> by reading the contents from a
        ///    specified position in a specified file.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="Asf.File" /> object containing the file from
        ///    which the contents of the new instance are to be read.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value specify at what position to
        ///    read the object.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    <paramref name="position" /> is less than zero or greater
        ///    than the size of the file.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    The object read from disk does not have the correct GUID
        ///    or smaller than the minimum size.
        /// </exception>
        public HeaderObject(Asf.File file, long position)
            : base(file, position)
        {
            if (!Guid.Equals (Asf.Guid.AsfHeaderObject))
                throw new CorruptFileException (
                    "Object GUID incorrect.");

            if (OriginalSize < 26)
                throw new CorruptFileException (
                    "Object size too small.");

            children = new List<Object> ();

            uint child_count = file.ReadDWord ();

            reserved = file.ReadBlock (2);

            children.AddRange (file.ReadObjects (child_count,
                file.Tell));
        }
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="FilePropertiesObject" /> by reading the contents
		///    from a specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langref="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The object read from disk does not have the correct GUID
		///    or smaller than the minimum size.
		/// </exception>
		public FilePropertiesObject (Asf.File file, long position)
			: base (file, position)
		{
			if (!Guid.Equals (Asf.Guid.AsfFilePropertiesObject))
				throw new CorruptFileException (
					"Object GUID incorrect.");
			
			if (OriginalSize < 104)
				throw new CorruptFileException (
					"Object size too small.");
			
			file_id = file.ReadGuid ();
			file_size = file.ReadQWord ();
			creation_date = file.ReadQWord ();
			data_packets_count = file.ReadQWord ();
			send_duration = file.ReadQWord ();
			play_duration = file.ReadQWord ();
			preroll = file.ReadQWord ();
			flags = file.ReadDWord ();
			minimum_data_packet_size = file.ReadDWord ();
			maximum_data_packet_size = file.ReadDWord ();
			maximum_bitrate = file.ReadDWord ();
		}
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="UnknownObject" /> by reading the contents from a
		///    specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langref="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		public UnknownObject (Asf.File file, long position)
			: base (file, position)
		{
			data = file.ReadBlock ((int) (OriginalSize - 24));
		}
		/// <summary>
		///    Populates the current instance by reading in the contents
		///    from a file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object to read the raw ASF
		///    Description Record from.
		/// </param>
		/// <returns>
		///    <see langword="true" /> if the data was read correctly.
		///    Otherwise <see langword="false" />.
		/// </returns>
		protected bool Parse (Asf.File file)
		{
			// Field name          Field type Size (bits)
			// Language List Index WORD       16
			// Stream Number       WORD       16
			// Name Length         WORD       16
			// Data Type           WORD       16
			// Data Length         DWORD      32
			// Name                WCHAR      varies
			// Data                See below  varies
			
			lang_list_index = file.ReadWord ();
			stream_number = file.ReadWord ();
			ushort name_length = file.ReadWord ();
			type = (DataType) file.ReadWord ();
			int data_length = (int) file.ReadDWord ();
			name = file.ReadUnicode (name_length);
			
			switch (type)
			{
			case DataType.Word:
				longValue = file.ReadWord ();
				break;
			case DataType.Bool:
			case DataType.DWord:
				longValue = file.ReadDWord ();
				break;
			case DataType.QWord:
				longValue = file.ReadQWord ();
				break;
			case DataType.Unicode:
				strValue = file.ReadUnicode (data_length);
				break;
			case DataType.Bytes:
				byteValue = file.ReadBlock (data_length);
				break;
			case DataType.Guid:
				guidValue = file.ReadGuid ();
				break;
			default:
				return false;
			}
			
			return true;
		}
Example #11
0
 public Texture(Asf asf)
 {
     _texture = asf;
 }
		/// <summary>
		///    Populates the current instance by reading in the contents
		///    from a file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object to read the raw ASF
		///    Content Descriptor from.
		/// </param>
		/// <returns>
		///    <see langword="true" /> if the data was read correctly.
		///    Otherwise <see langword="false" />.
		/// </returns>
		protected bool Parse (Asf.File file)
		{
			int name_count = file.ReadWord ();
			name = file.ReadUnicode (name_count);
			
			type = (DataType) file.ReadWord ();
			
			int value_count = file.ReadWord ();
			switch (type)
			{
			case DataType.Word:
				longValue = file.ReadWord ();
				break;
				
			case DataType.Bool:
				longValue = file.ReadDWord ();
				break;
				
			case DataType.DWord:
				longValue = file.ReadDWord ();
				break;
				
			case DataType.QWord:
				longValue = file.ReadQWord ();
				break;
				
			case DataType.Unicode:
				strValue = file.ReadUnicode (value_count);
				break;
				
			case DataType.Bytes:
				byteValue = file.ReadBlock (value_count);
				break;
				
			default:
				return false;
			}
			
			return true;
		}
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="ContentDescriptor" /> by reading its contents from
		///    a file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object to read the raw ASF
		///    Description Record from.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    A valid descriptor could not be read.
		/// </exception>
		/// <remarks>
		///    <paramref name="file" /> must be at a seek position at
		///    which the descriptor can be read.
		/// </remarks>
		protected internal ContentDescriptor (Asf.File file)
		{
			if (file == null)
				throw new ArgumentNullException ("file");
			
			if (!Parse (file))
				throw new CorruptFileException (
					"Failed to parse content descriptor.");
		}
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="PaddingObject" /> by reading the contents from a
		///    specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langref="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The object read from disk does not have the correct GUID
		///    or smaller than the minimum size.
		/// </exception>
		public StreamPropertiesObject (Asf.File file, long position)
			: base (file, position)
		{
			if (!Guid.Equals (Asf.Guid.AsfStreamPropertiesObject))
				throw new CorruptFileException (
					"Object GUID incorrect.");
			
			if (OriginalSize < 78)
				throw new CorruptFileException (
					"Object size too small.");
			
			stream_type = file.ReadGuid ();
			error_correction_type = file.ReadGuid ();
			time_offset = file.ReadQWord ();
			
			int type_specific_data_length = (int) file.ReadDWord ();
			int error_correction_data_length = (int)
				file.ReadDWord ();
			
			flags = file.ReadWord ();
			reserved = file.ReadDWord ();
			type_specific_data =
				file.ReadBlock (type_specific_data_length);
			error_correction_data =
				file.ReadBlock (error_correction_data_length);
		}
Example #15
0
        private void TagTestWithSave(ref Asf.File file,
		                              MemoryFileAbstraction abst,
		                              TagTestFunc testFunc)
        {
            testFunc (file.Tag, "Before Save");
            file.Save ();
            file = new Asf.File (abst);
            testFunc (file.Tag, "After Save");
        }
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="DescriptionRecord" /> by reading its contents from
		///    a file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object to read the raw ASF
		///    Description Record from.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    A valid record could not be read.
		/// </exception>
		/// <remarks>
		///    <paramref name="file" /> must be at a seek position at
		///    which the record can be read.
		/// </remarks>
		protected internal DescriptionRecord (Asf.File file)
		{
			if (file == null)
				throw new ArgumentNullException ("file");
			
			if (!Parse (file))
				throw new CorruptFileException (
					"Failed to parse description record.");
		}
Example #17
0
 public Texture(Asf asf, int frameBegin, int count)
 {
     _texture    = asf;
     _frameBegin = frameBegin;
     _frameEnd   = frameBegin + count;
 }
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="ContentDescriptionObject" /> by reading the
		///    contents from a specified position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="Asf.File" /> object containing the file from
		///    which the contents of the new instance are to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the object.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langref="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The object read from disk does not have the correct GUID
		///    or smaller than the minimum size.
		/// </exception>
		public ContentDescriptionObject (Asf.File file, long position)
			: base (file, position)
		{
			if (Guid != Asf.Guid.AsfContentDescriptionObject)
				throw new CorruptFileException (
					"Object GUID incorrect.");
			
			if (OriginalSize < 34)
				throw new CorruptFileException (
					"Object size too small.");
			
			ushort title_length = file.ReadWord ();
			ushort author_length = file.ReadWord ();
			ushort copyright_length = file.ReadWord ();
			ushort description_length = file.ReadWord ();
			ushort rating_length = file.ReadWord ();
			
			title = file.ReadUnicode (title_length);
			author = file.ReadUnicode (author_length);
			copyright = file.ReadUnicode (copyright_length);
			description = file.ReadUnicode (description_length);
			rating = file.ReadUnicode (rating_length);
		}
Example #19
0
        /// <summary>
        /// This method reads file info from files, things like ID3v2 in mp3 files and FLAC fileinfo.
        /// </summary>
        public void ReadFileData()
        {
            var extension = Path.GetExtension(this.FullPath)?.ToLowerInvariant();

            if (extension == ".mp3")
            {
                var mp3Reader = new Mp3(this.FullPath);
                if (string.IsNullOrWhiteSpace(mp3Reader.Artist) || string.IsNullOrWhiteSpace(mp3Reader.Title))
                {
                    SetDefaultSongSmartName();
                    return;
                }

                SmartName = mp3Reader.Artist + " - " + mp3Reader.Album + " - " + mp3Reader.Track + " " + mp3Reader.Title;
                ArtistTitleToName(mp3Reader.Artist, mp3Reader.Title, mp3Reader.Track);
            }
            else if (extension == ".flac" || extension == ".ogg")
            {
                var mp3Reader  = new Mp3(this.FullPath);
                var flacReader = new FlacOgg(this.FullPath);
                if (!string.IsNullOrWhiteSpace(mp3Reader.Title))
                {
                    SmartName = mp3Reader.Artist + " - " + mp3Reader.Album + " - " + mp3Reader.Track + " " + mp3Reader.Title;
                    ArtistTitleToName(mp3Reader.Artist, mp3Reader.Title, mp3Reader.Track);
                }
                else if (!string.IsNullOrWhiteSpace(flacReader.Title))
                {
                    SmartName = flacReader.Artist + " - " + flacReader.Album + " - " + flacReader.Track + " " + flacReader.Title;
                    ArtistTitleToName(flacReader.Artist, flacReader.Title, flacReader.Track);
                }
                else
                {
                    SetDefaultSongSmartName();
                }
            }
            else if (extension == ".wma")
            {
                var asfReader = new Asf(this.FullPath);
                if (string.IsNullOrWhiteSpace(asfReader.Artist) || string.IsNullOrWhiteSpace(asfReader.Title))
                {
                    SetDefaultSongSmartName();
                    return;
                }
                SmartName = asfReader.Artist + " - " + asfReader.Album + " - " + asfReader.Track + " " + asfReader.Title;
                ArtistTitleToName(asfReader.Artist, asfReader.Title, asfReader.Track);
            }

            else if (extension == ".wmv")
            {
                var asfReader = new Asf(this.FullPath);
                if (string.IsNullOrWhiteSpace(asfReader.Artist) || string.IsNullOrWhiteSpace(asfReader.Title))
                {
                    return;
                }
                ArtistTitleToName(asfReader.Artist, asfReader.Title, asfReader.Track);
            }

            else if (extension == ".m4a")
            {
                var m4AReader = new M4A(this.FullPath);
                if (string.IsNullOrWhiteSpace(m4AReader.Artist) || string.IsNullOrWhiteSpace(m4AReader.Title))
                {
                    return;
                }

                SmartName = m4AReader.Artist + " - " + m4AReader.Album + " - " + m4AReader.Track + " " + m4AReader.Title;
                ArtistTitleToName(m4AReader.Artist, m4AReader.Title, m4AReader.Track);
            }
        }