-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #3631 Check free space before downloading
- Loading branch information
Showing
18 changed files
with
180 additions
and
32 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
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,54 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
|
||
namespace CKAN.Extensions | ||
{ | ||
public static class IOExtensions | ||
{ | ||
|
||
private static bool StringArrayStartsWith(string[] child, string[] parent) | ||
{ | ||
if (parent.Length > child.Length) | ||
// Only child is allowed to have extra pieces | ||
return false; | ||
var opt = Platform.IsWindows ? StringComparison.InvariantCultureIgnoreCase | ||
: StringComparison.InvariantCulture; | ||
for (int i = 0; i < parent.Length; ++i) { | ||
if (!parent[i].Equals(child[i], opt)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Check whether a given path is an ancestor of another | ||
/// </summary> | ||
/// <param name="parent">The path to treat as potential ancestor</param> | ||
/// <param name="child">The path to treat as potential descendant</param> | ||
/// <returns>true if child is a descendant of parent, false otherwise</returns> | ||
public static bool IsAncestorOf(this DirectoryInfo parent, DirectoryInfo child) | ||
=> StringArrayStartsWith( | ||
child.FullName.Split(new char[] {Path.DirectorySeparatorChar}, | ||
StringSplitOptions.RemoveEmptyEntries), | ||
parent.FullName.Split(new char[] {Path.DirectorySeparatorChar}, | ||
StringSplitOptions.RemoveEmptyEntries)); | ||
|
||
/// <summary> | ||
/// Extension method to fill in the gap of getting from a | ||
/// directory to its drive in .NET. | ||
/// Returns the drive with the longest RootDirectory.FullName | ||
/// that's a prefix of the dir's FullName. | ||
/// </summary> | ||
/// <param name="dir">Any DirectoryInfo object</param> | ||
/// <returns>The DriveInfo associated with this directory</returns> | ||
public static DriveInfo GetDrive(this DirectoryInfo dir) | ||
=> DriveInfo.GetDrives() | ||
.Where(dr => dr.RootDirectory.IsAncestorOf(dir)) | ||
.OrderByDescending(dr => dr.RootDirectory.FullName.Length) | ||
.FirstOrDefault(); | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
|
||
namespace CKAN | ||
{ | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
|
||
namespace CKAN.GUI | ||
|
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
Oops, something went wrong.