~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to LocateFiles/src/LocateFilesAction.cs

* Manual implementation of locate results limit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
        {
29
29
                
30
30
                bool allowHidden = false;
31
 
                uint maxResults = 1000;
 
31
                const uint maxResults = 500;
32
32
                
33
33
                public override string Name
34
34
                {
65
65
                        
66
66
                        locate = new System.Diagnostics.Process ();
67
67
                        locate.StartInfo.FileName = "locate";
68
 
                        locate.StartInfo.Arguments = string.Format ("-i -n {0} \"{1}\"", maxResults, query);
 
68
                        locate.StartInfo.Arguments = string.Format ("-i \"{0}\"", query);
69
69
                        locate.StartInfo.RedirectStandardOutput = true;
70
70
                        locate.StartInfo.UseShellExecute = false;
71
 
                        try {
72
 
                                locate.Start ();
73
 
                        } catch {
74
 
                                Console.Error.WriteLine ("LocateFilesAction error: The program 'locate' could not be found.");
75
 
                                return null;
76
 
                        }
 
71
                        locate.Start ();
77
72
 
78
73
                        string path;
 
74
                        uint results = 0;
79
75
                        query = query.ToLower ();
80
 
                        while (null != (path = locate.StandardOutput.ReadLine ())) {
 
76
                        while (results < maxResults &&
 
77
                                       null != (path = locate.StandardOutput.ReadLine ())) {
81
78
                                // Disallow hidden directories in the absolute path.
82
79
                                // This gets rid of messy .svn directories and their contents.
83
80
                                if (!allowHidden &&
87
84
                                // Only allow files that contain the query as a substring
88
85
                                // of the file name. It may be faster to use grep, but I've
89
86
                                // tested this and it seems prety snappy.
90
 
                                if (Path.GetFileName (path).ToLower().Contains (query))
 
87
                                if (Path.GetFileName (path).ToLower().Contains (query)) {
 
88
                                        results++;
91
89
                                        files.Add (new FileItem (path));
 
90
                                }
92
91
                        }
93
92
                        files.Sort (new FileItemNameComparer (query));
94
93
                        return files.ToArray ();