Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #496 from devedse/develop
Added file open helper which fixes opening files with too strict FileShare configuration
- Loading branch information
Showing
11 changed files
with
51 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.IO; | ||
|
||
/// <summary> | ||
/// Helper class for file open operations | ||
/// </summary> | ||
public static class FileOpenHelper | ||
{ | ||
/// <summary> | ||
/// Opens a file for reading without a read/write lock | ||
/// This allows other applications to read/write to the file while it is being read | ||
/// </summary> | ||
/// <param name="file">the file to open</param> | ||
/// <returns>the file stream</returns> | ||
public static FileStream OpenRead_NoLocks(string file) | ||
=> File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | ||
|
||
/// <summary> | ||
/// Opens a file for reading and writing without a read/write lock | ||
/// This allows other applications to keep reading/writing the file while it's being opened | ||
/// This is useful to check if CanRead/CanWrite is true on a file | ||
/// Actually writing to the file with this stream might have undesired effects | ||
/// </summary> | ||
/// <param name="file">the file to open</param> | ||
/// <returns>the file stream</returns> | ||
public static FileStream OpenForCheckingReadWriteAccess(string file) | ||
=> File.Open(file, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); | ||
|
||
/// <summary> | ||
/// Opens a file for writing without a write lock | ||
/// This allows other applications to read the file while it is being written to | ||
/// </summary> | ||
public static FileStream OpenWrite_NoReadLock(string file, FileMode fileMode) | ||
=> File.Open(file, fileMode, FileAccess.Write, FileShare.Read); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters