Exemplo n.º 1
0
        internal Window(IntPtr hWnd, string className, string displayName, string processName, int workspacesCount, bool is64BitProcess,
            NativeMethods.WS originalStyle, NativeMethods.WS_EX originalExStyle, ProgramRule.Rule rule, ProgramRule programRule, IntPtr menu)
            : base(hWnd)
        {
            IsFloating = rule.isFloating;
            Titlebar = rule.titlebar;
            InAltTabAndTaskbar = rule.inAltTabAndTaskbar;
            WindowBorders = rule.windowBorders;
            this.WorkspacesCount = workspacesCount;
            this.DisplayName = displayName;
            this.className = className;
            this.processName = processName;
            this.is64BitProcess = is64BitProcess;
            redrawOnShow = rule.redrawOnShow;
            ShowMenu = programRule.showMenu;
            updateIcon = programRule.updateIcon;
            onHiddenWindowShownAction = programRule.onHiddenWindowShownAction;
            this.menu = menu;
            this.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace = rule.hideFromAltTabAndTaskbarWhenOnInactiveWorkspace;

            this.originalStyle = originalStyle;
            this.originalExStyle = originalExStyle;

            windowPlacement = NativeMethods.WINDOWPLACEMENT.Default;
            SavePosition();
            originalWindowPlacement = windowPlacement;

            this.customOwnedWindowMatchingFunction = programRule.customOwnedWindowMatchingFunction;

            this.ownedWindows = new LinkedList<IntPtr>();
            this.ownedWindows.AddFirst(hWnd);
        }
Exemplo n.º 2
0
        internal static new IFileSystemInformation Create(NativeMethods.FileManagement.FindResult findResult, IFileService fileService)
        {
            if ((findResult.Attributes & System.IO.FileAttributes.Directory) == 0) throw new ArgumentOutOfRangeException(nameof(findResult));

            var directoryInfo = new DirectoryInformation(fileService);
            directoryInfo.PopulateData(findResult);
            return directoryInfo;
        }
Exemplo n.º 3
0
        internal static new IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info, IFileService fileService)
        {
            if ((info.dwFileAttributes & System.IO.FileAttributes.Directory) == 0) throw new ArgumentOutOfRangeException(nameof(info));

            var directoryInfo = new DirectoryInformation(fileService);
            directoryInfo.PopulateData(originalPath, fileHandle, info);
            return directoryInfo;
        }
Exemplo n.º 4
0
        private NativeExtension()
        {
            this.nativeMethods = new NativeMethods(Load());
            
            // Redirect the the native logs as the very first thing after loading the native extension
            // to make sure we don't lose any logs.
            NativeLogRedirector.Redirect(this.nativeMethods);

            Logger.Debug("gRPC native library loaded successfully.");
        }
Exemplo n.º 5
0
 protected virtual void PopulateData(NativeMethods.FileManagement.FindResult findResult)
 {
     this.source = Source.FindResult;
     this.Path = Paths.Combine(findResult.BasePath, findResult.FileName);
     this.Attributes = findResult.Attributes;
     this.CreationTime = findResult.Creation;
     this.LastAccessTime = findResult.LastAccess;
     this.LastWriteTime = findResult.LastWrite;
     this.Name = findResult.FileName;
     this.Exists = true;
 }
Exemplo n.º 6
0
 internal static IFileSystemInformation Create(NativeMethods.FileManagement.FindResult findResult, IFileService fileService)
 {
     if (findResult.Attributes.HasFlag(System.IO.FileAttributes.Directory))
     {
         return DirectoryInformation.Create(findResult, fileService);
     }
     else
     {
         return FileInformation.Create(findResult, fileService);
     }
 }
Exemplo n.º 7
0
 private void OnProgramRuleMatched(ProgramRule programRule, IntPtr hWnd, string className, string displayName, string processName, NativeMethods.WS style, NativeMethods.WS_EX exStyle)
 {
     if (programRule != null)
     {
         writer.WriteLine("MATCHED - class '{0}'; caption '{1}'; processName '{2}';",
             className, displayName, processName);
         writer.WriteLine("\tAGAINST RULE WITH class '{0}'; caption '{1}'; process name '{2}';",
             programRule.className, programRule.displayName, programRule.processName);
         writer.WriteLine("\tstyle contains: '{0}'; style not contains '{1}'; ex style contains '{2}'; ex style not contains '{3}'; is managed '{4}'",
             programRule.styleContains, programRule.styleNotContains, programRule.exStyleContains, programRule.exStyleNotContains, programRule.isManaged);
     }
     else
     {
         writer.WriteLine("COULD NOT MATCH - class '{0}'; caption '{1}'; processName '{2}' AGAINST ANY RULE",
             className, displayName, processName);
     }
 }
Exemplo n.º 8
0
        protected virtual void PopulateData(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info)
        {
            this.source = Source.FileInfo;

            string originalRoot = Paths.GetRoot(originalPath);
            string finalPath = NativeMethods.FileManagement.GetFinalPathName(fileHandle, NativeMethods.FileManagement.FinalPathFlags.FILE_NAME_NORMALIZED);
            finalPath = Paths.ReplaceRoot(originalPath, finalPath);

            this.source = Source.FindResult;
            this.Path = finalPath;
            this.Attributes = info.dwFileAttributes;
            this.CreationTime = NativeMethods.GetDateTime(info.ftCreationTime);
            this.LastAccessTime = NativeMethods.GetDateTime(info.ftLastAccessTime);
            this.LastWriteTime = NativeMethods.GetDateTime(info.ftLastWriteTime);
            this.Name = Paths.GetFileOrDirectoryName(finalPath) ?? finalPath;
            this.FileIndex = NativeMethods.HighLowToLong(info.nFileIndexHigh, info.nFileSizeLow);
            this.NumberOfLinks = info.nNumberOfLinks;
            this.VolumeSerialNumber = info.dwVolumeSerialNumber;
            this.Exists = true;
        }
Exemplo n.º 9
0
 internal bool IsMatch(IntPtr hWnd, string cName, string dName, string pName, NativeMethods.WS style, NativeMethods.WS_EX exStyle)
 {
     return className.IsMatch(cName) && displayName.IsMatch(dName) && processName.IsMatch(pName) &&
         (style & styleContains) == styleContains && (style & styleNotContains) == 0 &&
         (exStyle & exStyleContains) == exStyleContains && (exStyle & exStyleNotContains) == 0 &&
         customMatchingFunction(hWnd);
 }
		public void Apply(ref NativeMethods.DTTOPTS options) {
			options.dwFlags |= NativeMethods.DTTOPSFlags.DTT_GLOWSIZE;
			options.iGlowSize = Size;
		}
Exemplo n.º 11
0
            /// <summary>
            /// ��ȡָ����ӡ���������Ϣ
            /// </summary>
            /// <param name="szPrinterName">��ӡ������</param>
            /// <param name="stPrinterInfo">��ӡ����Ϣ</param>
            /// <returns>�Ƿ�ִ�гɹ�</returns>
            public static bool GetPrinterInfo(string szPrinterName, ref NativeMethods.WinSpool.PRINTER_INFO stPrinterInfo)
            {
                IntPtr hPrinter = IntPtr.Zero;
                NativeMethods.WinSpool.StructPrinterDefaults defaults = new NativeMethods.WinSpool.StructPrinterDefaults();
                if (!NativeMethods.WinSpool.OpenPrinter(szPrinterName, out hPrinter, ref defaults))
                    return false;

                int cbNeeded = 0;
                NativeMethods.WinSpool.GetPrinter(hPrinter, 2, IntPtr.Zero, 0, out cbNeeded);
                if (cbNeeded <= 0)
                {
                    NativeMethods.WinSpool.ClosePrinter(hPrinter);
                    return false;
                }
                try
                {
                    IntPtr pAddr = System.Runtime.InteropServices.Marshal.AllocHGlobal((int)cbNeeded);
                    if (NativeMethods.WinSpool.GetPrinter(hPrinter, 2, pAddr, cbNeeded, out cbNeeded))
                    {
                        stPrinterInfo = (NativeMethods.WinSpool.PRINTER_INFO)
                            System.Runtime.InteropServices.Marshal.PtrToStructure(pAddr, typeof(NativeMethods.WinSpool.PRINTER_INFO));
                    }
                    System.Runtime.InteropServices.Marshal.FreeHGlobal(pAddr);
                }
                catch (Exception ex)
                {
                    LogManager.Instance.WriteLog("GlobalMethods.GetPrinterInfo", new string[] { "szPrinterName" }
                        , new object[] { szPrinterName }, ex);
                }
                NativeMethods.WinSpool.ClosePrinter(hPrinter);
                return true;
            }
Exemplo n.º 12
0
 protected override void PopulateData(NativeMethods.FileManagement.FindResult findResult)
 {
     base.PopulateData(findResult);
 }
Exemplo n.º 13
0
 internal override void Apply(ref NativeMethods.DTTOPTS options)
 {
     options.dwFlags |= NativeMethods.DTTOPSFlags.DTT_APPLYOVERLAY;
     options.fApplyOverlay = Enabled;
 }
Exemplo n.º 14
0
        private static bool processShiftState(uint shiftState, NativeMethods.INPUT[] input, int inputIndex, bool midKeyPress)
        {
            try
            {
                switch (shiftState)
                {
                    case 0:
                        return false;

                    #region SHIFT
                    case 1:
                        {
                            if (!midKeyPress)
                            {
                                // SHIFT DOWN
                                input[inputIndex].type = NativeMethods.INPUT_KEYBOARD;
                                input[inputIndex].ki.wVk = NativeMethods.VK_SHIFT;
                                input[inputIndex].ki.wScan = 42; // left shift
                            }
                            else
                            {
                                // SHIFT UP
                                input[inputIndex].type = NativeMethods.INPUT_KEYBOARD;
                                input[inputIndex].ki.wVk = NativeMethods.VK_SHIFT;
                                input[inputIndex].ki.dwFlags = NativeMethods.KEYEVENTF_KEYUP;
                                input[inputIndex].ki.wScan = 42; // left shift
                            }
                            break;
                        }
                    #endregion

                    #region CTRL
                    //case 2:
                    //{
                    //    if (!midKeyPress)
                    //    {
                    //        // CTRL DOWN
                    //        input[inputIndex].type = NativeMethods.INPUT_KEYBOARD;
                    //        input[inputIndex].ki.wVk = NativeMethods.VK_CONTROL;
                    //        input[inputIndex].ki.wScan = 29; // left ctrl
                    //    }
                    //    else
                    //    {
                    //        // CTRL UP
                    //        input[inputIndex].type = NativeMethods.INPUT_KEYBOARD;
                    //        input[inputIndex].ki.wVk = NativeMethods.VK_CONTROL;
                    //        input[inputIndex].ki.dwFlags = NativeMethods.KEYEVENTF_KEYUP;
                    //        input[inputIndex].ki.wScan = 29; // left ctrl
                    //    }
                    //    break;
                    //}
                    #endregion

                    #region ALT
                    //case 4:
                    //{
                    //    if (!midKeyPress)
                    //    {
                    //        // ALT DOWN
                    //        input[inputIndex].type = NativeMethods.INPUT_KEYBOARD;
                    //        input[inputIndex].ki.wVk = NativeMethods.VK_MENU;
                    //        input[inputIndex].ki.wScan = 56; // left alt
                    //    }
                    //    else
                    //    {
                    //        // ALT UP
                    //        input[inputIndex].type = NativeMethods.INPUT_KEYBOARD;
                    //        input[inputIndex].ki.wVk = NativeMethods.VK_MENU;
                    //        input[inputIndex].ki.dwFlags = NativeMethods.KEYEVENTF_KEYUP;
                    //        input[inputIndex].ki.wScan = 56; // left alt
                    //    }
                    //    break;
                    //}
                    #endregion

                    default:
                        throw new Exception("Unsupported shift state detected. Cannot process PressKey request.");
                }

                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
Exemplo n.º 15
0
        private NativeMethods.RM_PROCESS_INFO[] ListAppsInternal(out uint arrayLength, out NativeMethods.RM_REBOOT_REASON rebootReasons)
        {
            int ret;
            uint arrayLengthNeeded = 1;
            NativeMethods.RM_PROCESS_INFO[] processInfo;
            do
            {
                arrayLength = arrayLengthNeeded;
                processInfo = new NativeMethods.RM_PROCESS_INFO[arrayLength];
                ret = NativeMethods.RmGetList(_sessionHandle, out arrayLengthNeeded, ref arrayLength, processInfo, out rebootReasons);
            } while (ret == WindowsUtils.Win32ErrorMoreData);

            if (ret != 0) throw BuildException(ret);

            return processInfo;
        }
Exemplo n.º 16
0
 private bool OnBreakReceived(NativeMethods.CtrlTypes ctrlType)
 {
     Break();
     return true;
 }
Exemplo n.º 17
0
        public static void RestoreScreen(NativeMethods.CHAR_INFO[] buffer, int left, int top, int right, int bottom)
        {
            lock (_Lock)
            {
                if (OSUtils.IsWindows)
                {
                    NativeMethods.COORD BufferCoord = new NativeMethods.COORD();
                    BufferCoord.X = 0;
                    BufferCoord.Y = 0;

                    NativeMethods.COORD BufferSize = new NativeMethods.COORD();
                    BufferSize.X = (short)(right - left + 1);
                    BufferSize.Y = (short)(bottom - top + 1);

                    NativeMethods.SMALL_RECT WriteRegion = new NativeMethods.SMALL_RECT();
                    WriteRegion.Left = (short)(left - 1);
                    WriteRegion.Top = (short)(top - 1);
                    WriteRegion.Right = (short)(right - 1);
                    WriteRegion.Bottom = (short)(bottom - 1);

                    NativeMethods.WriteConsoleOutput(_StdOutputHandle, buffer, BufferSize, BufferCoord, ref WriteRegion);
                }
                else
                {
                    if (buffer != null)
                    {
                        // TODO Restore from buffer
                    }
                }
            }
        }
Exemplo n.º 18
0
 internal abstract void Apply(ref NativeMethods.DTTOPTS options);
Exemplo n.º 19
0
        public ProgramRule(string className = ".*", string displayName = ".*", string processName = ".*",
            NativeMethods.WS styleContains = (NativeMethods.WS) 0, NativeMethods.WS styleNotContains = (NativeMethods.WS) 0,
            NativeMethods.WS_EX exStyleContains = (NativeMethods.WS_EX) 0, NativeMethods.WS_EX exStyleNotContains = (NativeMethods.WS_EX) 0,
            CustomMatchingFunction customMatchingFunction = null, CustomMatchingFunction customOwnedWindowMatchingFunction = null,
            
            bool isManaged = true, int tryAgainAfter = -1, int windowCreatedDelay = -1, bool redrawDesktopOnWindowCreated = false,
            bool showMenu = true, bool updateIcon = false,
            OnWindowCreatedOrShownAction onWindowCreatedAction = OnWindowCreatedOrShownAction.SwitchToWindowsWorkspace,
            OnWindowCreatedOrShownAction onHiddenWindowShownAction = OnWindowCreatedOrShownAction.SwitchToWindowsWorkspace,
            OnWindowCreatedOnWorkspaceAction onWindowCreatedOnCurrentWorkspaceAction = OnWindowCreatedOnWorkspaceAction.MoveToTop,
            OnWindowCreatedOnWorkspaceAction onWindowCreatedOnInactiveWorkspaceAction = OnWindowCreatedOnWorkspaceAction.MoveToTop,
            int showOnWorkspacesCount = 0, IEnumerable<Rule> rules = null)
        {
            this.className = new Regex(className, RegexOptions.Compiled);
            this.displayName = new Regex(displayName, RegexOptions.Compiled);
            this.processName = new Regex(processName, RegexOptions.Compiled);
            this.styleContains = styleContains;
            this.styleNotContains = styleNotContains;
            this.exStyleContains = exStyleContains;
            this.exStyleNotContains = exStyleNotContains;
            this.customMatchingFunction = customMatchingFunction ?? Utilities.IsAltTabWindow;
            this.customOwnedWindowMatchingFunction = customOwnedWindowMatchingFunction ?? DefaultOwnedWindowMatchingFunction;

            this.isManaged = isManaged;
            if (isManaged)
            {
                this.tryAgainAfter = tryAgainAfter;
                this.windowCreatedDelay = windowCreatedDelay;
                this.redrawDesktopOnWindowCreated = redrawDesktopOnWindowCreated;
                this.showMenu = showMenu;
                this.updateIcon = updateIcon;
                this.onWindowCreatedAction = onWindowCreatedAction;
                this.onHiddenWindowShownAction = onHiddenWindowShownAction;
                this.onWindowCreatedOnCurrentWorkspaceAction = onWindowCreatedOnCurrentWorkspaceAction;
                this.onWindowCreatedOnInactiveWorkspaceAction = onWindowCreatedOnInactiveWorkspaceAction;

                if (showOnWorkspacesCount > 0)
                {
                    if (rules == null)
                    {
                        rules = new Rule[] { };
                    }

                    // This is slow (n ^ 2), but it doesn't matter in this case
                    this.rules = rules.Concat(
                        Enumerable.Range(1, showOnWorkspacesCount).Where(i => rules.All(r => r.workspace != i)).Select(i => new Rule(i))).
                        ToArray();
                }
                else
                {
                    this.rules = rules == null ? new[] { new Rule() } : rules.ToArray();
                }
            }
        }
Exemplo n.º 20
0
 protected override void PopulateData(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info)
 {
     base.PopulateData(originalPath, fileHandle, info);
     Length = NativeMethods.HighLowToLong(info.nFileSizeHigh, info.nFileSizeLow);
     _directory = Paths.GetDirectory(Path);
 }
Exemplo n.º 21
0
 protected override void PopulateData(NativeMethods.FileManagement.FindResult findResult)
 {
     base.PopulateData(findResult);
     Length = findResult.Length;
     _directory = findResult.BasePath;
 }
Exemplo n.º 22
0
 internal override void Apply(ref NativeMethods.DTTOPTS options)
 {
     options.dwFlags |= NativeMethods.DTTOPSFlags.DTT_GLOWSIZE;
     options.iGlowSize = Size;
 }
Exemplo n.º 23
0
 internal static IFileSystemInformation Create(string originalPath, SafeFileHandle fileHandle, NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info, IFileService fileService)
 {
     if ((info.dwFileAttributes & System.IO.FileAttributes.Directory) != 0)
     {
         return DirectoryInformation.Create(originalPath, fileHandle, info, fileService);
     }
     else
     {
         return FileInformation.Create(originalPath, fileHandle, info, fileService);
     }
 }