示例#1
0
            private unsafe void FileSystemEventCallback(
                FSEventStreamRef streamRef,
                IntPtr clientCallBackInfo,
                size_t numEvents,
                byte **eventPaths,
                FSEventStreamEventFlags *eventFlags,
                FSEventStreamEventId *eventIds)
            {
                // Try to get the actual watcher from our weak reference.  We maintain a weak reference most of the time
                // so as to avoid a rooted cycle that would prevent our processing loop from ever ending
                // if the watcher is dropped by the user without being disposed. If we can't get the watcher,
                // there's nothing more to do (we can't raise events), so bail.
                FileSystemWatcher watcher;

                if (!_weakWatcher.TryGetTarget(out watcher))
                {
                    CancellationCallback();
                    return;
                }

                ExecutionContext context = _context;

                if (context is null)
                {
                    // Flow suppressed, just run here
                    ProcessEvents(numEvents.ToInt32(), eventPaths, new Span <FSEventStreamEventFlags>(eventFlags, numEvents.ToInt32()), new Span <FSEventStreamEventId>(eventIds, numEvents.ToInt32()), watcher);
                }
                else
                {
                    ExecutionContext.Run(
                        context,
                        (object o) => ((RunningInstance)o).ProcessEvents(numEvents.ToInt32(), eventPaths, new Span <FSEventStreamEventFlags>(eventFlags, numEvents.ToInt32()), new Span <FSEventStreamEventId>(eventIds, numEvents.ToInt32()), watcher),
                        this);
                }
            }
示例#2
0
        void OnRenderObject()
        {
            //if (Input.GetKey(KeyCode.Joystick1Button0))
            //{
            //    currentOverlayType = OverlayType.None;
            //}
            //else if (Input.GetKey(KeyCode.Joystick1Button1))
            //{
            //    currentOverlayType = OverlayType.OverlayShowLod;
            //}
            //else
            //{
            //    currentOverlayType = OverlayType.Overlay;
            //}

            //int eyeNum = (Camera.current.depth == (int)RenderEventType.RightEyeEndFrame) ? 1 : 0;
            //Matrix4x4 mv_Left = LeftAnchor.worldToCameraMatrix * this.transform.localToWorldMatrix * toOculusMatrix;

            //IVR_SetOverlay(LeftAnchor.targetTexture.GetNativeTextureID(), 0);
            System.IntPtr texutre = mCamera.targetTexture.GetNativeTexturePtr();
            mActivity.Interface_javaobjcall("SetEyeTexture", texutre.ToInt32(), (int)eyeType);
            //Matrix4x4 mv_Right = RightAnchor.worldToCameraMatrix * this.transform.localToWorldMatrix * toOculusMatrix;
            //IVR_SetOverlay(RightAnchor.targetTexture.GetNativeTextureID(), 1);
            //mActivity.Interface_javaobjcall("SetEyeTexture", RightAnchor.targetTexture.GetNativeTextureID(), 1);
        }
示例#3
0
        // display windows dialog
        private void displayDialog(System.IntPtr wndHandle, int dialogToShow)
        {
            // prep variables
            int i       = -1;
            int iHandle = 0;

            // get parent handle
            if (wndHandle != System.IntPtr.Zero)
            {
                iHandle = wndHandle.ToInt32();
            }

            // choose dialog to show bassed on
            if (dialogToShow == 1)
            {
                i = WNetConnectionDialog(iHandle, RESOURCETYPE_DISK);
            }
            else if (dialogToShow == 2)
            {
                i = WNetDisconnectDialog(iHandle, RESOURCETYPE_DISK);
            }

            // if error returned, throw
            if (i > 0)
            {
                throw new System.ComponentModel.Win32Exception(i);
            }
        }
示例#4
0
 private void StyleComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
 {
     if (this.iarray_0.Count != 0)
     {
         e.DrawBackground();
         try
         {
             IStyleGalleryItem styleGalleryItem = this.iarray_0.get_Element(e.Index) as IStyleGalleryItem;
             if (styleGalleryItem != null)
             {
                 System.IntPtr hdc       = e.Graphics.GetHdc();
                 IStyleDraw    styleDraw = StyleDrawFactory.CreateStyleDraw(styleGalleryItem.Item);
                 if (styleDraw != null)
                 {
                     e.Bounds.Inflate(-2, -4);
                     styleDraw.Draw(hdc.ToInt32(), e.Bounds, 72.0, 1.0);
                 }
                 e.Graphics.ReleaseHdc(hdc);
             }
             else
             {
                 Brush brush = new SolidBrush(e.ForeColor);
                 e.Graphics.DrawString(base.Items[e.Index].ToString(), e.Font, brush, (float)(e.Bounds.Left + 3),
                                       (float)(e.Bounds.Top + 3));
             }
         }
         catch
         {
         }
     }
 }
示例#5
0
 private void SymbolItem_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
 {
     if (this.object_0 != null)
     {
         if (this.bool_0 && this.object_0 is IMarkerSymbol)
         {
             System.Drawing.Point pt = new System.Drawing.Point(base.ClientSize.Width / 2,
                                                                base.ClientRectangle.Top + 2);
             System.Drawing.Point pt2 = new System.Drawing.Point(base.ClientSize.Width / 2,
                                                                 base.ClientRectangle.Bottom - 2);
             e.Graphics.DrawLine(Pens.Green, pt, pt2);
             pt.X  = base.ClientRectangle.Left + 2;
             pt.Y  = base.ClientSize.Height / 2;
             pt2.X = base.ClientRectangle.Right - 2;
             pt2.Y = base.ClientSize.Height / 2;
             e.Graphics.DrawLine(Pens.Green, pt, pt2);
         }
         else if (this.object_0 is ITextSymbol)
         {
             System.Drawing.Point point = new System.Drawing.Point(base.ClientSize.Width / 2,
                                                                   base.ClientRectangle.Height + 2);
             e.Graphics.DrawEllipse(Pens.Black, point.X, point.Y, 2, 2);
         }
         System.IntPtr hdc = e.Graphics.GetHdc();
         this.DrawSymbol(hdc.ToInt32(), base.ClientRectangle, this.object_0);
         e.Graphics.ReleaseHdc(hdc);
     }
 }
示例#6
0
 private void ColorRampComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
 {
     if (this.iarray_0.Count != 0)
     {
         e.DrawBackground();
         System.IntPtr hdc = e.Graphics.GetHdc();
         this.DrawColorRamp(hdc.ToInt32(), e.Bounds, (IColorRamp)this.iarray_0.get_Element(e.Index));
         e.Graphics.ReleaseHdc(hdc);
     }
 }
示例#7
0
        /// <summary>
        /// Converts Byte array to Unity Color32 array.
        /// </summary>
        /// <param name="bytes">Input Byte array.</param>
        /// <param name="colors">Output Color32 array.</param>
        public static void ByteArrayToColor32Array(byte[] bytes, out Color32[] colors)
        {
            int size = bytes.Length;

            colors = new Color32[size / 4];
            System.IntPtr ptr = CvUtil.GetIntPtr(bytes);
            for (int i = 0; i < size / 4; i++)
            {
                colors[i] = (Color32)Marshal.PtrToStructure(ptr, typeof(Color32));
                ptr       = new System.IntPtr(ptr.ToInt32() + 4);
            }
        }
示例#8
0
        public void StyleGalleryItemToBmp(Bitmap bitmap_0, double double_0, double double_1)
        {
            Size     size     = bitmap_0.Size;
            Graphics graphics = Graphics.FromImage(bitmap_0);

            System.IntPtr hdc        = graphics.GetHdc();
            Rectangle     rectangle_ = new Rectangle(0, 0, size.Width, size.Height);

            this.Draw(hdc.ToInt32(), rectangle_, double_0, double_1);
            graphics.ReleaseHdc(hdc);
            graphics.Dispose();
        }
        public void ControllCamWithScreenshot()
        {
            string dName    = "".PadRight(100);
            string dVersion = "".PadRight(100);

            System.IntPtr hWndC = capCreateCaptureWindowA("VFW Capture", WS_POPUP | WS_CHILD, 0, 0, 320, 240, 0, 0); // get camera handle
            SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);                                                         // connect to camera
            string path = System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\Pictures\\" + System.DateTime.Now.ToString("yyyy.MM.dd HH.mm.ss") + ".jpg";

            System.IntPtr hBmp = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(path);
            SendMessage(hWndC, WM_CAP_SAVEDIB, 0, hBmp.ToInt32()); // save screenshot
            SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);    // turn off the camera
        }
示例#10
0
            private unsafe void FileSystemEventCallback(
                FSEventStreamRef streamRef,
                IntPtr clientCallBackInfo,
                size_t numEvents,
                byte **eventPaths,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                Interop.EventStream.FSEventStreamEventFlags[] eventFlags,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                FSEventStreamEventId[] eventIds)
            {
                Debug.Assert((eventPaths != null) && (numEvents.ToInt32() == eventFlags.Length) && (numEvents.ToInt32() == eventIds.Length));

                // Try to get the actual watcher from our weak reference.  We maintain a weak reference most of the time
                // so as to avoid a rooted cycle that would prevent our processing loop from ever ending
                // if the watcher is dropped by the user without being disposed. If we can't get the watcher,
                // there's nothing more to do (we can't raise events), so bail.
                FileSystemWatcher watcher;

                if (!_weakWatcher.TryGetTarget(out watcher))
                {
                    CancellationCallback();
                    return;
                }

                ExecutionContext context = _context;

                if (context is null)
                {
                    // Flow suppressed, just run here
                    ProcessEvents(numEvents.ToInt32(), eventPaths, eventFlags, eventIds, watcher);
                }
                else
                {
                    ExecutionContext.Run(
                        context,
                        (object o) => ((RunningInstance)o).ProcessEvents(numEvents.ToInt32(), eventPaths, eventFlags, eventIds, watcher),
                        this);
                }
            }
示例#11
0
        public Bitmap StyleGalleryItemToBmp(Size size_0, double double_0, double double_1)
        {
            Bitmap   bitmap   = new Bitmap(size_0.Width, size_0.Height);
            Graphics graphics = Graphics.FromImage(bitmap);

            System.IntPtr hdc        = graphics.GetHdc();
            Rectangle     rectangle_ = new Rectangle(0, 0, size_0.Width, size_0.Height);

            this.Draw(hdc.ToInt32(), rectangle_, double_0, double_1);
            graphics.ReleaseHdc(hdc);
            graphics.Dispose();
            return(bitmap);
        }
示例#12
0
 private void StyleButton_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
 {
     if (this.object_0 != null)
     {
         System.IntPtr hdc = e.Graphics.GetHdc();
         if (this.istyleDraw_0 != null)
         {
             Rectangle clipRectangle = e.ClipRectangle;
             clipRectangle.Inflate(-3, -3);
             this.istyleDraw_0.Draw(hdc.ToInt32(), clipRectangle, 72.0, 1.0);
         }
         e.Graphics.ReleaseHdc(hdc);
     }
 }
示例#13
0
        private int HookCallbackProc(int nCode, System.IntPtr wParam, System.IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(ColorPicker_NativeMethods.CallNextHookEx(m_hHook, nCode, wParam, lParam));
            }
            else
            {
                //Marshall the data from the callback.
                WinUtil.KeyboardHookStruct hookstruct =
                    (WinUtil.KeyboardHookStruct)
                    System.Runtime.InteropServices.Marshal.PtrToStructure(lParam, typeof(WinUtil.KeyboardHookStruct));

                if (OnKeyDown != null && wParam.ToInt32() == WinUtil.WM_KEYDOWN)
                {
                    var        key     = (System.Windows.Forms.Keys)hookstruct.vkCode;
                    const Keys shift   = System.Windows.Forms.Keys.Shift;
                    const Keys control = System.Windows.Forms.Keys.Control;
                    Keys       modkeys = System.Windows.Forms.Control.ModifierKeys;

                    if ((modkeys & shift) == shift)
                    {
                        key |= shift;
                    }

                    if ((modkeys & control) == control)
                    {
                        key |= control;
                    }

                    var e = new System.Windows.Forms.KeyEventArgs(key);
                    e.Handled = false;
                    OnKeyDown(e);

                    if (e.Handled)
                    {
                        return(1);
                    }
                }

                int result = 0;
                if (m_hHook != 0)
                {
                    result = ColorPicker_NativeMethods.CallNextHookEx(m_hHook, nCode, wParam, lParam);
                }

                return(result);
            }
        }
示例#14
0
 private void NewSymbolButton_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
 {
     if (this.object_0 != null)
     {
         System.IntPtr hdc       = e.Graphics.GetHdc();
         IStyleDraw    styleDraw = StyleDrawFactory.CreateStyleDraw(this.object_0);
         if (styleDraw != null)
         {
             Rectangle clipRectangle = e.ClipRectangle;
             clipRectangle.Inflate(-3, -3);
             styleDraw.Draw(hdc.ToInt32(), clipRectangle, 96.0, 1.0);
         }
         e.Graphics.ReleaseHdc(hdc);
     }
 }
示例#15
0
 private void SymbolListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
 {
     if (base.Items.Count != 0)
     {
         SymbolListItem symbolListItem = (SymbolListItem)base.Items[e.Index];
         e.DrawBackground();
         Bitmap image;
         if (symbolListItem.m_bVisible)
         {
             image =
                 new Bitmap(
                     base.GetType().Assembly.GetManifestResourceStream("Yutai.ArcGIS.Common.SymbolLib.Check.bmp"));
         }
         else
         {
             image =
                 new Bitmap(
                     base.GetType()
                     .Assembly.GetManifestResourceStream("Yutai.ArcGIS.Common.SymbolLib.UnCheck.bmp"));
         }
         Bitmap image2;
         if (symbolListItem.m_bLockColor)
         {
             image2 =
                 new Bitmap(
                     base.GetType().Assembly.GetManifestResourceStream("Yutai.ArcGIS.Common.SymbolLib.Lock.bmp"));
         }
         else
         {
             image2 =
                 new Bitmap(
                     base.GetType()
                     .Assembly.GetManifestResourceStream("Yutai.ArcGIS.Common.SymbolLib.UnLock.bmp"));
         }
         Rectangle rect      = new Rectangle(2, e.Bounds.Y + (e.Bounds.Height - 16) / 2, 16, 16);
         Rectangle rect2     = new Rectangle(e.Bounds.Right - 21, e.Bounds.Y + (e.Bounds.Height - 16) / 2, 16, 16);
         Rectangle rectangle = new Rectangle(rect.Right + 2, e.Bounds.Y + 1, e.Bounds.Width - 46,
                                             e.Bounds.Height - 2);
         e.Graphics.DrawImageUnscaled(image, rect);
         e.Graphics.DrawImageUnscaled(image2, rect2);
         e.Graphics.FillRectangle(Brushes.White, rectangle);
         Graphics      graphics = e.Graphics;
         System.IntPtr hdc      = graphics.GetHdc();
         this.DrawSymbol(hdc.ToInt32(), rectangle, symbolListItem.m_pSymbol);
         graphics.ReleaseHdc(hdc);
     }
 }
示例#16
0
        static System.IntPtr WndProc(System.IntPtr hwnd, int msg, System.IntPtr wparam, System.IntPtr lparam, ref bool handled)
        {
            switch (msg)
            {
            case 0x0312:            // WM_HOTKEY
                switch (wparam.ToInt32())
                {
                case 0:
                    System.Diagnostics.Debug.WriteLine("ホットキー「Alt + Shift + A」が押された。");
                    break;

                case 1:
                    System.Diagnostics.Debug.WriteLine("ホットキー「Ctrl + Windows + B」が押された。");
                    break;
                }
                break;
            }
            return(System.IntPtr.Zero);
        }
示例#17
0
 private void RepresentationruleListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
 {
     if (base.Items.Count != 0)
     {
         RepresentationruleListBox.RepresentationRuleWrap representationRuleWrap =
             (RepresentationruleListBox.RepresentationRuleWrap)base.Items[e.Index];
         e.DrawBackground();
         string s     = "(" + representationRuleWrap.RuleID.ToString() + ") " + representationRuleWrap.Name;
         Brush  brush = new SolidBrush(e.ForeColor);
         e.Graphics.DrawString(s, this.Font, brush, (float)e.Bounds.X, (float)e.Bounds.Y);
         brush.Dispose();
         System.IntPtr  hdc           = e.Graphics.GetHdc();
         IOutputContext outputContext = new OutputContext();
         IPoint         point         = new ESRI.ArcGIS.Geometry.Point();
         point.PutCoords((double)(e.Bounds.X + e.Bounds.Width / 2), (double)(e.Bounds.Y + e.Bounds.Height / 2 + 10));
         tagRECT tagRECT_ = default(tagRECT);
         tagRECT_.left   = e.Bounds.Left + 10;
         tagRECT_.right  = e.Bounds.Right - 10;
         tagRECT_.top    = e.Bounds.Top + 10;
         tagRECT_.bottom = e.Bounds.Bottom - 5;
         outputContext.Init(1.0, 1.5, 96.0, 0.0, point, ref tagRECT_, hdc.ToInt32());
         IGeometry geometry;
         if (this.esriGeometryType_0 == esriGeometryType.esriGeometryPolygon)
         {
             geometry = this.method_1(tagRECT_);
         }
         else if (this.esriGeometryType_0 == esriGeometryType.esriGeometryPolyline)
         {
             geometry = this.method_2(tagRECT_);
         }
         else
         {
             geometry = new ESRI.ArcGIS.Geometry.Point();
             (geometry as IPoint).PutCoords((double)((tagRECT_.left + tagRECT_.right) / 2),
                                            (double)((tagRECT_.top + tagRECT_.bottom) / 2));
         }
         representationRuleWrap.RepresentationRule.Draw(-1, outputContext, geometry, geometry.Envelope);
         e.Graphics.ReleaseHdc(hdc);
     }
 }
示例#18
0
 protected override void OnPaint(System.Windows.Forms.PaintEventArgs paintEventArgs_0)
 {
     if (this.object_0 == null)
     {
         this.Text = "无法绘制符号!";
     }
     else
     {
         this.Text = "";
         System.IntPtr hdc           = paintEventArgs_0.Graphics.GetHdc();
         Rectangle     clipRectangle = paintEventArgs_0.ClipRectangle;
         clipRectangle.Inflate(-3, -3);
         if (this.istyleDraw_0 != null)
         {
             this.istyleDraw_0.Draw(hdc.ToInt32(), clipRectangle, 72.0, 1.0);
         }
         else
         {
             paintEventArgs_0.Graphics.DrawString(this.Text, this.Font, Brushes.Black, clipRectangle);
         }
         paintEventArgs_0.Graphics.ReleaseHdc(hdc);
         base.OnPaint(paintEventArgs_0);
     }
 }
示例#19
0
            private unsafe void FileSystemEventCallback(
                FSEventStreamRef streamRef,
                IntPtr clientCallBackInfo,
                size_t numEvents,
                byte **eventPaths,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                Interop.EventStream.FSEventStreamEventFlags[] eventFlags,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                FSEventStreamEventId[] eventIds)
            {
                Debug.Assert((eventPaths != null) && (numEvents.ToInt32() == eventFlags.Length) && (numEvents.ToInt32() == eventIds.Length));

                // Try to get the actual watcher from our weak reference.  We maintain a weak reference most of the time
                // so as to avoid a rooted cycle that would prevent our processing loop from ever ending
                // if the watcher is dropped by the user without being disposed. If we can't get the watcher,
                // there's nothing more to do (we can't raise events), so bail.
                FileSystemWatcher watcher;

                if (!_weakWatcher.TryGetTarget(out watcher))
                {
                    CancellationCallback();
                    return;
                }

                ExecutionContext.Run(_context, delegate
                {
                    // Since renames come in pairs, when we find the first we need to search for the next one. Once we find it, we'll add it to this
                    // list so when the for-loop comes across it, we'll skip it since it's already been processed as part of the original of the pair.
                    List <FSEventStreamEventId> handledRenameEvents = null;
                    Memory <char>[] events = new Memory <char> [numEvents.ToInt32()];
                    ProcessEvents();

                    for (long i = 0; i < numEvents.ToInt32(); i++)
                    {
                        ReadOnlySpan <char> path = events[i].Span;
                        Debug.Assert(path[path.Length - 1] != '/', "Trailing slashes on events is not supported");

                        // Match Windows and don't notify us about changes to the Root folder
                        if (_fullDirectory.Length >= path.Length && path.Equals(_fullDirectory.AsSpan(0, path.Length), StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        WatcherChangeTypes eventType = 0;
                        // First, we should check if this event should kick off a re-scan since we can't really rely on anything after this point if that is true
                        if (ShouldRescanOccur(eventFlags[i]))
                        {
                            watcher.OnError(new ErrorEventArgs(new IOException(SR.FSW_BufferOverflow, (int)eventFlags[i])));
                            break;
                        }
                        else if ((handledRenameEvents != null) && (handledRenameEvents.Contains(eventIds[i])))
                        {
                            // If this event is the second in a rename pair then skip it
                            continue;
                        }
                        else if (CheckIfPathIsNested(path) && ((eventType = FilterEvents(eventFlags[i])) != 0))
                        {
                            // The base FileSystemWatcher does a match check against the relative path before combining with
                            // the root dir; however, null is special cased to signify the root dir, so check if we should use that.
                            ReadOnlySpan <char> relativePath = ReadOnlySpan <char> .Empty;
                            if (!path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase))
                            {
                                // Remove the root directory to get the relative path
                                relativePath = path.Slice(_fullDirectory.Length);
                            }

                            // Raise a notification for the event
                            if (((eventType & WatcherChangeTypes.Changed) > 0))
                            {
                                watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Changed, relativePath);
                            }
                            if (((eventType & WatcherChangeTypes.Created) > 0))
                            {
                                watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath);
                            }
                            if (((eventType & WatcherChangeTypes.Deleted) > 0))
                            {
                                watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath);
                            }
                            if (((eventType & WatcherChangeTypes.Renamed) > 0))
                            {
                                // Find the rename that is paired to this rename, which should be the next rename in the list
                                long pairedId = FindRenameChangePairedChange(i, eventFlags);
                                if (pairedId == long.MinValue)
                                {
                                    // Getting here means we have a rename without a pair, meaning it should be a create for the
                                    // move from unwatched folder to watcher folder scenario or a move from the watcher folder out.
                                    // Check if the item exists on disk to check which it is
                                    // Don't send a new notification if we already sent one for this event.
                                    if (DoesItemExist(path, IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemIsFile)))
                                    {
                                        if ((eventType & WatcherChangeTypes.Created) == 0)
                                        {
                                            watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath);
                                        }
                                    }
                                    else if ((eventType & WatcherChangeTypes.Deleted) == 0)
                                    {
                                        watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath);
                                    }
                                }
                                else
                                {
                                    // Remove the base directory prefix and add the paired event to the list of
                                    // events to skip and notify the user of the rename
                                    ReadOnlySpan <char> newPathRelativeName = events[pairedId].Span.Slice(_fullDirectory.Length);
                                    watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);

                                    // Create a new list, if necessary, and add the event
                                    if (handledRenameEvents == null)
                                    {
                                        handledRenameEvents = new List <FSEventStreamEventId>();
                                    }
                                    handledRenameEvents.Add(eventIds[pairedId]);
                                }
                            }
                        }

                        ArraySegment <char> underlyingArray;
                        if (MemoryMarshal.TryGetArray(events[i], out underlyingArray))
                        {
                            ArrayPool <char> .Shared.Return(underlyingArray.Array);
                        }
                    }

                    this._context = ExecutionContext.Capture();

                    void ProcessEvents()
                    {
                        for (int i = 0; i < events.Length; i++)
                        {
                            int byteCount = 0;
                            Debug.Assert(eventPaths[i] != null);
                            byte *temp = eventPaths[i];

                            // Finds the position of null character.
                            while (*temp != 0)
                            {
                                temp++;
                                byteCount++;
                            }

                            Debug.Assert(byteCount > 0, "Empty events are not supported");
                            events[i] = new Memory <char>(ArrayPool <char> .Shared.Rent(Encoding.UTF8.GetMaxCharCount(byteCount)));
                            int charCount;

                            // Converting an array of bytes to UTF-8 char array
                            charCount = Encoding.UTF8.GetChars(new ReadOnlySpan <byte>(eventPaths[i], byteCount), events[i].Span);
                            events[i] = events[i].Slice(0, charCount);
                        }
                    }
                }, null);
示例#20
0
            private void FileSystemEventCallback(
                FSEventStreamRef streamRef,
                IntPtr clientCallBackInfo,
                size_t numEvents,
                String[] eventPaths,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                Interop.EventStream.FSEventStreamEventFlags[] eventFlags,
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
                FSEventStreamEventId[] eventIds)
            {
                Debug.Assert((numEvents.ToInt32() == eventPaths.Length) && (numEvents.ToInt32() == eventFlags.Length) && (numEvents.ToInt32() == eventIds.Length));

                // Try to get the actual watcher from our weak reference.  We maintain a weak reference most of the time
                // so as to avoid a rooted cycle that would prevent our processing loop from ever ending
                // if the watcher is dropped by the user without being disposed. If we can't get the watcher,
                // there's nothing more to do (we can't raise events), so bail.
                FileSystemWatcher watcher;

                if (!_weakWatcher.TryGetTarget(out watcher))
                {
                    CancellationCallback();
                    return;
                }

                // Since renames come in pairs, when we find the first we need to search for the next one. Once we find it, we'll add it to this
                // list so when the for-loop comes across it, we'll skip it since it's already been processed as part of the original of the pair.
                List <FSEventStreamEventId> handledRenameEvents = null;

                for (long i = 0; i < numEvents.ToInt32(); i++)
                {
                    Debug.Assert(eventPaths[i].Length > 0, "Empty events are not supported");
                    Debug.Assert(eventPaths[i][eventPaths[i].Length - 1] != '/', "Trailing slashes on events is not supported");

                    // Match Windows and don't notify us about changes to the Root folder
                    string path = eventPaths[i];
                    if (string.Compare(path, 0, _fullDirectory, 0, path.Length, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        continue;
                    }

                    WatcherChangeTypes eventType = 0;
                    // First, we should check if this event should kick off a re-scan since we can't really rely on anything after this point if that is true
                    if (ShouldRescanOccur(eventFlags[i]))
                    {
                        watcher.OnError(new ErrorEventArgs(new IOException(SR.FSW_BufferOverflow, (int)eventFlags[i])));
                        break;
                    }
                    else if ((handledRenameEvents != null) && (handledRenameEvents.Contains(eventIds[i])))
                    {
                        // If this event is the second in a rename pair then skip it
                        continue;
                    }
                    else if (CheckIfPathIsNested(path) && ((eventType = FilterEvents(eventFlags[i], path)) != 0))
                    {
                        // The base FileSystemWatcher does a match check against the relative path before combining with
                        // the root dir; however, null is special cased to signify the root dir, so check if we should use that.
                        string relativePath = null;
                        if (path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase) == false)
                        {
                            // Remove the root directory to get the relative path
                            relativePath = path.Remove(0, _fullDirectory.Length);
                        }

                        // Raise a notification for the event
                        if (((eventType & WatcherChangeTypes.Changed) > 0))
                        {
                            watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Changed, relativePath);
                        }
                        if (((eventType & WatcherChangeTypes.Created) > 0))
                        {
                            watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath);
                        }
                        if (((eventType & WatcherChangeTypes.Deleted) > 0))
                        {
                            watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath);
                        }
                        if (((eventType & WatcherChangeTypes.Renamed) > 0))
                        {
                            // Find the rename that is paired to this rename, which should be the next rename in the list
                            long pairedId = FindRenameChangePairedChange(i, eventPaths, eventFlags, eventIds);
                            if (pairedId == long.MinValue)
                            {
                                // Getting here means we have a rename without a pair, meaning it should be a create for the
                                // move from unwatched folder to watcher folder scenario or a move from the watcher folder out.
                                // Check if the item exists on disk to check which it is
                                // Don't send a new notification if we already sent one for this event.
                                if (DoesItemExist(path, IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemIsFile)))
                                {
                                    if ((eventType & WatcherChangeTypes.Created) == 0)
                                    {
                                        watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath);
                                    }
                                }
                                else if ((eventType & WatcherChangeTypes.Deleted) == 0)
                                {
                                    watcher.NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath);
                                }
                            }
                            else
                            {
                                // Remove the base directory prefix and add the paired event to the list of
                                // events to skip and notify the user of the rename
                                string newPathRelativeName = eventPaths[pairedId].Remove(0, _fullDirectory.Length);
                                watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);

                                // Create a new list, if necessary, and add the event
                                if (handledRenameEvents == null)
                                {
                                    handledRenameEvents = new List <FSEventStreamEventId>();
                                }
                                handledRenameEvents.Add(eventIds[pairedId]);
                            }
                        }
                    }
                }
            }
示例#21
0
        private void FileSystemEventCallback(
            FSEventStreamRef streamRef,
            IntPtr clientCallBackInfo,
            size_t numEvents,
            String[] eventPaths,
            [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
            Interop.EventStream.FSEventStreamEventFlags[] eventFlags,
            [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
            FSEventStreamEventId[] eventIds)
        {
            Debug.Assert((numEvents.ToInt32() == eventPaths.Length) && (numEvents.ToInt32() == eventFlags.Length) && (numEvents.ToInt32() == eventIds.Length));

            // Since renames come in pairs, when we find the first we need to search for the next one. Once we find it, we'll add it to this
            // list so when the for-loop comes across it, we'll skip it since it's already been processed as part of the original of the pair.
            List <FSEventStreamEventId> handledRenameEvents = null;

            for (long i = 0; i < numEvents.ToInt32(); i++)
            {
                // First, we should check if this event should kick off a re-scan since we can't really rely on anything after this point if that is true
                if (ShouldRescanOccur(eventFlags[i]))
                {
                    OnError(new ErrorEventArgs(new IOException(SR.FSW_BufferOverflow, (int)eventFlags[i])));
                    break;
                }
                else if ((handledRenameEvents != null) && (handledRenameEvents.Contains(eventIds[i])))
                {
                    // If this event is the second in a rename pair then skip it
                    continue;
                }
                else if ((DoesPathPassNameFilter(eventPaths[i])) && ((_filterFlags & eventFlags[i]) != 0))
                {
                    // Remove the base directory prefix (including trailing / that OS X adds)
                    string relativePath = eventPaths[i].Remove(0, _directory.Length + 1);

                    // Check if this is a rename
                    if ((eventFlags[i] & Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemRenamed) == Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemRenamed)
                    {
                        // Find the rename that is paired to this rename, which should be the next rename in the list
                        long pairedId = FindRenameChangePairedChange(i, eventPaths, eventFlags, eventIds);
                        if (pairedId == long.MinValue)
                        {
                            OnError(new ErrorEventArgs(new ArgumentOutOfRangeException("pairedId")));
                        }
                        else
                        {
                            // Remove the base directory prefix (including trailing / that OS X adds) and
                            // add the paired event to the list of events to skip and notify the user of the rename
                            string newPathRelativeName = eventPaths[pairedId].Remove(0, _directory.Length + 1);
                            NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);

                            // Create a new list, if necessary, and add the event
                            if (handledRenameEvents == null)
                            {
                                handledRenameEvents = new List <FSEventStreamEventId>();
                            }
                            handledRenameEvents.Add(eventIds[pairedId]);
                        }
                    }
                    else
                    {
                        // Note: the order here matters due to coalescing since two events (such as a mod followed by a delete) could be coalesced into one notification
                        //       So look for deletes first since those will mean the listening app can't do anything with the item since it doesn't exist (such as stat
                        //       the file to determine what exactly changed, in this example).
                        if ((eventFlags[i] & Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemRemoved) == Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemRemoved)
                        {
                            NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath);
                        }
                        else if ((eventFlags[i] & Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemCreated) == Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemCreated)
                        {
                            // Next look for creates since a create + modification coalesced could confuse apps since a file they haven't heard of yet would get a mod event
                            NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath);
                        }
                        else if (((eventFlags[i] & Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemInodeMetaMod) == Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemInodeMetaMod) ||
                                 ((eventFlags[i] & Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemModified) == Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemModified) ||
                                 ((eventFlags[i] & Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemFinderInfoMod) == Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemChangeOwner) ||
                                 ((eventFlags[i] & Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemXattrMod) == Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemXattrMod))
                        {
                            // Everything else is a modification
                            NotifyFileSystemEventArgs(WatcherChangeTypes.Changed, relativePath);
                        }
                    }
                }
            }
        }
示例#22
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs paintEventArgs_0)
        {
            base.OnPaint(paintEventArgs_0);
            StringFormat stringFormat = new StringFormat();

            stringFormat.LineAlignment = StringAlignment.Center;
            if (base.View == System.Windows.Forms.View.Details)
            {
                for (int i = 0; i < base.Items.Count; i++)
                {
                    Rectangle bounds = base.Items[i].GetBounds(System.Windows.Forms.ItemBoundsPortion.Icon);
                    if (bounds.Bottom >= 0 && bounds.Top <= base.ClientRectangle.Height)
                    {
                        if (base.Items[i].SubItems[0].Text.Length == 0)
                        {
                            bounds.Width = base.Columns[0].Width + bounds.Width;
                        }
                        Rectangle  bounds2    = base.Items[i].GetBounds(System.Windows.Forms.ItemBoundsPortion.Entire);
                        float      x          = (float)(bounds2.Left + bounds.Width);
                        float      y          = (float)bounds2.Top;
                        RectangleF rectangleF = new RectangleF(x, y, 0f, (float)bounds2.Height);
                        if (base.Items[i].Tag != null)
                        {
                            Graphics      graphics = paintEventArgs_0.Graphics;
                            System.IntPtr hdc      = graphics.GetHdc();
                            if (base.Items[i].Tag is ISymbol)
                            {
                                this.DrawSymbol(hdc.ToInt32(), bounds, base.Items[i].Tag);
                            }
                            else if (base.Items[i].Tag is IStyleGalleryItem)
                            {
                                this.DrawSymbol(hdc.ToInt32(), bounds, (base.Items[i].Tag as IStyleGalleryItem).Item);
                            }
                            graphics.ReleaseHdc(hdc);
                        }
                        SolidBrush solidBrush;
                        SolidBrush solidBrush2;
                        if (base.Items[i].Selected)
                        {
                            solidBrush  = new SolidBrush(base.Items[i].ForeColor);
                            solidBrush2 = new SolidBrush(base.Items[i].BackColor);
                        }
                        else
                        {
                            solidBrush  = new SolidBrush(base.Items[i].BackColor);
                            solidBrush2 = new SolidBrush(base.Items[i].ForeColor);
                        }
                        for (int j = 0; j < base.Items[i].SubItems.Count; j++)
                        {
                            if (j > 1)
                            {
                                rectangleF.X += (float)base.Columns[j - 1].Width;
                            }
                            else if (j == 1)
                            {
                                rectangleF.X = rectangleF.X + (float)base.Columns[0].Width - (float)bounds.Width;
                            }
                            if (j == 0)
                            {
                                rectangleF.Width = (float)(base.Columns[j].Width - bounds.Width);
                            }
                            else
                            {
                                rectangleF.Width = (float)base.Columns[j].Width;
                            }
                            if (j == 0 || base.FullRowSelect)
                            {
                                if (j != 0 || base.Items[i].SubItems[j].Text.Length != 0)
                                {
                                    paintEventArgs_0.Graphics.FillRectangle(solidBrush, rectangleF);
                                    paintEventArgs_0.Graphics.DrawString(base.Items[i].SubItems[j].Text, this.Font,
                                                                         solidBrush2, rectangleF);
                                }
                            }
                            else
                            {
                                paintEventArgs_0.Graphics.DrawString(base.Items[i].SubItems[j].Text, this.Font,
                                                                     Brushes.Black, rectangleF);
                            }
                        }
                        solidBrush.Dispose();
                        solidBrush2.Dispose();
                    }
                }
            }
            else if (base.View == System.Windows.Forms.View.LargeIcon || base.View == System.Windows.Forms.View.SmallIcon ||
                     base.View == System.Windows.Forms.View.List)
            {
                for (int i = 0; i < base.Items.Count; i++)
                {
                    Rectangle bounds = base.Items[i].GetBounds(System.Windows.Forms.ItemBoundsPortion.Icon);
                    if (bounds.Bottom >= 0 && bounds.Top <= base.ClientRectangle.Height)
                    {
                        if (base.Items[i].Tag != null)
                        {
                            Graphics      graphics = paintEventArgs_0.Graphics;
                            System.IntPtr hdc      = graphics.GetHdc();
                            if (base.Items[i].Tag is ISymbol)
                            {
                                this.DrawSymbol(hdc.ToInt32(), bounds, base.Items[i].Tag);
                            }
                            else if (base.Items[i].Tag is IStyleGalleryItem)
                            {
                                this.DrawSymbol(hdc.ToInt32(), bounds, (base.Items[i].Tag as IStyleGalleryItem).Item);
                            }
                            graphics.ReleaseHdc(hdc);
                        }
                        SolidBrush solidBrush;
                        SolidBrush solidBrush2;
                        if (base.Items[i].Selected)
                        {
                            solidBrush  = new SolidBrush(base.Items[i].ForeColor);
                            solidBrush2 = new SolidBrush(base.Items[i].BackColor);
                        }
                        else
                        {
                            solidBrush  = new SolidBrush(base.Items[i].BackColor);
                            solidBrush2 = new SolidBrush(base.Items[i].ForeColor);
                        }
                        Rectangle  bounds2    = base.Items[i].GetBounds(System.Windows.Forms.ItemBoundsPortion.Label);
                        RectangleF rectangleF = new RectangleF((float)bounds2.X, (float)bounds2.Y,
                                                               (float)bounds2.Width, (float)bounds2.Height);
                        paintEventArgs_0.Graphics.FillRectangle(solidBrush, rectangleF);
                        paintEventArgs_0.Graphics.DrawString(base.Items[i].Text, this.Font, solidBrush2, rectangleF,
                                                             stringFormat);
                        solidBrush.Dispose();
                        solidBrush2.Dispose();
                    }
                }
            }
        }
示例#23
0
        // forwards to the 64-bit aware version.
        public static LONG GetWindowLong(HWND hWnd, int nIndex)
        {
            LONG_PTR ret = GetWindowLongPtr(hWnd, nIndex);

            return(ret.ToInt32());
        }
示例#24
0
        // forwards to the 64-bit aware version.
        public static LONG SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong)
        {
            LONG_PTR ret = SetWindowLongPtr(hWnd, nIndex, new LONG_PTR(dwNewLong));

            return(ret.ToInt32());
        }
        private void FileSystemEventCallback(
            FSEventStreamRef streamRef,
            IntPtr clientCallBackInfo,
            size_t numEvents,
            String[] eventPaths,
            [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
            Interop.EventStream.FSEventStreamEventFlags[] eventFlags,
            [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
            FSEventStreamEventId[] eventIds)
        {
            Debug.Assert((numEvents.ToInt32() == eventPaths.Length) && (numEvents.ToInt32() == eventFlags.Length) && (numEvents.ToInt32() == eventIds.Length));

            // Since renames come in pairs, when we find the first we need to search for the next one. Once we find it, we'll add it to this
            // list so when the for-loop comes across it, we'll skip it since it's already been processed as part of the original of the pair.
            List <FSEventStreamEventId> handledRenameEvents = null;

            for (long i = 0; i < numEvents.ToInt32(); i++)
            {
                // We need to special case the root path for pattern matching, so cache the path this way in case it is the root
                // and use it for pattern matching. We'll go back to the eventPaths[i] to get the actual path for notifications
                string path = eventPaths[i];
                if (path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase))
                {
                    path += "/.";
                }

                // First, we should check if this event should kick off a re-scan since we can't really rely on anything after this point if that is true
                if (ShouldRescanOccur(eventFlags[i]))
                {
                    OnError(new ErrorEventArgs(new IOException(SR.FSW_BufferOverflow, (int)eventFlags[i])));
                    break;
                }
                else if ((handledRenameEvents != null) && (handledRenameEvents.Contains(eventIds[i])))
                {
                    // If this event is the second in a rename pair then skip it
                    continue;
                }
                else if ((DoesPathPassNameFilter(path)) && ((_filterFlags & eventFlags[i]) != 0))
                {
                    // The base FileSystemWatcher does a match check against the relative path before combining with
                    // the root dir; however, null is special cased to signify the root dir, so check if we should use that.
                    string relativePath = null;
                    if (eventPaths[i].Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase) == false)
                    {
                        // Check if the event path, with the root directory removed, begins with a / and
                        // if so, remove it; otherwise, just remove the root path (which contains a trailing /)
                        if (eventPaths[i][_fullDirectory.Length] == '/')
                        {
                            relativePath = eventPaths[i].Remove(0, _fullDirectory.Length + 1);
                        }
                        else
                        {
                            relativePath = eventPaths[i].Remove(0, _fullDirectory.Length);
                        }
                    }

                    // Check if this is a rename
                    if (IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemRenamed))
                    {
                        // Find the rename that is paired to this rename, which should be the next rename in the list
                        long pairedId = FindRenameChangePairedChange(i, eventPaths, eventFlags, eventIds);
                        if (pairedId == long.MinValue)
                        {
                            // Getting here means we have a rename without a pair, meaning it should be a create for the
                            // move from unwatched folder to watcher folder scenario or a move from the watcher folder out.
                            // Check if the item exists on disk to check which it is
                            if (DoesItemExist(eventPaths[i], IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemIsFile)))
                            {
                                NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath);
                            }
                            else
                            {
                                NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath);
                            }
                        }
                        else
                        {
                            // Remove the base directory prefix (including trailing / that OS X adds) and
                            // add the paired event to the list of events to skip and notify the user of the rename
                            string newPathRelativeName = eventPaths[pairedId].Remove(0, _fullDirectory.Length + 1);
                            NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);

                            // Create a new list, if necessary, and add the event
                            if (handledRenameEvents == null)
                            {
                                handledRenameEvents = new List <FSEventStreamEventId>();
                            }
                            handledRenameEvents.Add(eventIds[pairedId]);
                        }
                    }
                    else
                    {
                        // OS X is wonky where it can give back kFSEventStreamEventFlagItemCreated and kFSEventStreamEventFlagItemRemoved
                        // for the same item. The only option we have is to stat and see if the item exists; if so send created, otherwise send deleted.
                        if ((IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemCreated)) ||
                            (IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemRemoved)))
                        {
                            if (DoesItemExist(eventPaths[i], IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemIsFile)))
                            {
                                NotifyFileSystemEventArgs(WatcherChangeTypes.Created, relativePath);
                            }
                            else
                            {
                                NotifyFileSystemEventArgs(WatcherChangeTypes.Deleted, relativePath);
                            }
                        }

                        if (IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemInodeMetaMod) ||
                            IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemModified) ||
                            IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemFinderInfoMod) ||
                            IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemChangeOwner) ||
                            IsFlagSet(eventFlags[i], Interop.EventStream.FSEventStreamEventFlags.kFSEventStreamEventFlagItemXattrMod))
                        {
                            // Everything else is a modification
                            NotifyFileSystemEventArgs(WatcherChangeTypes.Changed, relativePath);
                        }
                    }
                }
            }
        }
    public int EnumerateDevices()
    {
        int result      = 0;
        int deviceCount = 0;
        int dwSize      = (System.Runtime.InteropServices.Marshal.SizeOf(typeof(RAWINPUTDEVICELIST)));

        if (GetRawInputDeviceList(System.IntPtr.Zero, ref deviceCount, dwSize) == 0)
        {
            System.IntPtr pRawInputDeviceList = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Convert.ToInt32(dwSize * deviceCount));
            GetRawInputDeviceList(pRawInputDeviceList, ref deviceCount, System.Convert.ToInt32(dwSize));
            for (long i = 0; i <= deviceCount - 1; i++)
            {
                DeviceNameInfo     dName      = default(DeviceNameInfo);
                string             deviceName = null;
                int                pcbSizeA   = 0;
                int                pcbSizeB   = 0;
                RAWINPUTDEVICELIST rid        = (RAWINPUTDEVICELIST)System.Runtime.InteropServices.Marshal.PtrToStructure(new System.IntPtr((pRawInputDeviceList.ToInt32() + (dwSize * i))), typeof(RAWINPUTDEVICELIST));
                GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICENAME, System.IntPtr.Zero, ref pcbSizeA);
                if (pcbSizeA > 0)
                {
                    System.IntPtr pDataA = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Convert.ToInt32(pcbSizeA));
                    GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICENAME, pDataA, ref pcbSizeA);
                    deviceName = (string)System.Runtime.InteropServices.Marshal.PtrToStringAnsi(pDataA);
                    // Drop the "root" keyboard and mouse devices used for Terminal Services and the Remote Desktop
                    if (!deviceName.ToUpper().Contains("ROOT"))
                    {
                        dName              = new DeviceNameInfo();
                        dName.deviceName   = (string)System.Runtime.InteropServices.Marshal.PtrToStringAnsi(pDataA);
                        dName.deviceHandle = rid.hDevice;
                        dName.deviceType   = GetDeviceType(rid.dwType);
                        GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICEINFO, System.IntPtr.Zero, ref pcbSizeB);
                        if (pcbSizeB > 0)
                        {
                            System.IntPtr pDataB = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Convert.ToInt32(pcbSizeB));
                            System.Runtime.InteropServices.Marshal.Copy(new int[] { pcbSizeB }, 0, pDataB, 1);
                            GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICEINFO, pDataB, ref pcbSizeB);
                            byte[] deviceInfoBuffer = new byte[pcbSizeB];
                            System.Runtime.InteropServices.Marshal.Copy(pDataB, deviceInfoBuffer, 0, pcbSizeB);
                            System.Runtime.InteropServices.Marshal.FreeHGlobal(pDataB);
                            DeviceInfo dInfo = new DeviceInfo();
                            dInfo.Size = System.BitConverter.ToInt32(deviceInfoBuffer, 0);
                            dInfo.Type = System.BitConverter.ToInt32(deviceInfoBuffer, 4);
                            int pcbSizeC = pcbSizeB - 8;
                            if (((dInfo.Type == RIM_TYPEKEYBOARD) && (pcbSizeC >= System.Runtime.InteropServices.Marshal.SizeOf(typeof(DeviceInfoKeyboard)))))
                            {
                                dInfo.KeyboardInfo.Type                 = System.BitConverter.ToUInt32(deviceInfoBuffer, 8);
                                dInfo.KeyboardInfo.SubType              = System.BitConverter.ToUInt32(deviceInfoBuffer, 12);
                                dInfo.KeyboardInfo.KeyboardMode         = System.BitConverter.ToUInt32(deviceInfoBuffer, 16);
                                dInfo.KeyboardInfo.NumberOfFunctionKeys = System.BitConverter.ToUInt32(deviceInfoBuffer, 20);
                                dInfo.KeyboardInfo.NumberOfIndicators   = System.BitConverter.ToUInt32(deviceInfoBuffer, 24);
                                dInfo.KeyboardInfo.NumberOfKeysTotal    = System.BitConverter.ToUInt32(deviceInfoBuffer, 28);
                            }
                            else if (((dInfo.Type == RIM_TYPEHID) && (pcbSizeC >= System.Runtime.InteropServices.Marshal.SizeOf(typeof(DeviceInfoHID)))))
                            {
                                dInfo.HIDInfo.VendorID      = System.BitConverter.ToUInt32(deviceInfoBuffer, 8);
                                dInfo.HIDInfo.ProductID     = System.BitConverter.ToUInt32(deviceInfoBuffer, 12);
                                dInfo.HIDInfo.VersionNumber = System.BitConverter.ToUInt32(deviceInfoBuffer, 16);
                                dInfo.HIDInfo.UsagePage     = System.BitConverter.ToUInt16(deviceInfoBuffer, 20);
                                dInfo.HIDInfo.Usage         = System.BitConverter.ToUInt16(deviceInfoBuffer, 22);
                                if (!m_usagePagesList.ContainsKey(dInfo.HIDInfo.UsagePage))
                                {
                                    m_usagePagesList.Add(dInfo.HIDInfo.UsagePage, dInfo.HIDInfo.UsagePage);
                                }
                            }
                            else if (((dInfo.Type == RIM_TYPEMOUSE) && (pcbSizeC >= System.Runtime.InteropServices.Marshal.SizeOf(typeof(DeviceInfoMouse)))))
                            {
                                dInfo.MouseInfo.ID = System.BitConverter.ToUInt32(deviceInfoBuffer, 8);
                                dInfo.MouseInfo.NumberOfButtons = System.BitConverter.ToUInt32(deviceInfoBuffer, 12);
                                dInfo.MouseInfo.SampleRate      = System.BitConverter.ToUInt32(deviceInfoBuffer, 16);
                            }
                            result += 1;
                            m_deviceInfoList.Add(rid.hDevice, dInfo);
                            m_deviceNameList.Add(rid.hDevice, dName);
                        }
                    }
                    System.Runtime.InteropServices.Marshal.FreeHGlobal(pDataA);
                }
            }
            System.Runtime.InteropServices.Marshal.FreeHGlobal(pRawInputDeviceList);
        }
        else
        {
            m_errorMessage = "An error occurred while retrieving the list of raw input devices.";
            result         = 0;
        }
        return(result);
    }