Exemplo n.º 1
0
        FileList file_list;                       ///< Destination of the found files.

        /**
         * Create the scanner
         * @param fop Purpose of collecting the list.
         * @param callback_proc The function that is called where you need to do the filtering.
         * @param file_list Destination of the found files.
         */
        public FiosFileScanner(SaveLoadOperation fop, fios_getlist_callback_proc callback_proc, FileList file_list)
        {
            this.fop           = fop;
            this.callback_proc = callback_proc;
            this.file_list     = file_list;
        }
Exemplo n.º 2
0
        /**
         * Fill the list of the files in a directory, according to some arbitrary rule.
         * @param fop Purpose of collecting the list.
         * @param callback_proc The function that is called where you need to do the filtering.
         * @param subdir The directory from where to start (global) searching.
         * @param file_list Destination of the found files.
         */
        static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc callback_proc, Subdirectory subdir, FileList file_list)
        {
            int sort_start;

            file_list.Clear();

            /* A parent directory link exists if we are not in the root directory */
            if (Win32.FiosIsRoot(_fios_path) == false)
            {
                var fios = new FiosItem();
                fios.type  = FiosType.FIOS_TYPE_PARENT;
                fios.mtime = 0;

                fios.name  = "..";
                fios.title = ".. (Parent directory)";

                file_list.Add(fios);
            }

            /* Show subdirectories */
            var dir = Win32.opendir(_fios_path);

            if (dir != null)
            {
                /* found file must be directory, but not '.' or '..' */
                foreach (var directory in dir.GetDirectories())
                {
                    var d_name = directory.Name;

                    if (Win32.FiosIsHiddenFile(directory) == false || string.Equals(d_name, PERSONAL_DIR, StringComparison.CurrentCultureIgnoreCase))
                    {
                        var fios = new FiosItem();
                        fios.type  = FiosType.FIOS_TYPE_DIR;
                        fios.mtime = 0;
                        file_list.Add(fios);
                        fios.name  = d_name;
                        fios.title = $"{d_name}{Path.PathSeparator} (Directory)";

                        str.str_validate(fios.title);
                    }
                }
            }

            /* Sort the subdirs always by name, ascending, remember user-sorting order */
            var CompareFiosItems = new FiosItemComparer();

            {
                SortingBits order = _savegame_sort_order;
                _savegame_sort_order = SortingBits.SORT_BY_NAME | SortingBits.SORT_ASCENDING;


                file_list.files.Sort(CompareFiosItems);
                _savegame_sort_order = order;
            }

            /* This is where to start sorting for the filenames */
            sort_start = file_list.Count;

            /* Show files */
            var scanner = new FiosFileScanner(fop, callback_proc, file_list);

            if (subdir == Subdirectory.NO_DIRECTORY)
            {
                scanner.Scan(null, _fios_path, false);
            }
            else
            {
                scanner.Scan(null, subdir, true, true);
            }


            file_list.files.Sort(sort_start, file_list.files.Count - sort_start, CompareFiosItems);

            /* Show drives */
            Win32.FiosGetDrives(file_list);
        }