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

Refactoring Suggestion #214

Open
2 tasks done
rsb-23 opened this issue Feb 12, 2023 · 0 comments
Open
2 tasks done

Refactoring Suggestion #214

rsb-23 opened this issue Feb 12, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@rsb-23
Copy link

rsb-23 commented Feb 12, 2023

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
@rsb-23 rsb-23 added the enhancement New feature or request label Feb 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant