AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
CertificatePasswordWindow.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using UnityEditor;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Unity
9 {
10  public class CertificatePasswordWindow : EditorWindow
11  {
12  private static readonly GUILayoutOption LabelWidth = GUILayout.Width(110f);
13 
14  private static readonly GUILayoutOption ButtonWidth = GUILayout.Width(110f);
15 
16  private string path;
17 
18  private string password;
19 
20  private GUIContent message;
21 
22  private GUIStyle messageStyle;
23 
24  private string focus;
25 
26  public static void Show(string path)
27  {
28  CertificatePasswordWindow[] array = (CertificatePasswordWindow[])Resources.FindObjectsOfTypeAll(typeof(CertificatePasswordWindow));
29  CertificatePasswordWindow certificatePasswordWindow = (array.Length <= 0) ? CreateInstance<CertificatePasswordWindow>() : array[0];
30  path = path.Replace("\\", "/");
31  certificatePasswordWindow.path = path.Substring(path.LastIndexOf("Assets/", StringComparison.Ordinal));
32  certificatePasswordWindow.password = string.Empty;
33  certificatePasswordWindow.message = GUIContent.none;
34  certificatePasswordWindow.messageStyle = new GUIStyle(GUI.skin.label);
35  certificatePasswordWindow.messageStyle.fontStyle = FontStyle.Italic;
36  certificatePasswordWindow.focus = "password";
37  if (array.Length > 0)
38  {
39  certificatePasswordWindow.Focus();
40  }
41  else
42  {
43  certificatePasswordWindow.titleContent = new GUIContent("Enter Windows Store Certificate Password");
44  certificatePasswordWindow.position = new Rect(100f, 100f, 350f, 90f);
45  certificatePasswordWindow.minSize = new Vector2(certificatePasswordWindow.position.width, certificatePasswordWindow.position.height);
46  certificatePasswordWindow.maxSize = certificatePasswordWindow.minSize;
47  certificatePasswordWindow.ShowUtility();
48  }
49  }
50 
51  public void OnGUI()
52  {
53  Event current = Event.current;
54  bool flag = false;
55  bool flag2 = false;
56 
57  if (current.type == EventType.KeyDown)
58  {
59  flag = (current.keyCode == KeyCode.Escape);
60  flag2 = (current.keyCode == KeyCode.Return || current.keyCode == KeyCode.KeypadEnter);
61  }
62 
63  using (new EditorGUILayout.HorizontalScope())
64  {
65  GUILayout.Space(10f);
66  using (new EditorGUILayout.VerticalScope())
67  {
68  GUILayout.FlexibleSpace();
69  using (new EditorGUILayout.HorizontalScope())
70  {
71  GUILayout.Label(new GUIContent("Password|Certificate password."), LabelWidth);
72  GUI.SetNextControlName("password");
73  password = GUILayout.PasswordField(password, '●');
74  }
75  GUILayout.Space(10f);
76  using (new EditorGUILayout.HorizontalScope())
77  {
78  GUILayout.Label(message, messageStyle);
79  GUILayout.FlexibleSpace();
80  if (GUILayout.Button(new GUIContent("Ok"), ButtonWidth) || flag2)
81  {
82  message = GUIContent.none;
83  try
84  {
85  if (PlayerSettings.WSA.SetCertificate(path, password))
86  {
87  flag = true;
88  }
89  else
90  {
91  message = new GUIContent("Invalid password.");
92  }
93  }
94  catch (UnityException ex)
95  {
96  Debug.LogError(ex.Message);
97  }
98  }
99  }
100  GUILayout.FlexibleSpace();
101  }
102  GUILayout.Space(10f);
103  }
104 
105  if (flag)
106  {
107  Close();
108  }
109  else if (focus != null)
110  {
111  EditorGUI.FocusTextInControl(focus);
112  focus = null;
113  }
114  }
115  }
116 }