-
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #68 from ricaun-io/develop
Version 1.7.2
- Loading branch information
Showing
5 changed files
with
123 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace ricaun.Nuke.Extensions | ||
{ | ||
/// <summary> | ||
/// PathTooLongUtils | ||
/// </summary> | ||
public class PathTooLongUtils | ||
{ | ||
/// <summary> | ||
/// MAX_PATH | ||
/// </summary> | ||
public const int MAX_PATH = 260; | ||
/// <summary> | ||
/// FileMoveToTempUtils | ||
/// </summary> | ||
public class FileMoveToTemp : IDisposable | ||
{ | ||
private readonly string filePath; | ||
private string tempFilePath; | ||
/// <summary> | ||
/// FileMoveToTempUtils | ||
/// </summary> | ||
/// <param name="filePath"></param> | ||
public FileMoveToTemp(string filePath) | ||
{ | ||
this.filePath = filePath; | ||
Initialize(); | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
if (IsPathTooLong()) | ||
{ | ||
tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetFileName(this.filePath)); | ||
File.Move(this.filePath, tempFilePath, true); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// GetFilePathLong | ||
/// </summary> | ||
/// <returns></returns> | ||
public int GetFilePathLong() | ||
{ | ||
return GetFilePath().Length; | ||
} | ||
|
||
/// <summary> | ||
/// Check if path is too long | ||
/// </summary> | ||
/// <returns></returns> | ||
public bool IsPathTooLong() | ||
{ | ||
return GetFilePathLong() > MAX_PATH; | ||
} | ||
|
||
/// <summary> | ||
/// GetFilePath | ||
/// </summary> | ||
/// <returns></returns> | ||
public string GetFilePath() | ||
{ | ||
return tempFilePath ?? filePath; | ||
} | ||
|
||
/// <summary> | ||
/// Dispose | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
if (tempFilePath is null) | ||
return; | ||
|
||
File.Move(tempFilePath, filePath, true); | ||
} | ||
} | ||
} | ||
} |
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