本文整理汇总了C#中PathFormat类的典型用法代码示例。如果您正苦于以下问题:C# PathFormat类的具体用法?C# PathFormat怎么用?C# PathFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PathFormat类属于命名空间,在下文中一共展示了PathFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptDecryptFileInternal
internal static void EncryptDecryptFileInternal(bool isFolder, string path, bool encrypt, PathFormat pathFormat)
{
string pathLp = Path.GetExtendedLengthPathInternal(null, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
// Reset file/directory attributes.
// MSDN: If lpFileName specifies a read-only file, the function fails and GetLastError returns ERROR_FILE_READ_ONLY.
SetAttributesInternal(isFolder, null, pathLp, FileAttributes.Normal, true, PathFormat.LongFullPath);
// EncryptFile() / DecryptFile()
// In the ANSI version of this function, the name is limited to 248 characters.
// To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
// 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
if (!(encrypt
? NativeMethods.EncryptFile(pathLp)
: NativeMethods.DecryptFile(pathLp, 0)))
{
int lastError = Marshal.GetLastWin32Error();
switch ((uint)lastError)
{
case Win32Errors.ERROR_ACCESS_DENIED:
string root = Path.GetPathRoot(pathLp, false);
if (!string.Equals("NTFS", new DriveInfo(root).DriveFormat, StringComparison.OrdinalIgnoreCase))
throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "The drive does not support NTFS encryption: [{0}]", root));
break;
default:
if (lastError == Win32Errors.ERROR_FILE_NOT_FOUND && isFolder)
lastError = (int)Win32Errors.ERROR_PATH_NOT_FOUND;
NativeError.ThrowException(lastError, pathLp);
break;
}
}
}
示例2: EnumerateAlternateDataStreamsInternal
internal static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsInternal(KernelTransaction transaction, string path, PathFormat pathFormat)
{
using (var buffer = new SafeGlobalMemoryBufferHandle(Marshal.SizeOf(typeof(NativeMethods.WIN32_FIND_STREAM_DATA))))
{
path = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars | GetFullPathOptions.CheckAdditional);
using (var handle = transaction == null
? NativeMethods.FindFirstStreamW(path, NativeMethods.StreamInfoLevels.FindStreamInfoStandard, buffer, 0)
: NativeMethods.FindFirstStreamTransactedW(path, NativeMethods.StreamInfoLevels.FindStreamInfoStandard, buffer, 0, transaction.SafeHandle))
{
if (handle.IsInvalid)
{
int errorCode = Marshal.GetLastWin32Error();
if (errorCode == Win32Errors.ERROR_HANDLE_EOF)
yield break;
NativeError.ThrowException(errorCode);
}
while (true)
{
NativeMethods.WIN32_FIND_STREAM_DATA data = buffer.PtrToStructure<NativeMethods.WIN32_FIND_STREAM_DATA>();
yield return new AlternateDataStreamInfo(path, data);
if (!NativeMethods.FindNextStreamW(handle, buffer))
{
int lastError = Marshal.GetLastWin32Error();
if (lastError == Win32Errors.ERROR_HANDLE_EOF)
break;
NativeError.ThrowException(lastError, path);
}
}
}
}
}
示例3: GetParentInternal
internal static DirectoryInfo GetParentInternal(KernelTransaction transaction, string path, PathFormat pathFormat)
{
string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.CheckInvalidPathChars);
pathLp = Path.GetRegularPathInternal(pathLp, GetFullPathOptions.None);
string dirName = Path.GetDirectoryName(pathLp, false);
return Utils.IsNullOrWhiteSpace(dirName) ? null : new DirectoryInfo(transaction, dirName, PathFormat.RelativePath);
}
示例4: Parse
public void Parse(DirectoryInfo moaiSourceDirectory, PathFormat messagePathFormat)
{
// Check that the input directory looks like the Moai src directory
if (!moaiSourceDirectory.GetDirectoryInfo("moai-core").Exists) {
throw new ApplicationException(string.Format("Path '{0}' does not appear to be the 'src' directory of a Moai source copy.", moaiSourceDirectory));
}
// Initialize type list with primitive types
typesByName = new Dictionary<string, MoaiType>();
var primitiveTypeNames = new[] { "nil", "boolean", "number", "string", "userdata", "function", "thread", "table" };
foreach (string primitiveTypeName in primitiveTypeNames) {
typesByName[primitiveTypeName] = new MoaiType { Name = primitiveTypeName, IsPrimitive = true };
}
// Parse Moai types and store them by type name
log.Info("Parsing Moai types.");
ParseMoaiCodeFiles(moaiSourceDirectory, messagePathFormat);
// MOAILuaObject is not documented, probably because it would mess up
// the Doxygen-generated documentation. Use dummy code instead.
log.Info("Adding hard-coded documentation for MoaiLuaObject base class.");
FilePosition dummyFilePosition = new FilePosition(new FileInfo("MoaiLuaObject dummy code"), new DirectoryInfo("."), messagePathFormat);
ParseMoaiFile(MoaiLuaObject.DummyCode, dummyFilePosition);
// Make sure every class directly or indirectly inherits from MOAILuaObject
MoaiType moaiLuaObjectType = GetOrCreateType("MOAILuaObject", null);
foreach (MoaiType type in typesByName.Values) {
if (!(type.AncestorTypes.Contains(moaiLuaObjectType)) && type != moaiLuaObjectType) {
type.BaseTypes.Add(moaiLuaObjectType);
}
}
// Check if we have information on all referenced classes
IEnumerable<MoaiType> typesReferencedInDocumentation = typesByName.Values
.Where(type => type.DocumentationReferences.Any());
foreach (MoaiType type in typesReferencedInDocumentation.ToArray()) {
WarnIfSpeculative(type);
}
log.Info("Creating compact method signatures.");
foreach (MoaiType type in typesByName.Values) {
foreach (MoaiMethod method in type.Members.OfType<MoaiMethod>()) {
if (!method.Overloads.Any()) {
log.WarnFormat("No method documentation found. [{0}]", method.MethodPosition);
continue;
}
try {
method.InParameterSignature = GetCompactSignature(method.Overloads.Select(overload => overload.InParameters.ToArray()));
method.OutParameterSignature = GetCompactSignature(method.Overloads.Select(overload => overload.OutParameters.ToArray()));
} catch (Exception e) {
log.WarnFormat("Error determining method signature. {0} [{1}]", e.Message, method.MethodPosition);
}
}
}
}
示例5: HasInheritedPermissions
/// <summary>[AlphaFS] Check if the directory has permission inheritance enabled.</summary>
/// <returns><see langword="true"/> if permission inheritance is enabled, <see langword="false"/> if permission inheritance is disabled.</returns>
/// <param name="path">The full path to the directory to check.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
public static bool HasInheritedPermissions(string path, PathFormat pathFormat)
{
if (Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");
//DirectorySecurity acl = GetAccessControl(directoryPath);
DirectorySecurity acl = File.GetAccessControlInternal<DirectorySecurity>(true, path, AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner, pathFormat);
return acl.GetAccessRules(false, true, typeof(SecurityIdentifier)).Count > 0;
}
示例6: Replace
public FileInfo Replace(string destinationFileName, string destinationBackupFileName, PathFormat pathFormat)
{
var options = GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck;
string destinationFileNameLp = Path.GetExtendedLengthPathInternal(Transaction, destinationFileName, pathFormat, options);
string destinationBackupFileNameLp = Path.GetExtendedLengthPathInternal(Transaction, destinationBackupFileName, pathFormat, options);
File.ReplaceInternal(LongFullName, destinationFileNameLp, destinationBackupFileNameLp, false, PathFormat.LongFullPath);
return new FileInfo(Transaction, destinationFileNameLp, PathFormat.LongFullPath);
}
示例7: Shell32Info
/// <summary>Initializes a Shell32Info instance.
/// <remarks>Shell32 is limited to MAX_PATH length.</remarks>
/// <remarks>This constructor does not check if a file exists. This constructor is a placeholder for a string that is used to access the file in subsequent operations.</remarks>
/// </summary>
/// <param name="fileName">The fully qualified name of the new file, or the relative file name. Do not end the path with the directory separator character.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
public Shell32Info(string fileName, PathFormat pathFormat)
{
if (Utils.IsNullOrWhiteSpace(fileName))
throw new ArgumentNullException("fileName");
// Shell32 is limited to MAX_PATH length.
// Get a full path of regular format.
FullPath = Path.GetExtendedLengthPathInternal(null, fileName, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
Initialize();
}
示例8: GetEncryptionStatusInternal
internal static FileEncryptionStatus GetEncryptionStatusInternal(string path, PathFormat pathFormat)
{
if (pathFormat != PathFormat.LongFullPath && Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");
string pathLp = Path.GetExtendedLengthPathInternal(null, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
FileEncryptionStatus status;
// FileEncryptionStatus()
// In the ANSI version of this function, the name is limited to 248 characters.
// To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
// 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
if (!NativeMethods.FileEncryptionStatus(pathLp, out status))
NativeError.ThrowException(Marshal.GetLastWin32Error(), pathLp);
return status;
}
示例9: Move
public static void Move(string sourceFileName, string destinationFileName, PathFormat pathFormat)
{
CopyMoveInternal(false, null, sourceFileName, destinationFileName, false, null, MoveOptions.CopyAllowed, null, null, pathFormat);
}
示例10: ParseMoaiCodeFiles
private void ParseMoaiCodeFiles(DirectoryInfo moaiSourceDirectory, PathFormat messagePathFormat)
{
IEnumerable<FileInfo> codeFiles = Directory
.EnumerateFiles(moaiSourceDirectory.FullName, "*.*", SearchOption.AllDirectories)
.Where(name => name.EndsWith(".cpp") || name.EndsWith(".h"))
.Select(name => new FileInfo(name));
foreach (var codeFile in codeFiles) {
FilePosition filePosition = new FilePosition(codeFile, moaiSourceDirectory, messagePathFormat);
ParseMoaiCodeFile(codeFile, filePosition);
}
}
示例11: ReadAllLines
public static string[] ReadAllLines(string path, Encoding encoding, PathFormat pathFormat)
{
return ReadAllLinesInternal(null, path, encoding, pathFormat).ToArray();
}
示例12: Delete
public static void Delete(string path, bool ignoreReadOnly, PathFormat pathFormat)
{
DeleteFileInternal(null, path, ignoreReadOnly, pathFormat);
}
示例13: ReadAllText
public static string ReadAllText(string path, Encoding encoding, PathFormat pathFormat)
{
return ReadAllTextInternal(null, path, encoding, pathFormat);
}
示例14: ReadAllTextInternal
internal static string ReadAllTextInternal(KernelTransaction transaction, string path, Encoding encoding, PathFormat pathFormat)
{
using (StreamReader sr = new StreamReader(OpenInternal(transaction, path, FileMode.Open, 0, FileAccess.Read, FileShare.Read, ExtendedFileAttributes.SequentialScan, pathFormat), encoding))
return sr.ReadToEnd();
}
示例15: CountFileSystemObjects
public static long CountFileSystemObjects(string path, DirectoryEnumerationOptions options, PathFormat pathFormat)
{
return EnumerateFileSystemEntryInfosInternal<string>(null, path, Path.WildcardStarMatchAll, options, pathFormat).Count();
}