OpenFile() public method

public OpenFile ( String FileName, FileMode FileMode ) : FileSystemFileStream
FileName String
FileMode FileMode
return FileSystemFileStream
Ejemplo n.º 1
0
 static public void CopyFile(this FileSystem FileSystem, String SourcePath, String DestinationPath)
 {
     using (var SourceStream = FileSystem.OpenFile(SourcePath, FileMode.Open))
     {
         using (var DestinationStream = FileSystem.OpenFile(DestinationPath, FileMode.Create))
         {
             SourceStream.CopyToFast(DestinationStream);
         }
     }
 }
Ejemplo n.º 2
0
 static public byte[] ReadFile(this FileSystem FileSystem, String Path)
 {
     using (var FileStream = FileSystem.OpenFile(Path, FileMode.Open))
     {
         return(FileStream.ReadAll());
     }
 }
Ejemplo n.º 3
0
 static public void WriteFile(this FileSystem FileSystem, String Path, byte[] Data)
 {
     using (var FileStream = FileSystem.OpenFile(Path, FileMode.Create))
     {
         FileStream.Write(Data, 0, Data.Length);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="SourceFileSystem"></param>
        /// <param name="SourcePath"></param>
        /// <param name="DestFileSystem"></param>
        /// <param name="DestPath"></param>
        /// <param name="ActionValidate"></param>
        /// <param name="ActionProgress"></param>
        static public void CopyTree(FileSystem SourceFileSystem, String SourcePath, FileSystem DestFileSystem, String DestPath, Func <FileSystemEntry, bool> ActionValidate = null, Action <FileSystemEntry, long, long> ActionProgress = null, byte[] Buffer = null)
        {
            if (ActionValidate == null)
            {
                ActionValidate = ((Entry) => true);
            }
            if (ActionProgress == null)
            {
                ActionProgress = (Entry, Current, Max) => { }
            }
            ;
            //if (Buffer == null) Buffer = new byte[16 * 1024 * 1024];
            if (Buffer == null)
            {
                Buffer = new byte[2 * 1024 * 1024];
            }

            foreach (var SourceEntry in SourceFileSystem.FindFiles(SourcePath))
            {
                var SourceFullPath = SourcePath + "/" + SourceEntry.Name;
                var DestFullPath   = DestPath + "/" + SourceEntry.Name;

                if (!ActionValidate(SourceEntry))
                {
                    continue;
                }

                if (SourceEntry.Type == FileSystemEntry.EntryType.Directory)
                {
                    DestFileSystem.CreateDirectory(DestFullPath, 0777, false);
                    CopyTree(SourceFileSystem, SourceFullPath, DestFileSystem, DestFullPath, ActionValidate, ActionProgress, Buffer);
                }
                else
                {
                    //
                    if (
                        !DestFileSystem.Exists(DestFullPath) ||
                        (SourceFileSystem.GetFileInfo(SourceFullPath).Size != DestFileSystem.GetFileInfo(DestFullPath).Size)
                        )
                    {
                        using (var SourceStream = SourceFileSystem.OpenFileRead(SourceFullPath))
                            using (var DestStream = DestFileSystem.OpenFile(DestFullPath, FileMode.Create))
                            {
                                SourceStream.CopyToFast(DestStream, Buffer, (Current, Max) =>
                                {
                                    ActionProgress(SourceEntry, Current, Max);
                                });
                            }
                    }
                }
            }

            Buffer = null;
        }
 public int CreateFile(string filename, System.IO.FileAccess access, System.IO.FileShare share, System.IO.FileMode mode, System.IO.FileOptions options, Dokan.DokanFileInfo info)
 {
     try
     {
         info.Context = FileSystem.OpenFile(filename, mode);
         return(0);
     }
     catch (Exception e)
     {
         Console.WriteLine(" -- CreateFile Error: " + e.Message);
         info.Context = null;
         //return -1;
         return(0);
     }
     finally
     {
         NotImplemented(filename, info.Context);
     }
     //info.Context = FileSystem.OpenFile(filename, mode);
 }
Ejemplo n.º 6
0
 virtual public Stream Open(FileMode FileMode)
 {
     return(FileSystem.OpenFile(Path, FileMode));
 }
Ejemplo n.º 7
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="SourceFileSystem"></param>
		/// <param name="SourcePath"></param>
		/// <param name="DestFileSystem"></param>
		/// <param name="DestPath"></param>
		/// <param name="ActionValidate"></param>
		/// <param name="ActionProgress"></param>
		static public void CopyTree(FileSystem SourceFileSystem, String SourcePath, FileSystem DestFileSystem, String DestPath, Func<FileSystemEntry, bool> ActionValidate = null, Action<FileSystemEntry, long, long> ActionProgress = null, byte[] Buffer = null)
		{
			if (ActionValidate == null) ActionValidate = ((Entry) => true);
			if (ActionProgress == null) ActionProgress = (Entry, Current, Max) => { };
			//if (Buffer == null) Buffer = new byte[16 * 1024 * 1024];
			if (Buffer == null) Buffer = new byte[2 * 1024 * 1024];

			foreach (var SourceEntry in SourceFileSystem.FindFiles(SourcePath))
			{
				var SourceFullPath = SourcePath + "/" + SourceEntry.Name;
				var DestFullPath = DestPath + "/" + SourceEntry.Name;

				if (!ActionValidate(SourceEntry)) continue;

				if (SourceEntry.Type == FileSystemEntry.EntryType.Directory)
				{
					DestFileSystem.CreateDirectory(DestFullPath, 0777, false);
					CopyTree(SourceFileSystem, SourceFullPath, DestFileSystem, DestFullPath, ActionValidate, ActionProgress, Buffer);
				}
				else
				{
					//
					if (
						!DestFileSystem.Exists(DestFullPath) ||
						(SourceFileSystem.GetFileInfo(SourceFullPath).Size != DestFileSystem.GetFileInfo(DestFullPath).Size)
					)
					{
						using (var SourceStream = SourceFileSystem.OpenFileRead(SourceFullPath))
						using (var DestStream = DestFileSystem.OpenFile(DestFullPath, FileMode.Create))
						{
							SourceStream.CopyToFast(DestStream, Buffer, (Current, Max) =>
							{
								ActionProgress(SourceEntry, Current, Max);
							});
						}
					}
				}
			}

			Buffer = null;
		}