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

Commit f0258a4

Browse files
Final bit of cleanup
1 parent 6c1ab1a commit f0258a4

File tree

3 files changed

+83
-84
lines changed

3 files changed

+83
-84
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using UnityEditorInternal;
5+
using UnityEngine;
6+
using Object = UnityEngine.Object;
7+
8+
namespace GitHub.Unity
9+
{
10+
sealed class ApplicationCache : ScriptableObject, ISerializationCallbackReceiver
11+
{
12+
private static ApplicationCache instance;
13+
private static string cachePath;
14+
15+
[SerializeField] private bool firstRun = true;
16+
public bool FirstRun
17+
{
18+
get { return firstRun; }
19+
private set
20+
{
21+
firstRun = value;
22+
Flush();
23+
}
24+
}
25+
26+
[SerializeField] private string createdDate;
27+
public string CreatedDate
28+
{
29+
get { return createdDate; }
30+
}
31+
32+
public static ApplicationCache Instance
33+
{
34+
get { return instance ?? CreateApplicationCache(EntryPoint.Environment); }
35+
}
36+
37+
private static ApplicationCache CreateApplicationCache(IEnvironment environment)
38+
{
39+
cachePath = environment.UnityProjectPath + "/Temp/github_cache.yaml";
40+
41+
if (File.Exists(cachePath))
42+
{
43+
var objects = InternalEditorUtility.LoadSerializedFileAndForget(cachePath);
44+
if (objects.Any())
45+
{
46+
instance = objects[0] as ApplicationCache;
47+
if (instance != null)
48+
{
49+
if (instance.FirstRun)
50+
{
51+
instance.FirstRun = false;
52+
}
53+
54+
return instance;
55+
}
56+
}
57+
}
58+
59+
instance = CreateInstance<ApplicationCache>();
60+
instance.createdDate = DateTime.Now.ToLongTimeString();
61+
instance.Flush();
62+
63+
return instance;
64+
}
65+
66+
private void Flush()
67+
{
68+
InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { this }, cachePath, true);
69+
}
70+
71+
void ISerializationCallbackReceiver.OnBeforeSerialize()
72+
{
73+
Debug.LogFormat("ApplicationCache OnBeforeSerialize {0} {1}", firstRun, GetInstanceID());
74+
}
75+
76+
void ISerializationCallbackReceiver.OnAfterDeserialize()
77+
{
78+
Debug.LogFormat("ApplicationCache OnAfterDeserialize {0} {1}", firstRun, GetInstanceID());
79+
}
80+
}
81+
}

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

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,11 @@
1-
using System;
2-
using System.Linq;
3-
using System.Net;
1+
using System.Net;
42
using System.Net.Security;
53
using System.Security.Cryptography.X509Certificates;
64
using UnityEditor;
75
using UnityEngine;
8-
using Object = UnityEngine.Object;
96

107
namespace GitHub.Unity
118
{
12-
internal sealed class ApplicationCache : ScriptableObject, ISerializationCallbackReceiver
13-
{
14-
private static ApplicationCache instance;
15-
private static string cachePath;
16-
17-
[SerializeField] private bool firstRun = true;
18-
public bool FirstRun { get { return firstRun; } private set { firstRun = value; Flush(); } }
19-
[SerializeField] private string createdDate;
20-
public string CreatedDate { get { return createdDate; } }
21-
22-
public static ApplicationCache Instance {
23-
get {
24-
return instance ?? CreateApplicationCache(EntryPoint.Environment);
25-
}
26-
}
27-
28-
private static ApplicationCache CreateApplicationCache(IEnvironment environment)
29-
{
30-
cachePath = environment.UnityProjectPath + "/Temp/github_cache.yaml";
31-
32-
if (System.IO.File.Exists(cachePath))
33-
{
34-
Debug.Log("Loading from cache");
35-
36-
var objects = UnityEditorInternal.InternalEditorUtility.LoadSerializedFileAndForget(cachePath);
37-
if (objects.Any())
38-
{
39-
instance = objects[0] as ApplicationCache;
40-
if (instance != null)
41-
{
42-
Debug.LogFormat("Loading from cache successful {0}", instance);
43-
if (instance.FirstRun)
44-
instance.FirstRun = false;
45-
return instance;
46-
}
47-
}
48-
}
49-
50-
Debug.Log("Creating instance");
51-
instance = CreateInstance<ApplicationCache>();
52-
return instance.Initialize();
53-
}
54-
55-
private ApplicationCache Initialize()
56-
{
57-
createdDate = DateTime.Now.ToLongTimeString();
58-
Flush();
59-
return this;
60-
}
61-
62-
private void Flush()
63-
{
64-
UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { this }, cachePath, true);
65-
}
66-
67-
void ISerializationCallbackReceiver.OnBeforeSerialize()
68-
{
69-
Debug.LogFormat("ApplicationCache OnBeforeSerialize {0} {1}", firstRun, GetInstanceID());
70-
}
71-
72-
void ISerializationCallbackReceiver.OnAfterDeserialize()
73-
{
74-
Debug.LogFormat("ApplicationCache OnAfterDeserialize {0} {1}", firstRun, GetInstanceID());
75-
}
76-
}
77-
789
[InitializeOnLoad]
7910
class EntryPoint : ScriptableObject
8011
{
@@ -107,28 +38,14 @@ private static void Initialize()
10738
if (ApplicationCache.Instance.FirstRun)
10839
{
10940
Logging.Info("Initializing GitHub for Unity version " + ApplicationInfo.Version);
110-
//Logging.Info("ApplicationCache: " + ApplicationCache.Instance.CreatedDate);
111-
Logging.Info("Initializing GitHub for Unity log file: " + logPath);
11241
}
11342

114-
//try
115-
//{
116-
// if (logPath.FileExists())
117-
// {
118-
// logPath.Move(logPath.Parent.Combine(string.Format("github-unity-{0}.log"), System.DateTime.Now.ToString("s")));
119-
// }
120-
//}
121-
//catch
122-
//{}
123-
12443
Logging.LoggerFactory = s => new FileLogAdapter(logPath, s);
12544
logger = Logging.GetLogger<EntryPoint>();
12645

12746
Logging.Info("Initializing GitHub for Unity version " + ApplicationInfo.Version);
12847

12948
ApplicationManager.Run();
130-
131-
//Logging.Trace("ApplicationCache: " + ApplicationCache.Instance.CreatedDate);
13249
}
13350

13451
private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate,

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
</Reference>
7373
</ItemGroup>
7474
<ItemGroup>
75+
<Compile Include="ApplicationCache.cs" />
7576
<Compile Include="ApplicationManager.cs" />
7677
<Compile Include="Extensions\ActionExtensions.cs" />
7778
<Compile Include="Misc\RepositoryInitializer.cs" />

0 commit comments

Comments
 (0)