11using System ;
22using System . Collections ;
33using System . Diagnostics ;
4- using PatchKit . Unity . Patcher ;
5- using PatchKit . Unity . Patcher . Debug ;
4+ using System . IO ;
5+ using PatchKit . Unity . Utilities ;
66using UnityEngine ;
77using UnityEngine . UI ;
88
@@ -17,6 +17,7 @@ public class DebugMenu : MonoBehaviour
1717 private bool _showPopup ;
1818 private string _popupMessage ;
1919 private GraphicRaycaster _graphicRaycaster ;
20+ private PlatformType _platformType ;
2021
2122 void Start ( )
2223 {
@@ -29,6 +30,7 @@ void Start()
2930 _popupRect = new Rect ( x , popupRectY , windowWidth , 120 ) ;
3031 _texturePopupRect = new Rect ( 0 , popupRectY - y , windowWidth , 120 ) ;
3132 _graphicRaycaster = FindObjectOfType < GraphicRaycaster > ( ) ;
33+ _platformType = Platform . GetPlatformType ( ) ;
3234 }
3335
3436 void OnGUI ( )
@@ -87,7 +89,8 @@ void Draw(int id)
8789 OpenLauncherLogFileLocation ( ) ;
8890 }
8991
90- if ( Patcher . Instance . IsAppInstalled . Value )
92+ if ( Patcher . Instance . IsAppInstalled . Value &&
93+ Patcher . Instance . State . Value == PatcherState . WaitingForUserDecision )
9194 {
9295 if ( GUILayout . Button ( "Verify all app files" ) )
9396 {
@@ -128,14 +131,15 @@ private IEnumerator SetUserDecision(Patcher.UserDecision userDecision)
128131 Close ( ) ;
129132 }
130133
131- void OpenFile ( string path )
134+ void OpenFileSystemEntry ( string path , bool isFile )
132135 {
133- try
136+ if ( File . Exists ( path ) || Directory . Exists ( path ) )
134137 {
135- Process . Start ( path ) ;
138+ var processStartInfo = GetProcessStartInfo ( path ) ;
139+ StartProcess ( processStartInfo , isFile ) ;
136140 Close ( ) ;
137141 }
138- catch ( Exception e )
142+ else
139143 {
140144 OpenPopup ( string . Format ( "The directory/file cannot be found: {0}" , path ) ) ;
141145 }
@@ -152,20 +156,36 @@ private void OpenLauncherLogFileLocation()
152156 {
153157#if UNITY_EDITOR
154158 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" , "" ) ;
155163#else
156164 string logDirectoryPath = Patcher . Instance . Data . Value . LockFilePath . Replace ( ".lock" , "" ) ;
157- OpenFile ( logDirectoryPath ) ;
165+ #endif
166+ OpenFileSystemEntry ( logDirectoryPath , false ) ;
158167#endif
159168 }
160169
161170 private void OpenLauncherLogFile ( )
162171 {
163172#if UNITY_EDITOR
164173 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" ) ;
165179#else
166180 string logPath = Patcher . Instance . Data . Value . LockFilePath . Replace ( ".lock" , "launcher-log.txt" ) ;
167- OpenFile ( logPath ) ;
168181#endif
182+ OpenFileSystemEntry ( logPath , true ) ;
183+ #endif
184+ }
185+
186+ public string GetHashAppSecret ( string appSecret )
187+ {
188+ return appSecret . Substring ( 0 , 8 ) ;
169189 }
170190
171191 private void OpenPatcherLogFileLocation ( )
@@ -174,23 +194,26 @@ private void OpenPatcherLogFileLocation()
174194 var logDirectoryPath = Application . consoleLogPath . Replace ( "Editor.log" , "" ) ;
175195#else
176196#if UNITY_STANDALONE_WIN
177- var logDirectoryPath = string . Format ( "{0}" ,
178- Application . persistentDataPath ) ;
197+ var logDirectoryPath = string . Format ( "{0}" ,
198+ Application . persistentDataPath ) ;
179199#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 ) ;
183204#elif UNITY_STANDALONE_OSX
184205 #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 ) ;
188210 #else
189- var logDirectoryPath = "~/Library/Logs/Unity" ;
211+ var logDirectoryPath = string . Format ( "{0}/Library/Logs/Unity" ,
212+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ) ;
190213 #endif
191214#endif
192215#endif
193- OpenFile ( logDirectoryPath ) ;
216+ OpenFileSystemEntry ( logDirectoryPath , false ) ;
194217 }
195218
196219 private void OpenPatcherLogFile ( )
@@ -200,28 +223,30 @@ private void OpenPatcherLogFile()
200223#else
201224#if UNITY_STANDALONE_WIN
202225#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 ) ;
205228#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 ) ;
208231#endif
209232#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 ) ;
213237#elif UNITY_STANDALONE_OSX
214238#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 ) ;
219243#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 ) ) ;
221246#endif
222247#endif
223248#endif
224- OpenFile ( logPath ) ;
249+ OpenFileSystemEntry ( logPath , true ) ;
225250 }
226251
227252 void DrawPopup ( int id )
@@ -245,5 +270,52 @@ void Open()
245270 _show = true ;
246271 _graphicRaycaster . enabled = false ;
247272 }
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+ }
248320 }
249- }
321+ }
0 commit comments