Skip to content
This repository was archived by the owner on Dec 7, 2023. It is now read-only.
This repository was archived by the owner on Dec 7, 2023. It is now read-only.

Refactoring Suggestion #214

@rsb-23

Description

@rsb-23

Feature description

We can introduce a intermediatory class like below to ease development and reduce code duplicates.
New components can be added by just inheriting from this class and mentioning instance variables.

using Microsoft.Win32;

namespace ThisIsWin11.OpenTweaks.Assessment
{
    internal class SingleKeyAssessmentBase : AssessmentBase
    {
        private static readonly ErrorHelper logger = ErrorHelper.Instance;

        string id;
        string info;
        string keyName;
        string valueType = RegistryValueKind.String;
        string desiredValue; /// or doValue
        string undesiredValue; /// or undoValue
	string doLog;
	string undoLog;

        public override string ID()        {            return id;        }
        public override string Info()        {            return info;        }

        public override bool CheckAssessment()
        {
            return !(
               RegistryHelper.StringEquals(keyName, "Value", desiredValue)
             );
        }

        public override bool DoAssessment()
        {
            try
            {
                Registry.SetValue(keyName, "Value", desiredValue, valueType);

                logger.Log(doLog);
                logger.Log(keyName);
                return true;
            }
            catch
            { }
            return false;
        }

        public override bool UndoAssessment()
        {
            try
            {
                Registry.SetValue(keyName, "Value", undesiredValue, valueType);
                logger.Log(undoLog);
                return true;
            }
            catch
            { }
            return false;
        }
    }
}

Logs

No response

Issue tracker rule checks (please read carefully)

  • I have checked that this feature is not already asked.
  • I have checked that this feature is not already implemented

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions