1
1
using System ;
2
2
using System . Collections ;
3
3
using System . Diagnostics ;
4
- using PatchKit . Unity . Patcher ;
5
- using PatchKit . Unity . Patcher . Debug ;
4
+ using System . IO ;
5
+ using PatchKit . Unity . Utilities ;
6
6
using UnityEngine ;
7
7
using UnityEngine . UI ;
8
8
@@ -17,6 +17,7 @@ public class DebugMenu : MonoBehaviour
17
17
private bool _showPopup ;
18
18
private string _popupMessage ;
19
19
private GraphicRaycaster _graphicRaycaster ;
20
+ private PlatformType _platformType ;
20
21
21
22
void Start ( )
22
23
{
@@ -29,6 +30,7 @@ void Start()
29
30
_popupRect = new Rect ( x , popupRectY , windowWidth , 120 ) ;
30
31
_texturePopupRect = new Rect ( 0 , popupRectY - y , windowWidth , 120 ) ;
31
32
_graphicRaycaster = FindObjectOfType < GraphicRaycaster > ( ) ;
33
+ _platformType = Platform . GetPlatformType ( ) ;
32
34
}
33
35
34
36
void OnGUI ( )
@@ -87,7 +89,8 @@ void Draw(int id)
87
89
OpenLauncherLogFileLocation ( ) ;
88
90
}
89
91
90
- if ( Patcher . Instance . IsAppInstalled . Value )
92
+ if ( Patcher . Instance . IsAppInstalled . Value &&
93
+ Patcher . Instance . State . Value == PatcherState . WaitingForUserDecision )
91
94
{
92
95
if ( GUILayout . Button ( "Verify all app files" ) )
93
96
{
@@ -128,14 +131,15 @@ private IEnumerator SetUserDecision(Patcher.UserDecision userDecision)
128
131
Close ( ) ;
129
132
}
130
133
131
- void OpenFile ( string path )
134
+ void OpenFileSystemEntry ( string path , bool isFile )
132
135
{
133
- try
136
+ if ( File . Exists ( path ) || Directory . Exists ( path ) )
134
137
{
135
- Process . Start ( path ) ;
138
+ var processStartInfo = GetProcessStartInfo ( path ) ;
139
+ StartProcess ( processStartInfo , isFile ) ;
136
140
Close ( ) ;
137
141
}
138
- catch ( Exception e )
142
+ else
139
143
{
140
144
OpenPopup ( string . Format ( "The directory/file cannot be found: {0}" , path ) ) ;
141
145
}
@@ -152,20 +156,36 @@ private void OpenLauncherLogFileLocation()
152
156
{
153
157
#if UNITY_EDITOR
154
158
OpenPopup ( "Access to Launcher in the editor is not possible" ) ;
159
+ #else
160
+ #if UNITY_STANDALONE_OSX
161
+ string logDirectoryPath = Patcher . Instance . Data . Value . LockFilePath . Replace (
162
+ GetHashAppSecret ( Patcher . Instance . AppSecret ) + Path . DirectorySeparatorChar + ".lock" , "" ) ;
155
163
#else
156
164
string logDirectoryPath = Patcher . Instance . Data . Value . LockFilePath . Replace ( ".lock" , "" ) ;
157
- OpenFile ( logDirectoryPath ) ;
165
+ #endif
166
+ OpenFileSystemEntry ( logDirectoryPath , false ) ;
158
167
#endif
159
168
}
160
169
161
170
private void OpenLauncherLogFile ( )
162
171
{
163
172
#if UNITY_EDITOR
164
173
OpenPopup ( "Access to Launcher in the editor is not possible" ) ;
174
+ #else
175
+ #if UNITY_STANDALONE_OSX
176
+ string logPath = Patcher . Instance . Data . Value . LockFilePath . Replace (
177
+ GetHashAppSecret ( Patcher . Instance . AppSecret ) + Path . DirectorySeparatorChar + ".lock" ,
178
+ "launcher-log.txt" ) ;
165
179
#else
166
180
string logPath = Patcher . Instance . Data . Value . LockFilePath . Replace ( ".lock" , "launcher-log.txt" ) ;
167
- OpenFile ( logPath ) ;
168
181
#endif
182
+ OpenFileSystemEntry ( logPath , true ) ;
183
+ #endif
184
+ }
185
+
186
+ public string GetHashAppSecret ( string appSecret )
187
+ {
188
+ return appSecret . Substring ( 0 , 8 ) ;
169
189
}
170
190
171
191
private void OpenPatcherLogFileLocation ( )
@@ -174,23 +194,26 @@ private void OpenPatcherLogFileLocation()
174
194
var logDirectoryPath = Application . consoleLogPath . Replace ( "Editor.log" , "" ) ;
175
195
#else
176
196
#if UNITY_STANDALONE_WIN
177
- var logDirectoryPath = string . Format ( "{0}" ,
178
- Application . persistentDataPath ) ;
197
+ var logDirectoryPath = string . Format ( "{0}" ,
198
+ Application . persistentDataPath ) ;
179
199
#elif UNITY_STANDALONE_LINUX
180
- var logDirectoryPath = string . Format ( "~/.config/unity3d/{0}/{1}" ,
181
- Application . companyName ,
182
- Application . productName ) ;
200
+ var logDirectoryPath = string . Format ( "{0}/.config/unity3d/{1}/{2}" ,
201
+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ,
202
+ Application . companyName ,
203
+ Application . productName ) ;
183
204
#elif UNITY_STANDALONE_OSX
184
205
#if UNITY_2019_1_OR_NEWER
185
- var logDirectoryPath = string . Format ( "~/Library/Logs/{0}/{1}" ,
186
- Application . companyName ,
187
- Application . productName ) ;
206
+ var logDirectoryPath = string . Format ( "{1}/Library/Logs/{2}/{3}" ,
207
+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ,
208
+ Application . companyName ,
209
+ Application . productName ) ;
188
210
#else
189
- var logDirectoryPath = "~/Library/Logs/Unity" ;
211
+ var logDirectoryPath = string . Format ( "{0}/Library/Logs/Unity" ,
212
+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ) ;
190
213
#endif
191
214
#endif
192
215
#endif
193
- OpenFile ( logDirectoryPath ) ;
216
+ OpenFileSystemEntry ( logDirectoryPath , false ) ;
194
217
}
195
218
196
219
private void OpenPatcherLogFile ( )
@@ -200,28 +223,30 @@ private void OpenPatcherLogFile()
200
223
#else
201
224
#if UNITY_STANDALONE_WIN
202
225
#if UNITY_2019_1_OR_NEWER
203
- var logPath = string . Format ( "{0}/Player.log" ,
204
- Application . persistentDataPath ) ;
226
+ var logPath = string . Format ( "{0}/Player.log" ,
227
+ Application . persistentDataPath ) ;
205
228
#else
206
- var logPath = string . Format ( "{0}/output_log.txt" ,
207
- Application . persistentDataPath ) ;
229
+ var logPath = string . Format ( "{0}/output_log.txt" ,
230
+ Application . persistentDataPath ) ;
208
231
#endif
209
232
#elif UNITY_STANDALONE_LINUX
210
- var logPath = string . Format ( "~/.config/unity3d/{0}/{1}/Player.log" ,
211
- Application . companyName ,
212
- Application . productName ) ;
233
+ var logPath = string . Format ( "{0}/.config/unity3d/{1}/{2}/Player.log" ,
234
+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ,
235
+ Application . companyName ,
236
+ Application . productName ) ;
213
237
#elif UNITY_STANDALONE_OSX
214
238
#if UNITY_2019_1_OR_NEWER
215
- var logPath = string . Format ( "~ /Library/Logs/{0}/{1}/Player.log" ,
216
- Application . companyName ,
217
- Application . productName ) ;
218
-
239
+ var logPath = string . Format ( "{0} /Library/Logs/{0}/{1}/Player.log" ,
240
+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ,
241
+ Application . companyName ,
242
+ Application . productName ) ;
219
243
#else
220
- var logPath = "~/Library/Logs/Unity/Player.log" ;
244
+ var logPath = string . Format ( "{0}/Library/Logs/Unity/Player.log" ,
245
+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ) ;
221
246
#endif
222
247
#endif
223
248
#endif
224
- OpenFile ( logPath ) ;
249
+ OpenFileSystemEntry ( logPath , true ) ;
225
250
}
226
251
227
252
void DrawPopup ( int id )
@@ -245,5 +270,52 @@ void Open()
245
270
_show = true ;
246
271
_graphicRaycaster . enabled = false ;
247
272
}
273
+
274
+ private ProcessStartInfo GetProcessStartInfo ( string executablePath )
275
+ {
276
+ string workingDir = Path . GetDirectoryName ( executablePath ) ?? string . Empty ;
277
+ switch ( _platformType )
278
+ {
279
+ case PlatformType . Unknown :
280
+ throw new ArgumentException ( "Unknown" ) ;
281
+ case PlatformType . Windows :
282
+ return new ProcessStartInfo
283
+ {
284
+ FileName = executablePath ,
285
+ WorkingDirectory = workingDir
286
+ } ;
287
+ case PlatformType . OSX :
288
+ return new ProcessStartInfo
289
+ {
290
+ FileName = "open" ,
291
+ Arguments = string . Format ( "\" {0}\" " , executablePath ) ,
292
+ WorkingDirectory = workingDir
293
+ } ;
294
+ case PlatformType . Linux :
295
+ return new ProcessStartInfo
296
+ {
297
+ FileName = executablePath ,
298
+ WorkingDirectory = workingDir
299
+ } ;
300
+ default :
301
+ throw new ArgumentOutOfRangeException ( "platform" , _platformType , null ) ;
302
+ }
303
+ }
304
+
305
+ private void StartProcess ( ProcessStartInfo processStartInfo , bool isFile )
306
+ {
307
+ DebugLogger . Log ( string . Format ( "Starting process '{0}'" , processStartInfo . FileName ) ) ;
308
+
309
+ var process = Process . Start ( processStartInfo ) ;
310
+ if ( process == null )
311
+ {
312
+ DebugLogger . LogError ( string . Format ( "Failed to start process {0}" , processStartInfo . FileName ) ) ;
313
+ }
314
+ else if ( isFile && process . HasExited )
315
+ {
316
+ DebugLogger . LogError ( string . Format ( "Process '{0}' prematurely exited with code '{1}'" ,
317
+ processStartInfo . FileName , process . ExitCode ) ) ;
318
+ }
319
+ }
248
320
}
249
- }
321
+ }
0 commit comments