Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Wrap Panel Virtualization

, 2 Jan 2012 CPOL
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
MediaAssistant_bin.zip
MediaAssistant_src
DokanNet.dll
Id3Lib.dll
Media Assistant.exe
Media Assistant.exe.manifest
MediaAssistant.DAL.dll
MediaFS.dll
MefBasic.dll
Microsoft.Practices.Composite.dll
Microsoft.Practices.Composite.MefExtensions.dll
Microsoft.Practices.Composite.Presentation.dll
Microsoft.Practices.ServiceLocation.dll
Mp3Lib.dll
Newtonsoft.Json.Net35.dll
SharpZipLib.dll
Tags.dll
MediaAssistant_src.zip
DokanNet
Properties
Lib
CommonServiceLocation
Desktop
Microsoft.Practices.ServiceLocation.dll
CompositeApplicationLibrary
Desktop
Microsoft.Practices.Composite.dll
Microsoft.Practices.Composite.MefExtensions.dll
Microsoft.Practices.Composite.Presentation.dll
Dokan
dokan.lib
Moq
Desktop
Moq.dll
Mp3Lib
Id3Lib.dll
Mp3Lib.dll
SharpZipLib.dll
Newtonsoft
Newtonsoft.Json.Net35.dll
NUnit
nunit.framework.dll
MediaAssistant
MediaAssistant.csproj.user
MediaAssistant.ico
MusicAssistant_TemporaryKey.pfx
Constants
Controls
About
AddMovie
AlternativeLocation
BottomPanel
Dialog
LeftPanel
Library
MessageBox
MovieDetail
MovieList
MovieMiddlePanel
MovieResult
MovieSearchControl
MovieThumbnails
MusicList
MusicMiddlePanel
MusicSearchControl
PlayerControl
PlayingMusicInfo
PlaylistSelector
ProfileSelector
SendFeedback
SmartDJPreferance
SplashScreen
SplashPage.png
StatusMessageBar
TagEditor
TopPanel
WaitScreen
Converters
Data
EventArguments
HeaderImages
Close_act.png
Close_inact.png
Close_pr.png
Maximize_act.png
Maximize_inact.png
Maximize_pr.png
Minimize_act.png
Minimize_inact.png
Minimize_pr.png
Helper
Images
AcceptFolder.png
Actor.png
ActorLibrary.png
AddFolder.png
Album.png
Artist.png
Close.png
Composer.png
Default.png
DeleteFolder.png
Director.png
DrivesMovies.png
eye16.png
FailedToPlayMusic.png
Genre.png
IMDB.png
Library.png
ListView.png
Logo.png
Maximize.png
Menu.png
Mount.png
MovieBackground.jpg
MovieBackground.png
MovieFolder.png
MovieGenre.png
MovieLibrary.png
MoviePoster.png
Music.png
MusicAssistant.png
MusicLibrary.png
Mute.png
New.png
NewMovies.png
NoDJ.png
NonPlayingMusic.png
NormalShuffle.png
NoShuffle.png
NowPlayingMusic.png
PlayingMusic.png
playlist.png
PlayMovie.png
ProcessDone.png
ProcessFailed.png
Processing.png
Rated.png
Recent.png
RecommendedMovie.png
Restore.png
Runtime.png
SmartShuffle.png
Song.png
Star.png
Swap.png
ThumbnailView.png
Tools.png
TreeCollapse.png
TreeExpand.png
Unread.png
Volume.png
WatchList.png
WishList.png
Writer.png
Year.png
Management
MusicDJ
Properties
Settings.settings
Resources
MediaAssistant.DAL
MediaAssistant.sdf
MediaAssistantModels.edmx
Constants
DBUpdateScript
Helper
Properties
Settings.settings
DataSources
MusicAssistantEntities.datasource
TasteKidEntities.datasource
Virtualization
MediaAssistant.Setup
MusicAssistant.Setup.vdproj
MediaFS
DokanInstall_0.6.0.exe
Properties
MefBasic
Behaviors
Commans
Controls
Converters
Data
Extensions
Helper
Properties
Settings.settings
Themes
Threading
UserControls
Properties
TagClass
ASF Classes
Frames Classes
ID3
Properties
Text Files
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.ComponentModel;

namespace Tags.ID3
{
    /// <summary>
    /// Provide a class to read and write ID3v1
    /// </summary>
    public class ID3v1
    {
        private string _FilePath;
        private string _Title;
        private string _Artist;
        private string _Album;
        private string _Year;
        private string _Comment;
        private byte _TrackNumber;
        private byte _Genre;
        private bool _HaveTag;

        private bool _IsTemplate;
        /// <summary>
        /// Indicate if current ID3v1 is template
        /// </summary>
        [DefaultValue(false)]
        public bool IsTemplate
        {
            get { return _IsTemplate; }
            set { _IsTemplate = value; }
        }

        #region -> Public Properties <-

        /// <summary>
        /// Get file path of current ID3v1
        /// </summary>
        public string FilePath
        {
            get
            { return _FilePath; }
            internal set
            { _FilePath = value; }
        }

        /// <summary>
        /// Get file name of current ID3v1
        /// </summary>
        public string FileName
        {
            get
            { return Path.GetFileName(_FilePath); }
        }

        /// <summary>
        /// Get or set Title of current ID3v1
        /// </summary>
        public string Title
        {
            get
            { return _Title; }
            set
            {
                if (value.Length > 30)
                    throw (new ArgumentException("Title Length must be less than 30 characters"));

                _Title = value;
            }
        }

        /// <summary>
        /// Get or set Artist of current ID3v1
        /// </summary>
        public string Artist
        {
            get
            { return _Artist; }
            set
            {
                if (value.Length > 30)
                    throw (new ArgumentException("Artist Length must be less than 30 characters"));
                _Artist = value;
            }
        }

        /// <summary>
        /// Get or set Album of current ID3v1
        /// </summary>
        public string Album
        {
            get
            { return _Album; }
            set
            {
                if (value.Length > 30)
                    throw (new ArgumentException("Album Length must be less than 30 characters"));

                _Album = value;
            }
        }

        /// <summary>
        /// Get or set Year of current ID3v1
        /// </summary>
        public string Year
        {
            get
            { return _Year; }
            set
            {
                if (value.Length > 4)
                    throw (new ArgumentException("Year Length must be less than 4 characters"));
                _Year = value;
            }
        }

        /// <summary>
        /// Get or set Comment of current ID3v1
        /// </summary>
        public string Comment
        {
            get
            { return _Comment; }
            set
            {
                if (value.Length > 28)
                    throw (new ArgumentException("Comment Length must be less than 4 characters"));
                _Comment = value;
            }
        }

        /// <summary>
        /// Get or set TrackNumber of current ID3v1
        /// </summary>
        public byte TrackNumber
        {
            get
            { return _TrackNumber; }
            set
            { _TrackNumber = value; }
        }

        /// <summary>
        /// Get or set Genre of current ID3v1
        /// </summary>
        public byte Genre
        {
            get
            { return _Genre; }
            set
            { _Genre = value; }
        }

        /// <summary>
        /// Indicate if current File contain ID3v1 Information
        /// </summary>
        public bool HaveTag
        {
            get
            { return _HaveTag; }
            set
            { _HaveTag = value; }
        }

        #endregion

        /// <summary>
        /// Create new ID3v1 class
        /// </summary>
        /// <param name="FilePath">Path of file</param>
        /// <param name="LoadData">Indicate load data in constructor or not</param>
        public ID3v1(string FilePath, bool LoadData)
        {
            _FilePath = FilePath;
            _Title = "";
            _Artist = "";
            _Album = "";
            _Year = "";
            _Comment = "";
            _TrackNumber = 0;
            _Genre = 255;
            _HaveTag = false;

            if (LoadData)
                Load();
        }

        /// <summary>
        /// Load ID3v1 information from file
        /// </summary>
        public void Load()
        {
            TagStream FS = new TagStream(_FilePath, FileMode.Open);
            if (!FS.HaveID3v1()) // HaveID3v1 go to beginning of ID3v1 if exist
            {
                FS.Close();
                _HaveTag = false;
                return;
            }
            _Title = FS.ReadText(30, TextEncodings.Ascii);
            FS.Seek(-95, SeekOrigin.End);
            _Artist = FS.ReadText(30, TextEncodings.Ascii);
            FS.Seek(-65, SeekOrigin.End);
            _Album = FS.ReadText(30, TextEncodings.Ascii);
            FS.Seek(-35, SeekOrigin.End);
            _Year = FS.ReadText(4, TextEncodings.Ascii);
            FS.Seek(-31, SeekOrigin.End);
            _Comment = FS.ReadText(28, TextEncodings.Ascii);
            FS.Seek(-2, SeekOrigin.End);
            _TrackNumber = FS.ReadByte();
            _Genre = FS.ReadByte();
            FS.Close();
            _HaveTag = true;
        }

        /// <summary>
        /// Save ID3v1 information to file
        /// </summary>
        public void Save()
        {
            TagStream fs = new TagStream(_FilePath, FileMode.Open);
            bool HTag = fs.HaveID3v1();
            if (HTag && !_HaveTag) // just delete ID3
                (fs).SetLength(fs.Length - 128);
            else if (!HTag && _HaveTag)
            {
                fs.Seek(0, SeekOrigin.End);
                fs.Write(GetTagBytes, 0, 128);
            }
            else if (HTag && _HaveTag)
            {
                fs.Seek(-128, SeekOrigin.End);
                fs.Write(GetTagBytes, 0, 128);
            }
            fs.Close();
        }

        /// <summary>
        /// Clear all values
        /// </summary>
        public void ClearAll()
        {
            this.Album = "";
            this.Artist = "";
            this.Comment = "";
            this.Genre = 255;
            this.Title = "";
            this.TrackNumber = 0;
            this.Year = "";
        }

        /// <summary>
        /// Convert data tot Byte Array to write to file
        /// </summary>
        private byte[] GetTagBytes
        {
            get
            {
                byte[] Buf = new byte[128];
                Array.Clear(Buf, 0, 128);
                Encoding.Default.GetBytes("TAG").CopyTo(Buf, 0);
                Encoding.Default.GetBytes(_Title).CopyTo(Buf, 3);
                Encoding.Default.GetBytes(_Artist).CopyTo(Buf, 33);
                Encoding.Default.GetBytes(_Album).CopyTo(Buf, 63);
                Encoding.Default.GetBytes(_Year).CopyTo(Buf, 93);
                Encoding.Default.GetBytes(_Comment).CopyTo(Buf, 97);
                Buf[126] = _TrackNumber;
                Buf[127] = _Genre;
                return Buf;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

H. S. Masud
Software Developer (Senior) KAZ Software Limited
Bangladesh Bangladesh
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 2 Jan 2012
Article Copyright 2012 by H. S. Masud
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid