private static async Task applyTweakIfNecessary <OutputType, Params>(Tweak <OutputType, Params> tweak, Params tweakParams) where Params : TweakParams where OutputType : class
        {
            OutputType?editedFile = await tweak.readFileAndEditIfNecessary(tweakParams);

            if (editedFile != null)
            {
                await tweak.saveFile(editedFile, tweakParams);
            }
        }
        void tweak_Click(object sender, RoutedEventArgs e)
        {
            Tweak tweak = (Tweak)(sender as TweakControl).Tag;

            foreach (TweakControl curBtn in this.tweakGrid.Children)
            {
                curBtn.SetFocus(curBtn == sender);
            }

            // todo:
        }
        void group_Click(object sender, RoutedEventArgs e)
        {
            Group group = (Group)(sender as TweakGroup).Tag;

            foreach (TweakGroup curBtn in this.groupGrid.Children)
            {
                curBtn.SetFocus(curBtn == sender);
            }

            this.tweakGrid.Children.Clear();
            this.tweakGrid.RowDefinitions.Clear();

            for (int i = 0; i < group.Tweaks.Count; ++i)
            {
                Tweak tweak = group.Tweaks[i];
                if (!showAll && !tweak.IsAvailable())
                {
                    continue;
                }
                TweakControl item;
                if (!myTweaks.TryGetValue(group.Label + "|" + tweak.Label, out item))
                {
                    item = new TweakControl(tweak);
                    myTweaks.Add(group.Label + "|" + tweak.Label, item);
                    //item.MouseDown += new MouseButtonEventHandler(tweak_Click);
                    item.Click += new RoutedEventHandler(tweak_Click);
                    item.ReqSU += new RoutedEventHandler(req_su);
                }
                item.label.Content       = tweak.Label;
                item.Tag                 = tweak;
                item.VerticalAlignment   = VerticalAlignment.Top;
                item.HorizontalAlignment = HorizontalAlignment.Stretch;
                item.Margin              = new Thickness(1, 1, 1, 1);

                if (!tweak.IsAvailable())
                {
                    item.toggle.IsEnabled = false;
                }

                this.tweakGrid.Children.Add(item);
                RowDefinition row = new RowDefinition();
                row.Height = new GridLength(item.Height + 2);
                this.tweakGrid.RowDefinitions.Add(row);
                Grid.SetRow(item, tweakGrid.RowDefinitions.Count - 1);
                //Grid.SetColumn(item, 1);
            }
        }
示例#4
0
        static public bool UndoTweak(Tweak tweak)
        {
            switch (tweak.Type)
            {
            case TweakType.SetRegistry: return(UndoRegistryTweak(tweak.Path, tweak.Key, tweak.usrLevel));

            case TweakType.SetGPO: return(UndoGPOTweak(tweak.Path, tweak.Key, tweak.usrLevel));

            case TweakType.DisableService: return(EnableService(tweak.Key));

            case TweakType.DisableTask: return(DisableTask(tweak.Path, tweak.Key, true));

            case TweakType.BlockFile: return(UnBlockFile(tweak.Path));
                //case TweakType.UseFirewall:   return ...
            }
            return(false);
        }
示例#5
0
        static public bool TestTweak(Tweak tweak)
        {
            switch (tweak.Type)
            {
            case TweakType.SetRegistry: return(TestRegistryTweak(tweak.Path, tweak.Key, tweak.Value, tweak.usrLevel));

            case TweakType.SetGPO: return(TestGPOTweak(tweak.Path, tweak.Key, tweak.Value, tweak.usrLevel));

            case TweakType.DisableService: return(IsServiceEnabled(tweak.Key) == false);

            case TweakType.DisableTask: return(IsTaskEnabled(tweak.Path, tweak.Key) == false);

            case TweakType.BlockFile: return(IsFileBlocked(tweak.Path));
                //case TweakType.UseFirewall:   return ...
            }
            return(false);
        }
示例#6
0
    void FormMain_Load(object sender, EventArgs e)
    {
        DataGridViewTweaks.AutoGenerateColumns = false;
        DataGridViewTweaks.DataSource          = tweaks;

        // Populate list from data folder.
        foreach (var path in Directory.EnumerateFiles("Tweaky", "*.ini", SearchOption.AllDirectories))
        {
            if (path.Split('\\').Length > 2)
            {
                var tweak = new Tweak(path);
                tweaks.Add(tweak);

                if (!ComboBoxSearch.Items.Contains(tweak.Category))
                {
                    ComboBoxSearch.Items.Add(tweak.Category);
                }
            }
        }

        ComboBoxSearch.Select();
    }
示例#7
0
        /// <summary>
        /// Starts all tweak runners.
        /// </summary>
        private static void StartTweaks()
        {
            HashSet <string> tweakIds = new HashSet <string>();

            // Create runners for all the tweaks
            foreach (Type tweakType in allTweakTypes)
            {
                // Verify tweaks do not have conflicting IDs
                RegisterTweakAttribute registerAttribute =
                    tweakType.GetCustomAttribute <RegisterTweakAttribute>();
                if (tweakIds.Contains(registerAttribute.Id))
                {
                    throw new InvalidOperationException(
                              "Found conflicting tweaks with the ID '{0}', ");
                }

                // Create the tweak
                ConstructorInfo constructor = tweakType.GetConstructor(new Type[] { });
                Tweak           tweak       = (Tweak)constructor.Invoke(null);
                TweakSettings   settings    =
                    synchronizer.GetSettingsForType(registerAttribute.SettingsType);

                // Create and register the runner
                TweakRunner runner = new TweakRunner(tweak, settings);
                tweakRunners.Add(runner);
                synchronizer.Register(runner.Tweak);
                synchronizer.Register(runner.TweakMetadata.PatchesType);
            }

            // Sync patch/tweak references with their respective settings
            synchronizer.Sync();

            // Start all runners
            foreach (TweakRunner runner in tweakRunners)
            {
                runner.Start();
            }
        }
示例#8
0
        public bool Load(string FilePath, Dictionary <string, TweakPresets.Category> Categorys)
        {
            if (!File.Exists(FilePath))
            {
                return(false);
            }

            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(FilePath);

                double fileVersion = 0.0;
                double.TryParse(xDoc.DocumentElement.GetAttribute("Version"), out fileVersion);
#if false
                if (fileVersion != xmlVersion)
                {
                    if (fileVersion != 0 && fileVersion < xmlVersion)
                    {
                        FileOps.MoveFile(FilePath, App.dataPath + @"\Tweaks_old.xml", true);
                        Priv10Logger.LogWarning(App.EventIDs.AppWarning, null, App.EventFlags.Notifications, Translate.fmt("msg_tweaks_updated", App.dataPath + @"\Tweaks_old.xml"));
                    }
                    else
                    {
                        Priv10Logger.LogError("Failed to load tweaklist, unknown file version {0}, expected {1}", fileVersion, xmlVersion);
                    }
                    return(false);
                }
#endif

                int TotalCount = 0;
                int ErrorCount = 0;

                foreach (XmlNode node in xDoc.DocumentElement.ChildNodes)
                {
                    TotalCount++;
                    Tweak tweak = new Tweak();
                    if (!tweak.Load(node))
                    {
                        ErrorCount++;
                        continue;
                    }

                    TweakPresets.Category tweak_cat;
                    if (!Categorys.TryGetValue(tweak.Category, out tweak_cat))
                    {
                        tweak_cat = new TweakPresets.Category(tweak.Category);
                        Categorys.Add(tweak.Category, tweak_cat);
                    }

                    tweak_cat.Add(tweak);
                }

#if false
                if (ErrorCount != 0)
                {
                    Priv10Logger.LogError("Failed to load {0} tweak entries out of {1}", ErrorCount, TotalCount);
                }
                Priv10Logger.LogInfo("TweakManager loaded {0} entries", TotalCount - ErrorCount);
#endif
            }
            catch (Exception err)
            {
                AppLog.Exception(err);
                return(false);
            }
            return(true);
        }