[refactor] 重构Installer

main
walon 2023-07-11 12:27:11 +08:00
parent 9b4aa904ef
commit 88404cbbfc
2 changed files with 34 additions and 65 deletions

View File

@ -93,10 +93,6 @@ namespace HybridCLR.Editor.Installer
private static readonly Regex s_unityVersionPat = new Regex(@"(\d+)\.(\d+)\.(\d+)"); private static readonly Regex s_unityVersionPat = new Regex(@"(\d+)\.(\d+)\.(\d+)");
public const int min2020_3_CompatibleMinorVersion = 26;
public const int min2021_3_CompatibleMinorVersion = 0;
public const int min2022_3_CompatibleMinorVersion = 0;
private UnityVersion ParseUnityVersion(string versionStr) private UnityVersion ParseUnityVersion(string versionStr)
{ {
var matches = s_unityVersionPat.Matches(versionStr); var matches = s_unityVersionPat.Matches(versionStr);
@ -104,9 +100,7 @@ namespace HybridCLR.Editor.Installer
{ {
return null; return null;
} }
// 找最后一个匹配的
Match match = matches[matches.Count - 1]; Match match = matches[matches.Count - 1];
// Debug.Log($"capture count:{match.Groups.Count} {match.Groups[1].Value} {match.Groups[2].Value}");
int major = int.Parse(match.Groups[1].Value); int major = int.Parse(match.Groups[1].Value);
int minor1 = int.Parse(match.Groups[2].Value); int minor1 = int.Parse(match.Groups[2].Value);
int minor2 = int.Parse(match.Groups[3].Value); int minor2 = int.Parse(match.Groups[3].Value);
@ -122,10 +116,10 @@ namespace HybridCLR.Editor.Installer
{ {
switch(majorVersion) switch(majorVersion)
{ {
case 2020: return $"2020.3.{min2020_3_CompatibleMinorVersion}"; case 2020: return $"2020.3.0";
case 2021: return $"2021.3.{min2021_3_CompatibleMinorVersion}"; case 2021: return $"2021.3.0";
case 2022: return $"2022.3.{min2022_3_CompatibleMinorVersion}"; case 2022: return $"2022.3.0";
default: return $"2020.3.{min2020_3_CompatibleMinorVersion}"; default: return $"2020.3.0";
} }
} }
@ -140,22 +134,7 @@ namespace HybridCLR.Editor.Installer
{ {
return false; return false;
} }
switch (version.major) return true;
{
case 2020:
{
return version.minor2 >= min2021_3_CompatibleMinorVersion;
}
case 2021:
{
return version.minor2 >= min2021_3_CompatibleMinorVersion;
}
case 2022:
{
return version.minor2 >= min2022_3_CompatibleMinorVersion;
}
default: throw new Exception($"not support il2cpp_plus branch:{version.major}");
}
} }
public string HybridclrLocalVersion => _curDefaultVersion?.hybridclr?.branch; public string HybridclrLocalVersion => _curDefaultVersion?.hybridclr?.branch;
@ -225,7 +204,7 @@ namespace HybridCLR.Editor.Installer
{ {
if (!IsCompatibleVersion()) if (!IsCompatibleVersion())
{ {
Debug.LogError($"il2cpp 版本不兼容,最小版本为 {GetCurrentUnityVersionMinCompatibleVersionStr()}"); Debug.LogError($"Incompatible with current version, minimum compatible version: {GetCurrentUnityVersionMinCompatibleVersionStr()}");
return; return;
} }
string workDir = SettingsUtil.HybridCLRDataDir; string workDir = SettingsUtil.HybridCLRDataDir;
@ -250,11 +229,11 @@ namespace HybridCLR.Editor.Installer
if (HasInstalledHybridCLR()) if (HasInstalledHybridCLR())
{ {
Debug.Log("安装成功"); Debug.Log("Install Sucessfully");
} }
else else
{ {
Debug.LogError("安装失败"); Debug.LogError("Installation failed!");
} }
} }
} }

View File

@ -30,7 +30,7 @@ namespace HybridCLR.Editor.Installer
height = 24 height = 24
}; };
var content = EditorGUIUtility.IconContent("Settings"); var content = EditorGUIUtility.IconContent("Settings");
content.tooltip = "点击打开HybridCLR Settings"; content.tooltip = "HybridCLR Settings";
if (GUI.Button(rect, content, GUI.skin.GetStyle("IconButton"))) if (GUI.Button(rect, content, GUI.skin.GetStyle("IconButton")))
{ {
SettingsService.OpenProjectSettings("Project/HybridCLR Settings"); SettingsService.OpenProjectSettings("Project/HybridCLR Settings");
@ -41,67 +41,57 @@ namespace HybridCLR.Editor.Installer
GUILayout.Space(10f); GUILayout.Space(10f);
EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginVertical("box");
EditorGUILayout.LabelField($"安装状态:{(hasInstall ? "" : "")}", EditorStyles.boldLabel); EditorGUILayout.LabelField($"Installed: {hasInstall}", EditorStyles.boldLabel);
GUILayout.Space(10f); GUILayout.Space(10f);
EditorGUILayout.LabelField($"Package Version: v{_controller.PackageVersion}");
EditorGUILayout.LabelField($"{SettingsUtil.PackageName} 版本: v{_controller.PackageVersion}");
GUILayout.Space(5f);
EditorGUILayout.LabelField($"hybridclr 版本: {_controller.HybridclrLocalVersion}");
GUILayout.Space(5f);
EditorGUILayout.LabelField($"il2cpp_plus 版本: {_controller.Il2cppPlusLocalVersion}");
GUILayout.Space(5f); GUILayout.Space(5f);
GUILayout.Space(10f); GUILayout.Space(10f);
if (_controller.IsCompatibleVersion()) if (_controller.IsCompatibleVersion())
{ {
GUIInstallButton("安装hybridclr+il2cpp_plus代码到本地目录", "安装"); 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)))
{
InstallLocalHybridCLR();
GUIUtility.ExitGUI();
}
EditorGUILayout.EndHorizontal();
} }
else else
{ {
EditorGUILayout.HelpBox($"与当前版本不兼容,最小兼容版本:{_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}", MessageType.Error); EditorGUILayout.HelpBox($"Incompatible with current version, minimum compatible version:{_controller.GetCurrentUnityVersionMinCompatibleVersionStr()}", MessageType.Error);
} }
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();
} }
private void GUIInstallButton(string content, string button)
{
EditorGUILayout.BeginHorizontal();
_installFromDir = EditorGUILayout.Toggle("从本地复制libil2cpp", _installFromDir);
EditorGUI.BeginDisabledGroup(!_installFromDir);
EditorGUILayout.TextField(_installLibil2cppWithHybridclrSourceDir, GUILayout.Width(400));
if (GUILayout.Button("选择目录", GUILayout.Width(100)))
{
_installLibil2cppWithHybridclrSourceDir = EditorUtility.OpenFolderPanel("选择libil2cpp目录", Application.dataPath, "libil2cpp");
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(content);
if (GUILayout.Button(button, GUILayout.Width(100)))
{
InstallLocalHybridCLR();
GUIUtility.ExitGUI();
}
EditorGUILayout.EndHorizontal();
}
private void InstallLocalHybridCLR() private void InstallLocalHybridCLR()
{ {
if (_installFromDir) if (_installFromDir)
{ {
if (!Directory.Exists(_installLibil2cppWithHybridclrSourceDir)) if (!Directory.Exists(_installLibil2cppWithHybridclrSourceDir))
{ {
Debug.LogError($"本地libil2cpp复制目录不存在. '{_installLibil2cppWithHybridclrSourceDir}'"); Debug.LogError($"Source libil2cpp:'{_installLibil2cppWithHybridclrSourceDir}' doesn't exist.");
return; return;
} }
if (!File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/il2cpp-config.h") || !File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/hybridclr/RuntimeApi.cpp")) if (!File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/il2cpp-config.h") || !File.Exists($"{_installLibil2cppWithHybridclrSourceDir}/hybridclr/RuntimeApi.cpp"))
{ {
Debug.LogError($"本地libil2cpp不是合法有效的源码目录. '{_installLibil2cppWithHybridclrSourceDir}'"); Debug.LogError($"Source libil2cpp:' {_installLibil2cppWithHybridclrSourceDir} ' is invalid");
return; return;
} }
_controller.InstallFromLocal(_installLibil2cppWithHybridclrSourceDir); _controller.InstallFromLocal(_installLibil2cppWithHybridclrSourceDir);