示例#1
0
        public static void WriteAllBytes(string path, byte[] contents)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            File.WriteAllBytes(realPath, contents);
        }
示例#2
0
        public static FileStream Create(string path, int bufferSize, FileOptions fileOptions, FileSecurity fileSecurity)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            return(File.Create(path, bufferSize, fileOptions, fileSecurity));
        }
示例#3
0
        public static void PrependAllLines(string path, List <string> contents, Encoding encoding = null)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            IList <string> oldContents = new List <string>();

            if (File.Exists(realPath))
            {
                oldContents = File.ReadAllLines(realPath)
                              .ToList();
            }
            IList <string> newContents = new List <string>(contents);

            foreach (string oldContent in oldContents)
            {
                newContents.Add(oldContent);
            }
            if (encoding == null)
            {
                File.WriteAllLines(realPath, newContents);
            }
            else
            {
                File.WriteAllLines(realPath, newContents, encoding);
            }
        }
示例#4
0
        public static FileStream Create(string path, int bufferSize)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            return(File.Create(path, bufferSize));
        }
示例#5
0
        public static FileDescriptor SaveToDisk(string path, byte[] contents, bool overwrite = false)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            if (overwrite && File.Exists(realPath))
            {
                File.Delete(realPath);
            }
            using (Stream outputStream = new FileStream(realPath, FileMode.CreateNew))
            {
                outputStream.Write(contents, 0, contents.Length);
            }
            FileGetFileDescriptorArgument fileGetFileDecriptorArgument = new FileGetFileDescriptorArgument
            {
                Path             = realPath,
                IncludePathInfo  = true,
                IncludeAttribute = true,
                IncludeMd5       = true,
                IncludeSha1      = true,
                IncludeSha256    = true,
                IncludeSha512    = true
            };
            FileDescriptor fileDescriptor = GetFileDescriptor(fileGetFileDecriptorArgument);

            return(fileDescriptor);
        }
示例#6
0
        public static FileDescriptor SaveToDisk(string path, Stream stream, bool overwrite = false)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            if (overwrite && File.Exists(realPath))
            {
                File.Delete(realPath);
            }
            using (Stream outputStream = new FileStream(realPath, FileMode.CreateNew))
            {
                if (stream.CanSeek)
                {
                    stream.Position = 0;
                }
                stream.CopyTo(outputStream, TfxCentral.BufferLength);
            }
            FileGetFileDescriptorArgument fileGetFileDecriptorArgument = new FileGetFileDescriptorArgument
            {
                Path             = realPath,
                IncludePathInfo  = true,
                IncludeAttribute = true,
                IncludeMd5       = true,
                IncludeSha1      = true,
                IncludeSha256    = true,
                IncludeSha512    = true
            };
            FileDescriptor fileDescriptor = GetFileDescriptor(fileGetFileDecriptorArgument);

            return(fileDescriptor);
        }
示例#7
0
        public static void Move(string sourcePath, string tartgetPath)
        {
            string realSourcePath = PathExpress.ResolvePath(sourcePath);
            string realTargetPath = PathExpress.ResolvePath(tartgetPath);

            DirectoryExpress.CreateParentDirectory(tartgetPath);
            File.Move(realSourcePath, realTargetPath);
        }
示例#8
0
        public static void Replace(string sourcePath, string tartgetPath, string backupPath, bool ignoreMetadataErrors = false)
        {
            string realSourcePath = PathExpress.ResolvePath(sourcePath);
            string realTargetPath = PathExpress.ResolvePath(tartgetPath);
            string realBackupPath = PathExpress.ResolvePath(backupPath);

            DirectoryExpress.CreateParentDirectory(tartgetPath);
            File.Replace(realSourcePath, realTargetPath, realBackupPath, ignoreMetadataErrors);
        }
示例#9
0
        public static void WriteAllText(string path, string contents, Encoding encoding = null)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            if (encoding == null)
            {
                File.WriteAllText(realPath, contents);
            }
            else
            {
                File.WriteAllText(realPath, contents, encoding);
            }
        }
示例#10
0
        public static void AppendAllLines(string path, IEnumerable <string> contents, Encoding encoding = null)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            if (encoding == null)
            {
                File.AppendAllLines(realPath, contents);
            }
            else
            {
                File.AppendAllLines(realPath, contents, encoding);
            }
        }
示例#11
0
        public static void ExtractManifestResources(Assembly assembly, string source, string target, bool overwrite = false)
        {
            string realTarget = PathExpress.ResolvePath(target);

            if (overwrite == false && File.Exists(realTarget))
            {
                return;
            }
            DirectoryExpress.CreateParentDirectory(realTarget);
            using (Stream reader = assembly.GetManifestResourceStream(source))
            {
                if (reader == null)
                {
                    throw new NullReferenceException(nameof(reader));
                }
                Stream writer = File.Create(realTarget);
                _ = reader.Seek(0, SeekOrigin.Begin);
                reader.CopyTo(writer);
                writer.Close();
            }
        }
示例#12
0
        private static FileStream OpenInner(string path, FileMode fileMode, FileAccess?fileAccess = null, FileShare?fileShare = null)
        {
            string realPath = PathExpress.ResolvePath(path);

            if (fileMode == FileMode.Append || fileMode == FileMode.Create || fileMode == FileMode.CreateNew || fileMode == FileMode.OpenOrCreate)
            {
                DirectoryExpress.CreateParentDirectory(realPath);
            }
            if (fileAccess == null)
            {
                return(File.Open(realPath, fileMode));
            }
            else if (fileShare == null)
            {
                return(File.Open(realPath, fileMode, fileAccess.Value));
            }
            else
            {
                return(File.Open(realPath, fileMode, fileAccess.Value, fileShare.Value));
            }
        }
示例#13
0
        public static void PrependAllText(string path, string content, Encoding encoding = null)
        {
            string realPath = PathExpress.ResolvePath(path);

            DirectoryExpress.CreateParentDirectory(realPath);
            string oldContent = string.Empty;

            if (File.Exists(realPath))
            {
                oldContent = File.ReadAllText(realPath);
            }
            string newContent = content + oldContent;

            if (encoding == null)
            {
                File.WriteAllText(realPath, newContent);
            }
            else
            {
                File.WriteAllText(realPath, newContent, encoding);
            }
        }
示例#14
0
 static DirectoryExpress()
 {
     s_instance = new DirectoryExpress();
 }