Exemple #1
0
        //void LoadFileSystems()
        //{
        //    string safeFullName = @"\\?\" + FullName;
        //    List<string> results = new List<string>();
        //    WIN32_FIND_DATA findData;
        //    IntPtr findHandle = LongPath.Directory.FindFirstFile(safeFullName + @"\*", out findData);

        //    string newFullName="";
        //    string currentFileName = "";

        //    if (findHandle != INVALID_HANDLE_VALUE)
        //    {
        //        bool found;

        //        do
        //        {
        //            currentFileName = findData.cFileName;
        //            newFullName = Path.Combine(FullName, currentFileName);

        //            // if this is a directory, find its contents
        //            if (((int)findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
        //            {
        //                if (currentFileName != "." && currentFileName != "..")
        //                {
        //                    Directories.Add(newFullName);
        //                }
        //            }
        //            else // This is a file
        //            {
        //                Files.Add(new FileDataInfo
        //                {
        //                    FullName = newFullName,
        //                    DestinyDirectoryPath = DestinyPath,
        //                    Name = Path.GetFileName(newFullName),
        //                    DestinyPath = Path.Combine(DestinyPath, Path.GetFileName(newFullName)),
        //                    Size = findData.Length,
        //                    //FileAttributes = findData.dwFileAttributes,
        //                    //CreationTime=findData.ftCreationTime,
        //                    //LastAccessTime=findData.ftLastAccessTime,
        //                    //LastWriteTime=findData.ftLastWriteTime
        //                });
        //            }

        //            // find next
        //            found = LongPath.Directory.FindNextFile(findHandle, out findData);
        //        }
        //        while (found);
        //    }

        //    // close the find handle
        //    LongPath.File.FindClose(findHandle);

        //    FileSystemsLoaded = true;
        //}

        public List <FileDataInfo> GetFiles()
        {
            //if (!FileSystemsLoaded)
            //    LoadFileSystems();

            var dinfo = new Delimon.Win32.IO.DirectoryInfo(FullName);

            //var newFullName = Delimon.Win32.IO.Path.Combine(FullName, f.Name);
            Files = dinfo.GetFiles().Select(f => new FileDataInfo()
            {
                FullName             = Delimon.Win32.IO.Path.Combine(FullName, f.Name),
                DestinyDirectoryPath = DestinyPath,
                Name           = Path.GetFileName(f.Name),
                DestinyPath    = Path.Combine(DestinyPath, Path.GetFileName(Delimon.Win32.IO.Path.Combine(FullName, f.Name))),
                Size           = f.Length,
                FileAttributes = f.Attributes,
                CreationTime   = f.CreationTime,
                LastAccessTime = f.LastAccessTime,
                LastWriteTime  = f.LastWriteTime
            }).ToList();

            Files.Sort(Compare);

            return(Files);
        }
        /// <summary>
        /// Determines whether the specified folder contains files with
        /// file extensions that do not match the content.
        /// </summary>
        /// <param name="folderPath">The folder path.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <returns>
        ///     <c>true</c> if [contains folder prohibited content]
        /// [the specified folder path]; otherwise, <c>false</c>.
        /// </returns>
        public void ContainsFolderVerifyContent(
            Delimon.Win32.IO.DirectoryInfo folderPath,
            bool recursive,
            ref List <FileResult> verifiedFiles,
            ref List <FileResult> unVerifiedFiles,
            ref List <FileResult> unknownFiles,
            ref List <FileResult> ProhibitedFiles,
            ref bool blShuttingDown,
            string excludeFolders,
            System.Data.DataTable dtSignatures,
            bool blValidateZipFiles,
            bool blHeaderVerificationIgnoreFileExtensions,
            bool blProhibitedFilesIgnoreFileExtensions
            )
        {
            WriteError(
                string.Format(
                    @"Audit Folder ContentDetectorEngine: Checking folder '{0}'.",
                    folderPath.FullName), System.Diagnostics.EventLogEntryType.Information, 6000, 60, true);

            HeaderSignature[] sigs = null;
            try
            {
                if (dtSignatures == null)
                {
                    sigs = HeaderSignature.StockSignatures;
                }
                else if (dtSignatures.Rows.Count == 0)
                {
                    sigs = HeaderSignature.StockSignatures;
                }
                else
                {
                    sigs = HeaderSignature.CustomSignatures(dtSignatures);
                }
            }
            catch (Exception)
            {
                sigs = null;
            }

            if (sigs != null)
            {
                containsFolderVerifyContent(folderPath, recursive, ref verifiedFiles, ref unVerifiedFiles, ref unknownFiles, ref ProhibitedFiles, ref blShuttingDown, excludeFolders, sigs, blValidateZipFiles, blHeaderVerificationIgnoreFileExtensions, blProhibitedFilesIgnoreFileExtensions);
            }
            else
            {
                WriteError(
                    string.Format(
                        @"Audit Folder ContentDetectorEngine: Error Checking folder '{0}' Error loading signatures.",
                        folderPath.FullName), System.Diagnostics.EventLogEntryType.Error, 6000, 60, false);
            }
        }
Exemple #3
0
        protected void CreateEmptysDirectories(FilesList list)
        {
            Delimon.Win32.IO.DirectoryInfo di = null;

            //Creating empty directories
            foreach (var d in list.EmptyDirectories)
            {
                Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(d.DestinyPath);
                di            = new Delimon.Win32.IO.DirectoryInfo(d.DestinyPath);
                di.Attributes = d.FileAttributes;
            }
        }
Exemple #4
0
        private void select_Dir(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();

            folderDialog.ShowNewFolderButton = false;
            DialogResult result = folderDialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                System.Windows.Application.Current.Dispatcher.Invoke(() => Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait);
                sPath               = folderDialog.SelectedPath;
                textBox.Text        = sPath;
                total               = 0;
                textBlock2.Text     = "";
                progressBar.Minimum = 0;
                progressBar.Value   = 0;
                folder              = new Delimon.Win32.IO.DirectoryInfo(sPath);

                if (folder.Exists)
                {
                    validDir = true;

                    Stopwatch stopWatch = new Stopwatch();
                    stopWatch.Start();

                    DirSearch(sPath);

                    stopWatch.Stop();
                    TimeSpan ts          = stopWatch.Elapsed;
                    string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                    Console.WriteLine($"DirSearch RunTime {elapsedTime}");
                    //System.Windows.Forms.MessageBox.Show(elapsedTime, "DirSearch RunTime", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    System.Windows.Application.Current.Dispatcher.Invoke(() => Mouse.OverrideCursor = null);

                    if (total != 0 && validDir)
                    {
                        progressBar.Maximum = total;
                        button1.IsEnabled   = true;
                        textBlock1.Text     = "Total de arquivos: " + String.Format("{0:n0}", total);
                    }
                    else
                    {
                        progressBar.Value = 0;
                        button1.IsEnabled = false;
                        textBox.Text      = "";
                        textBlock1.Text   = "";
                        System.Windows.Forms.MessageBox.Show("Favor selecionar um diretório válido.", "Diretório inválido", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemple #5
0
 private void FileResultContructor(Delimon.Win32.IO.DirectoryInfo ddir, string strComment, string strFileFilterSearched)
 {
     Name                = ddir.Name;
     FullPath            = ddir.FullName;
     Extension           = "";
     CreationTime        = ddir.CreationTime;
     LastWriteTime       = ddir.LastWriteTime;
     Owner               = Common.GetFileOwner(FullPath);
     Length              = 0;
     ParentDirectoryPath = ddir.Parent.FullName;
     ObjectType          = Common.FileFilterObjectType.Folder;
     Comment             = strComment;
     FileFilterSearched  = strFileFilterSearched;
     Deleted             = false;
 }
 public void ContainsFolderVerifyContent(
     Delimon.Win32.IO.DirectoryInfo folderPath,
     bool recursive,
     ref List <FileResult> verifiedFiles,
     ref List <FileResult> unVerifiedFiles,
     ref List <FileResult> unknownFiles,
     ref List <FileResult> ProhibitedFiles,
     ref bool blShuttingDown,
     string excludeFolders,
     bool blValidateZipFiles,
     bool blHeaderVerificationIgnoreFileExtensions,
     bool blProhibitedFilesIgnoreFileExtensions
     )
 {
     System.Data.DataTable dtSignatures = null;
     ContainsFolderVerifyContent(folderPath, recursive, ref verifiedFiles, ref unVerifiedFiles, ref unknownFiles, ref ProhibitedFiles, ref blShuttingDown, excludeFolders, dtSignatures, blValidateZipFiles, blHeaderVerificationIgnoreFileExtensions, blProhibitedFilesIgnoreFileExtensions);
 }
Exemple #7
0
        /// <summary>
        /// detect dir change for two way synchronisation.
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        private static TwoWayCompareResult DetectDirChange_TwoWay(MyDirInfo dir)
        {
            Delimon.Win32.IO.DirectoryInfo dirInfo1 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath1);
            Delimon.Win32.IO.DirectoryInfo dirInfo2 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath2);
            Delimon.Win32.IO.DirectoryInfo parent1  = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath1);
            Delimon.Win32.IO.DirectoryInfo parent2  = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath2);
            bool remove = dir.SyncDirInfo.SyncInfo.Link.Remove;

            if (!dirInfo1.Exists)
            {
                // if parent dir 1 is older than parent dir 2 -> create dir in parent dir 1
                if (parent2.LastWriteTime >= parent1.LastWriteTime)
                {
                    return(new TwoWayCompareResult(SyncDirection.To1, false));
                }

                // otherwise remove dir 2 if remove ist enabled
                if (remove)
                {
                    return(new TwoWayCompareResult(SyncDirection.To2, true));
                }

                return(null);
            }

            if (!dirInfo2.Exists)
            {
                // if parent dir 2 is older than parent dir 1 -> create dir in parent dir 2
                if (parent1.LastWriteTime >= parent2.LastWriteTime)
                {
                    return(new TwoWayCompareResult(SyncDirection.To2, false));
                }

                // otherwise remove dir 1 if remove ist enabled
                if (remove)
                {
                    return(new TwoWayCompareResult(SyncDirection.To1, true));
                }

                return(null);
            }

            return(null);
        }
Exemple #8
0
        /// <summary>
        /// delete folder
        /// </summary>
        /// <param name="sdei">sync execution information about directory</param>
        /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param>
        /// <returns>true if the operation was canceled</returns>
        public static bool DeleteFolder(SyncDirExecutionInfo sdei, Func <bool> interruptChecker)
        {
            if (interruptChecker())
            {
                return(true);
            }

            string ddp = sdei.AbsoluteDestPath;

            Delimon.Win32.IO.DirectoryInfo ddi = new Delimon.Win32.IO.DirectoryInfo(ddp);

            if (!ddi.Exists)
            {
                return(false);
            }

            //do not remove if directory is not empty
            if (ddi.GetFiles().Length > 0 || ddi.GetDirectories().Length > 0)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.DirNotEmpty,
                                                                sdei.Direction == SyncDirection.To1 ? 1 : 2, "RunFolderDeletionTask",
                                                                $"The directory to be deleted was not empty. Path: {sdei.SyncDirInfo.DirInfo.FullPath}", null));
                return(false);
            }

            interruptChecker();

            sdei.StartedNow();
            try
            {
                ddi.Delete();
                sdei.SyncDirInfo.SyncStatus = SyncElementStatus.ChangeApplied;
            }
            catch (Exception e)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.Unknown,
                                                                sdei.Direction == SyncDirection.To2 ? 2 : 1, "RunFolderDeletionTask", e.Message, e));
            }
            sdei.EndedNow();

            return(false);
        }
Exemple #9
0
        public static string ResolveSingleFilePath(this string sourcePath)
        {
            var results = string.Empty;

            if (!string.IsNullOrEmpty(sourcePath))
            {
                if (sourcePath.Length < GlobalDefinitions.MAX_PATH)
                {
                    if (System.IO.File.Exists(sourcePath))
                    {
                        var path = System.IO.Path.GetDirectoryName(sourcePath);
                        if (sourcePath.StartsWith(@".\"))
                        {
                            path       = string.Empty;
                            sourcePath = sourcePath.Replace(@".\", string.Empty);
                        }
                        path = string.IsNullOrEmpty(path) ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, sourcePath)
                                                          : sourcePath;
                        results = path;
                    }
                }

                if (string.IsNullOrEmpty(results))
                {
                    if (sourcePath.StartsWith(@".\"))
                    {
                        sourcePath = sourcePath.Replace(@".\", AppDomain.CurrentDomain.BaseDirectory);
                    }
                    var longformat = string.Format(@"\\?\{0}", sourcePath);
                    var fileInfo   = new Delimon.Win32.IO.FileInfo(longformat);
                    var dirInfo    = new Delimon.Win32.IO.DirectoryInfo(sourcePath);
                    if (Delimon.Win32.IO.File.Exists(longformat) &&
                        fileInfo.Length > 0)
                    {
                        results = longformat;
                    }
                }
            }

            return(results);
        }
Exemple #10
0
        /// <summary>
        /// delete folder
        /// </summary>
        /// <param name="sdei">sync execution information about directory</param>
        /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param>
        /// <returns>true if the operation was canceled</returns>
        public static bool DeleteFolder(SyncDirExecutionInfo sdei, Func<bool> interruptChecker)
        {
            if (interruptChecker()) return true;

            string ddp = sdei.AbsoluteDestPath;
            Delimon.Win32.IO.DirectoryInfo ddi = new Delimon.Win32.IO.DirectoryInfo(ddp);

            if (!ddi.Exists)
                return false;

            //do not remove if directory is not empty
            if (ddi.GetFiles().Length > 0 || ddi.GetDirectories().Length > 0)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.DirNotEmpty,
                    sdei.Direction == SyncDirection.To1 ? 1 : 2, "RunFolderDeletionTask",
                    $"The directory to be deleted was not empty. Path: {sdei.SyncDirInfo.DirInfo.FullPath}", null));
                return false;
            }

            interruptChecker();

            sdei.StartedNow();
            try
            {
                ddi.Delete();
                sdei.SyncDirInfo.SyncStatus = SyncElementStatus.ChangeApplied;
            }
            catch (Exception e)
            {
                sdei.SyncDirInfo.Conflicted(new DirConflictInfo(sdei.SyncDirInfo, ConflictType.Unknown,
                    sdei.Direction == SyncDirection.To2 ? 2 : 1, "RunFolderDeletionTask", e.Message, e));
            }
            sdei.EndedNow();

            return false;
        }
Exemple #11
0
 public FileResult(Delimon.Win32.IO.DirectoryInfo ddir, string strComment)
 {
     FileResultContructor(ddir, strComment, "");
 }
Exemple #12
0
 public FileResult(Delimon.Win32.IO.DirectoryInfo ddir)
 {
     FileResultContructor(ddir, "", "");
 }
Exemple #13
0
 public FileResult(Delimon.Win32.IO.DirectoryInfo ddir, string strComment, string strFileFilterSearched)
 {
     FileResultContructor(ddir, strComment, strFileFilterSearched);
 }
        /// <summary>
        /// Determines whether the specified folder contains files with
        /// file extensions that do not match the content.
        /// </summary>
        /// <param name="folderPath">The folder path.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <returns>
        ///     <c>true</c> if [contains folder prohibited content]
        /// [the specified folder path]; otherwise, <c>false</c>.
        /// </returns>
        private void containsFolderVerifyContent(
            Delimon.Win32.IO.DirectoryInfo folderPath,
            bool recursive,
            ref List <FileResult> verifiedFiles,
            ref List <FileResult> unVerifiedFiles,
            ref List <FileResult> unknownFiles,
            ref List <FileResult> ProhibitedFiles,
            ref bool blShuttingDown,
            string excludeFolders,
            HeaderSignature[] sigs,
            bool blValidateZipFiles,
            bool blHeaderVerificationIgnoreFileExtensions,
            bool blProhibitedFilesIgnoreFileExtensions
            )
        {
            WriteError(
                string.Format(
                    @"Audit Folder ContentDetectorEngine: Checking folder '{0}'.",
                    folderPath.FullName), System.Diagnostics.EventLogEntryType.Information, 6000, 60, true);



            if (sigs == null)
            {
                sigs = HeaderSignature.StockSignatures;
            }



            Delimon.Win32.IO.FileInfo[] filePaths = folderPath.GetFiles();

            int index = 0;

            //Load either default signatures or custom for determining ExtensionSupported?



            foreach (Delimon.Win32.IO.FileInfo filePath in filePaths)
            {
                if (blShuttingDown)
                {
                    WriteError(
                        string.Format(
                            @"Audit Folder ContentDetectorEngine: Shutting Down: was about to check file '{0}'.",
                            filePath.FullName), System.Diagnostics.EventLogEntryType.Information, 6000, 60, true);
                    break;
                }
                try
                {
                    WriteError(
                        string.Format(
                            @"Audit Folder ContentDetectorEngine: [{0}/{1}] Checking file '{2}' ({3:0,0} bytes).",
                            index + 1, filePaths.Length,
                            filePath.FullName,
                            filePath.Length), System.Diagnostics.EventLogEntryType.Information, 6000, 60, true);

                    bool blVerifiedContent = false;

                    blVerifiedContent = DoVerifyFileHeader(filePath, sigs, blHeaderVerificationIgnoreFileExtensions);

                    //Verify File Headers
                    if (!HeaderSignature.ExtensionSupported(filePath.Extension, sigs))
                    {
                        unknownFiles.Add(new FileResult(filePath));
                    }
                    else if (!blVerifiedContent)
                    {
                        if (blValidateZipFiles && HeaderSignature.ZipRelatedExtension(filePath.Extension))
                        {
                            using (Stream filestream1 = filePath.Open(Delimon.Win32.IO.FileMode.Open, Delimon.Win32.IO.FileAccess.Read, Delimon.Win32.IO.FileShare.ReadWrite))
                            {
                                try
                                {
                                    if (ZipFile.IsZipFile(filestream1, true) == false)
                                    {
                                        unVerifiedFiles.Add(new FileResult(filePath, "Error: Zip File is Corrupted or Encrypted!"));
                                    }
                                    try
                                    {
                                        filestream1.Close();
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                                catch (Exception ex)
                                {
                                    WriteError(
                                        string.Format(
                                            @"Audit Folder ContentDetectorEngine: [{0}/{1}] Error Zip Checking file '{2}' ({3:0,0} bytes). " + ex.Message,
                                            index + 1, filePaths.Length,
                                            filePath.FullName,
                                            filePath.Length), System.Diagnostics.EventLogEntryType.Error, 6000, 60, false);
                                    unknownFiles.Add(new FileResult(filePath, "Error checking the file"));
                                }
                            }
                        }
                        else
                        {
                            unVerifiedFiles.Add(new FileResult(filePath, "Extension and file header for the file does not match any expected file signature."));
                        }
                    }
                    else
                    {
                        if (blValidateZipFiles && blVerifiedContent && HeaderSignature.IsZipRelatedFile(filePath))
                        {
                            if (ZipFile.IsZipFile(filePath.OpenRead(), true) == false)
                            {
                                unVerifiedFiles.Add(new FileResult(filePath, "Error: Zip File is Corrupted or Encrypted!"));
                            }
                            else
                            {
                                verifiedFiles.Add(new FileResult(filePath, "Zip File Verified"));
                            }
                        }
                        else
                        {
                            verifiedFiles.Add(new FileResult(filePath));
                        }
                    }

                    //check for prohibited files
                    if (ContainsProhibitedFileContent(filePath, sigs, blProhibitedFilesIgnoreFileExtensions))
                    {
                        ProhibitedFiles.Add(new FileResult(filePath));
                    }
                }
                catch (Exception)
                {
                    WriteError(
                        string.Format(
                            @"Audit Folder ContentDetectorEngine: [{0}/{1}] Error Checking file '{2}' ({3:0,0} bytes).",
                            index + 1, filePaths.Length,
                            filePath.FullName,
                            filePath.Length), System.Diagnostics.EventLogEntryType.Error, 6000, 60, false);
                    unknownFiles.Add(new FileResult(filePath, "Error checking the file"));
                }


                index++;
            }



            // --

            if (recursive)
            {
                Delimon.Win32.IO.DirectoryInfo[] folderPaths = folderPath.GetDirectories();

                foreach (Delimon.Win32.IO.DirectoryInfo childFolderPath in folderPaths)
                {
                    bool blIgnoreDirectory = false;
                    if (blShuttingDown)
                    {
                        WriteError(
                            string.Format(
                                @"Audit Folder ContentDetectorEngine: Shutting Down: was about to check folder '{0}'.",
                                childFolderPath.FullName), System.Diagnostics.EventLogEntryType.Information, 6000, 60, true);
                        break;
                    }

                    try
                    {
                        char[]   delimiters             = new char[] { ';' };
                        string[] strArr_excludedfolders = excludeFolders.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                        if (!(strArr_excludedfolders == null || strArr_excludedfolders.Length == 0))
                        {
                            //loop through excluded folders
                            foreach (string strExclude in strArr_excludedfolders)
                            {
                                if (childFolderPath.Name.ToLower() == strExclude.ToLower())
                                {
                                    blIgnoreDirectory = true;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }

                    if (!blIgnoreDirectory)
                    {
                        containsFolderVerifyContent(childFolderPath, recursive, ref verifiedFiles, ref unVerifiedFiles, ref unknownFiles, ref ProhibitedFiles, ref blShuttingDown, excludeFolders, sigs, blValidateZipFiles, blHeaderVerificationIgnoreFileExtensions, blProhibitedFilesIgnoreFileExtensions);
                    }
                }
            }
        }
Exemple #15
0
 public DirectoryInfo(string path)
 {
     if (isLinux) {
       sys_fi = new System.IO.DirectoryInfo (path);
     } else {
       delim_fi = new Delimon.Win32.IO.DirectoryInfo (path);
     }
 }
Exemple #16
0
        /// <summary>
        /// Check if 2 Files are updated for two way synchronisation.
        /// The order of the files does not matter.
        /// </summary>
        /// <param name="fi1">file 1</param>
        /// <param name="fi2">file 2</param>
        /// <param name="remove">if remove is enabled</param>
        /// <param name="parentDir1">parent directory of file 1</param>
        /// <param name="parentDir2">parent directory of file 2</param>
        /// <returns>compare result</returns>
        public static TwoWayCompareResult CompareFiles_TwoWay(SyncFileInfo file)
        {
            Delimon.Win32.IO.FileInfo fi1 = new Delimon.Win32.IO.FileInfo(file.AbsolutePath1);
            Delimon.Win32.IO.FileInfo fi2 = new Delimon.Win32.IO.FileInfo(file.AbsolutePath2);
            Delimon.Win32.IO.DirectoryInfo parent1 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath1);
            Delimon.Win32.IO.DirectoryInfo parent2 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath2);
            bool remove = file.SyncInfo.Link.Remove;

            if (!fi1.Exists)
            {
                // if the parent directory of file 1 is older than file 2 -> create file in parent directory 1
                // otherwise remove file 2 if remove ist enabled

                if(file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null)
                {
                    if (parent1.LastWriteTime <= parent2.LastWriteTime)
                        return new TwoWayCompareResult(SyncDirection.To1, false);
                    else if (remove)
                        return new TwoWayCompareResult(SyncDirection.To2, true);
                }
                else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To1)
                    return new TwoWayCompareResult(SyncDirection.To1, false);
                else if (remove)
                    return new TwoWayCompareResult(SyncDirection.To2, true);

                return null;
            }

            if (!fi2.Exists)
            {
                // if the parent directory of file 2 is older than file 1 -> create file in parent directory 2
                // otherwise remove file 1 if remove ist enabled

                if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null)
                {
                    if (parent2.LastWriteTime <= parent1.LastWriteTime)
                        return new TwoWayCompareResult(SyncDirection.To2, false);
                    else if (remove)
                        return new TwoWayCompareResult(SyncDirection.To1, true);
                }
                else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To2)
                    return new TwoWayCompareResult(SyncDirection.To2, false);
                else if (remove)
                    return new TwoWayCompareResult(SyncDirection.To1, true);

                return null;
            }

            // update file 1 if file 2 is newer
            if (fi1.LastWriteTime < fi2.LastWriteTime)
                return new TwoWayCompareResult(SyncDirection.To1, false);

            // update file 2 if file 1 is newer
            if (fi1.LastWriteTime > fi2.LastWriteTime)
                return new TwoWayCompareResult(SyncDirection.To2, false);

            return null;
        }
 public DirectoryInfoBase FromDirectoryName(string directoryName)
 {
     var realDirectoryInfo = new Delimon.Win32.IO.DirectoryInfo(directoryName);
     return new DelimonDirectoryInfoWrapper(realDirectoryInfo);
 }
Exemple #18
0
        /// <summary>
        /// Check if 2 Files are updated for two way synchronisation.
        /// The order of the files does not matter.
        /// </summary>
        /// <param name="fi1">file 1</param>
        /// <param name="fi2">file 2</param>
        /// <param name="remove">if remove is enabled</param>
        /// <param name="parentDir1">parent directory of file 1</param>
        /// <param name="parentDir2">parent directory of file 2</param>
        /// <returns>compare result</returns>
        public static TwoWayCompareResult CompareFiles_TwoWay(SyncFileInfo file)
        {
            Delimon.Win32.IO.FileInfo      fi1     = new Delimon.Win32.IO.FileInfo(file.AbsolutePath1);
            Delimon.Win32.IO.FileInfo      fi2     = new Delimon.Win32.IO.FileInfo(file.AbsolutePath2);
            Delimon.Win32.IO.DirectoryInfo parent1 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath1);
            Delimon.Win32.IO.DirectoryInfo parent2 = new Delimon.Win32.IO.DirectoryInfo(file.FileInfo.Parent.SyncDirInfo.AbsolutePath2);
            bool remove = file.SyncInfo.Link.Remove;

            if (!fi1.Exists)
            {
                // if the parent directory of file 1 is older than file 2 -> create file in parent directory 1
                // otherwise remove file 2 if remove ist enabled

                if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null)
                {
                    if (parent1.LastWriteTime <= parent2.LastWriteTime)
                    {
                        return(new TwoWayCompareResult(SyncDirection.To1, false));
                    }
                    else if (remove)
                    {
                        return(new TwoWayCompareResult(SyncDirection.To2, true));
                    }
                }
                else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To1)
                {
                    return(new TwoWayCompareResult(SyncDirection.To1, false));
                }
                else if (remove)
                {
                    return(new TwoWayCompareResult(SyncDirection.To2, true));
                }

                return(null);
            }

            if (!fi2.Exists)
            {
                // if the parent directory of file 2 is older than file 1 -> create file in parent directory 2
                // otherwise remove file 1 if remove ist enabled

                if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo == null)
                {
                    if (parent2.LastWriteTime <= parent1.LastWriteTime)
                    {
                        return(new TwoWayCompareResult(SyncDirection.To2, false));
                    }
                    else if (remove)
                    {
                        return(new TwoWayCompareResult(SyncDirection.To1, true));
                    }
                }
                else if (file.FileInfo.Parent.SyncDirInfo.SyncDirExecutionInfo.Direction == SyncDirection.To2)
                {
                    return(new TwoWayCompareResult(SyncDirection.To2, false));
                }
                else if (remove)
                {
                    return(new TwoWayCompareResult(SyncDirection.To1, true));
                }

                return(null);
            }

            // update file 1 if file 2 is newer
            if (fi1.LastWriteTime < fi2.LastWriteTime)
            {
                return(new TwoWayCompareResult(SyncDirection.To1, false));
            }

            // update file 2 if file 1 is newer
            if (fi1.LastWriteTime > fi2.LastWriteTime)
            {
                return(new TwoWayCompareResult(SyncDirection.To2, false));
            }

            return(null);
        }
Exemple #19
0
        /// <summary>
        /// fetch files and subdirectories for Two-Way synchronisation recursively
        /// </summary>
        /// <param name="dir">the directory, in which you want to search</param>
        /// <param name="si">sync info</param>
        /// <param name="onFileFound">is called when a file was found</param>
        /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param>
        public static void FetchElementsInDirRecursively_TwoWay(MyDirInfo dir, SyncInfo si, 
            Action<SyncFileInfo> onFileFound, Func<bool> interruptChecker)
        {
            interruptChecker();

            string path1 = si.Link.Path1 + dir.FullPath;
            string path2 = si.Link.Path2 + dir.FullPath;

            //directory info
            Delimon.Win32.IO.DirectoryInfo di1 = new Delimon.Win32.IO.DirectoryInfo(path1);
            Delimon.Win32.IO.DirectoryInfo di2 = new Delimon.Win32.IO.DirectoryInfo(path2);

            List<string> dirNames = new List<string>();
            List<string> fileNames = new List<string>();

            try
            {
                #region detect changes of directories
                if (di1.Exists)
                {
                    //loop through path1 dir
                    foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path1))
                    {
                        string newDirname = Delimon.Win32.IO.Path.GetFileName(name);
                        dirNames.Add(newDirname);

                        MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname);
                        new SyncDirInfo(si, newDir, true);
                        FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker);
                    }
                }

                if(di2.Exists)
                {
                    //loop through path2 dir except the dirs, which have already been detected in path1
                    foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path2))
                    {
                        string newDirname = Delimon.Win32.IO.Path.GetFileName(name);
                        if (!dirNames.Contains(newDirname))
                        {
                            MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname);
                            new SyncDirInfo(si, newDir, true);
                            FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker);
                        }
                    }
                }
                #endregion

                #region detect files
                if (di1.Exists)
                {
                    //Loop through all files in path1
                    foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path1))
                    {
                        string name = Delimon.Win32.IO.Path.GetFileName(filepath);
                        MyFileInfo file = new MyFileInfo(dir.FullPath, name);
                        new SyncFileInfo(si, file, true);

                        fileNames.Add(name);

                        onFileFound(file.SyncFileInfo);
                    }
                }

                if (di2.Exists)
                {
                    //Loop through all files in path2 except the files, which have already been detected in path1
                    foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path2))
                    {
                        string name = Delimon.Win32.IO.Path.GetFileName(filepath);
                        if (fileNames.Contains(name)) continue;

                        MyFileInfo file = new MyFileInfo(dir.FullPath, name);
                        new SyncFileInfo(si, file, true);

                        onFileFound(file.SyncFileInfo);
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                si.Log(new LogMessage(LogType.ERROR, e.Message, e));
            }
        }
Exemple #20
0
        /// <summary>
        /// fetch files and subdirectories for Two-Way synchronisation recursively
        /// </summary>
        /// <param name="dir">the directory, in which you want to search</param>
        /// <param name="si">sync info</param>
        /// <param name="onFileFound">is called when a file was found</param>
        /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param>
        public static void FetchElementsInDirRecursively_TwoWay(MyDirInfo dir, SyncInfo si,
                                                                Action <SyncFileInfo> onFileFound, Func <bool> interruptChecker)
        {
            interruptChecker();

            string path1 = si.Link.Path1 + dir.FullPath;
            string path2 = si.Link.Path2 + dir.FullPath;

            //directory info
            Delimon.Win32.IO.DirectoryInfo di1 = new Delimon.Win32.IO.DirectoryInfo(path1);
            Delimon.Win32.IO.DirectoryInfo di2 = new Delimon.Win32.IO.DirectoryInfo(path2);

            List <string> dirNames  = new List <string>();
            List <string> fileNames = new List <string>();

            try
            {
                #region detect changes of directories
                if (di1.Exists)
                {
                    //loop through path1 dir
                    foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path1))
                    {
                        string newDirname = Delimon.Win32.IO.Path.GetFileName(name);
                        dirNames.Add(newDirname);

                        MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname);
                        new SyncDirInfo(si, newDir, true);
                        FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker);
                    }
                }

                if (di2.Exists)
                {
                    //loop through path2 dir except the dirs, which have already been detected in path1
                    foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path2))
                    {
                        string newDirname = Delimon.Win32.IO.Path.GetFileName(name);
                        if (!dirNames.Contains(newDirname))
                        {
                            MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname);
                            new SyncDirInfo(si, newDir, true);
                            FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker);
                        }
                    }
                }
                #endregion

                #region detect files
                if (di1.Exists)
                {
                    //Loop through all files in path1
                    foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path1))
                    {
                        string     name = Delimon.Win32.IO.Path.GetFileName(filepath);
                        MyFileInfo file = new MyFileInfo(dir.FullPath, name);
                        new SyncFileInfo(si, file, true);

                        fileNames.Add(name);

                        onFileFound(file.SyncFileInfo);
                    }
                }

                if (di2.Exists)
                {
                    //Loop through all files in path2 except the files, which have already been detected in path1
                    foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path2))
                    {
                        string name = Delimon.Win32.IO.Path.GetFileName(filepath);
                        if (fileNames.Contains(name))
                        {
                            continue;
                        }

                        MyFileInfo file = new MyFileInfo(dir.FullPath, name);
                        new SyncFileInfo(si, file, true);

                        onFileFound(file.SyncFileInfo);
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                si.Log(new LogMessage(LogType.ERROR, e.Message, e));
            }
        }
Exemple #21
0
        /// <summary>
        /// detect dir change for two way synchronisation.
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        private static TwoWayCompareResult DetectDirChange_TwoWay(MyDirInfo dir)
        {
            Delimon.Win32.IO.DirectoryInfo dirInfo1 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath1);
            Delimon.Win32.IO.DirectoryInfo dirInfo2 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath2);
            Delimon.Win32.IO.DirectoryInfo parent1 = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath1);
            Delimon.Win32.IO.DirectoryInfo parent2 = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath2);
            bool remove = dir.SyncDirInfo.SyncInfo.Link.Remove;

            if (!dirInfo1.Exists)
            {
                // if parent dir 1 is older than parent dir 2 -> create dir in parent dir 1
                if (parent2.LastWriteTime >= parent1.LastWriteTime)
                    return new TwoWayCompareResult(SyncDirection.To1, false);

                // otherwise remove dir 2 if remove ist enabled
                if (remove)
                    return new TwoWayCompareResult(SyncDirection.To2, true);

                return null;
            }

            if (!dirInfo2.Exists)
            {
                // if parent dir 2 is older than parent dir 1 -> create dir in parent dir 2
                if (parent1.LastWriteTime >= parent2.LastWriteTime)
                    return new TwoWayCompareResult(SyncDirection.To2, false);

                // otherwise remove dir 1 if remove ist enabled
                if (remove)
                    return new TwoWayCompareResult(SyncDirection.To1, true);

                return null;
            }

            return null;
        }
Exemple #22
0
        //private String DecodeStream(string s) {
        //	Encoding defEnc = Encoding.Default;
        //	Encoding isoEnc = Encoding.GetEncoding(850);
        //	byte[] defBytes = defEnc.GetBytes(s);
        //	byte[] isoBytes = Encoding.Convert(defEnc, isoEnc, defBytes);
        //	name = isoEnc.GetString(isoBytes);

        //	return name;
        //}

        private void CreateList(string sDir)
        {
            try {
                folder = new Delimon.Win32.IO.DirectoryInfo(sDir);

                foreach (Delimon.Win32.IO.FileInfo f in folder.GetFiles())
                {
                    lista.Add($"{f.Length}\t{f.DirectoryName}\t{f.Name}\t{f.Extension.ToLower()}");
                    //await FileWriteAsync($"{Environment.NewLine}{f.Length}\t{f.DirectoryName}\t{f.Name}\t{f.Extension.ToLower()}");
                    //using (System.IO.StreamWriter w = Delimon.Win32.IO.File.AppendText($"{baseDir}lista_arquivos.txt")) {
                    //    w.Write($"{Environment.NewLine}{f.Length}\t{f.DirectoryName}\t{f.Name}\t{f.Extension.ToLower()}");
                    //    w.Close();
                    //    w.Dispose();
                    //}
                    //sb.Append($"{Environment.NewLine}{f.Length}\t{f.DirectoryName}\t{f.Name}\t{f.Extension.ToLower()}");
                    if (lista.Count >= 100000)
                    {
                        System.IO.File.AppendAllLines($"{baseDir}lista_arquivos.txt", lista);
                        //List<List<String>> l = new List<List<String>>();
                        //l.Add(lista.ToList());
                        lista.Clear();
                        lista.TrimExcess();
                    }

                    progressBar.Dispatcher.Invoke(() => progressBar.Value++, DispatcherPriority.Background);

                    if (f.Extension.Equals(".pdf", StringComparison.OrdinalIgnoreCase))
                    {
                        using (var stream = Delimon.Win32.IO.File.OpenRead(f.FullName)) {
                            using (var ms = new System.IO.MemoryStream()) {
                                stream.CopyTo(ms);
                                ms.Position = 0;
                                CountPdfPages(ms);
                            }
                        }
                    }

                    if (f.Extension.Equals(".doc", StringComparison.OrdinalIgnoreCase) || f.Extension.Equals(".docx", StringComparison.OrdinalIgnoreCase))
                    {
                        using (var stream = Delimon.Win32.IO.File.OpenRead(f.FullName)) {
                            using (var ms = new System.IO.MemoryStream()) {
                                stream.CopyTo(ms);
                                ms.Position = 0;
                                CountWordPages(ms);
                            }
                        }
                    }

                    if (f.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
                    {
                        //using (var fs = new System.IO.StreamReader(Delimon.Win32.IO.File.OpenRead(f.FullName), Encoding.GetEncoding(850))) {
                        //using(ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Read, Encoding.GetEncoding(850))) {

                        //ICSharpCode.SharpZipLib.Zip.ZipFile zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(fs);
                        //System.IO.Stream zipStream = zipFile.GetInputStream(fs);
                        fs = Delimon.Win32.IO.File.OpenRead(f.FullName);

                        using (var archive = new ZipArchive(fs, ZipArchiveMode.Read, false, Encoding.GetEncoding(850))) {
                            foreach (ZipArchiveEntry entry in archive.Entries)
                            {
                                if (entry.Name != "")
                                {
                                    if (entry.Name.Contains("."))
                                    {
                                        ext = entry.Name.Substring(entry.Name.LastIndexOf(".")).ToLower();
                                    }
                                    else
                                    {
                                        ext = "null";
                                    }
                                    rep = new StringBuilder(@"\");

                                    if (entry.FullName.Contains("/"))
                                    {
                                        rep.Append(entry.FullName.Substring(0, entry.FullName.LastIndexOf("/")));
                                        rep.Replace("/", @"\");
                                    }
                                    else
                                    {
                                        rep.Clear();
                                    }

                                    lista.Add($"{entry.Length}\t{f.FullName}{rep}\t{entry.Name}\t{ext}");
                                    //await FileWriteAsync($"{Environment.NewLine}{entry.Length}\t{f.FullName}{rep}\t{entry.Name}\t{ext}");
                                    //using (System.IO.StreamWriter w = Delimon.Win32.IO.File.AppendText($"{baseDir}lista_arquivos.txt")) {
                                    //    w.Write($"{Environment.NewLine}{entry.Length}\t{f.FullName}{rep}\t{entry.Name}\t{ext}");
                                    //    w.Close();
                                    //    w.Dispose();
                                    //}
                                    //sb.Append($"{Environment.NewLine}{entry.Length}\t{f.FullName}{rep}\t{entry.Name}\t{ext}");

                                    if (lista.Count >= 100000)
                                    {
                                        System.IO.File.AppendAllLines($"{baseDir}lista_arquivos.txt", lista);
                                        lista.Clear();
                                        lista.TrimExcess();
                                    }

                                    if (ext.Equals(".pdf", StringComparison.OrdinalIgnoreCase))
                                    {
                                        using (var stream = entry.Open()) {
                                            using (var ms = new System.IO.MemoryStream()) {
                                                stream.CopyTo(ms);
                                                ms.Position = 0;
                                                CountPdfPages(ms);
                                            }
                                        }
                                    }

                                    if (ext.Equals(".doc", StringComparison.OrdinalIgnoreCase) || ext.Equals(".docx", StringComparison.OrdinalIgnoreCase))
                                    {
                                        using (var stream = entry.Open()) {
                                            using (var ms = new System.IO.MemoryStream()) {
                                                stream.CopyTo(ms);
                                                ms.Position = 0;
                                                CountWordPages(ms);
                                            }
                                        }
                                    }

                                    if (ext.Equals(".zip", StringComparison.OrdinalIgnoreCase))
                                    {
                                        fn = f.FullName;
                                        ZipList(fn, entry);
                                    }
                                }
                            }
                        }
                        //}
                        //}
                    }
                }

                foreach (string d in Delimon.Win32.IO.Directory.GetDirectories(sDir))
                {
                    CreateList(d);
                }
            } catch {
                //System.Windows.Forms.MessageBox.Show($"{exc.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #23
0
        /// <summary>
        /// Find Files and Directories in the immediate folder - handles long path names, expects local or UNC path
        /// </summary>
        /// <param name="dirName">Directory to search in UNC path or local path format</param>
        /// <param name="dtFilters">Data table with "Enabled" and "FileFilter" columns required</param>
        /// <param name="checkSubFolders">Recursively check all sub folders</param>
        /// <returns></returns>
        public static List <ContentDetectorLib.FileResult> FindImmediateFilesAndDirs(string dirName, DataTable dtFilters, bool checkSubFolders)
        {
            string strDirConverted = LongPathPrepend(dirName);
            List <ContentDetectorLib.FileResult> results = new List <ContentDetectorLib.FileResult>();
            IntPtr          findHandle   = INVALID_HANDLE_VALUE;
            bool            blIgnoreFile = false;
            WIN32_FIND_DATA findData;

            if (dtFilters != null)
            {
                //For Each File filter find them in the current folder
                foreach (DataRow row in dtFilters.Rows)
                {
                    try
                    {
                        FindFileFilter filter = new FindFileFilter(row);


                        if (filter.Enabled && filter.FileFilter != "")
                        {
                            //Valid File Filter?
                            if (VerifyPattern(filter.FileFilter) && Delimon.Win32.IO.Directory.Exists(dirName))
                            {
                                try
                                {
                                    //Search for the file filter in the current directory
                                    if (filter.ObjectType == ContentDetectorLib.Common.FileFilterObjectType.Folder)
                                    {
                                        findHandle = FindFirstFileEx(strDirConverted + @"\" + filter.FileFilter, FINDEX_INFO_LEVELS.FindExInfoBasic, out findData, FINDEX_SEARCH_OPS.FindExSearchLimitToDirectories, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);
                                    }
                                    else
                                    {
                                        findHandle = FindFirstFileEx(strDirConverted + @"\" + filter.FileFilter, FINDEX_INFO_LEVELS.FindExInfoBasic, out findData, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);
                                    }

                                    if (findHandle != INVALID_HANDLE_VALUE)
                                    {
                                        bool found;
                                        do
                                        {
                                            string currentFileName = findData.cFileName;
                                            blIgnoreFile = false;
                                            char[] delimiters = new char[] { ';' };
                                            if (filter.ExcludeFiles != "")
                                            {
                                                string[] strArr_excludedfiles = filter.ExcludeFiles.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                                                if (!(strArr_excludedfiles == null || strArr_excludedfiles.Length == 0))
                                                {
                                                    //loop through excluded folders
                                                    foreach (string strExclude in strArr_excludedfiles)
                                                    {
                                                        if (currentFileName.ToLower() == strExclude.ToLower())
                                                        {
                                                            blIgnoreFile = true;
                                                        }
                                                    }
                                                }
                                            }
                                            if (!blIgnoreFile)
                                            {
                                                // if this is a directory, add directory found to the results.
                                                if (((int)findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
                                                {
                                                    if (filter.ObjectType == ContentDetectorLib.Common.FileFilterObjectType.Folder || filter.ObjectType == ContentDetectorLib.Common.FileFilterObjectType.Both)
                                                    {
                                                        if (currentFileName != "." && currentFileName != "..")
                                                        {
                                                            string strFilePath = RemovePrependGetPath(Path.Combine(dirName, currentFileName));
                                                            try
                                                            {
                                                                Delimon.Win32.IO.DirectoryInfo ddir = new Delimon.Win32.IO.DirectoryInfo(strFilePath);
                                                                ContentDetectorLib.FileResult  fr1  = new ContentDetectorLib.FileResult(ddir);
                                                                fr1.FileFilterSearched = filter.FileFilter;
                                                                results.Add(fr1);
                                                                //results.Add("\"" + strFilePath + "\"" + ",FolderCreated: " + ddir.CreationTime.ToString("G") + ",Owner: " + strOwner);
                                                            }
                                                            catch (Exception)
                                                            {
                                                                ContentDetectorLib.FileResult fr1 = new ContentDetectorLib.FileResult();
                                                                fr1.FileFilterSearched = filter.FileFilter;
                                                                fr1.ObjectType         = ContentDetectorLib.Common.FileFilterObjectType.Folder;
                                                                fr1.FullPath           = strFilePath;
                                                                results.Add(fr1);
                                                            }
                                                        }
                                                    }
                                                }
                                                // it’s a file; add it to the results
                                                else
                                                {
                                                    if (filter.ObjectType == ContentDetectorLib.Common.FileFilterObjectType.File || filter.ObjectType == ContentDetectorLib.Common.FileFilterObjectType.Both)
                                                    {
                                                        string strFilePath = RemovePrependGetPath(Path.Combine(dirName, currentFileName));
                                                        Delimon.Win32.IO.FileInfo dfile;

                                                        try
                                                        {
                                                            dfile = new Delimon.Win32.IO.FileInfo(strFilePath);

                                                            if (filter.DeleteFilesFound)
                                                            {
                                                                ContentDetectorLib.FileResult fr1 = new ContentDetectorLib.FileResult(dfile);
                                                                fr1.FileFilterSearched = filter.FileFilter;
                                                                fr1.Deleted            = true;
                                                                results.Add(fr1);
                                                                //Delete the ransomware related file
                                                                //results.Add("File Deleted: " + "\"" + strFilePath + "\"" + ",FileCreated: " + dfile.CreationTime.ToString("G") + ",Owner: " + strOwner);
                                                                dfile.Delete();
                                                            }
                                                            else
                                                            {
                                                                ContentDetectorLib.FileResult fr1 = new ContentDetectorLib.FileResult(dfile);
                                                                fr1.FileFilterSearched = filter.FileFilter;
                                                                results.Add(fr1);
                                                                //Document the file found
                                                                //results.Add("\"" + strFilePath + "\"" + ",FileCreated: " + dfile.CreationTime.ToString("G") + ",Owner: " + strOwner);
                                                            }
                                                        }
                                                        catch (Exception)
                                                        {
                                                            ContentDetectorLib.FileResult fr1 = new ContentDetectorLib.FileResult();
                                                            fr1.FileFilterSearched = filter.FileFilter;
                                                            fr1.FullPath           = strFilePath;
                                                            fr1.ObjectType         = ContentDetectorLib.Common.FileFilterObjectType.None;
                                                            fr1.Comment            = "\"" + strFilePath + "\"";
                                                            results.Add(fr1);
                                                            //results.Add("\"" + strFilePath + "\"");
                                                        }
                                                    }
                                                }
                                            }

                                            // find next if any
                                            found = FindNextFile(findHandle, out findData);
                                        }while (found);
                                    }
                                }
                                finally
                                {
                                    // close the find handle
                                    FindClose(findHandle);
                                }
                            }
                            else
                            {
                                //invalid search filter
                                if (results.Count == 0)
                                {
                                    ContentDetectorLib.FileResult fr1 = new ContentDetectorLib.FileResult();
                                    fr1.FileFilterSearched = filter.FileFilter;
                                    fr1.ObjectType         = ContentDetectorLib.Common.FileFilterObjectType.None;
                                    fr1.Comment            = "Invalid Search Filter or Directory Problem: " + filter.FileFilter + " " + dirName;
                                    results.Add(fr1);
                                    //results.Add("Invalid Search Filter or Directory Problem: " + filter.FileFilter + " " + dirName);
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }

            return(results);
        }