1
1
using System ;
2
- using System . Collections . Generic ;
3
2
using System . IO ;
4
3
using System . Linq ;
5
4
using System . Reflection ;
6
- using System . Text . RegularExpressions ;
7
5
using UnityEditor ;
8
6
using UnityEngine ;
9
7
10
8
namespace GitHub . Unity
11
9
{
12
10
class Utility : ScriptableObject
13
11
{
14
- private static readonly ILogging logger = Logging . GetLogger < Utility > ( ) ;
15
-
16
- public const string StatusRenameDivider = "->" ;
17
- public static readonly Regex LogCommitRegex = new Regex ( @"commit\s(\S+)" ) ;
18
- public static readonly Regex LogMergeRegex = new Regex ( @"Merge:\s+(\S+)\s+(\S+)" ) ;
19
- public static readonly Regex LogAuthorRegex = new Regex ( @"Author:\s+(.+)\s<(.+)>" ) ;
20
- public static readonly Regex LogTimeRegex = new Regex ( @"Date:\s+(.+)" ) ;
21
- public static readonly Regex LogDescriptionRegex = new Regex ( @"^\s+(.+)" ) ;
22
- public static readonly Regex StatusStartRegex = new Regex ( @"(?<status>[AMRDC]|\?\?)(?:\d*)\s+(?<path>[\w\d\/\.\-_ \@]+)" ) ;
23
- public static readonly Regex StatusEndRegex = new Regex ( @"->\s(?<path>[\w\d\/\.\-_ ]+)" ) ;
24
- public static readonly Regex StatusBranchLineValidRegex = new Regex ( @"\#\#\s+(?:[\w\d\/\-_\.]+)" ) ;
25
- public static readonly Regex StatusAheadBehindRegex =
26
- new Regex (
27
- @"\[ahead (?<ahead>\d+), behind (?<behind>\d+)\]|\[ahead (?<ahead>\d+)\]|\[behind (?<behind>\d+>)\]" ) ;
28
-
29
- private static bool ready ;
30
- private static Action onReady ;
31
-
32
- public static void RegisterReadyCallback ( Action callback )
33
- {
34
- if ( ! ready )
35
- {
36
- onReady += callback ;
37
- }
38
- else
39
- {
40
- try
41
- {
42
- callback ( ) ;
43
- }
44
- catch ( Exception ex )
45
- {
46
- Debug . LogException ( ex ) ;
47
- }
48
-
49
- }
50
- }
51
-
52
- public static void UnregisterReadyCallback ( Action callback )
53
- {
54
- onReady -= callback ;
55
- }
56
-
57
- public static void Initialize ( )
58
- {
59
- // Evaluate project settings
60
- Issues = new List < ProjectConfigurationIssue > ( ) ;
61
- }
62
-
63
- public static void Run ( )
64
- {
65
- ready = true ;
66
- onReady . SafeInvoke ( ) ;
67
- }
68
-
69
12
public static Texture2D GetIcon ( string filename , string filename2x = "" )
70
13
{
71
14
if ( EditorGUIUtility . pixelsPerPoint > 1f && ! string . IsNullOrEmpty ( filename2x ) )
@@ -77,73 +20,9 @@ public static Texture2D GetIcon(string filename, string filename2x = "")
77
20
if ( stream != null )
78
21
return stream . ToTexture2D ( ) ;
79
22
80
- var iconPath = ExtensionInstallPath . ToNPath ( ) . Combine ( "IconsAndLogos" , filename ) . ToString ( SlashMode . Forward ) ;
23
+ var iconPath = EntryPoint . Environment . ExtensionInstallPath . Combine ( "IconsAndLogos" , filename ) . ToString ( SlashMode . Forward ) ;
81
24
return AssetDatabase . LoadAssetAtPath < Texture2D > ( iconPath ) ;
82
25
}
83
-
84
- public static Texture2D CreateTextureFromColor ( Color color )
85
- {
86
- Texture2D backgroundTexture = new Texture2D ( 1 , 1 ) ;
87
- Color c = color ;
88
- backgroundTexture . SetPixel ( 1 , 1 , c ) ;
89
- backgroundTexture . Apply ( ) ;
90
-
91
- return backgroundTexture ;
92
- }
93
-
94
- public static string GitInstallPath
95
- {
96
- get { return EntryPoint . Environment . GitExecutablePath ; }
97
- }
98
-
99
- public static string GitRoot
100
- {
101
- get { return EntryPoint . Environment . RepositoryPath ; }
102
- }
103
-
104
- public static string UnityAssetsPath
105
- {
106
- get { return EntryPoint . Environment . UnityAssetsPath ; }
107
- }
108
-
109
- public static string UnityProjectPath
110
- {
111
- get { return EntryPoint . Environment . UnityProjectPath ; }
112
- }
113
-
114
- public static string ExtensionInstallPath
115
- {
116
- get { return EntryPoint . Environment . ExtensionInstallPath ; }
117
- }
118
-
119
- public static List < ProjectConfigurationIssue > Issues { get ; protected set ; }
120
-
121
- public static bool GitFound
122
- {
123
- get { return ! string . IsNullOrEmpty ( GitInstallPath ) ; }
124
- }
125
-
126
- public static bool ActiveRepository
127
- {
128
- get { return ! string . IsNullOrEmpty ( GitRoot ) ; }
129
- }
130
-
131
- public static bool IsDevelopmentBuild
132
- {
133
- get { return File . Exists ( Path . Combine ( UnityProjectPath . Replace ( '/' , Path . DirectorySeparatorChar ) , ".devroot" ) ) ; }
134
- }
135
-
136
- public static Texture2D GetTextureFromColor ( Color color )
137
- {
138
- Color [ ] pix = new Color [ 1 ] ;
139
- pix [ 0 ] = color ;
140
-
141
- Texture2D result = new Texture2D ( 1 , 1 ) ;
142
- result . SetPixels ( pix ) ;
143
- result . Apply ( ) ;
144
-
145
- return result ;
146
- }
147
26
}
148
27
149
28
static class StreamExtensions
0 commit comments