Exemplo n.º 1
0
            private string getIFSConfig()
            {
                if (mInitinfo == null)
                {
                    ADebug.LogError("[DataIFS]  mInitinfo is null");
                    return(null);
                }

                string haspassword = "******";

                if (mInitinfo.isHasPwd)
                {
                    haspassword = "******";
                }

                string config = string.Format(@"
		        {{
		            ""ifs"" : 
		            {{
		                ""filelist"" : 
		                [
		                   {{
		                        ""filemetaurl"" : """",
		                        ""filename"" : ""{1}"",
		                        ""filepath"" : ""{0}"",
		                        ""filesize"" : {2},
		                        ""readonly"" : true,
		                        ""resfilename"" : """",
		                        ""url"" : ""{0}""
		                    }}
		                 ],
		                  ""hasifs"" : true,
		                  ""password"" : 
			              {{
		                     ""haspassword"" : {3},
		                     ""value"" : ""{4}""
		                  }}
		             }}
		         }}"        , mInitinfo.ifspath, mInitinfo.ifsname, mInitinfo.ifsFileSize, haspassword, mInitinfo.password);

                ADebug.Log(config);
                return(config);
            }
Exemplo n.º 2
0
 protected internal override string GetDocumentationForSymbol(string documentationMemberID, CultureInfo preferredCulture, CancellationToken cancellationToken = default)
 {
     if (_db != null)
     {
         lock (_db) {                    //sometimes not in main thread
             try {
                 _stat ??= _db.Statement("SELECT xml FROM doc WHERE name=?");
                 if (_stat.Bind(1, documentationMemberID).Step())
                 {
                     return(_stat.GetText(0));
                 }
                 //ADebug.Print(documentationMemberID);
             }
             catch (SLException ex) { ADebug.Print(ex.Message); }
             finally { _stat?.Reset(); }
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets check state of this check box or radio button.
 /// Returns 0 if unchecked, 1 if checked, 2 if indeterminate. Also returns 0 if this is not a button or if failed to get state.
 /// </summary>
 /// <param name="useAcc">Use <see cref="AAcc.State"/>. If false (default) and this button has a standard checkbox style, uses API <msdn>BM_GETCHECK</msdn>.</param>
 public int GetCheckState(bool useAcc = false)
 {
     if (useAcc || !_IsCheckbox())
     {
         //info: Windows Forms controls are user-drawn and don't have one of the styles, therefore BM_GETCHECK does not work.
         try {                     //avoid exception in property-get functions
             using var a = AAcc.FromWindow(W, AccOBJID.CLIENT, flags: AWFlags.NoThrow);
             if (a == null)
             {
                 return(0);
             }
             return(_GetAccCheckState(a));
         }
         catch (Exception ex) { ADebug.Print(ex); }                    //CONSIDER: if fails, show warning. In all AWnd property-get functions.
         return(0);
     }
     else
     {
         return((int)W.Send(BM_GETCHECK));
     }
 }
Exemplo n.º 4
0
            public bool Init(DataIFSInitInfo initinfo)
            {
                ADebug.Log(string.Format("[ApolloUpdate] initupdatemgr ifspath:{0},ifsname:{1},ifsFileSize:{2}"
                                         , initinfo.ifspath, initinfo.ifsname, initinfo.ifsFileSize));

                mFactory = new IIPSMobile.IIPSMobileData();

                mInitinfo.ifsname     = initinfo.ifsname;
                mInitinfo.ifspath     = initinfo.ifspath;
                mInitinfo.ifsFileSize = initinfo.ifsFileSize;
                mInitinfo.isHasPwd    = initinfo.isHasPwd;
                mInitinfo.password    = initinfo.password;

                if (mFactory == null)
                {
                    ADebug.LogError("[DataIFS] new mFactory fail");
                    return(false);
                }
                string config = getIFSConfig();

                mgr = mFactory.CreateDataMgr(config);
                if (mgr == null)
                {
                    ADebug.LogError("[DataIFS] new data mgr fail,Please check init param format!");
                    return(false);
                }
                mReader = mgr.GetDataReader();
                if (mReader == null)
                {
                    ADebug.LogError("[DataIFS]  GetDataReader fail");
                    return(false);
                }
                mFinder = mgr.GetDataQuery();
                if (mFinder == null)
                {
                    ADebug.LogError("[DataIFS]  GetDataQuery fail");
                    return(false);
                }
                return(true);
            }
Exemplo n.º 5
0
Arquivo: Log_.cs Projeto: alexfordc/Au
            public void Write(string s)
            {
                Debug.Assert(ATask.Role == ATRole.MiniProgram);                 //could be any, but currently we log only in miniProgram processes. Would be no task name if called in editor process.

                if (_openState != 3)
                {
                    //First time open and write async. Else it would be the slowest part of starting a preloaded assembly in Au.Task.exe.
                    if (0 == Interlocked.CompareExchange(ref _openState, 1, 0))
                    {
                        ThreadPool.QueueUserWorkItem(_ => {
                            lock (this) {
                                _openState = 2;
                                try {
                                    _mutex  = new Mutex(false, "Au.Mutex.LogFile");
                                    _writer = new StreamWriter(new FileStream(_Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite));
                                }
                                catch (Exception ex) {
                                    ADebug.Print(ex.ToStringWithoutStack());
                                    _openState = -1;
                                    return;
                                }
                                _Write(s);
                                _openState = 3;
                            }
                        });
                        return;
                    }
                    while (_openState == 1)
                    {
                        Thread.Sleep(15);
                    }
                    lock (this) {
                        if (_openState < 0)
                        {
                            return;
                        }
                    }
                }
                _Write(s);
            }
Exemplo n.º 6
0
        public LockStepRoomUserCollection GetRoomUserCollection()
        {
            byte[] buf  = new byte[102400];
            int    used = buf.Length;

            if (gcloud_lockstep_test_get_room_detail_info(buf, ref used))
            {
                LockStepRoomUserCollection co = new LockStepRoomUserCollection();
                if (co.Decode(buf))
                {
                    return(co);
                }
                else
                {
                    ADebug.LogError("GetRoomUserCollection decode error");
                }
            }
            else
            {
                ADebug.LogError("GetRoomUserCollection gcloud_lockstep_test_get_room_detail_info return false");
            }
            return(null);
        }
Exemplo n.º 7
0
 void OnStateChangedProc(int state, byte[] data)
 {
     ADebug.Log("OnStateChangedProc:" + state);
     if (data != null)
     {
         LockStepResult result = new LockStepResult();
         if (result.Decode(data))
         {
             if (StateChangedEvent != null)
             {
                 StateChangedEvent((LockStepState)state, result);
             }
         }
         else
         {
             ADebug.LogError("OnStateChangedProc Decoce Error");
         }
     }
     else
     {
         ADebug.LogError("OnStateChangedProc data is null");
     }
 }
Exemplo n.º 8
0
    /// <summary>
    /// Checks or unchecks command's menu item and toolbar buttons.
    /// </summary>
    /// <param name="cmd">Command name. See Strips.xml.</param>
    /// <param name="check"></param>
    public static void CheckCmd(string cmd, bool check)
    {
        var a = _strips.Find(cmd);
        int i, n = a.Count;

        if (n == 0)
        {
            ADebug.Print("item not found: " + cmd); return;
        }
        for (i = 0; i < n; i++)
        {
            switch (a[i])
            {
            case ToolStripMenuItem m:
                m.Checked = check;
                break;

            case ToolStripButton b:
                b.Checked = check;
                break;
            }
        }
    }
Exemplo n.º 9
0
        void OnLogoutProc(byte[] data)
        {
            ADebug.Log("OnLogoutProc");

            if (data != null)
            {
                LockStepResult result = new LockStepResult();
                if (result.Decode(data))
                {
                    if (logoutEventHandler != null)
                    {
                        logoutEventHandler(result);
                    }
                }
                else
                {
                    ADebug.LogError("OnLogoutProc Decoce Error");
                }
            }
            else
            {
                ADebug.LogError("OnLogoutProc data is null");
            }
        }
Exemplo n.º 10
0
        void OnBroadcastProc(byte[] data)
        {
            //ADebug.Log("OnBroadcastProc");

            if (data != null)
            {
                FrameCollection frames = new FrameCollection();
                if (frames.Decode(data))
                {
                    if (BroadcastEvent != null)
                    {
                        BroadcastEvent(frames);
                    }
                }
                else
                {
                    ADebug.LogError("OnBroadcastProc Decoce Error");
                }
            }
            else
            {
                ADebug.LogError("OnBroadcastProc data is null");
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Loads image and returns its data in .bmp file format.
        /// Returns null if fails, for example file not found or invalid Base64 string.
        /// </summary>
        /// <param name="s">Depends on t. File path or resource name without prefix or Base64 image data without prefix.</param>
        /// <param name="t">Image type and string format.</param>
        /// <param name="searchPath">Use <see cref="AFile.SearchPath"/></param>
        /// <remarks>Supports environment variables etc. If not full path, searches in <see cref="AFolders.ThisAppImages"/>.</remarks>
        public static byte[] BmpFileDataFromString(string s, ImageType t, bool searchPath = false)
        {
            //AOutput.Write(t, s);
            try {
                switch (t)
                {
                case ImageType.Bmp:
                case ImageType.PngGifJpg:
                case ImageType.Cur:
                    if (searchPath)
                    {
                        s = AFile.SearchPath(s, AFolders.ThisAppImages);
                        if (s == null)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        if (!APath.IsFullPathExpandEnvVar(ref s))
                        {
                            return(null);
                        }
                        s = APath.Normalize(s, AFolders.ThisAppImages);
                        if (!AFile.ExistsAsFile(s))
                        {
                            return(null);
                        }
                    }
                    break;
                }

                switch (t)
                {
                case ImageType.Base64CompressedBmp:
                    return(AConvert.Decompress(Convert.FromBase64String(s)));

                case ImageType.Base64PngGifJpg:
                    using (var stream = new MemoryStream(Convert.FromBase64String(s), false)) {
                        return(_ImageToBytes(Image.FromStream(stream)));
                    }

                case ImageType.Resource:
                    return(_ImageToBytes(AResources.GetAppResource(s) as Image));

                case ImageType.Bmp:
                    return(File.ReadAllBytes(s));

                case ImageType.PngGifJpg:
                    return(_ImageToBytes(Image.FromFile(s)));

                case ImageType.Ico:
                case ImageType.IconLib:
                case ImageType.ShellIcon:
                case ImageType.Cur:
                    return(_IconToBytes(s, t == ImageType.Cur, searchPath));
                }
            }
            catch (Exception ex) { ADebug.Print(ex.Message + "    " + s); }
            return(null);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Makes triggers alive.
        /// </summary>
        /// <remarks>
        /// This function monitors hotkeys, activated windows and other events. When an event matches an added trigger, launches the thrigger's action, which runs in other thread by default.
        /// Does not return immediately. Runs until this process is terminated or <see cref="Stop"/> called.
        /// </remarks>
        /// <example>See <see cref="ActionTriggers"/>.</example>
        /// <exception cref="InvalidOperationException">Already running.</exception>
        /// <exception cref="AuException">Something failed.</exception>
        public unsafe void Run()
        {
            //ADebug.PrintLoadedAssemblies(true, true, true);

            ThrowIfRunning_();

            //bool haveTriggers = false;
            HooksThread.UsedEvents hookEvents = 0;
            _windowTriggers = null;
            for (int i = 0; i < _t.Length; i++)
            {
                var t = _t[i];
                if (t == null || !t.HasTriggers)
                {
                    continue;
                }
                //haveTriggers = true;
                switch ((TriggerType)i)
                {
                case TriggerType.Hotkey: hookEvents |= HooksThread.UsedEvents.Keyboard; break;

                case TriggerType.Autotext: hookEvents |= HooksThread.UsedEvents.Keyboard | HooksThread.UsedEvents.Mouse; break;

                case TriggerType.Mouse: hookEvents |= (t as MouseTriggers).UsedHookEvents_; break;

                case TriggerType.Window: _windowTriggers = t as WindowTriggers; break;
                }
            }
            //AOutput.Write(haveTriggers, (uint)llHooks);
            //if(!haveTriggers) return; //no. The message loop may be used for toolbars etc.

            if (!s_wasRun)
            {
                s_wasRun = true;
                AWnd.More.RegisterWindowClass(c_cn);
            }
            _wMsg             = AWnd.More.CreateMessageOnlyWindow(_WndProc, c_cn);
            _mainThreadId     = AThread.NativeId;
            _winTimerPeriod   = 0;
            _winTimerLastTime = 0;

            if (hookEvents != 0)
            {
                //prevent big delay later on first LL hook event while hook proc waits
                if (!s_wasKM)
                {
                    s_wasKM = true;
                    ThreadPool.QueueUserWorkItem(_ => {
                        try {
                            //using var p1 = APerf.Create();
                            new AWnd.Finder("*a").IsMatch(AWnd.GetWnd.Root);               //if used window scopes etc
                            _ = AHookWin.LowLevelHooksTimeout;                             //slow JIT of registry functions
                            Util.AJit.Compile(typeof(ActionTriggers), nameof(_WndProc), nameof(_KeyMouseEvent));
                            Util.AJit.Compile(typeof(TriggerHookContext), nameof(TriggerHookContext.InitContext), nameof(TriggerHookContext.PerfEnd), nameof(TriggerHookContext.PerfWarn));
                            Util.AJit.Compile(typeof(ActionTrigger), nameof(ActionTrigger.MatchScopeWindowAndFunc));
                            Util.AJit.Compile(typeof(HotkeyTriggers), nameof(HotkeyTriggers.HookProc));
                            AutotextTriggers.JitCompile();
                            MouseTriggers.JitCompile();
                        }
                        catch (Exception ex) { ADebug.Print(ex); }
                    });
                }

                _thc = new TriggerHookContext(this);

                _ht = new HooksThread(hookEvents, _wMsg);
            }

            try {
                _evStop = Api.CreateEvent(false);
                _StartStopAll(true);
                IntPtr h = _evStop;
                _Wait(&h, 1);
            }
            finally {
                if (hookEvents != 0)
                {
                    _ht.Dispose(); _ht = null;
                }
                Api.DestroyWindow(_wMsg); _wMsg = default;
                Stopping?.Invoke(this, EventArgs.Empty);
                _evStop.Dispose();
                _StartStopAll(false);
                _mainThreadId = 0;
                _threads?.Dispose(); _threads = null;
            }

            void _StartStopAll(bool start)
            {
                foreach (var t in _t)
                {
                    if (t?.HasTriggers ?? false)
                    {
                        t.StartStop(start);
                    }
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a menu or toolbar item.
        /// </summary>
        /// <param name="x">XML element containing item properties.</param>
        /// <param name="isMenu">false if toolbar item, true if menu item (also if menu bar item).</param>
        ToolStripItem _CreateChildItem(XElement x, bool isMenu)
        {
            string s, tag = x.Name.LocalName;

            if (tag == "sep")
            {
                return new ToolStripSeparator()
                       {
                           Tag = x
                       }
            }
            ;

            ToolStripItem item; ToolStripMenuItem mi;
            bool          isControl = false, needHandler = false;

            if (isMenu)
            {
                mi = new ToolStripMenuItem();

                item = mi;
                if (x.HasElements || x.HasAttr("dd"))
                {
                    _Submenu(x, mi, tag);
                }
                else
                {
                    needHandler = true;
                }
            }
            else if (x.HasAttr("type"))
            {
                isControl = true;
                string cue = x.Attr("cue");
                s = x.Attr("type");
                switch (s)
                {
                case "edit":
                    var ed = new ToolStripSpringTextBox();
                    if (cue != null)
                    {
                        ed.ZSetCueBanner(cue);
                    }
                    item = ed;
                    break;

                case "combo":
                    var combo = new ToolStripSpringComboBox();
                    if (cue != null)
                    {
                        combo.ZSetCueBanner(cue);
                    }
                    item = combo;
                    break;

                default:
                    Debug.Assert(false);
                    return(null);
                }
                if (cue != null)
                {
                    item.AccessibleName = cue;
                }
            }
            else if (x.HasElements || x.HasAttr("dd"))
            {
                ToolStripDropDownItem ddi;
                var handler = _callbacks.GetClickHandler(tag);
                if (handler != null)
                {
                    var sb = new ToolStripSplitButton();
                    sb.ButtonClick += handler;
                    ddi             = sb;
                }
                else
                {
                    ddi = new ToolStripDropDownButton();
                }
                item = ddi;
                _Submenu(x, ddi, tag);
            }
            else
            {
                needHandler = true;
                var b = new ToolStripButton();
                item = b;
            }

            item.Name = tag;
            item.Tag  = x;

            _SetItemProperties(x, item, isMenu, isControl);

            if (needHandler)
            {
                var handler = _callbacks.GetClickHandler(tag);
                if (handler != null)
                {
                    item.Click += handler;
                }
                else
                {
                    ADebug.Print("no handler of " + tag);
                    //return null;
                    //item.Enabled = false;
                    item.Visible = false;
                }
            }

            return(item);
        }

        void _Submenu(XElement x, ToolStripDropDownItem ddItem, string tag)
        {
            var s = x.Attr("dd");

            if (!s.NE())
            {
                ddItem.DropDown = Submenus[s];
            }
            else
            {
                var dd = ddItem.DropDown as ToolStripDropDownMenu;                 //note: not ddItem.DropDown=new ToolStripDropDownMenu(). Then eg hotkeys don't work.
                dd.Name = tag;
                dd.Tag  = x;
                Submenus.Add(tag, dd);

                if (s != null)                              //attribute dd="". Will be filled later, eg on Opening event.
                {
                    dd.Items.Add(new ToolStripSeparator()); //else no drop arrow and no Opening event
                    return;
                }
#if !LAZY_MENUS
                dd.SuspendLayout();                 //with this don't need lazy menus
                _AddChildItems(x, dd, true);
                dd.ResumeLayout(false);
#else
                //Fill menu items later. This saves ~50 ms of startup time if not using dd.SuspendLayout. With dd.SuspendLayout - just 5 ms.
                //Can do it with Opening event or with timer. With timer easier. With event users cannot use MSAA etc to automate clicking menu items (with timer cannot use it only the first 1-2 seconds).
#if true
                ATimer.After(500, t =>
                {
                    dd.SuspendLayout();
                    _AddChildItems(x, dd, true);
                    dd.ResumeLayout(false);
                });
#else
                dd.Items.Add(new ToolStripSeparator());
                CancelEventHandler eh = null;
                eh = (sender, e) =>
                {
                    dd.Opening -= eh;
                    dd.Items.Clear();
                    _AddChildItems(x, dd, true);
                };
                dd.Opening += eh;
#endif
#endif
            }
        }

        void _SetItemProperties(XElement x, ToolStripItem item, bool isMenu, bool isControl)
        {
            string s, defaultText = null;

            var tt = x.Attr("tt");             //tooltip

            item.ToolTipText = tt ?? (isMenu ? null : (defaultText = _GetDefaultItemText(x)));

            if (!isMenu)
            {
                if (x.HasAttr("hide"))
                {
                    item.Overflow = ToolStripItemOverflow.Always;
                }
                else if (!_inBuildAll)
                {
                    item.Overflow = ToolStripItemOverflow.AsNeeded;
                }
            }
            if (isControl)
            {
                return;
            }

            Image im = null;

            if (x.Attr(out s, "i2"))              //custom image as icon file
            {
                im = AIcon.GetFileIconImage(s);
                if (im == null)
                {
                    AOutput.Write($"Failed to get {(isMenu ? "menu item" : "toolbar button")} {x.Name} icon from file {s}\n\tTo fix this, right-click it and select Properties...");
                }
                //SHOULDDO: async or cache
            }
            if (im == null && x.Attr(out s, "i"))
            {
                im = _callbacks.GetImage(s);                                              //image from resources
            }
            item.Image = im;

            if (x.Attr(out s, "color") && ColorInt.FromString(s, out var color))
            {
                item.ForeColor = (Color)color;
            }
            else if (!_inBuildAll)
            {
                item.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
            }

            bool hasCustomText = x.Attr(out s, "t2");             //custom text

            item.Text = s ?? defaultText ?? _GetDefaultItemText(x);

            if (isMenu)
            {
                var mi = item as ToolStripMenuItem;
                if (!_inBuildAll)
                {
                    mi.ShortcutKeys             = 0;
                    mi.ShortcutKeyDisplayString = null;
                }
                if (x.Attr(out s, "hk"))
                {
                    bool ok = AKeys.More.ParseHotkeyString(s, out var hk);
                    if (ok)
                    {
                        try { mi.ShortcutKeys = hk; } catch { ok = false; }
                    }
                    if (!ok)
                    {
                        ADebug.Print("Invalid hotkey: " + s);
                    }
                }
                if (x.Attr(out string ss, "hkText"))
                {
                    mi.ShortcutKeyDisplayString = (s == null) ? ss : s + ", " + ss;
                }
            }
            else
            {
                var style = item.Image == null ? ToolStripItemDisplayStyle.ImageAndText : (ToolStripItemDisplayStyle)x.Attr("style", 0);
                if (style == 0)
                {
                    style = hasCustomText ? ToolStripItemDisplayStyle.ImageAndText : ToolStripItemDisplayStyle.Image;                            //0 is ToolStripItemDisplayStyle.None
                }
                item.DisplayStyle = style;
            }
        }

        /// <summary>
        /// If x has attribute t, gets its value.
        /// Else gets its name and converts to text, eg "File_OneTwo" to "One Two".
        /// </summary>
        string _GetDefaultItemText(XElement x)
        {
            if (!x.Attr(out string s, "t"))
            {
                string tag = x.Name.LocalName;
                s = tag.Remove(0, tag.LastIndexOf('_') + 1);                 //eg "Edit_Copy" -> "Copy"
                s = s.RegexReplace("(?<=[^A-Z])(?=[A-Z])", " ");             //"OneTwoThree" -> "One Two Three". //speed: don't need to optimize.
            }
            return(s);
        }

        /// <summary>
        /// Merges custom attributes into default menubar or toolbar XML.
        /// Reorders toolbar buttons if need.
        /// </summary>
        /// <param name="xCustom">Root element of customizations file.</param>
        /// <param name="xtsDef">Default menustrip or toolstrip. For custom toolbars the function can replace it.</param>
        /// <param name="name">xtsDef name, just to avoid getting it again.</param>
        /// <param name="isMenu"></param>
        void _MergeCustom(XElement xCustom, ref XElement xtsDef, string name, bool isMenu)
        {
            var xtsCust = xCustom.Element(xtsDef.Name); if (xtsCust == null)

            {
                return;
            }

            if (isMenu)
            {
            }
            else if (name.Starts("Custom"))
            {
                var xc = xCustom.Element(name); if (xc == null)
                {
                    return;
                }
                xc.Remove();
                xtsDef.ReplaceWith(xc);
                xtsDef = xc;
                return;
                //MSDN: "if the new content has no parent, then the objects are simply attached to the XML tree. If the new content already is parented and is part of another XML tree, then the new content is cloned". Tested, it's true.
            }
            else
            {
                //reorder toolbar buttons
                if (xtsCust.Attr(out string s, "order"))
                {
                    xtsDef.Elements("sep").Remove();                     //remove all default <sep/>, because all separators now are in the 'order' attribute
                    var a = s.SegSplit(" ");
                    for (int i = a.Length - 1; i >= 0; i--)
                    {
                        if (a[i] == "sep")
                        {
                            xtsDef.AddFirst(new XElement("sep"));
                        }
                        else
                        {
                            var xb = xtsDef.Element(a[i]); if (xb == null)
                            {
                                continue;
                            }
                            xb.Remove(); xtsDef.AddFirst(xb);
                        }
                    }
                }
            }

            foreach (var xCust in xtsCust.Elements())
            {
                foreach (var xDef in xtsDef.Descendants(xCust.Name))
                {
                    foreach (var att in xCust.Attributes())
                    {
                        xDef.SetAttributeValue(att.Name, att.Value);
                    }
                }
            }
        }

        /// <summary>
        /// Extracts differences between _xmlFileDefault and _xStrips and saves to _xmlFileCustom.
        /// </summary>
        void _DiffCustom()
        {
            var    xStripsDefault = AExtXml.LoadElem(_xmlFileDefault);
            var    xStripsCustom  = new XElement("strips");
            string s;

            //menus
            _DiffDescendants(MenuBar.Tag as XElement, true);

            //standard toolbars
            foreach (var ts in Toolbars.Values)
            {
                if (ts == _tsCustom1 || ts == _tsCustom2)
                {
                    continue;
                }
                _DiffDescendants(ts.Tag as XElement, false);
            }

            void _DiffDescendants(XElement xts, bool isMenu)
            {
                XElement xtsDef = xStripsDefault.Element(xts.Name), xtsCust = null;

                foreach (var x in xts.Descendants())
                {
                    var name = x.Name; if (name == "sep")
                    {
                        continue;
                    }
                    XElement xDef = xtsDef.Desc(name), xCust = null;
                    foreach (var att in x.Attributes())
                    {
                        var aname = att.Name;
                        if (att.Value == xDef.Attr(aname))
                        {
                            continue;
                        }
                        if (xtsCust == null)
                        {
                            xStripsCustom.Add(xtsCust = new XElement(xts.Name));
                        }
                        if (xCust == null)
                        {
                            xtsCust.Add(xCust = new XElement(name));
                        }
                        xCust.SetAttributeValue(aname, att.Value);
                    }
                }
                if (isMenu)
                {
                    return;
                }
                //order
                var s1 = new StringBuilder();
                var s2 = new StringBuilder();

                foreach (var x in xts.Elements())
                {
                    if (s1.Length > 0)
                    {
                        s1.Append(' ');
                    }
                    s1.Append(x.Name);
                }
                foreach (var x in xtsDef.Elements())
                {
                    if (s2.Length > 0)
                    {
                        s2.Append(' ');
                    }
                    s2.Append(x.Name);
                }
                s = s1.ToString();
                if (s != s2.ToString())
                {
                    if (xtsCust == null)
                    {
                        xStripsCustom.Add(xtsCust = new XElement(xts.Name));
                    }
                    xtsCust.SetAttributeValue("order", s);
                }
            }

            //custom toolbars. Temporarily move them from _xStrips to xCustom.
            var xCust1 = _tsCustom1.Tag as XElement;
            var xCust2 = _tsCustom2.Tag as XElement;

            if (xCust1.HasElements)
            {
                xCust1.Remove(); xStripsCustom.Add(xCust1);
            }
            if (xCust2.HasElements)
            {
                xCust2.Remove(); xStripsCustom.Add(xCust2);
            }

            //AOutput.Clear();
            //AOutput.Write(xStripsCustom);
#if true
            //save
            try {
                AFile.CreateDirectoryFor(_xmlFileCustom);
                xStripsCustom.SaveElem(_xmlFileCustom);
            }
            catch (Exception e) {
                AOutput.Write("Failed to save XML file", _xmlFileCustom, e.Message);
            }
#endif

            if (xCust1.HasElements)
            {
                xCust1.Remove(); _xStrips.Add(xCust1);
            }
            if (xCust2.HasElements)
            {
                xCust2.Remove(); _xStrips.Add(xCust2);
            }
        }
Exemplo n.º 14
0
    //[STAThread] //we use TrySetApartmentState instead
    static void Main(string[] args)
    {
        string asmFile, fullPathRefs; int pdbOffset, flags;

        if (args.Length != 1)
        {
            return;
        }
        string pipeName = args[0];         //if(!pipeName.Starts(@"\\.\pipe\Au.Task-")) return;

        int nr = 0;

#if false
        //With NamedPipeClientStream faster by 1 ms, because don't need to JIT. But problems:
        //1. Loads System and System.Core immediately, making slower startup.
        //2. This process does not end when editor process ended, because then Connect spin-waits for server created.
        using (var pipe = new NamedPipeClientStream(".", pipeName.Substring(9), PipeDirection.In)) {
            pipe.Connect();
            var b = new byte[10000];
            nr = pipe.Read(b, 0, b.Length);
        }
#else
        //APerf.First();
        //_PrepareTest();
        //APerf.NW();

        for (int i = 0; i < 3; i++)
        {
            if (Api.WaitNamedPipe(pipeName, i == 2 ? -1 : 100))
            {
                break;
            }
            if (Marshal.GetLastWin32Error() != Api.ERROR_SEM_TIMEOUT)
            {
                return;
            }
            //APerf.First();
            switch (i)
            {
            case 0: _Prepare1(); break;             //~25 ms with cold CPU
                //case 1: _Prepare2(); break; //~15 ms with cold CPU
            }
            //APerf.NW();
        }
        //APerf.First();
        using (var pipe = Api.CreateFile(pipeName, Api.GENERIC_READ, 0, default, Api.OPEN_EXISTING, 0)) {
            if (pipe.Is0)
            {
                ADebug.PrintNativeError_(); return;
            }
            //APerf.Next();
            int size; if (!Api.ReadFile(pipe, &size, 4, out nr, default) || nr != 4)
            {
                return;
            }
            //APerf.Next();
            if (!Api.ReadFileArr(pipe, out var b, size, out nr) || nr != size)
            {
                return;
            }
            //APerf.Next();

            //ADebug.PrintLoadedAssemblies(true, true);
            //APerf.First();

            var a = Au.Util.Serializer_.Deserialize(b);
            ATask.Init_(ATRole.MiniProgram, a[0]);
            asmFile = a[1]; pdbOffset = a[2]; flags = a[3]; args = a[4]; fullPathRefs = a[5];
            string wrp = a[6]; if (wrp != null)
            {
                Environment.SetEnvironmentVariable("ATask.WriteResult.pipe", wrp);
            }
            AFolders.Workspace = (string)a[7];
        }
#endif
        //APerf.Next();

        bool mtaThread = 0 != (flags & 2);         //app without [STAThread]
        if (mtaThread == s_isSTA)
        {
            _SetComApartment(mtaThread ? ApartmentState.MTA : ApartmentState.STA);
        }

        if (0 != (flags & 4))
        {
            Api.AllocConsole();                          //meta console true
        }
        //if(0 != (flags & 1)) { //hasConfig
        //	var config = asmFile + ".config";
        //	if(AFile.ExistsAsFile(config, true)) AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", config);
        //}

        if (s_hook == null)
        {
            _Hook();
        }

        //APerf.Next();
        try { RunAssembly.Run(asmFile, args, pdbOffset, fullPathRefs: fullPathRefs); }
        catch (Exception ex) { AOutput.Write(ex); }
        finally { s_hook?.Dispose(); }
    }
Exemplo n.º 15
0
 void OnRecvedFrameProc(int numberOfReceivedFrames)
 {
     ADebug.Log("OnRecvedFrameProc:" + numberOfReceivedFrames);
 }
Exemplo n.º 16
0
            /// <summary>
            /// Creates documentation provider for assembly <i>asmPath</i>.
            /// Returns null if its xml file does not exist.
            /// Returns _DocumentationProvider if xml file is big and found or successfully created and successfully loaded database for it.
            /// Else returns XmlDocumentationProvider.
            /// </summary>
            public static DocumentationProvider Create(string asmPath)
            {
                if (s_d.TryGetValue(asmPath, out var dp))
                {
                    return(dp);
                }

                var xmlPath = Path.ChangeExtension(asmPath, "xml");

                if (!AFile.GetProperties(xmlPath, out var px))
                {
                    return(null);
                }

                if (px.Size >= 10_000)
                {
                    var md5    = new Au.Util.AHash.MD5(); md5.Add(xmlPath.Lower());
                    var dbPath = AFolders.ThisAppTemp + md5.Hash.ToString() + ".db";
                    try {
                        if (!AFile.GetProperties(dbPath, out var pd) || pd.LastWriteTimeUtc != px.LastWriteTimeUtc)
                        {
                            //ADebug.Print($"creating db: {asmPath}  ->  {dbPath}");
                            AFile.Delete(dbPath);
                            using (var d = new ASqlite(dbPath)) {
                                using var trans = d.Transaction();
                                d.Execute("CREATE TABLE doc (name TEXT PRIMARY KEY, xml TEXT)");
                                using var statInsert = d.Statement("INSERT INTO doc VALUES (?, ?)");

                                var xr = AExtXml.LoadElem(xmlPath);
                                foreach (var e in xr.Descendants("member"))
                                {
                                    var name = e.Attr("name");

                                    //remove <remarks> and <example>.
                                    foreach (var v in e.Descendants("remarks").ToArray())
                                    {
                                        v.Remove();
                                    }
                                    foreach (var v in e.Descendants("example").ToArray())
                                    {
                                        v.Remove();
                                    }

                                    using var reader = e.CreateReader();
                                    reader.MoveToContent();
                                    var xml = reader.ReadInnerXml();
                                    //AOutput.Write(name, xml);

                                    statInsert.BindAll(name, xml).Step();
                                    statInsert.Reset();
                                }
                                trans.Commit();
                                d.Execute("VACUUM");
                            }
                            File.SetLastWriteTimeUtc(dbPath, px.LastWriteTimeUtc);
                        }
                        var db = new ASqlite(dbPath, SLFlags.SQLITE_OPEN_READONLY);                         //never mind: we don't dispose it on process exit
                        s_d[asmPath] = dp = new _DocumentationProvider {
                            _db = db
                        };
                        return(dp);
                    }
                    catch (Exception ex) { ADebug.Print(ex.ToStringWithoutStack()); }
                }
                return(XmlDocumentationProvider.CreateFromFile(xmlPath));
            }
Exemplo n.º 17
0
 public override bool Equals(object obj)
 {
     ADebug.PrintIf(obj != this, "Equals");
     return(obj == this);
 }
Exemplo n.º 18
0
 public override int GetHashCode()
 {
     ADebug.Print("GetHashCode");
     return(1);
 }
Exemplo n.º 19
0
 public static bool InnerInstall()
 {
     ADebug.Log("InnerInstall");
     return(Instance.Install());
 }
Exemplo n.º 20
0
    string _FormatHtml(int iSel, bool userSelected)
    {
        _data.iSelected = iSel;
        if (userSelected)
        {
            _data.iUserSelected = iSel;
        }

        var     r           = _data.r;
        ISymbol currentItem = null;
        SignatureHelpParameter currentParameter = null;
        var b = new StringBuilder("<body>");

        //AOutput.Clear();
        for (int i = 0; i < r.Items.Count; i++)
        {
            var sh = r.Items[i];
            if (sh is AbstractSignatureHelpProvider.SymbolKeySignatureHelpItem kk)
            {
                var sym = kk.Symbol;
                using var li = new CiHtml.HtmlListItem(b, i == iSel);
                if (i != iSel)
                {
                    b.AppendFormat("<a href='^{0}'>", i);
                }
                else
                {
                    currentItem = sym;
                }
#if false
                CiHtml.TaggedPartsToHtml(b, sh.PrefixDisplayParts);                 //works, but formats not as I like (too much garbage). Has bugs with tuples.
#else
                //if(nt != null) {
                //	AOutput.Write(1, nt.IsGenericType, nt.IsTupleType, nt.IsUnboundGenericType, nt.Arity, nt.CanBeReferencedByName);
                //	AOutput.Write(2, nt.IsAnonymousType, nt.IsDefinition, nt.IsImplicitlyDeclared, nt.Kind, nt.TypeKind);
                //	AOutput.Write(3, nt.MemberNames);
                //	AOutput.Write(4, nt.Name, nt.MetadataName, nt.OriginalDefinition, nt.TupleUnderlyingType);
                //	AOutput.Write("TypeParameters:");
                //	AOutput.Write(nt.TypeParameters);
                //	AOutput.Write("TypeArguments:");
                //	AOutput.Write(nt.TypeArguments);
                //	AOutput.Write("TupleElements:");
                //	try { var te = nt.TupleElements; if(!te.IsDefault) AOutput.Write(te); } catch(Exception e1) { AOutput.Write(e1.ToStringWithoutStack()); }
                //	AOutput.Write("---");
                //}

                int isTuple = 0;                 //1 ValueTuple<...>, 2 (...)
                var nt      = sym as INamedTypeSymbol;
                if (nt != null && nt.IsTupleType)
                {
                    isTuple = nt.IsDefinition ? 1 : 2;
                }

                if (isTuple == 1)
                {
                    b.Append("ValueTuple");                              //SymbolWithoutParametersToHtml formats incorrectly
                }
                else if (isTuple == 0)
                {
                    CiHtml.SymbolWithoutParametersToHtml(b, sym);
                }
                string b1 = "(", b2 = ")";
                if (nt != null)
                {
                    if (nt.IsGenericType && isTuple != 2)
                    {
                        b1 = "&lt;"; b2 = "&gt;";
                    }
                }
                else if (sym is IPropertySymbol)
                {
                    b1 = "["; b2 = "]";
                }
                b.Append(b1);
#endif
                int iArg = r.ArgumentIndex, lastParam = sh.Parameters.Length - 1;
                int selParam = iArg <= lastParam ? iArg : (sh.IsVariadic ? lastParam : -1);
                if (!r.ArgumentName.NE())
                {
                    var pa = sh.Parameters;
                    for (int pi = 0; pi < pa.Length; pi++)
                    {
                        if (pa[pi].Name == r.ArgumentName)
                        {
                            selParam = pi; break;
                        }
                    }
                }
                CiHtml.ParametersToHtml(b, sym, selParam, sh);
                //CiHtml.ParametersToHtml(b, sh, selParam); //works, but formats not as I like (too much garbage)
#if false
                CiHtml.TaggedPartsToHtml(b, sh.SuffixDisplayParts);
#else
                b.Append(b2);
#endif
                if (i != iSel)
                {
                    b.Append("</a>");
                }
                else if (selParam >= 0)
                {
                    currentParameter = sh.Parameters[selParam];
                }
            }
            else
            {
                ADebug.Print(sh);
            }
        }

        if (currentItem != null)
        {
            var    tt        = r.Items[iSel].DocumentationFactory?.Invoke(default);
Exemplo n.º 21
0
    /// <summary>
    /// Processes command line of this program.
    /// Returns true if this instance must exit: 1. If finds previous program instance; then sends the command line to it if need. 2. If incorrect command line.
    /// </summary>
    public static bool OnProgramStarted(string[] a)
    {
        string s           = null;
        int    cmd         = 0;
        bool   activateWnd = true;

        if (a.Length > 0)
        {
            //AOutput.Write(a);

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i].Starts('-'))
                {
                    a[i] = a[i].ReplaceAt(0, 1, "/");
                }
                if (a[i].Starts('/'))
                {
                    a[i] = a[i].Lower();
                }
            }

            s = a[0];
            if (s.Starts('/'))
            {
                for (int i = 0; i < a.Length; i++)
                {
                    s = a[i];
                    switch (s)
                    {
                    case "/test":
                        if (++i < a.Length)
                        {
                            TestArg = a[i];
                        }
                        break;

                    case "/v":
                        StartVisible = true;
                        break;

                    default:
                        ADialog.ShowError("Unknown command line parameter", s);
                        return(true);
                    }
                    //rejected: /h start hidden. Not useful.
                }
            }
            else                 //one or more files
            {
                if (a.Length == 1 && FilesModel.IsWorkspaceDirectory(s))
                {
                    switch (cmd = ADialog.Show("Workspace", s, "1 Open|2 Import|0 Cancel", footerText: FilesModel.GetSecurityInfo("v|")))
                    {
                    case 1: WorkspaceDirectory = s; break;

                    case 2: _importWorkspace = s; break;
                    }
                }
                else
                {
                    cmd          = 3;
                    _importFiles = a;
                }
            }
        }

        //single instance
        s_mutex = new Mutex(true, "Au.Mutex.1", out bool createdNew);
        if (createdNew)
        {
            return(false);
        }

        var w = AWnd.FindFast(null, "Au.Editor.Msg", true);

        if (!w.Is0)
        {
            if (activateWnd)
            {
                AWnd wMain = (AWnd)w.Send(Api.WM_USER);
                if (!wMain.Is0)
                {
                    try { wMain.Activate(); }
                    catch (Exception ex) { ADebug.Print(ex); }
                }
            }

            switch (cmd)
            {
            case 3:             //import files
                s = string.Join("\0", a);
                break;
            }
            if (cmd != 0)
            {
                AWnd.More.CopyDataStruct.SendString(w, cmd, s);
            }
        }
        return(true);
    }
Exemplo n.º 22
0
    //HtmlRenderer bug: text-decoration underline is randomly too high or low if using 'Segoe UI' font of good size.
    //	Workaround: body { font: 10.5pt Calibri; }. Or could use it only for links, and use body { font: 9.8pt 'Segoe UI'; }. But Calibri is better.
    //HtmlRenderer's default font is 'Segoe UI' 11pt. WebBrowser's - 12pt (16px).

    public static void TaggedPartsToHtml(StringBuilder b, IEnumerable <TaggedText> tags)
    {
        if (tags == null)
        {
            return;
        }
        int i = -1, iBr = -2;

        foreach (var v in tags)
        {
            i++;
            //AOutput.Write($"{v.Tag}, '{v.Text}', {v.Style}");
            //AOutput.Write($"{v.Tag}, '{v.Text}', {v.Style}, navHint='{v.NavigationHint}', navTarget='{v.NavigationTarget}'");
            string s = v.Text, c = null;
            switch (v.Tag)
            {
            case TextTags.Class:
            case TextTags.Struct:
            case TextTags.Enum:
            case TextTags.Interface:
            case TextTags.Delegate:
            case TextTags.TypeParameter:
                c = "type";
                break;

            case TextTags.Keyword:
                c = "keyword";
                break;

            case TextTags.StringLiteral:
                c = "string";
                break;

            case TextTags.NumericLiteral:
                c = "number";
                break;

            case TextTags.Namespace:
                c = "namespace";
                break;

            case TextTags.LineBreak:
                b.Append(i == iBr + 1 ? "<div class='br2'></div>" : "<br>");
                iBr = i;
                continue;

            case TextTags.Punctuation:
            case TextTags.Method:             //eg operator <
            case TextTags.Operator:
                if (s.Length > 0 && (s[0] == '<' || s[0] == '>' || s[0] == '&'))
                {
                    s = WebUtility.HtmlEncode(s);                                                                             //eg < in X<T>
                }
                break;

            case TextTags.Text:
                s = WebUtility.HtmlEncode(s);
                //SHOULDDO: parse [][xref:topic_id]
                break;

#if DEBUG
            case TextTags.Space:
            case TextTags.Constant:
            case TextTags.EnumMember:
            case TextTags.Event:
            case TextTags.ExtensionMethod:
            case TextTags.Field:
            case TextTags.Local:
            case TextTags.Parameter:
            case TextTags.Property:
            case TextTags.RangeVariable:
            case TextTags.Alias:
            case TextTags.Label:
            case TextTags.ContainerStart:
            case TextTags.ContainerEnd:
            case TextTags.ErrorType:
                break;

            default:
                ADebug.Print($"{v.Tag}, '{v.Text}', {v.Style}");
                break;
#endif
            }

            switch (v.Style)
            {
            case TaggedTextStyle.Strong: b.Append("<b>"); break;

            case TaggedTextStyle.Emphasis: b.Append("<i>"); break;

            case TaggedTextStyle.Code: b.Append("<code>"); break;
            }

            if (c != null)
            {
                b.AppendFormat("<span class='{0}'>{1}</span>", c, s);
            }
            else
            {
                b.Append(s);
            }

            switch (v.Style)
            {
            case TaggedTextStyle.Code: b.Append("</code>"); break;

            case TaggedTextStyle.Emphasis: b.Append("</i>"); break;

            case TaggedTextStyle.Strong: b.Append("</b>"); break;
            }
        }
    }
Exemplo n.º 23
0
    protected override unsafe void WndProc(ref Message m)
    {
        AWnd w = (AWnd)m.HWnd; LPARAM wParam = m.WParam, lParam = m.LParam;

        //AWnd.More.PrintMsg(m, Api.WM_ENTERIDLE, Api.WM_SETCURSOR, Api.WM_GETTEXT, Api.WM_GETTEXTLENGTH, Api.WM_GETICON, Api.WM_NCMOUSEMOVE);

        switch (m.Msg)
        {
        case RunningTasks.WM_TASK_ENDED:         //WM_USER+900
            Program.Tasks.TaskEnded2(m.WParam);
            return;

        case Api.WM_ACTIVATE:
            int isActive = AMath.LoUshort(wParam);             //0 inactive, 1 active, 2 click-active
            if (isActive == 1 && !w.IsActive && !Api.SetForegroundWindow(w))
            {
                //Normally at startup always inactive, because started as admin from task scheduler. SetForegroundWindow sometimes works, sometimes not.
                //workaround for: If clicked a window after our app started but before w activated, w is at Z bottom and in some cases without taskbar button.
                ADebug.Print("window inactive");
                AWnd.More.TaskbarButton.Add(w);
                if (!w.ActivateLL())
                {
                    AWnd.More.TaskbarButton.Flash(w, 5);
                }
            }
            //restore focused control correctly
            if (isActive == 0)
            {
                _wFocus = AWnd.ThisThread.Focused;
            }
            else if (_wFocus.IsAlive)
            {
                AWnd.ThisThread.Focus(_wFocus);
            }
            return;

        case Api.WM_SYSCOMMAND:
            int sc = (int)wParam;
            if (sc >= 0xf000)              //system
            {
                sc &= 0xfff0;
                if (sc == Api.SC_CLOSE && Visible && Program.Settings.runHidden)
                {
                    this.WindowState = FormWindowState.Minimized;
                    this.Visible     = false;
                    EdUtil.MinimizeProcessPhysicalMemory(500);
                    return;
                    //initially this code was in OnFormClosing, but sometimes hides instead of closing, because .NET gives incorrect CloseReason. Cannot reproduce and debug.
                }
            }
            else                 //our
            {
                switch (sc)
                {
                case c_menuid_Exit: Strips.Cmd.File_Exit(); return;
                }
            }
            break;

        case Api.WM_POWERBROADCAST:
            if (wParam == 4)
            {
                Program.Tasks.EndTask();                         //PBT_APMSUSPEND
            }
            break;

        case Api.WM_WINDOWPOSCHANGING:
            var p = (Api.WINDOWPOS *)lParam;
            //AOutput.Write(p->flags);
            //workaround: if started maximized, does not receive WM_SHOWWINDOW. Then .NET at first makes visible, then creates controls and calls OnLoad.
            if (p->flags.Has(Native.SWP.SHOWWINDOW) && Program.Loaded == EProgramState.LoadedWorkspace)
            {
                //p->flags &= ~Native.SWP.SHOWWINDOW; //no, adds 5 duplicate messages
                var m2 = Message.Create(m.HWnd, Api.WM_SHOWWINDOW, (IntPtr)1, default);
                base.WndProc(ref m2);                 //creates controls and calls OnLoad and OnVisibleChanged
                return;
            }
            break;
        }
Exemplo n.º 24
0
    void _DrawItem(AuListControl.ZItemDrawArgs e)
    {
        //var p1 = APerf.Create();
        var g     = e.graphics;
        var ci    = _VisibleItem(e.index);
        var r     = e.bounds;
        int xText = _TextHorzOffset;
        var sym   = ci.FirstSymbol;

        //draw images: kind, access, static/abstract
        var imageKind = ci.KindImage;

        if (imageKind != null)
        {
            int imgX     = r.X + Au.Util.ADpi.ScaleInt(18);
            int imgY     = (r.Y + r.Bottom + 1) / 2 - imageKind.Height / 2;
            int overlayX = r.X + Au.Util.ADpi.ScaleInt(4);
            int overlayY = imgY + Au.Util.ADpi.ScaleInt(4);
            g.DrawImage(imageKind, imgX, imgY, imageKind.Width, imageKind.Height);             //note: would be very slow, but is very fast if DoubleBuffered = true (the control sets it in ctor).
            var imageAccess = ci.AccessImage;
            if (imageAccess != null)
            {
                g.DrawImage(imageAccess, overlayX, overlayY, imageAccess.Width, imageAccess.Height);
            }
            if (sym != null)
            {
                Bitmap b = null;
                if (sym.IsStatic && ci.kind != CiItemKind.Constant && ci.kind != CiItemKind.EnumMember && ci.kind != CiItemKind.Namespace)
                {
                    b = _imgStatic;
                }
                else if (ci.kind == CiItemKind.Class && sym.IsAbstract)
                {
                    b = _imgAbstract;
                }
                if (b != null)
                {
                    g.DrawImage(b, overlayX, overlayY, b.Width, b.Height);
                }
            }
        }
        //p1.Next();

        //draw selection
        r.Width -= xText; r.X += xText;
        if (e.isSelected)
        {
            g.FillRectangle(s_selectedBrush, r);
        }

        //draw text
        var s = ci.DisplayText;

        ADebug.PrintIf(!ci.ci.DisplayTextPrefix.NE(), s);         //we don't support prefix; never seen.
        int xEndOfText = 0;

        using (var tr = new GdiTextRenderer(g)) {
            ColorInt color = ci.moveDown.HasAny(CiItemMoveDownBy.Name | CiItemMoveDownBy.FilterText) ? 0x808080 : 0;
            tr.MoveTo(r.X, r.Y);
            if (ci.hilite != 0)
            {
                ulong h = ci.hilite;
                for (int normalFrom = 0, boldFrom, boldTo, to = s.Length; normalFrom < to; normalFrom = boldTo)
                {
                    for (boldFrom = normalFrom; boldFrom < to && 0 == (h & 1); boldFrom++)
                    {
                        h >>= 1;
                    }
                    tr.DrawText(s, color, normalFrom, boldFrom);
                    if (boldFrom == to)
                    {
                        break;
                    }
                    for (boldTo = boldFrom; boldTo < to && 0 != (h & 1); boldTo++)
                    {
                        h >>= 1;
                    }
                    tr.FontBold(); tr.DrawText(s, color, boldFrom, boldTo); tr.FontNormal();
                }
            }
            else
            {
                tr.DrawText(s, color);
            }

            if (ci.moveDown.Has(CiItemMoveDownBy.Obsolete))
            {
                xEndOfText = tr.GetCurrentPosition().x;
            }

            string green = _GreenSuffix(e.index);
            if (green != null)
            {
                tr.DrawText(green, 0x40A000);
            }
        }

        //draw red line over obsolete items
        if (ci.moveDown.Has(CiItemMoveDownBy.Obsolete))
        {
            int vCenter = r.Y + r.Height / 2;
            g.DrawLine(Pens.OrangeRed, r.X, vCenter, xEndOfText, vCenter);
        }
        //p1.NW('i');

        //draw group separator
        if (e.index > 0)
        {
            var cip = _VisibleItem(e.index - 1);
            if (cip.moveDown != ci.moveDown || (_groupsEnabled && cip.group != ci.group))
            {
                g.DrawLine(Pens.YellowGreen, 0, r.Y, r.Right, r.Y);
            }
        }
    }
Exemplo n.º 25
0
Arquivo: Run.cs Projeto: alexfordc/Au
    /// <summary>
    /// Executes the compiled assembly in new process.
    /// Returns: process id if started now, 0 if failed, (int)ATask.ERunResult.deferred if scheduled to run later.
    /// </summary>
    /// <param name="f"></param>
    /// <param name="r"></param>
    /// <param name="args"></param>
    /// <param name="noDefer">Don't schedule to run later. If cannot run now, just return 0.</param>
    /// <param name="wrPipeName">Pipe name for ATask.WriteResult.</param>
    /// <param name="ignoreLimits">Don't check whether the task can run now.</param>
    /// <param name="runFromEditor">Starting from the Run button or menu Run command.</param>
    public unsafe int RunCompiled(FileNode f, Compiler.CompResults r, string[] args,
                                  bool noDefer = false, string wrPipeName = null, bool ignoreLimits = false, bool runFromEditor = false)
    {
g1:
        if (!ignoreLimits && !_CanRunNow(f, r, out var running, runFromEditor))
        {
            var  ifRunning = r.ifRunning;
            bool same      = running.f == f;
            if (!same)
            {
                ifRunning = r.ifRunning2 switch
                {
                    EIfRunning2.cancel => EIfRunning.cancel,
                    EIfRunning2.wait => EIfRunning.wait,
                    EIfRunning2.warn => EIfRunning.warn,
                    _ => (ifRunning & ~EIfRunning._restartFlag) switch { EIfRunning.cancel => EIfRunning.cancel, EIfRunning.wait => EIfRunning.wait, _ => EIfRunning.warn }
                };
            }
            else if (ifRunning.Has(EIfRunning._restartFlag))
            {
                if (runFromEditor)
                {
                    ifRunning = EIfRunning.restart;
                }
                else
                {
                    ifRunning &= ~EIfRunning._restartFlag;
                }
            }
            //AOutput.Write(same, ifRunning);
            switch (ifRunning)
            {
            case EIfRunning.cancel:
                break;

            case EIfRunning.wait when !noDefer:
                _q.Insert(0, new _WaitingTask(f, r, args));
                return((int)ATask.ERunResult.deferred);                //-1

            case EIfRunning.restart when _EndTask(running):
                goto g1;

            default:             //warn
                string s1 = same ? "it" : $"{running.f.SciLink}";
                AOutput.Write($"<>Cannot start {f.SciLink} because {s1} is running. You may want to <+properties \"{f.IdStringWithWorkspace}\">change<> <c green>ifRunning<>, <c green>ifRunning2<>, <c green>runMode<>.");
                break;
            }
            return(0);
        }

        _SpUac uac = _SpUac.normal; int preIndex = 0;

        if (!AUac.IsUacDisabled)
        {
            //info: to completely disable UAC on Win7: gpedit.msc/Computer configuration/Windows settings/Security settings/Local policies/Security options/User Account Control:Run all administrators in Admin Approval Mode/Disabled. Reboot.
            //note: when UAC disabled, if our uac is System, IsUacDisabled returns false (we probably run as SYSTEM user). It's OK.
            var IL = AUac.OfThisProcess.IntegrityLevel;
            if (r.uac == EUac.inherit)
            {
                switch (IL)
                {
                case UacIL.High: preIndex = 1; break;

                case UacIL.UIAccess: uac = _SpUac.uiAccess; preIndex = 2; break;
                }
            }
            else
            {
                switch (IL)
                {
                case UacIL.Medium:
                case UacIL.UIAccess:
                    if (r.uac == EUac.admin)
                    {
                        uac = _SpUac.admin;
                    }
                    break;

                case UacIL.High:
                    if (r.uac == EUac.user)
                    {
                        uac = _SpUac.userFromAdmin;
                    }
                    break;

                case UacIL.Low:
                case UacIL.Untrusted:
                case UacIL.Unknown:
                //break;
                case UacIL.System:
                case UacIL.Protected:
                    AOutput.Write($"<>Cannot run {f.SciLink}. Meta comment option <c green>uac {r.uac}<> cannot be used when the UAC integrity level of this process is {IL}. Supported levels are Medium, High and uiAccess.");
                    return(0);
                    //info: cannot start Medium IL process from System process. Would need another function. Never mind.
                }
                if (r.uac == EUac.admin)
                {
                    preIndex = 1;
                }
            }
        }

        string     exeFile, argsString;
        _Preloaded pre = null; byte[] taskParams = null;
        bool       bit32 = r.prefer32bit || AVersion.Is32BitOS;

        if (r.notInCache)          //meta role exeProgram
        {
            exeFile    = Compiler.DllNameToAppHostExeName(r.file, bit32);
            argsString = args == null ? null : Au.Util.AStringUtil.CommandLineFromArray(args);
        }
        else
        {
            exeFile = AFolders.ThisAppBS + (bit32 ? "Au.Task32.exe" : "Au.Task.exe");

            //int iFlags = r.hasConfig ? 1 : 0;
            int iFlags = 0;
            if (r.mtaThread)
            {
                iFlags |= 2;
            }
            if (r.console)
            {
                iFlags |= 4;
            }
            taskParams = Au.Util.Serializer_.SerializeWithSize(r.name, r.file, r.pdbOffset, iFlags, args, r.fullPathRefs, wrPipeName, (string)AFolders.Workspace);
            wrPipeName = null;

            if (bit32 && !AVersion.Is32BitOS)
            {
                preIndex += 3;
            }
            pre        = s_preloaded[preIndex] ??= new _Preloaded(preIndex);
            argsString = pre.pipeName;
        }

        int pid; WaitHandle hProcess = null; bool disconnectPipe = false;

        try {
            //APerf.First();
            var pp = pre?.hProcess;
            if (pp != null && 0 != Api.WaitForSingleObject(pp.SafeWaitHandle.DangerousGetHandle(), 0))              //preloaded process exists
            {
                hProcess     = pp; pid = pre.pid;
                pre.hProcess = null; pre.pid = 0;
            }
            else
            {
                if (pp != null)
                {
                    pp.Dispose(); pre.hProcess = null; pre.pid = 0;
                }                                                                                  //preloaded process existed but somehow ended
                (pid, hProcess) = _StartProcess(uac, exeFile, argsString, wrPipeName);
            }
            Api.AllowSetForegroundWindow(pid);

            if (pre != null)
            {
                //APerf.First();
                var o = new Api.OVERLAPPED {
                    hEvent = pre.overlappedEvent
                };
                if (!Api.ConnectNamedPipe(pre.hPipe, &o))
                {
                    int e = ALastError.Code;
                    if (e != Api.ERROR_PIPE_CONNECTED)
                    {
                        if (e != Api.ERROR_IO_PENDING)
                        {
                            throw new AuException(e);
                        }
                        var ha = stackalloc IntPtr[2] {
                            pre.overlappedEvent, hProcess.SafeWaitHandle.DangerousGetHandle()
                        };
                        int wr = Api.WaitForMultipleObjectsEx(2, ha, false, -1, false);
                        if (wr != 0)
                        {
                            Api.CancelIo(pre.hPipe); throw new AuException("*start task. Preloaded task process ended");
                        }                                                                                                                                    //note: if fails when 32-bit process, rebuild solution with platform x86
                        disconnectPipe = true;
                        if (!Api.GetOverlappedResult(pre.hPipe, ref o, out _, false))
                        {
                            throw new AuException(0);
                        }
                    }
                }
                //APerf.Next();
                if (!Api.WriteFileArr(pre.hPipe, taskParams, out _))
                {
                    throw new AuException(0);
                }
                //APerf.Next();
                Api.DisconnectNamedPipe(pre.hPipe); disconnectPipe = false;
                //APerf.NW('e');

                //start preloaded process for next task. Let it wait for pipe connection.
                if (uac != _SpUac.admin)                  //we don't want second UAC consent
                {
                    try { (pre.pid, pre.hProcess) = _StartProcess(uac, exeFile, argsString, null); }
                    catch (Exception ex) { ADebug.Print(ex); }
                }
            }
        }
        catch (Exception ex) {
            AOutput.Write(ex);
            if (disconnectPipe)
            {
                Api.DisconnectNamedPipe(pre.hPipe);
            }
            hProcess?.Dispose();
            return(0);
        }

        var rt = new RunningTask(f, hProcess, r.runMode != ERunMode.green);

        _Add(rt);
        return(pid);
    }
Exemplo n.º 26
0
            LPARAM _WndProc(AWnd w, int message, LPARAM wParam, LPARAM lParam)
            {
                //AWnd.More.PrintMsg(w, message, wParam, lParam);

                switch (message)
                {
                //case Api.WM_DESTROY:
                //	Api.ChangeClipboardChain(w, _wPrevClipViewer);
                //	break;
                case Api.WM_RENDERFORMAT:
                    if (_paste && !Success)
                    {
                        IsBadWindow = !_IsTargetWindow();

                        //note: need to set clipboard data even if bad window.
                        //	Else the clipboard program may retry in loop. Eg Ditto. Then often pasting fails.
                        //	If IsBadWindow, we'll then sleep briefly.
                        //	Good clipboard programs get clipboard data with a delay. Eg Ditto default is 100 ms and can be changed. Therefore usually they don't interfere, unless the target app is very slow.
                        //	Also, after setting clipboard data we cannot wait for good window, because we'll not receive second WM_RENDERFORMAT.

                        try { _SetClipboard(_data, false); }
                        catch (Exception ex) { FailedToSetData = ex; }                        //cannot throw in wndproc, will throw later
                        waitVar = true;
                    }
                    return(0);

                case Api.WM_CLIPBOARDUPDATE:
                    //this message was added in Vista. It is posted, not sent. Once, not for each format. QM2 used SetClipboardViewer/WM_DRAWCLIPBOARD.
                    if (!_paste)
                    {
                        waitVar = true;
                    }
                    return(0);
                }

                return(Api.DefWindowProc(w, message, wParam, lParam));

                //Returns false if probably not the target app reads from the clipboard. Probably a clipboard viewer/manager/etc.
                bool _IsTargetWindow()
                {
                    AWnd wOC = Api.GetOpenClipboardWindow();

                    //int color = 0; if(wOC != _wFocus) color = wOC.ProcessId == _wFocus.ProcessId ? 0xFF0000 : 0xFF;
                    //AOutput.Write($"<><c {color}>{wOC}</c>");

                    if (wOC == _wFocus)
                    {
                        return(true);
                    }
                    if (wOC.Is0)
                    {
                        return(true);                            //tested: none of tested apps calls OpenClipboard(0)
                    }
                    if (wOC.ProcessId == _wFocus.ProcessId)
                    {
                        return(true);                                                       //often classnamed "CLIPBRDWNDCLASS". Some clipboard managers are classnamed so too, eg Ditto.
                    }
                    if (wOC.ProgramName.Eqi("RuntimeBroker.exe"))
                    {
                        return(true);                                                             //Edge, Store apps
                    }
                    //CONSIDER: option to return true for user-known windows, eg using a callback. Print warning that includes wOC info.

                    ADebug.Print(wOC.ToString());
                    return(false);

                    //BlueStacks problems:
                    //	Uses an aggressive viewer. Always debugprints while it is running, even when other apps are active.
                    //	Sometimes pastes old text, usually after starting BlueStacks or after some time of not using it.
                    //		With or without clipboard restoring.
                    //		Then starts to work correctly always. Difficult to debug.
                    //		KeySpeedClipboard=100 usually helps, but sometimes even 300 does not help.
                }
            }
Exemplo n.º 27
0
        bool _FillGrid(bool newWindow)
        {
            bool isCon = !_con.Is0;

            var g = _grid;

            if (newWindow)
            {
                g.ZClear();
            }
            else
            {
                g.RowsCount = 5;
            }

            _WinInfo f = default;

            if (!_GetClassName(_wnd, out f.wClass))
            {
                return(false);                                               //note: get even if !newWindow, to detect closed window
            }
            if (isCon && !_GetClassName(_con, out f.cClass))
            {
                return(false);
            }
            _propError = null;

            _noeventGridValueChanged = true;

            var wndName = _wnd.NameTL_;

            if (newWindow)
            {
                g.ZAddHeaderRow("Window");
                g.ZAdd(null, "name", TUtil.EscapeWindowName(wndName, true), true, info: "Window name.$");
                g.ZAdd(null, "class", TUtil.StripWndClassName(f.wClass, true), true, info: "Window class name.$");
                f.wProg = _wnd.ProgramName;
                var ap = new List <string> {
                    f.wProg, "WOwner.Process(processId)", "WOwner.Thread(threadId)"
                }; if (!_wnd.OwnerWindow.Is0)
                {
                    ap.Add("WOwner.Window(ow)");
                }
                g.ZAdd(null, "program", ap, wndName.NE(), info: "Program.$", etype: ParamGrid.EditType.ComboText, comboIndex: 0);
                g.ZAdd(null, "contains", (Func <string[]>)_ContainsCombo_DropDown, false, info: "An accessible object in the window. Format: 'role' name.\r\nName$$", etype: ParamGrid.EditType.ComboText);
            }
            else if (wndName != _wndName)
            {
                if (TUtil.ShouldChangeGridWildex(g.ZGetCellText("name", 1), wndName))
                {
                    g.ZSetCellText("name", 1, TUtil.EscapeWindowName(wndName, true));
                }
            }
            f.wName = _wndName = wndName;

            if (isCon)
            {
                g.ZAddHeaderRow("Control", check: !_uncheckControl);
                g.ZAddHidden = _uncheckControl;

                //name combo
                f.cName = _con.Name;
                int iSel = f.cName.NE() ? -1 : 0;
                var an   = new List <string> {
                    TUtil.EscapeWildex(f.cName)
                };
                _ConNameAdd("***wfName ", f.cWF = _con.NameWinForms);
                /*bool isAcc =*/
                _ConNameAdd("***accName ", f.cAcc = _con.NameAcc);
                //bool isLabel = _ConNameAdd("***label ", f.cLabel = _con.NameLabel);
                //if(isAcc && isLabel && iSel == an.Count - 2 && f.cAcc == f.cLabel) iSel++; //if label == accName, prefer label
                if (iSel < 0)
                {
                    iSel = 0;                          //never select text, even if all others unavailable
                }
                _ConNameAdd("***text ", f.cText = _con.ControlText);
                bool _ConNameAdd(string prefix, string value)
                {
                    if (value.NE())
                    {
                        return(false);
                    }
                    if (iSel < 0)
                    {
                        iSel = an.Count;
                    }
                    an.Add(prefix + TUtil.EscapeWildex(value));
                    return(true);
                }

                bool idUseful = TUtil.GetUsefulControlId(_con, _wnd, out f.cId);
                if (idUseful)
                {
                    g.ZAdd(null, "id", f.cId, true);
                }
                else
                {
                    an.Add("***id " + f.cId + " (probably not useful)");
                }
                g.ZAdd("nameC", "name", an, !idUseful, info: "Control name.$", etype: ParamGrid.EditType.ComboText, comboIndex: iSel);
                g.ZAdd("classC", "class", TUtil.StripWndClassName(f.cClass, true), !idUseful, info: "Control class name.$");
                g.ZAddHidden = false;
            }

            _uncheckControl          = false;
            _noeventGridValueChanged = false;
            g.ZAutoSize();
            _FillWindowInfo(f);
            return(true);

            string[] _ContainsCombo_DropDown()
            {
                try {
                    var a1 = new List <string>();
                    //child
                    foreach (var c in _wnd.Get.Children(onlyVisible: true))
                    {
                        var cn = c.Name; if (cn.NE())
                        {
                            continue;
                        }
                        cn = "c '" + TUtil.StripWndClassName(c.ClassName, true) + "' " + TUtil.EscapeWildex(cn);
                        if (!a1.Contains(cn))
                        {
                            a1.Add(cn);
                        }
                    }
                    //acc
                    var    a2       = new List <string>();
                    var    a3       = AAcc.FindAll(_wnd, name: "?*", prop: "notin=SCROLLBAR\0maxcc=100", flags: AFFlags.ClientArea);            //all that have a name
                    string prevName = null;
                    for (int i = a3.Length; --i >= 0;)
                    {
                        if (!a3[i].GetProperties("Rn", out var prop))
                        {
                            continue;
                        }
                        if (prop.Name == prevName && prop.Role == "WINDOW")
                        {
                            continue;
                        }
                        prevName = prop.Name;                                                                                      //skip parent WINDOW
                        string rn = "a '" + prop.Role + "' " + TUtil.EscapeWildex(prop.Name);
                        if (!a2.Contains(rn))
                        {
                            a2.Add(rn);
                        }
                    }
                    a2.Reverse();
                    a1.AddRange(a2);

                    return(a1.ToArray());
                    //rejected: sort
                }
                catch (Exception ex) { ADebug.Print(ex); return(null); }
            }

            bool _GetClassName(AWnd w, out string cn)
            {
                cn = w.ClassName;
                if (cn != null)
                {
                    return(true);
                }
                _propError = "Failed to get " + (w == _wnd ? "window" : "control") + " properties: \r\n" + ALastError.Message;
                _grid.ZClear();
                _grid.Invalidate();
                _winInfo.Z.ClearText();
                return(false);
            }
        }