Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 9c7c535

Browse files
authored
Merge pull request #316 from github/fixes/settings
Fix location of settings files on mac/linux
2 parents 2cd9aef + ddb1f02 commit 9c7c535

File tree

8 files changed

+23
-36
lines changed

8 files changed

+23
-36
lines changed

src/GitHub.Api/ApplicationManagerBase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext)
2525
protected void Initialize(IUIDispatcher uiDispatcher)
2626
{
2727
// accessing Environment triggers environment initialization if it hasn't happened yet
28-
LocalSettings = new LocalSettings(Environment);
29-
UserSettings = new UserSettings(Environment);
30-
SystemSettings = new SystemSettings(Environment);
31-
32-
LocalSettings.Initialize();
28+
Platform = new Platform(Environment, FileSystem, uiDispatcher);
3329

30+
UserSettings = new UserSettings(Environment);
3431
UserSettings.Initialize();
35-
3632
Logging.TracingEnabled = UserSettings.Get("EnableTraceLogging", false);
3733

34+
LocalSettings = new LocalSettings(Environment);
35+
LocalSettings.Initialize();
36+
37+
SystemSettings = new SystemSettings(Environment);
3838
SystemSettings.Initialize();
3939

40-
Platform = new Platform(Environment, FileSystem, uiDispatcher);
40+
4141
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4242
Platform.Initialize(Environment, ProcessManager);
4343
}

src/GitHub.Api/DefaultEnvironment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public string GetEnvironmentVariable(string variable)
2828
public string ExtensionInstallPath { get; set; }
2929
public NPath UserCachePath { get; set; }
3030
public NPath SystemCachePath { get; set; }
31-
public string UserProfilePath { get { return Environment.GetEnvironmentVariable("USERPROFILE"); } }
3231
public string Path { get { return Environment.GetEnvironmentVariable("PATH"); } }
3332
public string NewLine { get { return Environment.NewLine; } }
3433

src/GitHub.Api/IEnvironment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface IEnvironment
99
string GetSpecialFolder(Environment.SpecialFolder folder);
1010

1111
string Path { get; }
12-
string UserProfilePath { get; }
1312
string NewLine { get; }
1413
string GitExecutablePath { get; set; }
1514
bool IsWindows { get; }

src/GitHub.Api/LocalSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public JsonBackedSettings()
4545
public override void Initialize()
4646
{
4747
cachePath = SettingsPath.Combine(SettingsFileName);
48+
logger.Trace("Initializing settings file at {0}", cachePath);
4849
LoadFromCache(cachePath);
4950
}
5051

src/GitHub.Api/Platform/Platform.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using GitHub.Unity;
21
using System.Threading.Tasks;
32

43
namespace GitHub.Unity
@@ -10,18 +9,30 @@ public Platform(IEnvironment environment, IFileSystem filesystem, IUIDispatcher
109
Environment = environment;
1110
UIDispatcher = uiDispatcher;
1211

12+
NPath localAppData;
13+
NPath commonAppData;
1314
if (environment.IsWindows)
1415
{
1516
GitEnvironment = new WindowsGitEnvironment(environment, filesystem);
17+
localAppData = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
18+
commonAppData = Environment.GetSpecialFolder(System.Environment.SpecialFolder.CommonApplicationData).ToNPath();
1619
}
1720
else if (environment.IsMac)
1821
{
1922
GitEnvironment = new MacGitEnvironment(environment, filesystem);
23+
localAppData = NPath.HomeDirectory.Combine("Library", "Application Support");
24+
// there is no such thing on the mac that is guaranteed to be user accessible (/usr/local might not be)
25+
commonAppData = Environment.GetSpecialFolder(System.Environment.SpecialFolder.ApplicationData).ToNPath();
2026
}
2127
else
2228
{
2329
GitEnvironment = new LinuxGitEnvironment(environment, filesystem);
30+
localAppData = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
31+
commonAppData = "/usr/local/share/";
2432
}
33+
34+
Environment.UserCachePath = localAppData.Combine(ApplicationInfo.ApplicationName);
35+
Environment.SystemCachePath = commonAppData.Combine(ApplicationInfo.ApplicationName);
2536
}
2637

2738
public Task<IPlatform> Initialize(IEnvironment environment, IProcessManager processManager)

src/IntegrationTests/Git/IntegrationTestEnvironment.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,11 @@ public string UnityProjectPath
105105
public string ExtensionInstallPath
106106
{
107107
get { return extensionInstallPath; }
108-
set { throw new NotImplementedException(); }
108+
set {}
109109
}
110110

111-
public NPath UserCachePath
112-
{
113-
get
114-
{
115-
return GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData).ToNPath().Combine(ApplicationInfo.ApplicationName);
116-
}
117-
set { throw new NotImplementedException(); }
118-
}
119-
120-
public NPath SystemCachePath
121-
{
122-
get
123-
{
124-
return GetSpecialFolder(Environment.SpecialFolder.CommonApplicationData).ToNPath().Combine(ApplicationInfo.ApplicationName);
125-
}
126-
set { throw new NotImplementedException(); }
127-
}
111+
public NPath UserCachePath { get; set; }
112+
public NPath SystemCachePath { get; set; }
128113

129114
public string RepositoryPath { get; set; }
130115

src/TestUtils/Substitutes/SubstituteFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public IEnvironment CreateEnvironment(CreateEnvironmentOptions createEnvironment
2525
var environment = Substitute.For<IEnvironment>();
2626
environment.RepositoryPath.Returns(createEnvironmentOptions.RepositoryPath);
2727
environment.ExtensionInstallPath.Returns(createEnvironmentOptions.Extensionfolder);
28-
environment.UserProfilePath.Returns(createEnvironmentOptions.UserProfilePath);
2928
environment.UnityProjectPath.Returns(createEnvironmentOptions.UnityProjectPath);
3029
environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).Returns(localAppData);
3130
environment.GetSpecialFolder(System.Environment.SpecialFolder.ApplicationData).Returns(appData);

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ protected override void InitializeEnvironment()
8484
Environment.UnityAssetsPath = assetsPath.ToString(SlashMode.Forward);
8585
Environment.UnityProjectPath = projectPath.ToString(SlashMode.Forward);
8686

87-
Environment.UserCachePath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData)
88-
.ToNPath()
89-
.Combine(ApplicationInfo.ApplicationName);
90-
Environment.SystemCachePath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.CommonApplicationData)
91-
.ToNPath()
92-
.Combine(ApplicationInfo.ApplicationName);
93-
9487
base.InitializeEnvironment();
9588
}
9689

0 commit comments

Comments
 (0)