Пример #1
0
        public static void StoreUserOptions(UserOptions userOptions)
        {
            using (var ms = new MemoryStream())
            {
                var serializer = new XmlSerializer(typeof(UserOptions));
                serializer.Serialize(ms, userOptions);

                var xml = Convert.ToBase64String(ms.ToArray());
                Settings.Default.duplicateFinderOptions = xml;
                Settings.Default.Save();
            }
        }
Пример #2
0
        public static UserOptions GetUserOptions()
        {
            UserOptions userOptions;

            try
            {
                using (var ms = new MemoryStream(Convert.FromBase64String(Settings.Default.duplicateFinderOptions)))
                {
                    var serializer = new XmlSerializer(typeof(UserOptions));
                    userOptions = (UserOptions)serializer.Deserialize(ms);
                }
            }
            catch
            {
                userOptions = new UserOptions();
            }

            return(userOptions);
        }
Пример #3
0
        public void GetTagsChecksum(UserOptions options)
        {
            if (!HasAudioTags)
            {
                return;
            }

            string hashString;
            var    hashAlgorithm = GetHashAlgorithm(options.HashAlgorithm.Algorithm);

            using (var memStream = new MemoryStream())
            {
                if (options.MusicTagAlbum.GetValueOrDefault() && !string.IsNullOrEmpty(Album))
                {
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(Album));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                if (options.MusicTagArtist.GetValueOrDefault() && !string.IsNullOrEmpty(Artist))
                {
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(Artist));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                if (options.MusicTagBitRate.GetValueOrDefault() && Bitrate > 0)
                {
                    var bitRate    = Convert.ToString(Bitrate);
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(bitRate));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                if (options.MusicTagDuration.GetValueOrDefault() && Duration != TimeSpan.Zero)
                {
                    var duration   = Duration.ToString();
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(duration));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                if (options.MusicTagGenre.GetValueOrDefault() && !string.IsNullOrEmpty(Genre))
                {
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(Genre));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                if (options.MusicTagTitle.GetValueOrDefault() && !string.IsNullOrEmpty(Title))
                {
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(Title));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                if (options.MusicTagTrackNo.GetValueOrDefault() && TrackNo > 0)
                {
                    var trackNo    = Convert.ToString(TrackNo);
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(trackNo));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                if (options.MusicTagYear.GetValueOrDefault() && Year > 0)
                {
                    var year       = Convert.ToString(Year);
                    var bufferHash = CalculateHashBytes(hashAlgorithm, Encoding.UTF8.GetBytes(year));
                    memStream.Write(bufferHash, 0, bufferHash.Length);
                }

                memStream.Seek(0, SeekOrigin.Begin);

                if (memStream.Length == 0)
                {
                    HasAudioTags = false;
                    TagsChecksum = string.Empty;

                    return;
                }

                hashString = CalculateHashString(hashAlgorithm, memStream);
            }

            TagsChecksum = hashString;
        }