private void BuildFileNode(string path, FileNode fileNode, bool handleSMBAttributes, PreserveSMBPermissions getPermissions) { fileNode.MD5 = Helper.GetFileContentMD5(LongPathExtension.GetFullPath(path)); // fileNode.LastModifiedTime = using (FileStream fs = LongPathFileExtension.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { fileNode.SizeInByte = fs.Length; } DateTimeOffset?creationTime = null; DateTimeOffset?lastWriteTime = null; FileAttributes?fileAttributes = null; LongPathFileExtension.GetFileProperties(path, out creationTime, out lastWriteTime, out fileAttributes); fileNode.CreationTime = creationTime; fileNode.LastWriteTime = lastWriteTime; if (handleSMBAttributes) { fileNode.SMBAttributes = Helper.ToCloudFileNtfsAttributes(fileAttributes.Value); } if (PreserveSMBPermissions.None != getPermissions) { fileNode.PortableSDDL = LongPathFileExtension.GetFilePortableSDDL(path, getPermissions); } fileNode.Metadata = new Dictionary <string, string>(); }
/// <summary> /// Initialize the database for the given context. /// Generates the SQLite-DDL from the model and executes it against the database. /// After that the <see cref="Seed" /> method is executed. /// All actions are be executed in transactions. /// </summary> /// <param name="context">The context.</param> public override void InitializeDatabase(TContext context) { string databaseFilePath = GetDatabasePathFromContext(context); bool dbExists = InMemoryAwareFile.Exists(databaseFilePath); if (dbExists) { if (IsSameModel(context)) { return; } FileAttributes?attributes = InMemoryAwareFile.GetFileAttributes(databaseFilePath); CloseDatabase(context); DeleteDatabase(context, databaseFilePath); base.InitializeDatabase(context); InMemoryAwareFile.SetFileAttributes(databaseFilePath, attributes); SaveHistory(context); } else { base.InitializeDatabase(context); SaveHistory(context); } }
private void processFile(string sourcePath, string destPath) { Action <bool, string> processFile = (bool exists, string logMessage) => { FileAttributes?attributes = null; if (exists) { attributes = File.GetAttributes(destPath); FileExtensions.RemoveAttribute(destPath, FileAttributes.ReadOnly); } File.Copy(sourcePath, destPath, true); _copied.Add(new TaskItem(sourcePath)); if (attributes.HasValue) { File.SetAttributes(destPath, attributes.Value); } Log.LogMessage(logMessage); }; if (!File.Exists(destPath)) { processFile.Invoke(false, string.Format("{0} copied to {1} - did not exist", sourcePath, destPath)); } else if (!FileExtensions.Equals(sourcePath, destPath)) { processFile.Invoke(true, string.Format("{0} copied to {1} - files are different", sourcePath, destPath)); } else { Log.LogMessage(string.Format("{0} skipped", sourcePath)); } }
private void BuildDirNode(string dirPath, DirNode parent, bool handleSMBAttributes) { dirPath = AppendDirectorySeparator(dirPath); DateTimeOffset?creationTime = null; DateTimeOffset?lastWriteTime = null; FileAttributes?fileAttributes = null; #if DOTNET5_4 LongPathFileExtension.GetFileProperties(dirPath, out creationTime, out lastWriteTime, out fileAttributes, true); #else LongPathFileExtension.GetFileProperties(dirPath, out creationTime, out lastWriteTime, out fileAttributes); #endif parent.CreationTime = creationTime; parent.LastWriteTime = lastWriteTime; foreach (var fileInfo in LongPathDirectoryExtension.GetFiles(dirPath)) { FileNode fileNode = new FileNode(fileInfo.Remove(0, dirPath.Length)); this.BuildFileNode(fileInfo, fileNode, handleSMBAttributes); parent.AddFileNode(fileNode); } foreach (var subDirInfo in LongPathDirectoryExtension.GetDirectories(dirPath)) { DirNode subDirNode = new DirNode(subDirInfo.Remove(0, dirPath.Length)); this.BuildDirNode(subDirInfo, subDirNode, handleSMBAttributes); parent.AddDirNode(subDirNode); } }
private void BuildFileNode(FileInfo fileInfo, FileNode fileNode, bool handleSMBAttributes, PreserveSMBPermissions getPermissions) { fileNode.MD5 = Helper.GetFileContentMD5(fileInfo.FullName); fileNode.LastModifiedTime = fileInfo.LastWriteTimeUtc; fileNode.SizeInByte = fileInfo.Length; fileNode.Metadata = new Dictionary <string, string>(); if (CrossPlatformHelpers.IsWindows) { DateTimeOffset?creationTime = null; DateTimeOffset?lastWriteTime = null; FileAttributes?fileAttributes = null; LongPathFileExtension.GetFileProperties(fileInfo.FullName, out creationTime, out lastWriteTime, out fileAttributes); fileNode.CreationTime = creationTime; fileNode.LastWriteTime = lastWriteTime; if (handleSMBAttributes) { fileNode.SMBAttributes = Helper.ToCloudFileNtfsAttributes(fileAttributes.Value); } if (PreserveSMBPermissions.None != getPermissions) { fileNode.PortableSDDL = LongPathFileExtension.GetFilePortableSDDL(fileInfo.FullName, getPermissions); } } }
public FakeFileSystemBuilder IncludingEmptyFile([NotNull] string path, [CanBeNull] FileAttributes?attributes = null) { Guard.NotNull(path, nameof(path)); IncludeFile(path, entry => { }, attributes); return(this); }
public static void AddMultipleFiles( DirNode dirNode, string filePrefix, int fileNumber, int fileSizeInKB, FileAttributes?fa = null, DateTime?lmt = null, string cacheControl = null, string contentDisposition = null, string contentEncoding = null, string contentLanguage = null, string contentType = null, string md5 = null, IDictionary <string, string> metadata = null) { DMLibDataHelper.AddTree( dirNode, string.Empty, filePrefix, fileNumber, 0, fileSizeInKB, fa, lmt, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentType, md5, metadata); }
/// <summary>Create a directory</summary> /// <returns>True if the directory has been created OK, or if pre-existed.</returns> public static void directoryCreate(string path) { path = dirName(path); if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } FileAttributes?a = getFileAttributes(path); if (a.HasValue) { if (a.Value.HasFlag(FileAttributes.Directory)) { return; } throw new Exception("Unable to create a directory: there's a file with same name."); } if (CreateDirectoryW(path, IntPtr.Zero)) { return; } throw new COMException("Unable to create a directory", Marshal.GetHRForLastWin32Error()); }
public HostsFileReader(string[] lines, HostsFileType fileType, string location, FileAttributes?attributes) { Lines = lines; FileType = fileType; Location = location; Attributes = attributes; }
/// <summary> /// Retrieves system icon and type description for specified file system path. /// </summary> /// <param name="path">File system path.</param> /// <param name="attr">File attributes, if null, file attributes will be read from path.</param> /// <param name="iconSize">Returned icon size.</param> /// <returns>File icon and type structure.</returns> public static FileIconAndType GetFileIconAndType(string path, FileAttributes?attr = null, SystemIconSize iconSize = SystemIconSize.Small) { if (path != null && path[1] == ':' && path.Length == 2) { path += @"\"; } var shFileInfo = new NativeMethods.SHFILEINFO(); int cbFileInfo = Marshal.SizeOf(shFileInfo); var flags = NativeMethods.SHGFI.TypeName; if (attr != null && path.Length > 3) { flags |= NativeMethods.SHGFI.UseFileAttributes; } switch (iconSize) { case SystemIconSize.Small: flags |= NativeMethods.SHGFI.Icon | NativeMethods.SHGFI.SmallIcon; break; case SystemIconSize.Medium: flags |= NativeMethods.SHGFI.Icon; break; case SystemIconSize.Large: flags |= NativeMethods.SHGFI.Icon | NativeMethods.SHGFI.LargeIcon; break; } NativeMethods.SHGetFileInfo(path, (int)attr, out shFileInfo, (uint)cbFileInfo, flags); return(new FileIconAndType { Icon = (shFileInfo.hIcon != IntPtr.Zero) ? GetImageFromHIcon(shFileInfo.hIcon) : null, TypeDescription = shFileInfo.szTypeName }); }
private void BuildDirNode(DirectoryInfo dirInfo, DirNode parent, bool handleSMBAttributes = false) { if (handleSMBAttributes) { DateTimeOffset?creationTime = null; DateTimeOffset?lastWriteTime = null; FileAttributes?fileAttributes = null; #if DOTNET5_4 LongPathFileExtension.GetFileProperties(dirInfo.FullName, out creationTime, out lastWriteTime, out fileAttributes, true); #else LongPathFileExtension.GetFileProperties(dirInfo.FullName, out creationTime, out lastWriteTime, out fileAttributes); #endif parent.CreationTime = creationTime; parent.LastWriteTime = lastWriteTime; } foreach (FileInfo fileInfo in dirInfo.GetFiles()) { FileNode fileNode = new FileNode(fileInfo.Name); this.BuildFileNode(fileInfo, fileNode, handleSMBAttributes); parent.AddFileNode(fileNode); } foreach (DirectoryInfo subDirInfo in dirInfo.GetDirectories()) { DirNode subDirNode = new DirNode(subDirInfo.Name); this.BuildDirNode(subDirInfo, subDirNode, handleSMBAttributes); parent.AddDirNode(subDirNode); } }
public static void SetFileAttributes(string path, FileAttributes?fileAttributes) { if (IsInMemoryPath(path) || fileAttributes == null) { return; } File.SetAttributes(path, fileAttributes.Value); }
public FakeFileSystemBuilder IncludingBinaryFile([NotNull] string path, [NotNull] byte[] contents, [CanBeNull] FileAttributes?attributes = null) { Guard.NotNull(path, nameof(path)); Guard.NotNullNorEmpty(contents, nameof(contents)); IncludeFile(path, entry => WriteBytesToFile(entry, contents), attributes); return(this); }
private FileAttributes GetFileAttributesUpdated(FileAttributes?attributes) { var result = FileAttributeArchiveCheckBox.Checked ? (attributes | FileAttributes.Archive) : (attributes & ~FileAttributes.Archive); result = FileAttributeHiddenCheckBox.Checked ? (result | FileAttributes.Hidden) : (result & ~FileAttributes.Hidden); result = FileAttributeReadonlyCheckBox.Checked ? (result | FileAttributes.ReadOnly) : (result & ~FileAttributes.ReadOnly); result = FileAttributeSystemCheckBox.Checked ? (result | FileAttributes.System) : (result & ~FileAttributes.System); return(result.Value); }
public void AppendDirectory(string name, FileAttributes?attributes, DateTime?creationDate, DateTime?lastWriteDate, DateTime?lastAccessDate) { var translatedAttributes = default(ArchivedAttributes?); if (attributes.HasValue) { translatedAttributes = (ArchivedAttributes)(int)attributes.Value; } AppendDirectory(name, translatedAttributes, creationDate, lastWriteDate, lastAccessDate); }
/// <summary>Checks whether the specified directory exists on the file system.</summary> public static bool directoryExists(string path) { path = dirName(path); FileAttributes?a = getFileAttributes(path); if (!a.HasValue) { return(false); } return(a.Value.HasFlag(FileAttributes.Directory)); }
public void AppendFile(string name, long length, Checksum?checksum, FileAttributes?attributes, DateTime?creationDate, DateTime?lastWriteDate, DateTime?lastAccessDate) { var translatedAttributes = default(ArchivedAttributes?); if (attributes.HasValue) { translatedAttributes = (ArchivedAttributes)(int)attributes.Value; } AppendFile(name, length, checksum, translatedAttributes, creationDate, lastWriteDate, lastAccessDate); }
public MPQFileInfo ( [NotNull] string inPath, [NotNull] HashTableEntry inHashEntry, [NotNull] BlockTableEntry inBlockEntry, [NotNull] FileAttributes inAttributes ) : this(inPath, inHashEntry, inBlockEntry) { Attributes = inAttributes; }
public static void AddTree( DirNode dirNode, string dirPrefix, string filePrefix, int width, int depth, int fileSizeInKB, FileAttributes?fa = null, DateTime?lmt = null, string cacheControl = null, string contentDisposition = null, string contentEncoding = null, string contentLanguage = null, string contentType = null, string md5 = null, IDictionary <string, string> metadata = null) { for (int i = 0; i < width; ++i) { string fileName = i == 0 ? filePrefix : filePrefix + "_" + i; FileNode fileNode = new FileNode(fileName) { SizeInByte = 1024L * fileSizeInKB, FileAttr = fa, LastModifiedTime = lmt, CacheControl = cacheControl, ContentDisposition = contentDisposition, ContentEncoding = contentEncoding, ContentLanguage = contentLanguage, ContentType = contentType, MD5 = md5, Metadata = metadata }; dirNode.AddFileNode(fileNode); } if (depth > 0) { for (int i = 0; i < width; ++i) { string dirName = i == 0 ? dirPrefix : dirPrefix + "_" + i; DirNode subDirNode = dirNode.GetDirNode(dirName); if (subDirNode == null) { subDirNode = new DirNode(dirName); dirNode.AddDirNode(subDirNode); } DMLibDataHelper.AddTree(subDirNode, dirPrefix, filePrefix, width, depth - 1, fileSizeInKB, fa, lmt: lmt); } } }
public BackedUpFileData(DateTime?creationTime = null, DateTime?lastWriteTime = null, long originSize = DefaultSize, FileAttributes?fileAttributes = null, string?sha1 = null) { CreationTime = creationTime; LastWriteTime = lastWriteTime; OriginSize = originSize; FileAttributes = fileAttributes; Sha1 = sha1; }
/// <summary> /// Deserializes passed string to file. /// </summary> /// <param name="input"> /// String to be deserialized. /// </param> /// <param name="parent"> /// Parent <see cref="IEntity">entity</see> for file. /// </param> /// <param name="encoding"> /// Encoding used for deserialization of file name. /// Usually passed from parent <see cref="Hypermedia">hypermedia</see> where file resides during deserialization of parent hypermedia. /// </param> public static File DeserializeFromString(string input, IEntity parent, Encoding encoding) { string path = null; string name = null; string extension = null; FileAttributes?attributes = null; long lastModDateTime = 0; DateTime? lastModifiedDateTime = null; List <Block> blocks = new List <Block>(); bool isSingleBlock = false; ulong size = 0; string parent_path = null; string hash = null; DeserializationTools.CheckStringFormat(input, false); string blockList; int count; List <string> stringList; DeserializationTools.SplitStringForSystemEntity(input, _startOfBlockListDeclaration, _endOfBlockListDeclaration, 13, out count, out blockList, out stringList, true); DeserializationTools.ParseStartBaseSystemEntitySerializationString(stringList, encoding, out path, out name); extension = new string(stringList[2].Skip(19).TakeWhile(x => x != ',').ToArray()); attributes = FileAttributesDeserializer(new string(stringList[3].Skip(34).TakeWhile(x => x != ',').ToArray())); lastModDateTime = long.Parse(new string(stringList[4].Skip(41).TakeWhile(x => x != ',').ToArray())); lastModifiedDateTime = DateTimeOffset.FromUnixTimeSeconds(lastModDateTime).UtcDateTime; isSingleBlock = (new string(stringList[5].Skip(26).TakeWhile(x => x != ',').ToArray()) == "true") ? true : false; DeserializationTools.ParseEndBaseSerializationString(stringList, 6, out size, out parent_path, out hash); DeserializationTools.CheckParent(parent, parent_path, false); File file = new File { Path = path, Name = name, Extension = extension, Attributes = attributes, LastModifiedDateTime = lastModifiedDateTime, IsSingleBlock = isSingleBlock, Size = size, Parent = parent, Hash = hash }; if (count != 0) { blocks = BlocksListDeserializer(blockList, file, count); } file.Blocks = blocks; return(file); }
public virtual bool TryGetAttributes(out FileAttributes?attributes) { try { attributes = FileSystem.Attributes; return(true); } catch (Exception) { attributes = default(FileAttributes?); return(false); } }
private static bool IsCategory(IFileSystemInfo fsInfo, FileCategories category) { FileAttributes?attrs = category.GetFileAttrs(); if (attrs is not null) { return(fsInfo.Attributes.HasFlag((FileAttributes)attrs)); } string fileExt = AppExtension.GetExtentionCoreFromPath(fsInfo.Name).ToLowerInvariant(); return(category.GetFileExtPattern().Contains(fileExt)); }
public FakeFileSystemBuilder IncludingDirectory([NotNull] string path, [CanBeNull] FileAttributes?attributes = null) { Guard.NotNull(path, nameof(path)); var absolutePath = new AbsolutePath(path); DirectoryEntry directory = CreateDirectories(absolutePath); if (attributes != null) { directory.Attributes = attributes.Value; } return(this); }
/// <summary> /// Deserializes passed string to directory. /// </summary> /// <param name="input"> /// String to be deserialized. /// </param> /// <param name="parent"> /// Parent <see cref="IEntity">entity</see> for directory. /// </param> /// <param name="encoding"> /// Encoding used for deserialization of directory name. /// Usually passed from parent <see cref="Hypermedia">hypermedia</see> where directory resides during deserialization of parent hypermedia. /// </param> public static Directory DeserializeFromString(string input, IEntity parent, Encoding encoding) { string path = null; string name = null; FileAttributes? attributes = null; long lastModDateTime = 0; DateTime? lastModifiedDateTime = null; List <ISystemEntity> entities = new List <ISystemEntity>(); ulong size = 0; string parent_path = null; string hash = null; DeserializationTools.CheckStringFormat(input, false); string entitiesList; int count; List <string> stringList; DeserializationTools.SplitStringForSystemEntity(input, _startOfSystemEntityListDeclaration, _endOfSystemEntityListDeclaration, 31, out count, out entitiesList, out stringList, false); DeserializationTools.ParseStartBaseSystemEntitySerializationString(stringList, encoding, out path, out name); attributes = FileAttributesDeserializer(new string(stringList[2].Skip(34).TakeWhile(x => x != ',').ToArray())); lastModDateTime = long.Parse(new string(stringList[3].Skip(41).TakeWhile(x => x != ',').ToArray())); lastModifiedDateTime = DateTimeOffset.FromUnixTimeSeconds(lastModDateTime).UtcDateTime; DeserializationTools.ParseEndBaseSerializationString(stringList, 4, out size, out parent_path, out hash); DeserializationTools.CheckParent(parent, parent_path, false); Directory directory = new Directory { Path = path, Name = name, Attributes = attributes, LastModifiedDateTime = lastModifiedDateTime, Size = size, Parent = parent, Hash = hash }; if (count != 0) { entities = SystemEntitiesListDeserializer(entitiesList, directory, count, encoding); } directory.Entities = entities; return(directory); }
public override FileAttributes?GetFileAttributes(IFileInfo file) { Requires.NotNull("file", file); FileAttributes?fileAttributes = null; try { fileAttributes = FileWrapper.Instance.GetAttributes(GetActualPath(file)); } catch (Exception ex) { Logger.Error(ex); } return(fileAttributes); }
public override FileAttributes?GetFileAttributes(IFileInfo file) { Requires.NotNull("file", file); FileAttributes?fileAttributes = null; try { fileAttributes = FileWrapper.Instance.GetAttributes(file.PhysicalPath + ProtectedExtension); } catch (Exception ex) { DnnLog.Error(ex); } return(fileAttributes); }
/// <summary>Checks whether the specified file exists on the file system.</summary> public static bool fileExists(string path) { FileAttributes?a = getFileAttributes(path); if (!a.HasValue) { return(false); } if (a.Value.HasFlag(FileAttributes.Directory)) { return(false); } if (a.Value.HasFlag(FileAttributes.Device)) { return(false); } return(true); }
/// <summary> /// Initialize the database for the given context. /// Generates the SQLite-DDL from the model and executs it against the database. /// All actions are be executed in transactions. /// </summary> /// <param name="context">The context.</param> public override void InitializeDatabase(TContext context) { string databseFilePath = GetDatabasePathFromContext(context); bool exists = InMemoryAwareFile.Exists(databseFilePath); if (exists) { FileAttributes?attributes = InMemoryAwareFile.GetFileAttributes(databseFilePath); InMemoryAwareFile.Delete(databseFilePath); base.InitializeDatabase(context); InMemoryAwareFile.SetFileAttributes(databseFilePath, attributes); } else { base.InitializeDatabase(context); } }
public static void GetFileProperties( string path, out DateTimeOffset?creationTime, out DateTimeOffset?lastWriteTime, out FileAttributes?fileAttributes, bool isDirectory = false) { fileAttributes = File.GetAttributes(path); if (isDirectory) { creationTime = Directory.GetCreationTimeUtc(path); lastWriteTime = Directory.GetLastWriteTimeUtc(path); } else { creationTime = File.GetCreationTimeUtc(path); lastWriteTime = File.GetLastWriteTimeUtc(path); } }