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

Commit b61570f

Browse files
committed
Make settings work
Add paths properties to environment for common places where we store things. Fix json serialization Remove unneeded code
1 parent 1d1be86 commit b61570f

File tree

10 files changed

+32
-43
lines changed

10 files changed

+32
-43
lines changed

src/GitHub.Api/AppConfiguration.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,11 @@ class AppConfiguration : IAppConfiguration
88
{
99
public AppConfiguration()
1010
{
11-
applicationName = ApplicationInfo.ApplicationName;
12-
applicationDescription = ApplicationInfo.ApplicationDescription;
13-
1411
var executingAssembly = typeof(AppConfiguration).Assembly;
1512
AssemblyName = executingAssembly.GetName();
1613
ProductHeader = new ProductHeaderValue(ApplicationInfo.ApplicationSafeName, AssemblyName.Version.ToString());
1714
}
1815

19-
readonly string applicationName;
20-
readonly string applicationDescription;
21-
22-
/// <summary>
23-
/// Name of this application
24-
/// </summary>
25-
public string ApplicationName { get { return applicationName; } }
26-
27-
/// <summary>
28-
/// Name of this application
29-
/// </summary>
30-
public string ApplicationDescription { get { return applicationDescription; } }
31-
3216
/// <summary>
3317
/// The currently executing assembly.
3418
/// </summary>

src/GitHub.Api/ApplicationManagerBase.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ protected void Initialize(IUIDispatcher uiDispatcher)
2626
{
2727
// accessing Environment triggers environment initialization if it hasn't happened yet
2828
LocalSettings = new LocalSettings(Environment);
29-
UserSettings = new UserSettings(Environment, ApplicationInfo.ApplicationName);
30-
SystemSettings = new SystemSettings(Environment, ApplicationInfo.ApplicationName);
29+
UserSettings = new UserSettings(Environment);
30+
SystemSettings = new SystemSettings(Environment);
3131

3232
LocalSettings.Initialize();
3333

3434
UserSettings.Initialize();
3535

36-
#if !DEVELOPER_BUILD
3736
Logging.TracingEnabled = UserSettings.Get("EnableTraceLogging", false);
38-
#endif
3937

4038
SystemSettings.Initialize();
4139

src/GitHub.Api/Authentication/Keychain.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class ConnectionCacheItem
2828
/// </summary>
2929
class Keychain : IKeychain
3030
{
31+
const string ConnectionFile = "connections.json";
32+
3133
private readonly ILogging logger = Logging.GetLogger<Keychain>();
3234

3335
private readonly ICredentialManager credentialManager;
@@ -42,7 +44,7 @@ class Keychain : IKeychain
4244

4345
public Keychain(IEnvironment environment, ICredentialManager credentialManager)
4446
{
45-
cachePath = environment.ConnectionCachePath;
47+
cachePath = environment.UserCachePath.Combine(ConnectionFile);
4648
this.credentialManager = credentialManager;
4749
}
4850

src/GitHub.Api/DefaultEnvironment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public string GetEnvironmentVariable(string variable)
2626
public string UnityAssetsPath { get; set; }
2727
public string UnityProjectPath { get; set; }
2828
public string ExtensionInstallPath { get; set; }
29-
public NPath ConnectionCachePath { get; set; }
29+
public NPath UserCachePath { get; set; }
30+
public NPath SystemCachePath { get; set; }
3031
public string UserProfilePath { get { return Environment.GetEnvironmentVariable("USERPROFILE"); } }
3132
public string Path { get { return Environment.GetEnvironmentVariable("PATH"); } }
3233
public string NewLine { get { return Environment.NewLine; } }

src/GitHub.Api/IAppConfiguration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ namespace GitHub.Unity
66
// Represents the currently executing program.
77
interface IAppConfiguration
88
{
9-
string ApplicationName { get; }
10-
string ApplicationDescription { get; }
119
AssemblyName AssemblyName { get; }
1210
ProductHeaderValue ProductHeader { get; }
1311
}

src/GitHub.Api/IEnvironment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ interface IEnvironment
1919
string UnityAssetsPath { get; set; }
2020
string UnityProjectPath { get; set; }
2121
string ExtensionInstallPath { get; set; }
22-
NPath ConnectionCachePath { get; set; }
22+
NPath UserCachePath { get; set; }
2323
string RepositoryPath { get; }
2424
string GitInstallPath { get; }
2525
IRepository Repository { get; set; }
26+
NPath SystemCachePath { get; set; }
2627
}
2728
}

src/GitHub.Api/LocalSettings.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class BaseSettings : ISettings
1616
public abstract void Unset(string key);
1717

1818
protected virtual string SettingsFileName { get; set; }
19-
protected virtual string SettingsPath { get; set; }
19+
protected virtual NPath SettingsPath { get; set; }
2020
}
2121

2222
class JsonBackedSettings : BaseSettings
@@ -44,7 +44,7 @@ public JsonBackedSettings()
4444

4545
public override void Initialize()
4646
{
47-
cachePath = Path.Combine(SettingsPath, SettingsFileName);
47+
cachePath = SettingsPath.Combine(SettingsFileName);
4848
LoadFromCache(cachePath);
4949
}
5050

@@ -157,7 +157,7 @@ private void EnsureCachePath(string cachePath)
157157

158158
private class CacheData
159159
{
160-
public Dictionary<string, object> GitHubUnity = new Dictionary<string, object>();
160+
public Dictionary<string, object> GitHubUnity { get; set; } = new Dictionary<string, object>();
161161
}
162162

163163
}
@@ -179,9 +179,9 @@ class UserSettings : JsonBackedSettings
179179
{
180180
private const string settingsFileName = "settings.json";
181181

182-
public UserSettings(IEnvironment environment, string path)
182+
public UserSettings(IEnvironment environment)
183183
{
184-
SettingsPath = environment.GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData).ToNPath().Combine(path);
184+
SettingsPath = environment.UserCachePath;
185185
}
186186

187187
protected override string SettingsFileName { get { return settingsFileName; } }
@@ -191,9 +191,9 @@ class SystemSettings : JsonBackedSettings
191191
{
192192
private const string settingsFileName = "settings.json";
193193

194-
public SystemSettings(IEnvironment environment, string path)
194+
public SystemSettings(IEnvironment environment)
195195
{
196-
SettingsPath = environment.GetSpecialFolder(Environment.SpecialFolder.ApplicationData).ToNPath().Combine(path);
196+
SettingsPath = environment.SystemCachePath;
197197
}
198198

199199
protected override string SettingsFileName { get { return settingsFileName; } }

src/GitHub.Logging/Logging.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ namespace GitHub.Unity
44
{
55
public static class Logging
66
{
7-
static Logging()
8-
{
9-
#if DEVELOPER_BUILD
10-
tracingEnabled = true;
11-
#endif
12-
}
13-
147
private static bool tracingEnabled;
158

169
public static bool TracingEnabled

src/IntegrationTests/Git/IntegrationTestEnvironment.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,20 @@ public string ExtensionInstallPath
108108
set { throw new NotImplementedException(); }
109109
}
110110

111-
public NPath ConnectionCachePath
111+
public NPath UserCachePath
112112
{
113113
get
114114
{
115-
return GetSpecialFolder(Environment.SpecialFolder.LocalApplicationData).ToNPath().Combine("connections.json");
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);
116125
}
117126
set { throw new NotImplementedException(); }
118127
}

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

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

87-
Environment.ConnectionCachePath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData)
87+
Environment.UserCachePath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData)
8888
.ToNPath()
89-
.Combine(AppConfiguration.ApplicationName, "connections.json");
89+
.Combine(ApplicationInfo.ApplicationName);
90+
Environment.SystemCachePath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.CommonApplicationData)
91+
.ToNPath()
92+
.Combine(ApplicationInfo.ApplicationName);
9093

9194
base.InitializeEnvironment();
9295
}

0 commit comments

Comments
 (0)