Exemple #1
0
        public async Task <bool> CreateNewNamedPipe()
        {
            try
            {
                if (ClientStream != null)
                {
                    return(true);
                }

                if (WindowsVersionChecker.IsNewerOrEqual(WindowsVersionChecker.Version.Windows10_2004))
                {
                    await FullTrustExcutorController.Current.RequestCreateNewPipeLine(GUID).ConfigureAwait(true);

                    PipeHandle   = WIN_Native_API.GetHandleFromNamedPipe($"Explorer_And_FullTrustProcess_NamedPipe-{GUID}");
                    ClientStream = new NamedPipeClientStream(PipeDirection.InOut, false, true, PipeHandle);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(false);
            }
        }
Exemple #2
0
        public async Task <bool> CreateNewNamedPipeAsync()
        {
            try
            {
                if (ClientStream != null)
                {
                    if (!ClientStream.IsConnected)
                    {
                        ClientStream.Dispose();
                        ClientStream = null;
                        PipeHandle.Dispose();
                        PipeHandle = null;

                        GUID = Guid.NewGuid();
                    }
                    else
                    {
                        return(true);
                    }
                }

                if (WindowsVersionChecker.IsNewerOrEqual(Version.Windows10_2004))
                {
                    await Controller.RequestCreateNewPipeLineAsync(GUID).ConfigureAwait(true);

                    PipeHandle = WIN_Native_API.GetHandleFromNamedPipe($"Explorer_And_FullTrustProcess_NamedPipe-{GUID}");

                    ClientStream = new NamedPipeClientStream(PipeDirection.InOut, false, true, PipeHandle);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, $"{ nameof(CreateNewNamedPipeAsync)} throw an error");
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// 初始化BackgroundController对象
        /// </summary>
        private BackgroundController()
        {
            UIS = new UISettings();
            UIS.ColorValuesChanged += UIS_ColorValuesChanged;

            ApplicationData.Current.DataChanged += Current_DataChanged;

            if (ApplicationData.Current.LocalSettings.Values["SolidColorType"] is string ColorType)
            {
                SolidColorBackgroundBrush = new SolidColorBrush(ColorType.ToColor());
            }
            else
            {
                if (UIS.GetColorValue(UIColorType.Background) == Colors.White)
                {
                    SolidColorBackgroundBrush = new SolidColorBrush(Colors.White);
                }
                else
                {
                    SolidColorBackgroundBrush = new SolidColorBrush("#1E1E1E".ToColor());
                }
            }

            if (ApplicationData.Current.LocalSettings.Values["UIDisplayMode"] is int ModeIndex)
            {
                switch (ModeIndex)
                {
                case 0:
                {
                    AcrylicBackgroundBrush = new AcrylicBrush
                    {
                        BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                        TintColor        = Colors.LightSlateGray,
                        TintOpacity      = 0.4,
                        FallbackColor    = Colors.DimGray
                    };

                    CurrentType = BackgroundBrushType.Acrylic;

                    break;
                }

                case 1:
                {
                    AcrylicBackgroundBrush = new AcrylicBrush
                    {
                        BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                        TintColor        = Colors.LightSlateGray,
                        TintOpacity      = 0.4,
                        FallbackColor    = Colors.DimGray
                    };

                    if (SolidColorBackgroundBrush.Color == Colors.White && AppThemeController.Current.Theme == ElementTheme.Dark)
                    {
                        AppThemeController.Current.Theme = ElementTheme.Light;
                    }
                    else if (SolidColorBackgroundBrush.Color == "#1E1E1E".ToColor() && AppThemeController.Current.Theme == ElementTheme.Light)
                    {
                        AppThemeController.Current.Theme = ElementTheme.Dark;
                    }

                    CurrentType = BackgroundBrushType.SolidColor;

                    break;
                }

                default:
                {
                    if (WindowsVersionChecker.IsNewerOrEqual(WindowsVersionChecker.Version.Windows10_1903))
                    {
                        if (double.TryParse(Convert.ToString(ApplicationData.Current.LocalSettings.Values["BackgroundTintOpacity"]), out double TintOpacity))
                        {
                            if (double.TryParse(Convert.ToString(ApplicationData.Current.LocalSettings.Values["BackgroundTintLuminosity"]), out double TintLuminosity))
                            {
                                AcrylicBackgroundBrush = new AcrylicBrush
                                {
                                    BackgroundSource                                                  = AcrylicBackgroundSource.HostBackdrop,
                                    TintColor                                                         = ApplicationData.Current.LocalSettings.Values["AcrylicThemeColor"] is string Color?Color.ToColor() : Colors.LightSlateGray,
                                                                                TintOpacity           = 1 - TintOpacity,
                                                                                TintLuminosityOpacity = 1 - TintLuminosity,
                                                                                FallbackColor         = Colors.DimGray
                                };
                            }
                            else
                            {
                                AcrylicBackgroundBrush = new AcrylicBrush
                                {
                                    BackgroundSource                                  = AcrylicBackgroundSource.HostBackdrop,
                                    TintColor                                         = ApplicationData.Current.LocalSettings.Values["AcrylicThemeColor"] is string Color?Color.ToColor() : Colors.LightSlateGray,
                                                                        TintOpacity   = 1 - TintOpacity,
                                                                        FallbackColor = Colors.DimGray
                                };
                            }
                        }
                        else
                        {
                            AcrylicBackgroundBrush = new AcrylicBrush
                            {
                                BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                                TintColor        = Colors.LightSlateGray,
                                TintOpacity      = 0.4,
                                FallbackColor    = Colors.DimGray
                            };
                        }
                    }
                    else
                    {
                        if (double.TryParse(Convert.ToString(ApplicationData.Current.LocalSettings.Values["BackgroundTintOpacity"]), out double TintOpacity))
                        {
                            AcrylicBackgroundBrush = new AcrylicBrush
                            {
                                BackgroundSource                                  = AcrylicBackgroundSource.HostBackdrop,
                                TintColor                                         = ApplicationData.Current.LocalSettings.Values["AcrylicThemeColor"] is string Color?Color.ToColor() : Colors.LightSlateGray,
                                                                    TintOpacity   = 1 - TintOpacity,
                                                                    FallbackColor = Colors.DimGray
                            };
                        }
                        else
                        {
                            AcrylicBackgroundBrush = new AcrylicBrush
                            {
                                BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                                TintColor        = Colors.LightSlateGray,
                                TintOpacity      = 0.4,
                                FallbackColor    = Colors.DimGray
                            };
                        }
                    }

                    if (ApplicationData.Current.LocalSettings.Values["CustomUISubMode"] is string SubMode)
                    {
                        CurrentType = (BackgroundBrushType)Enum.Parse(typeof(BackgroundBrushType), SubMode);

                        if (CurrentType == BackgroundBrushType.Acrylic && ApplicationData.Current.LocalSettings.Values["PreventFallBack"] is bool IsPrevent)
                        {
                            IsCompositionAcrylicEnabled = IsPrevent;
                        }
                    }

                    break;
                }
                }
            }
            else
            {
                AcrylicBackgroundBrush = new AcrylicBrush
                {
                    BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                    TintColor        = Colors.LightSlateGray,
                    TintOpacity      = 0.4,
                    FallbackColor    = Colors.DimGray
                };

                CurrentType = BackgroundBrushType.Acrylic;

                ApplicationData.Current.LocalSettings.Values["BackgroundTintOpacity"] = 0.6;
            }
        }