hybridclr_unity_v8150/Editor/Installer/InstallerWindow.cs

121 lines
4.5 KiB
C#
Raw Normal View History

// Copyright 2026 Code Philosophy
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.IO;
using UnityEditor;
2022-09-22 08:56:07 +08:00
using UnityEngine;
2022-09-22 08:56:07 +08:00
namespace HybridCLR.Installer
2022-09-22 08:56:07 +08:00
{
public class InstallerWindow : EditorWindow
{
private InstallerController _controller;
2022-09-22 08:56:07 +08:00
private bool _installFromDir;
private string _installLibil2cppWithHybridclrSourceDir;
2022-09-22 08:56:07 +08:00
private void OnEnable()
{
_controller = new InstallerController();
2022-09-22 08:56:07 +08:00
}
private void OnGUI()
{
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";
if (GUI.Button(rect, content, GUI.skin.GetStyle("IconButton")))
{
SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
}
bool hasInstall = _controller.HasInstalledHybridCLR();
2022-09-22 08:56:07 +08:00
GUILayout.Space(10f);
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);
GUILayout.Space(10f);
2024-02-28 14:20:39 +08:00
EditorGUILayout.LabelField($"Package Version: v{_controller.PackageVersion}");
GUILayout.Space(5f);
2024-02-28 14:20:39 +08:00
EditorGUILayout.LabelField($"Installed Version: v{_controller.InstalledLibil2cppVersion ?? " Unknown"}");
GUILayout.Space(5f);
2022-09-22 08:56:07 +08:00
GUILayout.Space(10f);
2022-09-22 08:56:07 +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();
GUILayout.Space(20f);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Install", GUILayout.Width(100)))
2022-09-22 08:56:07 +08:00
{
InstallLocalHybridCLR();
GUIUtility.ExitGUI();
2022-09-22 08:56:07 +08:00
}
EditorGUILayout.EndHorizontal();
2023-07-11 12:27:11 +08:00
EditorGUILayout.EndVertical();
2022-09-22 08:56:07 +08:00
}
private void InstallLocalHybridCLR()
{
if (_installFromDir)
{
if (!Directory.Exists(_installLibil2cppWithHybridclrSourceDir))
{
2023-07-11 12:27:11 +08:00
Debug.LogError($"Source libil2cpp:'{_installLibil2cppWithHybridclrSourceDir}' doesn't exist.");
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");
return;
}
_controller.InstallFromLocal(_installLibil2cppWithHybridclrSourceDir);
}
else
{
_controller.InstallDefaultHybridCLR();
}
}
2022-09-22 08:56:07 +08:00
}
}