Esempio n. 1
0
        internal static RegistrySettings GetRegistry(Boolean isStandart = false)
        {
            if (isStandart)
            {
                return(new RegistrySettings(null));
            }

            try
            {
                RegistryKey currentUserKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(SubKey) ?? throw new NullReferenceException();
                Int32.TryParse(GetRegistryValue(ref currentUserKey, RegKeyMonitorID), out Int32 monitorID);
                RegistrySettings registrySettings = new RegistrySettings(
                    GetRegistryValue(ref currentUserKey, RegKeyID),
                    GetRegistryValue(ref currentUserKey, RegKeyKey),
                    GetRegistryValue(ref currentUserKey, RegKeyLanguageCode),
                    monitorID,
                    ToBoolean(GetRegistryValue(ref currentUserKey, RegKeyIsDisguise)),
                    !ToBoolean(GetRegistryValue(ref currentUserKey, RegKeyUseRegistry)),
                    !ToBoolean(GetRegistryValue(ref currentUserKey, RegKeyShow)),
                    GetRegistryValue(ref currentUserKey, RegKeyBuildDateTimeHash));

                currentUserKey.Close();
                return(registrySettings);
            }
            catch (Exception ex) when
                (ex is NullReferenceException || ex is ObjectDisposedException ||
                ex is SecurityException)
            {
                return(new RegistrySettings(null));
            }
        }
Esempio n. 2
0
        internal static Boolean SetRegistry(RegistrySettings registrySettings)
        {
            try
            {
                RegistryKey currentUserKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(SubKey) ?? throw new NullReferenceException();
                currentUserKey.SetValue(RegKeyID, registrySettings.ID ?? Licence.FreeID);
                currentUserKey.SetValue(RegKeyKey, registrySettings.Key ?? Licence.FreeKey);
                currentUserKey.SetValue(RegKeyLanguageCode, registrySettings.LanguageCode);
                currentUserKey.SetValue(RegKeyMonitorID, registrySettings.MonitorID.ToString());
                currentUserKey.SetValue(RegKeyIsDisguise, registrySettings.IsDisguise);
                currentUserKey.SetValue(RegKeyUseRegistry, !registrySettings.DontUseRegistry);
                currentUserKey.SetValue(RegKeyShow, !registrySettings.DontShowAnymore);
                currentUserKey.SetValue(RegKeyBuildDateTimeHash, registrySettings.BuildDateTimeHash);

                currentUserKey.Close();
                return(true);
            }
            catch (Exception ex) when
                (ex is ObjectDisposedException || ex is SecurityException ||
                ex is UnauthorizedAccessException || ex is IOException)
            {
                return(false);
            }
        }