Ejemplo n.º 1
0
        public int find(string path, srch srch)
        {
            Console.WriteLine("searche for {0} at {1}", srch.val, path);
            stack.Push(path);
            if (threads.Count == 0)
            {
                for (int i1 = 0; i1 < nt; i1++)
                {
                    var x = new Thread(e =>
                    {
                        sleep.add(Thread.CurrentThread, false);
                        var m = _find(srch);
                        Console.WriteLine("i: {0};\t m:{1}", i, m);
                    });
                    threads.Add(x);
                }
                foreach (var thread in threads)
                {
                    thread.Start();
                }
                threads.Add(Thread.CurrentThread);
                sleep.add(Thread.CurrentThread, false);
            }
            var mm = _find(srch);

            Console.WriteLine("i: {0};\t m:{1}", i, mm);
            return(i);
        }
Ejemplo n.º 2
0
        private int _find(srch srch)
        {
            int    i = 0;
            string s;
            var    data = new WIN32_FIND_DATA();

deb:
            string path = null;

            lock (stack)
                if (stack.Count == 0)
                {
                    if (isallsleep())
                    {
                        return(i);
                    }
                    else
                    {
                        waiting = true;
                        Thread.Sleep(1);
                        goto deb;
                    }
                }
                else
                {
                    path = stack.Pop();
                }
            if (path == null)
            {
                goto deb;
            }
            waiting = false;
            rslts rslt = null;
            var   ff   = Win32Native.FindFirstFile(path + "*", data);

            if (!ff.IsInvalid)
            {
                do
                {
                    if (!data.IsFileOrDir)
                    {
                        continue;
                    }
                    s = data.cFileName;
                    if (data.IsDir)
                    {
                        stack.Push(string.Concat(path, data.cFileName, "\\"));
                    }
                    if (srch.match(s))
                    {
                        this.i++;
                        if (rslt == null)
                        {
                            rslt = new rslts(path);
                        }
                        rslt.files.Add(data);
                        data = new WIN32_FIND_DATA();
                    }
                } while (Win32Native.FindNextFile(ff, data));
            }
            if (rslt != null)
            {
                result.Add(rslt);
            }
            goto deb;
        }