NxrApkEncryptionEditor.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace Nxr.Internal
  4. {
  5. public class NxrApkEncryptionEditor : EditorWindow
  6. {
  7. string sdkurl = " https://dev.inibiru.com/#/download/pro";
  8. bool EnableEncryption = false;
  9. bool IsHasChecked;
  10. // <!-- 当前APK为加密版本,需要进行验证设备唯一标识 -->
  11. //<meta-data android:value="1" android:name="NIBIRU_ENCRYPTION_MODE"/>
  12. bool CheckEncryption()
  13. {
  14. string data = NxrPluginEditor.Read("AndroidManifest.xml");
  15. string[] lines = data.Split('\n');
  16. for (int i = 0, l = lines.Length; i < l; i++)
  17. {
  18. string lineContent = lines[i];
  19. if (lineContent.Contains("NIBIRU_ENCRYPTION_MODE"))
  20. {
  21. return lineContent.Contains("1");
  22. }
  23. }
  24. return false;
  25. }
  26. private void OnGUI()
  27. {
  28. if (!IsHasChecked)
  29. {
  30. IsHasChecked = true;
  31. EnableEncryption = CheckEncryption();
  32. }
  33. GUILayout.Space(20);
  34. GUIStyle labelStyle = new GUIStyle();
  35. labelStyle.normal.textColor = new Color(220 / 255.0f, 20 / 255.0f, 60 / 255.0f, 1.0f);
  36. labelStyle.fontSize = 13;
  37. GUILayout.Label(" APK Encryption: \n\n Step1: Use NibiruEncrypt Tool generate Encrypt Key file name is apkpass.txt.\n Step2: Put apkpass.txt to Assets\\Plugins\\Android\\assets.",
  38. labelStyle);
  39. GUILayout.Space(20);
  40. EditorGUILayout.Space();
  41. EditorGUILayout.LabelField("Get the lastest version of Tool:");
  42. GUIStyle style = new GUIStyle();
  43. style.normal.textColor = new Color(0, 122f / 255f, 204f / 255f);
  44. if (GUILayout.Button(sdkurl, style, GUILayout.Width(200)))
  45. {
  46. Application.OpenURL(sdkurl);
  47. }
  48. GUILayout.Space(20);
  49. EnableEncryption = GUILayout.Toggle(EnableEncryption, "Enable APK Encryption");
  50. GUILayout.Space(20);
  51. bool ApkPassExist = NxrPluginEditor.IsFileExists("assets/apkpass.txt");
  52. if (!ApkPassExist)
  53. {
  54. GUILayout.Label(" [Warning] apkpass.txt is not exist. [Warning] ", labelStyle);
  55. GUILayout.Space(20);
  56. }
  57. if (GUILayout.Button("Confirm", GUILayout.Width(100), GUILayout.Height(30)))
  58. {
  59. {
  60. string data = NxrPluginEditor.Read("AndroidManifest.xml");
  61. string[] lines = data.Split('\n');
  62. string newdata = "";
  63. for (int i = 0, l = lines.Length; i < l; i++)
  64. {
  65. string lineContent = lines[i];
  66. if (lineContent.Contains("NIBIRU_ENCRYPTION_MODE"))
  67. {
  68. lineContent = " <meta-data android:value=\"" + (EnableEncryption ? 1 : 0) + "\" android:name=\"NIBIRU_ENCRYPTION_MODE\"/>";
  69. }
  70. newdata = newdata + lineContent + "\n";
  71. }
  72. NxrPluginEditor.Write("AndroidManifest.xml", newdata);
  73. }
  74. Close();
  75. }
  76. }
  77. }
  78. }