Пример #1
0
        /// <summary>
        /// Given a directory and a filetype it recursively (infinite depth) scans the
        /// directory and subdirectories for the file type, creates records of them, and
        /// adds them to the catalog
        /// </summary>
        /// <param name="dir">The root of the directory tree to search</param>
        /// <param name="type">The filetype to search for</param>
        /// <param name="launcher">The class which knows how to execute the type</param>
        private void scanMenu(string dir, string type, Launcher launcher)
        {
            DirectoryInfo di;
            try
            {
                di = new DirectoryInfo(dir);
                DirectoryInfo[] dirs = di.GetDirectories();
                foreach(DirectoryInfo curDir in dirs)
                {
                    scanMenu(curDir.FullName, type, launcher);
                }
                FileInfo[] rgFiles = di.GetFiles("*" + type);

                foreach(FileInfo fi in rgFiles)
                {
                    Record rec = new Record();
                    rec.Name = fi.Name;
                    rec.LowName = fi.Name.ToLower();
                    rec.Path = fi.DirectoryName;

                    rec.type = type;
                    rec.launcher = launcher;

                    // Is it a duplicate?
                    bool isdup = false;

                    // This is expensive, it's n^2 just to add records
                    // to the catalog.  We need to find a slick way around this.
                    foreach(Record r in catalog)
                    {
                        if (r.Name == rec.Name)
                            isdup = true;
                    }
                    if (!isdup)
                        catalog.Add(rec);
                }
            }
            catch(Exception e) {return;}
        }
Пример #2
0
        /// <summary>
        /// Given a directory and a filetype it recursively (infinite depth) scans the
        /// directory and subdirectories for the file type, creates records of them, and
        /// adds them to the catalog
        /// </summary>
        /// <param name="dir">The root of the directory tree to search</param>
        /// <param name="type">The filetype to search for</param>
        /// <param name="launcher">The class which knows how to execute the type</param>
        private void scanMenu(string dir, string type, Launcher launcher)
        {
            DirectoryInfo di;
            try
            {
                di = new DirectoryInfo(dir);
                DirectoryInfo[] dirs = di.GetDirectories();
                foreach (DirectoryInfo curDir in dirs)
                {
                    scanMenu(curDir.FullName, type, launcher);
                }
                FileInfo[] rgFiles = di.GetFiles("*" + type);

                foreach (FileInfo fi in rgFiles)
                {
                    Record rec = new Record();
                    rec.Name = fi.Name;
                    rec.LowName = fi.Name.ToLower();
                    rec.Path = fi.DirectoryName;

                    rec.type = type;
                    rec.launcher = launcher;

                    int ind = rec.Name.IndexOf(type);
                    if (ind != -1)
                        rec.croppedName = rec.Name.Substring(0, ind);
                    else
                        rec.croppedName = rec.Name;

                    if (!catalog.ContainsKey(rec.Name))
                        catalog.Add(rec.Name, (object)rec);
                }
            }
            catch (Exception e) { return; }
        }