Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Cake.Core/CakeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public DirectoryPath WorkingDirectory
set { SetWorkingDirectory(value); }
}

/// <inheritdoc/>
public DirectoryPath UserHomeDirectory { get; }

/// <inheritdoc/>
public DirectoryPath ApplicationRoot { get; }

Expand All @@ -46,6 +49,9 @@ public CakeEnvironment(ICakePlatform platform, ICakeRuntime runtime)

// Get the working directory.
WorkingDirectory = new DirectoryPath(System.IO.Directory.GetCurrentDirectory());

// Get the Home directory.
UserHomeDirectory = GetSpecialPath(SpecialPath.UserProfile);
}

/// <inheritdoc/>
Expand Down
6 changes: 6 additions & 0 deletions src/Cake.Core/ICakeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public interface ICakeEnvironment
/// <value>The working directory.</value>
DirectoryPath WorkingDirectory { get; set; }

/// <summary>
/// Gets the user's home directory.
/// </summary>
/// <value>The user's home directory.</value>
DirectoryPath UserHomeDirectory => GetSpecialPath(SpecialPath.UserProfile);

/// <summary>
/// Gets the application root path.
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion src/Cake.Core/IO/SpecialPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public enum SpecialPath
/// <summary>
/// The current user's temporary folder.
/// </summary>
LocalTemp
LocalTemp,

/// <summary>
/// The user's profile folder.
/// </summary>
UserProfile,
}
}
5 changes: 5 additions & 0 deletions src/Cake.Core/Polyfill/SpecialPathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static DirectoryPath GetFolderPath(ICakePlatform platform, SpecialPath pa
return new DirectoryPath(System.IO.Path.GetTempPath());
}

if (path == SpecialPath.UserProfile)
{
return new DirectoryPath(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
}

var result = GetXPlatFolderPath(platform, path);
if (result != null)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Cake.Testing/FakeEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public sealed class FakeEnvironment : ICakeEnvironment
/// <inheritdoc/>
public DirectoryPath WorkingDirectory { get; set; }

/// <inheritdoc/>
public DirectoryPath UserHomeDirectory { get; set; }

/// <inheritdoc/>
public DirectoryPath ApplicationRoot { get; set; }

Expand Down Expand Up @@ -67,6 +70,7 @@ public static FakeEnvironment CreateUnixEnvironment(bool is64Bit = true)
{
var environment = new FakeEnvironment(PlatformFamily.Linux, is64Bit);
environment.WorkingDirectory = new DirectoryPath("/Working");
environment.UserHomeDirectory = new DirectoryPath("/Users/CakeUser");
environment.ApplicationRoot = "/Working/bin";
return environment;
}
Expand All @@ -80,6 +84,7 @@ public static FakeEnvironment CreateWindowsEnvironment(bool is64Bit = true)
{
var environment = new FakeEnvironment(PlatformFamily.Windows, is64Bit);
environment.WorkingDirectory = new DirectoryPath("C:/Working");
environment.UserHomeDirectory = new DirectoryPath("C:/Users/CakeUser");
environment.ApplicationRoot = "C:/Working/bin";
return environment;
}
Expand Down