2022-09-22 08:56:07 +08:00
using System ;
2023-04-29 12:11:16 +08:00
using System.IO ;
2022-10-09 03:25:56 +08:00
using System.Reflection ;
using UnityEditor ;
2022-09-22 08:56:07 +08:00
using UnityEngine ;
2022-10-09 03:25:56 +08:00
2022-09-22 08:56:07 +08:00
namespace HybridCLR.Editor.Installer
{
public class InstallerWindow : EditorWindow
{
2022-12-06 11:52:47 +08:00
private InstallerController _controller ;
2022-09-22 08:56:07 +08:00
2023-04-29 12:11:16 +08:00
private bool _installFromDir ;
private string _installLibil2cppWithHybridclrSourceDir ;
2022-09-22 08:56:07 +08:00
private void OnEnable ( )
{
2022-12-06 11:52:47 +08:00
_controller = new InstallerController ( ) ;
2022-09-22 08:56:07 +08:00
}
private void OnGUI ( )
{
2022-10-09 03:25:56 +08:00
var rect = new Rect
{
x = EditorGUIUtility . currentViewWidth - 24 ,
y = 5 ,
width = 24 ,
height = 24
} ;
var content = EditorGUIUtility . IconContent ( "Settings" ) ;
2023-07-11 12:27:11 +08:00
content . tooltip = "HybridCLR Settings" ;
2022-10-09 03:25:56 +08:00
if ( GUI . Button ( rect , content , GUI . skin . GetStyle ( "IconButton" ) ) )
{
SettingsService . OpenProjectSettings ( "Project/HybridCLR Settings" ) ;
}
2022-11-28 12:20:52 +08:00
2023-01-26 13:11:38 +08:00
bool hasInstall = _controller . HasInstalledHybridCLR ( ) ;
2022-09-22 08:56:07 +08:00
GUILayout . Space ( 10f ) ;
2022-11-09 11:28:09 +08:00
2022-09-22 08:56:07 +08:00
EditorGUILayout . BeginVertical ( "box" ) ;
2023-07-11 12:27:11 +08:00
EditorGUILayout . LabelField ( $"Installed: {hasInstall}" , EditorStyles . boldLabel ) ;
2023-01-26 13:11:38 +08:00
GUILayout . Space ( 10f ) ;
2022-11-28 12:20:52 +08:00
2023-07-11 12:27:11 +08:00
EditorGUILayout . LabelField ( $"Package Version: v{_controller.PackageVersion}" ) ;
2023-01-26 13:11:38 +08:00
GUILayout . Space ( 5f ) ;
2023-10-15 12:44:22 +08:00
EditorGUILayout . LabelField ( $"Installed libil2cpp Version: {_controller.InstalledLibil2cppVersion ?? " Unknown "}" ) ;
GUILayout . Space ( 5f ) ;
2022-09-22 08:56:07 +08:00
GUILayout . Space ( 10f ) ;
2022-11-28 12:20:52 +08:00
2023-09-17 23:30:09 +08:00
InstallerController . CompatibleType compatibleType = _controller . GetCompatibleType ( ) ;
if ( compatibleType ! = InstallerController . CompatibleType . Incompatible )
2023-06-12 13:30:32 +08:00
{
2023-09-17 23:30:09 +08:00
if ( compatibleType = = InstallerController . CompatibleType . MaybeIncompatible )
{
EditorGUILayout . HelpBox ( $"Maybe incompatible with current version, recommend minimum compatible version:{_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}" , MessageType . Warning ) ;
}
2023-07-11 12:27:11 +08:00
EditorGUILayout . BeginHorizontal ( ) ;
_installFromDir = EditorGUILayout . Toggle ( "Copy libil2cpp from local" , _installFromDir , GUILayout . MinWidth ( 100 ) ) ;
EditorGUI . BeginDisabledGroup ( ! _installFromDir ) ;
EditorGUILayout . TextField ( _installLibil2cppWithHybridclrSourceDir , GUILayout . Width ( 400 ) ) ;
if ( GUILayout . Button ( "Choose" , GUILayout . Width ( 100 ) ) )
{
_installLibil2cppWithHybridclrSourceDir = EditorUtility . OpenFolderPanel ( "Select libil2cpp" , Application . dataPath , "libil2cpp" ) ;
}
EditorGUI . EndDisabledGroup ( ) ;
EditorGUILayout . EndHorizontal ( ) ;
2022-11-28 12:20:52 +08:00
2023-07-11 12:27:11 +08:00
GUILayout . Space ( 20f ) ;
2022-09-22 08:56:07 +08:00
2023-07-11 12:27:11 +08:00
EditorGUILayout . BeginHorizontal ( ) ;
if ( GUILayout . Button ( "Install" , GUILayout . Width ( 100 ) ) )
{
InstallLocalHybridCLR ( ) ;
GUIUtility . ExitGUI ( ) ;
}
EditorGUILayout . EndHorizontal ( ) ;
2023-04-29 12:11:16 +08:00
}
2023-07-11 12:27:11 +08:00
else
2022-09-22 08:56:07 +08:00
{
2023-07-11 12:27:11 +08:00
EditorGUILayout . HelpBox ( $"Incompatible with current version, minimum compatible version:{_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}" , MessageType . Error ) ;
2022-09-22 08:56:07 +08:00
}
2022-10-09 03:25:56 +08:00
2023-07-11 12:27:11 +08:00
EditorGUILayout . EndVertical ( ) ;
2022-09-22 08:56:07 +08:00
}
2022-12-06 11:52:47 +08:00
private void InstallLocalHybridCLR ( )
2022-10-25 17:26:21 +08:00
{
2023-04-29 12:11:16 +08:00
if ( _installFromDir )
{
if ( ! Directory . Exists ( _installLibil2cppWithHybridclrSourceDir ) )
{
2023-07-11 12:27:11 +08:00
Debug . LogError ( $"Source libil2cpp:'{_installLibil2cppWithHybridclrSourceDir}' doesn't exist." ) ;
2023-04-29 12:11:16 +08:00
return ;
}
if ( ! File . Exists ( $"{_installLibil2cppWithHybridclrSourceDir}/il2cpp-config.h" ) | | ! File . Exists ( $"{_installLibil2cppWithHybridclrSourceDir}/hybridclr/RuntimeApi.cpp" ) )
{
2023-07-11 12:27:11 +08:00
Debug . LogError ( $"Source libil2cpp:' {_installLibil2cppWithHybridclrSourceDir} ' is invalid" ) ;
2023-04-29 12:11:16 +08:00
return ;
}
2023-05-03 12:22:16 +08:00
_controller . InstallFromLocal ( _installLibil2cppWithHybridclrSourceDir ) ;
}
else
{
_controller . InstallDefaultHybridCLR ( ) ;
2023-04-29 12:11:16 +08:00
}
2022-10-25 17:26:21 +08:00
}
2022-09-22 08:56:07 +08:00
}
}