Ejemplo n.º 1
0
    public static List <Type> GetTypes(string type_name)
    {
        if (ImmediateWindow.m_Assemblies == null)
        {
            ImmediateWindow.PopulateAssemblyCache();
        }
        List <Type> list = new List <Type>();
        Type        type = null;

        for (int i = 0; i < ImmediateWindow.m_Assemblies.Count; i++)
        {
            Assembly assembly = ImmediateWindow.m_Assemblies[i];
            Type     type2    = assembly.GetType(type_name, false, true);
            if (!(type2 == null))
            {
                type = type2;
                break;
            }
            foreach (Type type3 in assembly.GetTypes())
            {
                if (type3.Name.StartsWith(type_name, true, CultureInfo.InvariantCulture))
                {
                    list.Add(type3);
                }
            }
        }
        if (type != null)
        {
            list.Clear();
            list.Add(type);
        }
        return(list);
    }
Ejemplo n.º 2
0
    private static IList <string> GetUserAssemblyPaths()
    {
        List <string> result = new List <string>(20);

        ImmediateWindow.FindAssemblies(Application.dataPath + "/../Library/ScriptAssemblies/", 2, result);
        return(result);
    }
Ejemplo n.º 3
0
        private static void TestToolAdd()
        {
            ImmediateWindow immediateWindow = ShowDialog <ImmediateWindow>(SkylineWindow.ShowImmediateWindow);
            const string    exePath         = "example.exe"; //Not L10N

            RunUI(() =>
            {
                immediateWindow.Clear();

                int countStart = Settings.Default.ToolList.Count;
                const string addToolCommand = "--tool-add=ImToolAdded --tool-command=" + exePath; //Not L10N
                immediateWindow.WriteLine(addToolCommand);
                immediateWindow.RunLine(immediateWindow.LineCount - 1);
                AssertEx.AreComparableStrings(Resources.CommandLine_ImportTool__0__was_added_to_the_Tools_Menu_, immediateWindow.TextContent, 1); //Not L10N will be when command line stuff is localized.
                SkylineWindow.PopulateToolsMenu();
                Assert.AreEqual("ImToolAdded", SkylineWindow.GetToolText(countStart));

                immediateWindow.Clear();

                // Write the title of the tool and then run it from the immediate window.
                immediateWindow.WriteLine("ImToolAdded");
            });
            RunDlg <MessageDlg>(() => immediateWindow.RunLine(0), messageDlg =>
            {
                AssertEx.Contains(messageDlg.Message, Resources.ToolDescription_RunTool_Please_check_the_command_location_is_correct_for_this_tool_);
                messageDlg.OkDialog();
            });
            RunUI(immediateWindow.Dispose);
        }
Ejemplo n.º 4
0
    private static void PopulateAssemblyCache()
    {
        IList <string> userAssemblyPaths = ImmediateWindow.GetUserAssemblyPaths();

        foreach (string item in Directory.GetFiles((Application.dataPath + "/Managed/") ?? "", "*.dll"))
        {
            userAssemblyPaths.Add(item);
        }
        ImmediateWindow.m_Assemblies = new Assembly[userAssemblyPaths.Count];
        for (int j = 0; j < userAssemblyPaths.Count; j++)
        {
            ImmediateWindow.m_Assemblies[j] = Assembly.LoadFile(userAssemblyPaths[j]);
        }
    }
Ejemplo n.º 5
0
    public void OnUIListClicked(UIList list)
    {
        string selectedElementText = list.GetSelectedElementText();

        if (!selectedElementText.Empty())
        {
            string text;
            ImmediateWindow.Result result = ImmediateWindow.RunCommand(selectedElementText, out text);
            this.m_List.AddElement <MenuDebugLog.CommandData>(text, new MenuDebugLog.CommandData
            {
                result  = result,
                command = selectedElementText,
                output  = text
            });
        }
    }
Ejemplo n.º 6
0
 private static void FindAssemblies(string systemPath, int maxDepth, List <string> result)
 {
     if (maxDepth > 0)
     {
         try
         {
             if (Directory.Exists(systemPath))
             {
                 DirectoryInfo directoryInfo = new DirectoryInfo(systemPath);
                 result.AddRange(from file in directoryInfo.GetFiles()
                                 where ImmediateWindow.IsManagedAssembly(file.FullName)
                                 select file.FullName);
                 DirectoryInfo[] directories = directoryInfo.GetDirectories();
                 for (int i = 0; i < directories.Length; i++)
                 {
                     ImmediateWindow.FindAssemblies(directories[i].FullName, maxDepth - 1, result);
                 }
             }
         }
         catch
         {
         }
     }
 }
Ejemplo n.º 7
0
        private void InputBox_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            CommandLine commandLine;
            string      command;

            try
            {
                switch (e.Key)
                {
                case Key.Return:

                    command = CommandInputBox.Text;
                    if (command.Length == 0)
                    {
                        return;
                    }
                    for (var i = 0; i < _commandHistory.Count; i++)
                    {
                        if (command == (string)_commandHistory[i])
                        {
                            _commandHistory.RemoveAt(i);
                            i = _commandHistory.Count;
                        }
                    }
                    _commandHistory.Insert(0, command);
                    commandLine           = new CommandLine(command.Replace("\r\n", ""), _table);
                    command              += "\r\n[" + commandLine.Result + "]\r\n";
                    ImmediateWindow.Text += command;
                    ImmediateWindow.ScrollToEnd();
                    CommandInputBox.Text = "";
                    break;

                case Key.Up:
                    if (_historyCounter < _commandHistory.Count)
                    {
                        CommandInputBox.Text = _commandHistory[_historyCounter] as string;
                        _historyCounter++;
                    }
                    break;

                case Key.Down:
                    if (_historyCounter > 0)
                    {
                        _historyCounter--;
                        CommandInputBox.Text = _commandHistory[_historyCounter] as string;
                    }
                    break;

                default:

                    _historyCounter = 0;
                    break;
                }
                //If the count of Dots in the command line changed, perform a new search for members.
                //Note: the ComboBox is using the up/down key to search for the previous/next item.
                if (!(e.Key == Key.Down || e.Key == Key.Up))
                {
                    CheckDots();
                }
                OnError(null);
            }
            catch (Exception exception)
            {
                OnError(exception);
            }
        }
Ejemplo n.º 8
0
 private static ImmediateWindow.Result Execute(Type type, string[] members, string[] parameters, ref string result)
 {
     ImmediateWindow.Result result2;
     try
     {
         List <MemberInfo> list = new List <MemberInfo>();
         string            text = string.Empty;
         bool flag  = false;
         Type type2 = type;
         int  i     = 0;
         while (i < members.Length)
         {
             string text2 = members[i];
             result = string.Empty;
             MemberInfo   memberInfo = null;
             MemberInfo[] members2   = type.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
             MemberInfo[] members3   = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
             foreach (MemberInfo memberInfo2 in members2)
             {
                 if (memberInfo2.Name.ICompare(text2) == 0)
                 {
                     memberInfo = memberInfo2;
                     break;
                 }
                 if (memberInfo2.Name.StartsWith(text2, true, CultureInfo.InvariantCulture))
                 {
                     if (text.Empty())
                     {
                         result = result + memberInfo2.Name + " ";
                     }
                     else
                     {
                         result = string.Concat(new string[]
                         {
                             result,
                             text,
                             ".",
                             memberInfo2.Name,
                             " "
                         });
                     }
                 }
             }
             if (memberInfo == null)
             {
                 MemberInfo[] array = members3;
                 int          j     = 0;
                 while (j < array.Length)
                 {
                     MemberInfo memberInfo3 = array[j];
                     if (memberInfo3.Name.ICompare(text2) == 0)
                     {
                         memberInfo = memberInfo3;
                         if (i == 0)
                         {
                             flag = true;
                             break;
                         }
                         break;
                     }
                     else
                     {
                         if (memberInfo3.Name.StartsWith(text2, true, CultureInfo.InvariantCulture))
                         {
                             if (text.Empty())
                             {
                                 result = result + memberInfo3.Name + " ";
                             }
                             else
                             {
                                 result = string.Concat(new string[]
                                 {
                                     result,
                                     text,
                                     ".",
                                     memberInfo3.Name,
                                     " "
                                 });
                             }
                         }
                         j++;
                     }
                 }
             }
             if (memberInfo == null)
             {
                 if (result.Length > 0)
                 {
                     return(ImmediateWindow.Result.IncompleteMember);
                 }
                 return(ImmediateWindow.Result.InvalidMember);
             }
             else
             {
                 if (!text.Empty())
                 {
                     text += ".";
                 }
                 text  += memberInfo.Name;
                 result = string.Empty;
                 type   = ImmediateWindow.GetMemberUndelyingType(memberInfo);
                 list.Add(memberInfo);
                 i++;
             }
         }
         object obj = null;
         if (flag)
         {
             if (parameters.Length == 0)
             {
                 return(ImmediateWindow.Result.InstanceNameRequired);
             }
             foreach (UnityEngine.Object @object in UnityEngine.Object.FindObjectsOfTypeAll(type2))
             {
                 if (parameters[0].ICompare("?") == 0 || @object.name.ICompare(parameters[0]) == 0)
                 {
                     obj = @object;
                     break;
                 }
             }
             if (obj == null)
             {
                 return(ImmediateWindow.Result.InvalidInstanceName);
             }
             parameters = parameters.Skip(1).ToArray <string>();
         }
         if (list.Count > 0)
         {
             for (int k = 0; k < list.Count; k++)
             {
                 MemberInfo memberInfo4 = list[k];
                 bool       flag2       = k == list.Count - 1;
                 if (memberInfo4.MemberType == MemberTypes.Field)
                 {
                     FieldInfo fieldInfo = (FieldInfo)memberInfo4;
                     if (!flag2)
                     {
                         obj = fieldInfo.GetValue(obj);
                     }
                     else if (parameters.Length != 0)
                     {
                         object value = fieldInfo.GetValue(obj);
                         ((FieldInfo)memberInfo4).SetValue(obj, ImmediateWindow.ConvertFromString(parameters[0], fieldInfo.FieldType));
                         result = "> " + ((value != null) ? value.ToString() : null) + " -> " + parameters[0];
                     }
                     else
                     {
                         object value2 = fieldInfo.GetValue(obj);
                         result = "> " + ((value2 != null) ? value2.ToString() : null) + " " + ImmediateWindow.GetNameMemberValue(value2);
                     }
                 }
                 else if (memberInfo4.MemberType == MemberTypes.Property)
                 {
                     PropertyInfo propertyInfo = (PropertyInfo)memberInfo4;
                     if (!flag2)
                     {
                         obj = propertyInfo.GetValue(obj);
                     }
                     else if (parameters.Length != 0)
                     {
                         object value3 = propertyInfo.GetValue(obj);
                         ((PropertyInfo)memberInfo4).SetValue(obj, ImmediateWindow.ConvertFromString(parameters[0], propertyInfo.PropertyType));
                         result = "> " + ((value3 != null) ? value3.ToString() : null) + " -> " + parameters[0];
                     }
                     else
                     {
                         object value4 = propertyInfo.GetValue(obj);
                         result = "> " + ((value4 != null) ? value4.ToString() : null) + " " + ImmediateWindow.GetNameMemberValue(value4);
                     }
                 }
                 else if (memberInfo4.MemberType == MemberTypes.Method)
                 {
                     MethodInfo      methodInfo  = (MethodInfo)memberInfo4;
                     ParameterInfo[] parameters2 = methodInfo.GetParameters();
                     if (!flag2)
                     {
                         ParameterInfo[] array3 = parameters2;
                         for (int j = 0; j < array3.Length; j++)
                         {
                             if (!array3[j].IsOptional)
                             {
                                 return(ImmediateWindow.Result.MethodRequiresParameters);
                             }
                         }
                         object[] parameters3 = Enumerable.Repeat <object>(Type.Missing, parameters2.Length).ToArray <object>();
                         obj = methodInfo.Invoke(obj, parameters3);
                     }
                     else
                     {
                         List <object> list2 = new List <object>();
                         for (int l = 0; l < parameters2.Length; l++)
                         {
                             if (parameters.Length > l)
                             {
                                 list2.Add(ImmediateWindow.ConvertFromString(parameters[l], parameters2[l].ParameterType));
                             }
                         }
                         object obj2 = methodInfo.Invoke(obj, list2.ToArray());
                         result = "> " + ((obj2 != null) ? obj2.ToString() : null) + " " + ImmediateWindow.GetNameMemberValue(obj2);
                     }
                 }
             }
             result2 = ImmediateWindow.Result.Success;
         }
         else if (result.Length > 0)
         {
             result2 = ImmediateWindow.Result.IncompleteMember;
         }
         else
         {
             result2 = ImmediateWindow.Result.InvalidMember;
         }
     }
     catch (Exception ex)
     {
         result  = ex.ToString();
         result2 = ImmediateWindow.Result.Exception;
     }
     return(result2);
 }
Ejemplo n.º 9
0
    public static ImmediateWindow.Result RunCommand(string command, out string result)
    {
        result = string.Empty;
        while (command.Contains("  "))
        {
            command = command.Replace("  ", " ");
        }
        if (command.StartsWith(" "))
        {
            command = command.Substring(1);
        }
        if (command.EndsWith(" "))
        {
            command = command.Substring(0, command.Length - 1);
        }
        string[] array = command.Split(new char[]
        {
            ' '
        });
        if (array.Length == 0)
        {
            return(ImmediateWindow.Result.NoInput);
        }
        List <Type> list = new List <Type>();

        string[] array2 = array[0].Split(new char[]
        {
            '.'
        });
        string text = string.Empty;

        for (int i = 0; i < array2.Length; i++)
        {
            if (!text.Empty())
            {
                text += ".";
            }
            text += array2[i];
            List <Type> types = ImmediateWindow.GetTypes(text);
            if (types.Count != 1)
            {
                list = list.Concat(types).ToList <Type>();
                break;
            }
            list = types;
        }
        if (list.Count == 0)
        {
            return(ImmediateWindow.Result.InvalidType);
        }
        if (list.Count > 1)
        {
            result = string.Join <Type>(" ", list);
            return(ImmediateWindow.Result.IncompleteType);
        }
        if (array.Length < 2)
        {
            return(ImmediateWindow.Result.InvalidMember);
        }
        string[] members = array[1].Split(new char[]
        {
            '.'
        });
        string[] parameters = array.Skip(2).ToArray <string>();
        return(ImmediateWindow.Execute(list[0], members, parameters, ref result));
    }
Ejemplo n.º 10
0
 public void ImmediateWindowWorks()
 {
     ImmediateWindow.ShowPackageManagerWindow();
     Assert.That(ImmediateWindow.CurrentWindow != null);
 }
Ejemplo n.º 11
0
 protected override void Update()
 {
     base.Update();
     if (Input.GetKeyDown(KeyCode.Return))
     {
         if (this.m_ConsoleInput != null)
         {
             string text;
             ImmediateWindow.Result result = ImmediateWindow.RunCommand(this.m_ConsoleInput.text, out text);
             this.m_List.AddElement <MenuDebugLog.CommandData>(EnumUtils <ImmediateWindow.Result> .GetName(result) + " " + text, new MenuDebugLog.CommandData
             {
                 result  = result,
                 command = this.m_ConsoleInput.text,
                 output  = text
             });
             this.m_FastTypeHelper = 0;
             return;
         }
     }
     else if (Input.GetKeyDown(KeyCode.Tab))
     {
         if (this.m_List.GetCount() > 0)
         {
             int index = Mathf.Min(this.m_List.GetCount() - 1, this.m_List.GetCount() + this.m_UpDownNavigation);
             MenuDebugLog.CommandData elementData = this.m_List.GetElementData <MenuDebugLog.CommandData>(index);
             ImmediateWindow.Result   result2     = elementData.result;
             if (result2 == ImmediateWindow.Result.IncompleteType)
             {
                 string[] array = elementData.output.Split(new char[]
                 {
                     ' '
                 });
                 this.m_FastTypeHelper   %= array.Length;
                 this.m_ConsoleInput.text = (array[this.m_FastTypeHelper] ?? "");
                 this.m_ConsoleInput.ActivateInputField();
                 this.m_ConsoleInput.Select();
                 this.m_FastTypeHelper++;
                 return;
             }
             if (result2 != ImmediateWindow.Result.IncompleteMember)
             {
                 return;
             }
             string[] array2 = elementData.output.Split(new char[]
             {
                 ' '
             });
             this.m_FastTypeHelper   %= array2.Length;
             this.m_ConsoleInput.text = elementData.command.Split(new char[]
             {
                 ' '
             })[0] + " " + array2[this.m_FastTypeHelper];
             this.m_ConsoleInput.ActivateInputField();
             this.m_ConsoleInput.Select();
             this.m_FastTypeHelper++;
             return;
         }
     }
     else if ((Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.UpArrow)) && this.m_List.GetCount() > 0)
     {
         this.m_UpDownNavigation += (Input.GetKeyDown(KeyCode.DownArrow) ? 1 : -1);
         this.m_UpDownNavigation  = Mathf.Min(0, Mathf.Max(this.m_UpDownNavigation, -this.m_List.GetCount() + 1));
         MenuDebugLog.CommandData elementData2 = this.m_List.GetElementData <MenuDebugLog.CommandData>(this.m_List.GetCount() + this.m_UpDownNavigation);
         this.m_ConsoleInput.text = elementData2.command;
     }
 }