/** * Browse to a new path based on the passed \a item, starting at #_fios_path. * @param *item Item telling us what to do. * @return A filename w/path if we reached a file, otherwise \c null. */ public string FiosBrowseTo(FiosItem item) { switch (item.type) { case FiosType.FIOS_TYPE_DRIVE: _fios_path = $"{item.title[0]}:{Path.PathSeparator}"; break; case FiosType.FIOS_TYPE_INVALID: break; case FiosType.FIOS_TYPE_PARENT: _fios_path = new DirectoryInfo(_fios_path).Parent.FullName; break; case FiosType.FIOS_TYPE_DIR: _fios_path = $"{_fios_path}{item.name}{Path.PathSeparator}"; break; case FiosType.FIOS_TYPE_DIRECT: _fios_path = item.name; break; case FiosType.FIOS_TYPE_FILE: case FiosType.FIOS_TYPE_OLDFILE: case FiosType.FIOS_TYPE_SCENARIO: case FiosType.FIOS_TYPE_OLD_SCENARIO: case FiosType.FIOS_TYPE_PNG: case FiosType.FIOS_TYPE_BMP: return(item.name); } return(null); }
/** * Try to add a fios item set with the given filename. * @param filename the full path to the file to read * @param basepath_length amount of characters to chop of before to get a relative filename * @return true if the file is added. */ public override bool AddFile(string filename, string tar_filename = null) { var ext = Path.GetExtension(filename); if (string.IsNullOrEmpty(ext)) { return(false); } var(type, title) = this.callback_proc(this.fop, filename, ext); if (type == FiosType.FIOS_TYPE_INVALID) { return(false); } foreach (var item in file_list) { if (string.Equals(item.name, filename, StringComparison.CurrentCultureIgnoreCase)) { return(false); } } //FiosItem* fios = file_list.Append(); var fios = new FiosItem(); var fileInfo = new FileInfo(filename); //struct _stat sb; if (fileInfo.Exists) { fios.mtime = (ulong)fileInfo.LastWriteTime.Ticks; } else { fios.mtime = 0; } fios.type = type; fios.name = filename; /* If the file doesn't have a title, use its filename */ var t = title; if (string.IsNullOrEmpty(title)) { t = Path.GetFileName(filename); if (string.IsNullOrEmpty(t)) { t = filename; } } fios.title = t; str.str_validate(fios.title); return(true); }
/** * 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); }