Пример #1
0
        bool HashFiles()
        {
            foreach (var fileSystemItem in fileSystemItems)
            {
                OnProgressChanged?.Invoke(this, fileSystemItem.name);
                manualResetEvent.WaitOne();
                if (backgroundWorker.CancellationPending)
                {
                    return(false);
                }

                if (fileSystemItem.type == FileSystemItemType.Directory || FileSystemItemAccess.Default != fileSystemItem.access)
                {
                    hashWriter.WriteResultLine(new HashedFileSystemItem(fileSystemItem, hash: null));
                }
                else
                {
                    if (!HashAndAddToResult(fileSystemItem))
                    {
                        return(false);
                    }
                }
            }

            hashWriter.CloseFile();
            return(true);
        }
Пример #2
0
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            hashWriter = new HashWriter(this.OutputFile);
            try
            {
                hashWriter.OpenFileForWrite();
            }
            catch (Exception)
            {
                OnProgressChanged?.Invoke(this, "Error writing output file: " + OutputFile);
                return;
            }

            bool finished = HashFiles();

            if (backgroundWorker.CancellationPending)
            {
                hashWriter.CloseFile();
                e.Cancel = true;
                return;
            }
        }