コード例 #1
0
        private void FileFilter(string keywrods, CancellationToken token, bool?bSearchFolder)
        {
            try
            {
                // Wait for 10 ms in case someone is typing fast so we don't waste resources
                Thread.Sleep(10);

                // Were we already canceled?
                token.ThrowIfCancellationRequested();

                // Do the job for some time
                // ... Currenlty we do not bother dividing the job into smaller pieces

                // Poll to make sure we are not cancelling before continue on more job
                //if (token.IsCancellationRequested)
                //{
                //    // No clean up to do, so we just stop ourselves
                //    token.ThrowIfCancellationRequested();
                //}
                //else
                //{
                // Lock so we don't mess things up
                lock (newLocker)
                {
                    if (bSearchFolder == true)
                    {
                        JRootFolder_Filtered = QuickMatch.QuickMatchFolder(keywrods, JRootFolder, CurrentSearchMode == ContentSearchMode.MultiFolder);
                    }
                    else
                    {
                        JRootFolder_Filtered = QuickMatch.QuickMatchFile(keywrods, JRootFolder, CurrentSearchMode == ContentSearchMode.MultiFile);
                    }
                }

                /* Here are some information on lock vs mutex
                 * http://stackoverflow.com/questions/34524/what-is-a-mutex
                 * http://stackoverflow.com/questions/3735293/what-is-the-difference-between-lock-and-mutex
                 * https://msdn.microsoft.com/en-us/library/c5kehkcz.aspx
                 * http://stackoverflow.com/questions/6029804/how-does-lock-work-exactly
                 */
                //}

                // Were we actually canceled?
                token.ThrowIfCancellationRequested();
            }
            catch (OperationCanceledException)
            {
            }
        }
コード例 #2
0
        // Get file path for specifci JFile in tree, considering QuickMatch
        private string GetFilePath(JFile file)
        {
            // QuickMatch® (4/4): Use QuickMatch® for QuickMatched files
            if (file.Parent.FolderName == App.QuickMatchFolderName)
            {
                JFolder matches = QuickMatch.QuickMatchFile(file.FileName, JRootFolderExclusive);

                // If no match found
                if (matches == null)
                {
                    StatusLabel.Content = "No match found.";
                    return(null);
                }
                // If more than one match if found
                if (matches.Files.Count > 1)
                {
                    StatusLabel.Content = "More than one match is found, please do matching manually using magic explorer.";    // Better with a shortcut to it
                    return(null);
                }
                // Otherwise there can be only one match
                else
                {
                    // Get JFile first
                    List <JFolder> subFolders = matches.Folders;
                    while (subFolders[0].Folders.Count != 0)
                    {
                        subFolders = subFolders[0].Folders;
                    }
                    JFile foundFile = subFolders[0].Files[0];
                    // Then get the file's path
                    return(App.GetParentFolderPath(foundFile.Parent) + foundFile.FileName);
                }
            }
            else
            {
                return(App.GetParentFolderPath(file.Parent) + file.FileName);
            }
        }