/// <summary>
        /// Create a <see cref="VsDataGridHierarchialData"/>
        /// </summary>
        /// <param name="dataManager"><see cref="VsDataGridHierarchialData"/></param>
        /// <param name="fileName">file name</param>
        /// <param name="enabled">Hash calculation is enabled</param>
        public void CreateHierachialDataObject(VsDataGridHierarchialData dataManager, string fileName, params bool[] enabled)
        {
            var fileContainer = new WinMdChecksumData
            {
                FileName = fileName
            };

            var model = new VsDataGridHierarchialDataModel
            {
                DataManager = dataManager,
                Data        = fileContainer,
                IsVisible   = true
            };

            model.AddChild(CreateChildModel(HashNames.Md5, enabled.Length == 0 ? CurrentSettings.Md5IsEnabled : enabled[0]));
            model.AddChild(CreateChildModel(HashNames.Sha1, enabled.Length == 0 ? CurrentSettings.Sha1IsEnabled : enabled[1]));
            model.AddChild(CreateChildModel(HashNames.Sha256, enabled.Length == 0 ? CurrentSettings.Sha256IsEnabled : enabled[2]));
            model.AddChild(CreateChildModel(HashNames.Sha384, enabled.Length == 0 ? CurrentSettings.Sha384IsEnabled : enabled[3]));
            model.AddChild(CreateChildModel(HashNames.Sha512, enabled.Length == 0 ? CurrentSettings.Sha512IsEnabled : enabled[4]));

            dataManager.RowData.Add(model);
            dataManager.Initialize();

            dataManager.First().IsExpanded = true;
        }
        private VsDataGridHierarchialDataModel CreateChildModel(string childName, bool isEnabled)
        {
            var child = new WinMdChecksumData
            {
                FileName      = childName,
                HashIsEnabled = isEnabled
            };

            var childModel = new VsDataGridHierarchialDataModel
            {
                Data = child
            };

            return(childModel);
        }
Esempio n. 3
0
        private void CalculateHashGeneric <T>(WinMdChecksumData data, string fileName) where T : HashAlgorithm, new()
        {
            if (!data.HashIsEnabled)
            {
                data.Hash = string.Empty;
                return;
            }

            if (string.IsNullOrWhiteSpace(data.Hash))
            {
                data.Hash = HashOf <T>(fileName);
            }
            else if (data.Hash.Any(char.IsLower) && EnvironmentContainer.Instance.CurrentSettings.UpperCaseHash)
            {
                data.Hash = data.Hash.ToUpper();
            }
            else if (data.Hash.Any(char.IsUpper) && !EnvironmentContainer.Instance.CurrentSettings.UpperCaseHash)
            {
                data.Hash = data.Hash.ToLower();
            }

            data.Result = !string.IsNullOrWhiteSpace(data.HashToCompare) ? CompareHash(data.Hash, data.HashToCompare) : string.Empty;
        }