public static extern SafeFileMappingHandle CreateFileMapping( IntPtr hFile, IntPtr lpAttributes, FileProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
/// <summary> /// Create a <see cref="ProtectedFileProvider"/> with protected access using the given protection level. /// </summary> /// <param name="filePath">The path to the file.</param> /// <param name="protectionLevel">The <see cref="FileProtection"/> level for the file.</param> /// <param name="dataStore">The <see cref="IDataStore"/> to access.</param> /// <returns>A <see cref="ProtectedFileProvider"/> with specified access to the file.</returns> public static ProtectedFileProvider CreateFileProvider(string filePath, FileProtection protectionLevel, IDataStore dataStore) { if (null == dataStore) { throw new ArgumentNullException(nameof(dataStore), "IDataStore cannot be null."); } if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentOutOfRangeException(nameof(filePath), "A valid file path must be provided."); } ProtectedFileProvider provider; switch (protectionLevel) { case FileProtection.ExclusiveWrite: provider = new ExclusiveWriteFileProvider(); break; default: provider = new SharedReadOnlyFileProvider(); break; } provider.DataStore = dataStore; provider.FilePath = filePath; return(provider); }
public static uint MakeProtection(FileProtection protection) { return((uint)(((protection & FileProtection.Read) != 0 ? 0 : 1) | ((protection & FileProtection.Write) != 0 ? 0 : 1 << 1) | ((protection & FileProtection.Execute) != 0 ? 0 : 1 << 2) | ((protection & FileProtection.Delete) != 0 ? 0 : 1 << 3))); }
private static extern IntPtr CreateFileMapping( IntPtr hFile, int lpAttributes, FileProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
/// <summary> /// Handler for FileProtection ProgressChanged event /// </summary> private void ProgressUpdated(object sender, FileProtection value) { string message = $"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}"; StatusLabel.Content = message; ViewModels.LoggerViewModel.VerboseLogLn(message); }
public static extern IntPtr CreateFileMapping( IntPtr hFile, // Handle to the file IntPtr lpAttributes, // Security Attributes FileProtection flProtect, // File protection uint dwMaximumSizeHigh, // High-order DWORD of size uint dwMaximumSizeLow, // Low-order DWORD of size string lpName // File mapping object name );
public static unsafe extern IntPtr CreateFileMapping( IntPtr hFile, // handle to file void *lpAttributes, // security FileProtection flProtect, // protection int dwMaximumSizeHigh, // high-order DWORD of size int dwMaximumSizeLow, // low-order DWORD of size string lpName // object name );
public static byte[] MakeProtection(FileProtection system, FileProtection owner, FileProtection group, FileProtection world) { var result1 = MakeProtection(system) | (MakeProtection(owner) << 4); var result2 = MakeProtection(group) | (MakeProtection(world) << 4); return(new byte[] { (byte)result1, (byte)result2 }); }
public static VMSFileConfig MakeVar(FileProtection protection, uint ownerId) { return(new VMSFileConfig { RecordType = RecordTypes.C_VARIABLE, RecordLayout = RecordLayouts.C_SEQUENTIAL, System = FileProtection.Read | FileProtection.Write | FileProtection.Execute | FileProtection.Delete, Owner = protection, Group = protection, World = FileProtection.Read, RecordSize = 0, LineEndingOverride = "\r", OwnerId = ownerId }); }
private static void Changed(object source, FileProtection value) { Console.WriteLine($"{value.Percentage * 100}: {value.Filename} - {value.Protection}"); }
static extern IntPtr CreateFileMapping(IntPtr hFile, int lpAttributes, FileProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);
/// <summary> /// Create a <see cref="ProtectedFileProvider"/> with protected access using the given protection level. /// </summary> /// <param name="filePath">The path to the file.</param> /// <param name="protectionLevel">The <see cref="FileProtection"/> level for the file.</param> /// <returns>A <see cref="ProtectedFileProvider"/> with specified access to the file.</returns> public static ProtectedFileProvider CreateFileProvider(string filePath, FileProtection protectionLevel = FileProtection.SharedRead) { return(CreateFileProvider(filePath, protectionLevel, GraphSession.Instance.DataStore)); }
public static byte[] MakeVMSExtraBlock(RecordTypes recordType, RecordLayouts layout, FileAttributes attributes, ushort recordSize, uint fileSize, byte bucketSize, ushort maxRecordSize, ushort defaultExtend, DateTime created, DateTime modified, uint ownerId, FileProtection system, FileProtection owner, FileProtection group, FileProtection world) { var headerResult = new PK_header { tag = VMSAttributeHeader, size = VMSAttributeSize, data = new List <PK_field>() }; var evenFileSize = Math.DivRem(fileSize, 512, out var fileSizeRemainder) + 1; FatDef fatDef = new FatDef { b_rtype = MakeRecordType(recordType, layout), b_rattrib = (byte)attributes, w_rsize = recordSize, l_hiblk = (uint)(((evenFileSize + 1) << 16) | ((evenFileSize + 1) >> 16)), l_efblk = (uint)((evenFileSize << 16) | (evenFileSize >> 16)), w_ffbyte = (ushort)fileSizeRemainder, b_bktsize = bucketSize, b_vfcsize = (byte)(recordType == RecordTypes.C_VFC ? 2 : 0), w_maxrec = maxRecordSize, w_defext = defaultExtend, w_gbc = 0 }; headerResult.data.Add(new PK_field { size = 32, tag = 4, value = WriteFATDef(fatDef) }); headerResult.data.Add(new PK_field { size = 4, tag = 3, value = BitConverter.GetBytes((int)0) }); headerResult.data.Add(new PK_field { size = 8, tag = 17, value = ConvertToSmithsonianTime(created) }); headerResult.data.Add(new PK_field { size = 8, tag = 18, value = ConvertToSmithsonianTime(modified) }); headerResult.data.Add(new PK_field { size = 8, tag = 19, value = BitConverter.GetBytes((long)0) }); headerResult.data.Add(new PK_field { size = 8, tag = 20, value = BitConverter.GetBytes((long)0) }); headerResult.data.Add(new PK_field { size = 2, tag = 13, value = new byte[] { 1, 0 } }); headerResult.data.Add(new PK_field { size = 4, tag = 21, value = BitConverter.GetBytes(ownerId) }); headerResult.data.Add( new PK_field { size = 2, tag = 22, value = MakeProtection(system, owner, group, world) }); headerResult.data.Add(new PK_field { size = 2, tag = 23, value = new byte[] { 0, 0 } }); headerResult.data.Add(new PK_field { size = 1, tag = 29, value = new byte[] { 0 } }); return(WriteHeader(headerResult)); }
/// <summary> /// Simple process counter to write to console /// </summary> private static void ProgressUpdated(object sender, FileProtection value) { Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}"); }