2024-01-24 02:08:49 +00:00
|
|
|
namespace Guru.Editor
|
|
|
|
|
{
|
|
|
|
|
using System.IO;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class AndroidResMod
|
|
|
|
|
{
|
2024-04-09 13:00:18 +00:00
|
|
|
private static readonly string NetworkSecurityXmlName = "network_security_config.xml";
|
|
|
|
|
private static readonly string LibNetworkSecurity = "GuruNetworkSecurity";
|
|
|
|
|
private static readonly string LibNetworkSecurityPackageName = "com.guru.unity.sdk.android.res.network.security";
|
|
|
|
|
private static string OldSecurityXml = Path.Combine(Application.dataPath, $"Plugins/Android/res/xml/{NetworkSecurityXmlName}");
|
2024-01-24 02:08:49 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 应用补丁
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void Apply()
|
|
|
|
|
{
|
2024-04-09 13:00:18 +00:00
|
|
|
DeployNetworkSecurity();
|
2024-01-24 02:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-09 13:00:18 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// 部署网络安全配置
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static void DeployNetworkSecurity()
|
2024-01-24 02:08:49 +00:00
|
|
|
{
|
2024-04-09 13:00:18 +00:00
|
|
|
if(File.Exists(OldSecurityXml)) File.Delete(OldSecurityXml); // 清理旧文件
|
|
|
|
|
|
|
|
|
|
if (!AndroidLibHelper.IsEmbeddedAndroidLibExists(LibNetworkSecurity))
|
2024-01-24 02:08:49 +00:00
|
|
|
{
|
2024-04-09 13:00:18 +00:00
|
|
|
string dir = AndroidLibHelper.CreateLibRoot(LibNetworkSecurityPackageName, LibNetworkSecurity);
|
|
|
|
|
var d = GuruEditorHelper.GetAssetPath(nameof(AndroidResMod), "Script", true);
|
|
|
|
|
if (!string.IsNullOrEmpty(d))
|
2024-01-24 02:08:49 +00:00
|
|
|
{
|
2024-05-16 11:02:12 +00:00
|
|
|
var from = $"{Directory.GetParent(d)?.FullName ?? ""}/../Files/{NetworkSecurityXmlName}";
|
2024-04-09 13:00:18 +00:00
|
|
|
if (File.Exists(from))
|
2024-01-24 02:08:49 +00:00
|
|
|
{
|
2024-04-09 13:00:18 +00:00
|
|
|
string toDir = $"{dir}/res/xml";
|
|
|
|
|
if(!Directory.Exists(toDir))Directory.CreateDirectory(toDir);
|
|
|
|
|
string to = $"{toDir}/{NetworkSecurityXmlName}";
|
|
|
|
|
FileUtil.CopyFileOrDirectory(from, to);
|
2024-01-24 02:08:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-09 13:00:18 +00:00
|
|
|
}
|
2024-01-24 02:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|