public HResult GetDirectoryEnumerationCallback(int commandId, Guid enumerationId, string filterFileName, bool restartScan, IDirectoryEnumerationResults result) { if (!_activeEnumerations.TryGetValue(enumerationId, out var enumerator)) { return(HResult.InternalError); } if (restartScan) { enumerator.Reset(); } var entryAdded = false; var hr = HResult.Ok; while (enumerator.MoveNext()) { var file = enumerator.Current; var filename = Path.GetFileName(file.FullName); if (FilenameMatchesFilter(filename, filterFileName) && result.Add(filename, file.Length, file.IsDirectory, file.IsDirectory ? FileAttributes.Directory : FileAttributes.Normal, DateTime.MinValue, file.LastAccessTime, file.LastWriteTime, file.LastWriteTime)) { entryAdded = true; } else { hr = entryAdded ? HResult.Ok : HResult.InsufficientBuffer; break; } } return(hr); }
public HResult GetDirectoryEnumerationCallback(int commandId, Guid enumerationId, string filterFileName, bool restartScan, IDirectoryEnumerationResults enumResult) { if (!enumerations.TryGetValue(enumerationId, out FileEnumeration enumeration)) { return(HResult.InternalError); } if (restartScan) { enumeration.Reset(); } if (restartScan || enumeration.Filter == null) { enumeration.Filter = filterFileName ?? ""; } enumeration.MoveNext(); bool added = false; while (enumeration.Valid) { PakFileSystemInfo fileInfo = enumeration.Current; if (enumResult.Add( fileName: string.IsNullOrWhiteSpace(fileInfo.Name) ? "REPLACEME" : fileInfo.Name, fileSize: fileInfo.Size, isDirectory: fileInfo is PakDirectoryInfo, fileAttributes: fileInfo.Attributes, creationTime: DateTime.Now, lastAccessTime: DateTime.Now, lastWriteTime: DateTime.Now, changeTime: DateTime.Now)) { added = true; enumeration.MoveNext(); } else { return(added ? HResult.Ok : HResult.InsufficientBuffer); } } return(HResult.Ok); }
internal HResult GetDirectoryEnumerationCallback( int commandId, Guid enumerationId, string filterFileName, bool restartScan, IDirectoryEnumerationResults enumResult) { Log.Information("----> GetDirectoryEnumerationCallback filterFileName [{Filter}]", filterFileName); // Find the requested enumeration. It should have been put there by StartDirectoryEnumeration. if (!this.activeEnumerations.TryGetValue(enumerationId, out ActiveEnumeration enumeration)) { return(HResult.InternalError); } if (restartScan) { // The caller is restarting the enumeration, so we reset our ActiveEnumeration to the // first item that matches filterFileName. This also saves the value of filterFileName // into the ActiveEnumeration, overwriting its previous value. enumeration.RestartEnumeration(filterFileName); } else { // The caller is continuing a previous enumeration, or this is the first enumeration // so our ActiveEnumeration is already at the beginning. TrySaveFilterString() // will save filterFileName if it hasn't already been saved (only if the enumeration // is restarting do we need to re-save filterFileName). enumeration.TrySaveFilterString(filterFileName); } bool entryAdded = false; HResult hr = HResult.Ok; while (enumeration.IsCurrentValid) { ProjectedFileInfo fileInfo = enumeration.Current; if (enumResult.Add( fileName: fileInfo.Name, fileSize: fileInfo.Size, isDirectory: fileInfo.IsDirectory, fileAttributes: fileInfo.Attributes, creationTime: fileInfo.CreationTime, lastAccessTime: fileInfo.LastAccessTime, lastWriteTime: fileInfo.LastWriteTime, changeTime: fileInfo.ChangeTime)) { entryAdded = true; enumeration.MoveNext(); } else { if (entryAdded) { hr = HResult.Ok; } else { hr = HResult.InsufficientBuffer; } break; } } Log.Information("<---- GetDirectoryEnumerationCallback {Result}", hr); return(hr); }
public HResult GetDirectoryEnumerationCallback( int commandId, Guid enumerationId, string filterFileName, bool restartScan, IDirectoryEnumerationResults results) { Console.WriteLine($"GetDiretoryEnumeration: {enumerationId}, {filterFileName}"); try { ActiveEnumeration activeEnumeration = null; if (!this.activeEnumerations.TryGetValue(enumerationId, out activeEnumeration)) { return(HResult.InternalError); } if (restartScan) { activeEnumeration.RestartEnumeration(filterFileName); } else { activeEnumeration.TrySaveFilterString(filterFileName); } bool entryAdded = false; HResult result = HResult.Ok; while (activeEnumeration.IsCurrentValid) { ProjectedFileInfo fileInfo = activeEnumeration.Current; DateTime now = DateTime.UtcNow; if (results.Add( fileName: fileInfo.Name, fileSize: fileInfo.IsDirectory ? 0 : fileInfo.Size, isDirectory: fileInfo.IsDirectory, fileAttributes: fileInfo.IsDirectory ? FileAttributes.Directory : FileAttributes.Archive, creationTime: now, lastAccessTime: now, lastWriteTime: now, changeTime: now)) { entryAdded = true; activeEnumeration.MoveNext(); } else { result = entryAdded ? HResult.Ok : HResult.InsufficientBuffer; break; } } return(result); } catch (Win32Exception e) { return(HResultFromWin32(e.NativeErrorCode)); } catch (Exception) { return(HResult.InternalError); } }