示例#1
0
                public void SetFileName(int index, string newName)
                {
                    HashedFile item = Data.items[index];

                    item.oldFileName = item.FileName;
                    item.FileName    = newName;
                }
示例#2
0
                public void AddActual(string name, byte[] storedActualHash, HashStyle hashStyle = HashStyle.Binary)
                {
                    var item = new HashedFile(name, storedActualHash, hashStyle, storedActualHash);

                    Data.items.Add(item);
                    item.IsMatch = storedActualHash == null? (bool?)null : true;
                }
示例#3
0
                public void SetOldFileName(int index, string newOldName)
                {
                    HashedFile item = Data.items[index];

                    if (item.oldFileName != newOldName)
                    {
                        item.oldFileName = newOldName;
                        item.NotifyPropertyChanged(null);
                    }
                }
示例#4
0
                public void SetStoredHash(int index, byte[] newHash)
                {
                    HashedFile item = Data.items[index];

                    if (!newHash.SequenceEqual(item.storedHash))
                    {
                        item.storedHash = new byte[newHash.Length];
                        Array.Copy(newHash, item.storedHash, newHash.Length);
                        SetIsMatch(index, newHash.SequenceEqual(item.actualHash));
                        item.NotifyPropertyChanged(null);
                    }
                }
示例#5
0
            public string GetPath(int index)
            {
                HashedFile item = items[index];

                if (item.IsRelative == true)
                {
                    return(BaseDir + item.FileName);
                }
                else
                {
                    return(item.FileName);
                }
            }
示例#6
0
                public void SetActualHash(int index, byte[] newHash)
                {
                    HashedFile item = Data.items[index];

                    item.actualHash = newHash;
                    if (newHash == null)
                    {
                        SetIsMatch(index, false);
                    }
                    else
                    {
                        SetIsMatch(index, item.StoredHash != null && item.actualHash.SequenceEqual(item.StoredHash));
                    }
                }
示例#7
0
                public void SetIsMatch(int index, bool newValue)
                {
                    HashedFile item = Data.items[index];

                    if (newValue != item.IsMatch)
                    {
                        if (item.IsMatch == true)
                        {
                            --Data.MatchCount;
                        }
                        if (newValue == true)
                        {
                            ++Data.MatchCount;
                        }
                        item.IsMatch = newValue;
                    }
                }
示例#8
0
                public void SetStoredHashToActual(int index)
                {
                    HashedFile item = Data.items[index];

                    if (item.actualHash == null)
                    {
                        if (item.storedHash != null)
                        {
                            item.IsMatch    = item.actualHash != null? false : (bool?)null;
                            item.storedHash = null;
                            item.NotifyPropertyChanged(null);
                        }
                    }
                    else if (!item.actualHash.SequenceEqual(item.storedHash))
                    {
                        item.storedHash = new byte[item.actualHash.Length];
                        Array.Copy(item.actualHash, item.storedHash, item.storedHash.Length);
                        SetIsMatch(index, true);
                        item.NotifyPropertyChanged(null);
                    }
                }
示例#9
0
                public void SetIsFound(int index, bool newValue)
                {
                    HashedFile item = Data.items[index];

                    if (newValue != item.IsFound)
                    {
                        if (item.IsFound == true)
                        {
                            --Data.FoundCount;
                        }
                        if (newValue == true)
                        {
                            ++Data.FoundCount;
                        }
                        else if (newValue == false)
                        {
                            item.actualHash = null;
                        }
                        item.IsFound = newValue;
                    }
                }
示例#10
0
            protected void ComputeContentHashes(CryptoHasher hasher, Hashes mediaHash = Hashes.None)
            {
                System.Diagnostics.Debug.Assert(Data.HashedFiles.HashLength == hasher.HashLength);

                for (int index = 0; index < Data.HashedFiles.Items.Count; ++index)
                {
                    HashedFile item       = Data.HashedFiles.Items[index];
                    string     msg        = null;
                    var        targetName = Data.HashedFiles.GetPath(index);

                    try
                    {
                        using (var tfs = new FileStream(targetName, FileMode.Open, FileAccess.Read))
                        {
                            HashedModel.SetIsFound(index, true);
                            byte[] hash = null;

                            if (item.Style == HashStyle.Media)
                            {
                                if (mediaHash == Hashes.None)
                                {
                                    IssueModel.Add("Unexpected media hash on item " + (index + 1) + ".");
                                }
                                else
                                {
                                    var hdr = new byte[0x3F];
                                    tfs.Position = 0;
                                    int             got = tfs.Read(hdr, 0, hdr.Length);
                                    Mp3Format.Model fmt = Mp3Format.CreateModel(tfs, hdr, targetName);
                                    if (fmt == null)
                                    {
                                        // Only MP3 supported for now.
                                        IssueModel.Add("Unexpected file format.");
                                    }
                                    else
                                    {
                                        fmt.CalcHashes(mediaHash, Validations.None);
                                        fmt.CloseFile();
                                        hash = fmt.Data.MediaSHA1;
                                    }
                                }
                            }
                            else
                            {
                                hasher.Append(tfs);
                                hash = hasher.GetHashAndReset();
                            }

                            HashedModel.SetActualHash(index, hash);
                            if (item.IsMatch == false)
                            {
                                IssueModel.Add(Data.HasherName + " mismatch on '" + item.FileName + "'.");
                            }
                        }
                    }
                    catch (FileNotFoundException ex)
                    { msg = ex.Message.TrimEnd(null); }
                    catch (IOException ex)
                    { msg = ex.Message.TrimEnd(null); }
                    catch (UnauthorizedAccessException ex)
                    { msg = ex.Message.TrimEnd(null); }

                    if (msg != null)
                    {
                        HashedModel.SetIsFound(index, false);
                        IssueModel.Add(msg);
                    }
                }

                string tx = Data.HasherName + " validation of " + Data.HashedFiles.Items.Count + " file";

                if (Data.HashedFiles.Items.Count != 1)
                {
                    tx += "s";
                }
                if (base.Data.Issues.MaxSeverity < Severity.Error)
                {
                    tx += " successful.";
                }
                else
                {
                    tx += " failed with " + Data.HashedFiles.FoundCount + " found and " + Data.HashedFiles.MatchCount + " matched.";
                }

                IssueModel.Add(tx, Severity.Advisory);
            }