public void PurgeRedundantFiles(FileListType list) { var fileTemplate = _fileNames.FileTemplate; var path = Path.GetDirectoryName(fileTemplate); var fileName = Path.GetFileName(fileTemplate); var files = Directory.GetFiles(path, fileName); HashSet <string> fileNameList = new HashSet <string>(); foreach (var e in list) { fileNameList.Add(Path.GetFullPath(e.Value.FileName)); } // Delete all old files matching the fileTemplate which are not found in the current index list foreach (var file in files) { if (fileNameList.Contains(Path.GetFullPath(file)) == false) { try { File.Delete(file); } catch (Exception) { } } } }
/// <summary>Reads the file verification list into this object.</summary> /// <param name="filename">The file verification list to build the FileList from.</param> /// <param name="reader">The FileListReader to use.</param> private void Read(string filename, FileListReader reader) { reader.Read(filename); this.filelist = reader.FileList.filelist; this.information = reader.FileList.information; this.sourceFile = reader.FileList.sourceFile; this.type = reader.FileList.type; this.version = reader.FileList.version; }
/// <summary> /// Creates a <see cref="FileInfo"/>-Object /// </summary> /// <param name="channel"><see cref="Channel"/> for which a <see cref="FileInfo"/> was requested.</param> /// <param name="path">Subdirectory inside the channel for which the FileInfo was requested. “/” indicates the root directory is listed.</param> /// <param name="name">File name.</param> /// <param name="size">File size.</param> /// <param name="lastModified">The date and time on which the file was last modified.</param> /// <param name="type">Indicates if this entry is a directory or a file. </param> /// <param name="incompleteSize"> If the file is currently still being transferred, this indicates the currently transferred file size.</param> public FileInfo(Channel channel, string path, string name, ulong size, DateTimeOffset lastModified, FileListType type, ulong incompleteSize) { Require.NotNull(nameof(channel), channel); Channel = channel; Path = path; Name = name; Size = size; LastModified = lastModified; Type = type; IncompleteSize = incompleteSize; }
static Mod() { Name = Properties.Settings.Default.ModName; string fileListFileName = Properties.Settings.Default.FileListFileName; FileListPath = new IO.PathContainer(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), fileListFileName)); ConfigPath = new IO.PathContainer(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), Path.GetFileName(Application.ExecutablePath) + ".config")); try { if (File.Exists(FileListPath.GetPath())) { FileList = (FileListType)XML.Read <FileListType>(File.ReadAllText(FileListPath.GetPath())); } } catch { } }
/// <summary>Retrieves the appropriate FileListReader given a specific file type.</summary> /// <param name="type">The FileListType of the FileListReader wanted.</param> /// <returns>The appropriate FileListReader.</returns> static public FileListReader GetReader(FileListType type) { FileListReader flr; switch (type) { case FileListType.BSDMD5: flr = new MD5FileListReader(); break; case FileListType.MD5SUM: flr = new MD5FileListReader(); break; case FileListType.SFV: flr = new SFVFileListReader(); break; case FileListType.VERIFYXML: flr = new VerifyXMLFileListReader(); break; default: throw new FileTypeException(); } return(flr); }
public void WriteListToFile(FileListType fileList) { List <string> stringList = new List <string>(); var list = fileList; foreach (var entry in list) { entry.Value.FileName = Path.GetFullPath(entry.Value.FileName); string line = JsonSerializer.Serialize <EndlessStreamFileListEntry>(entry.Value); stringList.Add(line); } var hash = CalcHashCodeString(stringList); File.WriteAllText(_fileNames.IndexHashFileName, hash); File.WriteAllLines(_fileNames.IndexListFileName, stringList); PurgeRedundantFiles(fileList); }
public FileInfoEx[] GetListFiles(FileListType type, string value) { FileInfoEx[] filesEx = null; try { using (FileTransferContext context = new FileTransferContext()) { switch (type) { case FileListType.AllFiles: filesEx = context.Files.ToArray(); break; case FileListType.ByAuthor: filesEx = context.Files.Where(f => f.Author.ToLower().Contains(value.ToLower())).ToArray(); break; case FileListType.ByFileName: filesEx = context.Files.Where(f => f.OriginalFileName.ToLower().Contains(value.ToLower())).ToArray(); break; case FileListType.ByDateUpload: DateTime date = DateTime.Parse(value); filesEx = context.Files.Where(f => EntityFunctions.TruncateTime(f.DateUpload) >= EntityFunctions.TruncateTime(date)).ToArray(); break; } } } catch (Exception e) { Console.WriteLine(e); } return(filesEx); }
/// <summary> /// Adds a new file mapping tab /// </summary> /// <param name="listType">Type of list that will provide data to /// the new tab.</param> private void AddFileMappingTab(FileListType listType) { TabPage tp = new TabPage("-new-"); FileMapDisplay display = new FileMapDisplay(); switch (listType) { case FileListType.Cell: display.FileList = m_cellFileList; break; case FileListType.Portal: display.FileList = m_portalFileList; break; default: throw new ArgumentException("Unknown file list type"); } display.Parser = m_parser; tp.Controls.Add(display); display.Dock = DockStyle.Fill; tcFiles.TabPages.Add(tp); tcFiles.SelectedTab = tp; }
/// <summary>Initializes a new instance of FileList.</summary> /// <param name="filename">The file verification list to build the FileList from.</param> /// <param name="type">The specific file verification list format to try to parse.</param> public FileList(string filename, FileListType type) { Read(filename, FileListReader.GetReader(type)); }