Esempio n. 1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            // Add the quick toggles defined in Tweaks
            foreach (TweakCategory cat in Tweaks.Tweaks.Categories)
            {
                if (cat.Tweaks.Count > 0)
                {
                    addCategory(cat.Title);
                    foreach (Tweak t in cat.Tweaks)
                    {
                        if (!Versions.IsNewerOrCurrentOS(t.MinOSVersion))
                        {
                            continue;
                        }
                        if (!Versions.IsOlderOS(t.MaxOSVersion))
                        {
                            continue;
                        }
                        if (t is ToggleTweak)
                        {
                            var tweak = (ToggleTweak)t;
                            ToggleSwitch control = new ToggleSwitch();
                            control.Tag = tweak;
                            control.Header = tweak.Title;
                            if (tweak.Description != "")
                                control.Content = tweak.Description;

                            control.FontSize = 22;

                            //get valuelolo
                            if (tweak.KeyType == TweakType.DWORD)
                            {
                                uint val = Registry.ReadDWORD(tweak.Hive, tweak.KeyName, tweak.ValueName);
                                control.IsChecked = (val == (int)tweak.OnValue);
            #if DEBUG
                                System.Diagnostics.Debug.WriteLine(tweak.Title + " = " + val);
            #endif
                            }
                            else if (tweak.KeyType == TweakType.String)
                            {
                                string val = Registry.ReadString(tweak.Hive, tweak.KeyName, tweak.ValueName);
                                control.IsChecked = (val == (string)tweak.OnValue);
            #if DEBUG
                                System.Diagnostics.Debug.WriteLine(tweak.Title + " = " + val);
            #endif
                            }

                            control.Checked += new EventHandler<RoutedEventArgs>(control_Checked);
                            control.Unchecked += new EventHandler<RoutedEventArgs>(control_Checked);

                            controlsPanel.Children.Add(control);
                        }
                        else if (t is SelectorTweak)
                        {
                            var tweak = (SelectorTweak)t;
                            ListPicker lp = new ListPicker();
                            lp.Tag = tweak;
                            lp.Header = tweak.Title;
                            lp.ItemsSource = tweak.Options;
                            lp.SetValue(ListPicker.ItemCountThresholdProperty, 10);
                            if (tweak.KeyType == TweakType.DWORD)
                            {
                                uint val = Registry.ReadDWORD(tweak.Hive, tweak.KeyName, tweak.ValueName);
                                foreach (var opt in tweak.Options)
                                {
                                    if ((int)opt.Value == val)
                                    {
                                        lp.SelectedItem = opt;
                                        break;
                                    }
                                }
            #if DEBUG
                                System.Diagnostics.Debug.WriteLine(tweak.Title + " = " + val);
            #endif
                            }
                            else if (tweak.KeyType == TweakType.String)
                            {
                                string val = Registry.ReadString(tweak.Hive, tweak.KeyName, tweak.ValueName);
                                foreach (var opt in tweak.Options)
                                {
                                    if ((string)opt.Value == val)
                                    {
                                        lp.SelectedItem = opt;
                                        break;
                                    }
                                }
            #if DEBUG
                                System.Diagnostics.Debug.WriteLine(tweak.Title + " = " + val);
            #endif
                            }
                            lp.SelectionChanged += new SelectionChangedEventHandler(lp_SelectionChanged);
                            lp.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(lp_Tap);
                            controlsPanel.Children.Add(lp);
                        }
                        else if (t is SliderTweak)
                        {
                            var tweak = (SliderTweak)t;
                            uint val = Registry.ReadDWORD(tweak.Hive, tweak.KeyName, tweak.ValueName);
                            if (val == 2147942487)
                            {
                                val = (uint)tweak.DefaultValue;
                            }
                            else if (val < tweak.MinValue)
                            {
                                val = (uint)tweak.MinValue;
                            }
                            else if (val > tweak.MaxValue)
                            {
                                val = (uint)tweak.MaxValue;
                            }

                            StackPanel sliderStack = new StackPanel();
                            Grid vertStack = new Grid();

                            TextBlock tb2 = new TextBlock();
                            tb2.FontSize = (double)Application.Current.Resources["PhoneFontSizeNormal"];
                            tb2.Padding = new Thickness(10, 0, 0, 0);
                            tb2.Text = tweak.Title;
                            tb2.FontFamily = (FontFamily)Application.Current.Resources["PhoneFontFamilyNormal"];
                            tb2.Foreground = (Brush)Application.Current.Resources["PhoneSubtleBrush"];
                            vertStack.Children.Add(tb2);

                            TextBlock tb = new TextBlock();
                            tb.FontSize = 18;
                            tb.Text = val.ToString();
                            tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                            tb.Margin = new Thickness(0, 0, 10, 0);
                            vertStack.Children.Add(tb);
                            sliderStack.Children.Add(vertStack);

                            Slider sl = new Slider();
                            sl.Tag = tweak;
                            sl.Name = tweak.Title;
                            sl.Minimum = tweak.MinValue;
                            sl.Maximum = tweak.MaxValue;
                            sl.SmallChange = 1;
                            sl.LargeChange = 2;

                            sl.Value = val;

                            sl.ValueChanged += sl_ValueChanged;
                            sliderStack.Children.Add(sl);
                            controlsPanel.Children.Add(sliderStack);

                        }
                    }
                }
            }
        }
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Check for root
            if (WP7RootToolsSDK.Environment.HasRootAccess())
            {
                // Add the quick toggles defined in Tweaks
                foreach (Tweak tweak in Tweaks.tweaks)
                {
                    if (tweak.type == Tweak.controlType.toggle)
                    {
                        ToggleSwitch control = new ToggleSwitch();

                        control.Header = tweak.title;
                        if (tweak.description != "")
                            control.Content = tweak.description;

                        control.FontSize = 22;

                        //get valuelolo
                        if (tweak.keyType == Tweak.tweakType.dword)
                        {
                            var val = 0;
                            try
                            {
                                val = (int)WP7RootToolsSDK.Registry.GetDWordValue(tweak.getHyve(), tweak.getKeyName(), tweak.getValueName());
                            }
                            catch
                            {

                            }
                            control.IsChecked = (val == tweak.onValue);
                        }
                        if (tweak.keyType == Tweak.tweakType.str)
                        {
                            var val = "";
                            try
                            {
                                val = WP7RootToolsSDK.Registry.GetStringValue(tweak.getHyve(), tweak.getKeyName(), tweak.getValueName());
                            }
                            catch
                            {
                            }
                            control.IsChecked = (val == tweak.strOnValue);
                        }

                        control.Checked += new EventHandler<RoutedEventArgs>(control_Checked);
                        control.Unchecked += new EventHandler<RoutedEventArgs>(control_Checked);

                        controlsPanel.Children.Add(control);
                    }
                    if (tweak.type == Tweak.controlType.selector)
                    {
                        ListPicker lp = new ListPicker();
                        lp.Header = tweak.title;
                        lp.ItemsSource = tweak.options;
                        lp.SetValue(ListPicker.ItemCountThresholdProperty, 10);
                        lp.SelectionChanged += new SelectionChangedEventHandler(lp_SelectionChanged);
                        lp.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(lp_Tap);
                        controlsPanel.Children.Add(lp);
                    }
                    if (tweak.type == Tweak.controlType.title)
                    {
                        addCategory(tweak.title);
                    }
                }
            }
            else
            {
                LayoutRoot.Visibility = System.Windows.Visibility.Collapsed;
            }
        }