Ejemplo n.º 1
0
        /// <summary>
        /// 获取MP3文件
        /// </summary>
        private void GetMP3File()
        {
            DateTime dt1 = DateTime.Now;
            FileDirectoryFinder finder = new FileDirectoryFinder();
            this.isScanMP3End = false;
            MP3FileData mp3File = new MP3FileData();
            bool isQueueEmpty = false;
            while (true)
            {
                //如果用户执行了停止索引,结束。
                if (this.isStopIndexMP3 == true)
                    break;
                lock (this.mp3DirectoryStack)
                {
                    if (this.mp3DirectoryStack.Count > 0)
                    {
                        isQueueEmpty = false;
                        finder.SearchPath = this.mp3DirectoryStack.Pop();
                        finder.Reset();
                    }
                    else
                    {
                        isQueueEmpty = true;
                    }
                }
                if (isQueueEmpty == false)
                {
                    while (finder.MoveNext())
                    {
                        //当前对象为目录
                        if (finder.IsFile == true)
                        {
                            //不是mp3文件,继续。
                            if (finder.CurrentFileData.name.ToLower().EndsWith(".mp3") == false)
                            {
                                continue;
                            }

                            lock (this.mp3FileQueue)
                            {
                                mp3File.name = finder.CurrentFileData.name;
                                mp3File.directory = finder.CurrentFileData.directory;

                                mp3File.length = Deal.ToLong(finder.CurrentFileData.nFileSizeHigh,
                                        finder.CurrentFileData.nFileSizeLow).ToString();

                                mp3File.lastWriteTime = Deal.ToDateTimeString(
                                    finder.CurrentFileData.ftLastWriteTime_dwHighDateTime,
                                   finder.CurrentFileData.ftLastWriteTime_dwLowDateTime);

                                lock (this.mp3FileQueue)
                                {
                                    this.mp3FileQueue.Enqueue(mp3File);
                                }
                                this.mp3FileCounter++;
                            }
                        }
                        else
                        {
                            lock (this.mp3DirectoryStack)
                            {
                                this.mp3DirectoryStack.Push(finder.FullName);
                            }
                            this.mp3FolderCounter++;
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            double d = (DateTime.Now - dt1).TotalSeconds;
            //Console.Out.WriteLine("GetMP3File" + d);
            this.isScanMP3End = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据目录队列逐个扫描,获取文件或目录。
        /// </summary>
        private void GetFilesDirectorys()
        {
            DateTime dt1 = DateTime.Now;
            this.isScanFileEnd = false;
            FileDirectoryFinder finder = new FileDirectoryFinder();
            bool isQueueEmpty = false;
            while (true)
            {
                //如果用户执行了停止索引,结束。
                if (this.isStopIndexFile == true)
                    break;
                lock (this.scanDirectoryStack)
                {
                    if (this.scanDirectoryStack.Count > 0)
                    {
                        isQueueEmpty = false;
                        finder.SearchPath = this.scanDirectoryStack.Pop();
                        finder.Reset();
                    }
                    else
                    {
                        isQueueEmpty = true;
                    }
                }
                if (isQueueEmpty == false)
                {
                    while (finder.MoveNext())
                    {
                        //将找到的文件数据放入findFileData队列。
                        lock (this.findFileDataQueue)
                        {
                            this.findFileDataQueue.Enqueue(finder.CurrentFileData);
                        }

                        //当前对象为目录
                        if (finder.IsFile == false)
                        {
                            lock (this.scanDirectoryStack)
                            {
                                this.scanDirectoryStack.Push(finder.FullName);
                            }
                            this.folderCounter++;//文件夹计数
                        }
                        else
                        {
                            this.fileCounter++;//文件计数
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            double d = (DateTime.Now - dt1).TotalSeconds;
            //Console.Out.WriteLine("扫描磁盘" + d);
            this.isScanFileEnd = true;//完成扫描目录获取文件
        }