|
1 |
| -using System; |
2 |
| -using System.Linq; |
3 |
| -using System.Net; |
| 1 | +using System.Net; |
4 | 2 | using System.Net.Security;
|
5 | 3 | using System.Security.Cryptography.X509Certificates;
|
6 | 4 | using UnityEditor;
|
7 | 5 | using UnityEngine;
|
8 |
| -using Object = UnityEngine.Object; |
9 | 6 |
|
10 | 7 | namespace GitHub.Unity
|
11 | 8 | {
|
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 |
| - |
78 | 9 | [InitializeOnLoad]
|
79 | 10 | class EntryPoint : ScriptableObject
|
80 | 11 | {
|
@@ -107,28 +38,14 @@ private static void Initialize()
|
107 | 38 | if (ApplicationCache.Instance.FirstRun)
|
108 | 39 | {
|
109 | 40 | 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); |
112 | 41 | }
|
113 | 42 |
|
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 |
| - |
124 | 43 | Logging.LoggerFactory = s => new FileLogAdapter(logPath, s);
|
125 | 44 | logger = Logging.GetLogger<EntryPoint>();
|
126 | 45 |
|
127 | 46 | Logging.Info("Initializing GitHub for Unity version " + ApplicationInfo.Version);
|
128 | 47 |
|
129 | 48 | ApplicationManager.Run();
|
130 |
| - |
131 |
| - //Logging.Trace("ApplicationCache: " + ApplicationCache.Instance.CreatedDate); |
132 | 49 | }
|
133 | 50 |
|
134 | 51 | private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate,
|
|
0 commit comments