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