Пример #1
0
        /// <summary>
        /// Сохранение параметров в реестре
        /// </summary>
        /// <param name="paramInfo">Структура, содержащая все сохраняемые параметры</param>
        public void SaveParameter(UninstallParametersInfo paramInfo)
        {
            if (!_useRegister)
            {
                return;
            }

            RegistryKey regKey = Registry.CurrentUser;

            regKey = regKey.CreateSubKey(RegPath);

            if (regKey != null)
            {
                // Сохранение размера и позиции формы
                regKey.SetValue("UninstLocation", paramInfo.UninstLocation.X + ";" + paramInfo.UninstLocation.Y);
                regKey.SetValue("UninstSize", paramInfo.UninstSize.Width + ";" + paramInfo.UninstSize.Height);

                string res = "";
                for (int i = 0; i < paramInfo.UninstColumnsWidth.Length; i++)
                {
                    res += paramInfo.UninstColumnsWidth[i] + ";";
                }
                regKey.SetValue("UninstColumnsWidth", res);
            }
        }
Пример #2
0
        /// <summary>
        /// Загрузка параметров из реестра
        /// </summary>
        /// <returns>Структура, содержащая все загруженные параметры</returns>
        public void LoadParameter(out UninstallParametersInfo paramInfo)
        {
            paramInfo = new UninstallParametersInfo
            {
                UninstLocation     = new Point(44, 123),
                UninstSize         = new Size(1099, 621),
                UninstColumnsWidth = new[] { "370", "251", "100", "308", "18" }
            };


            if (!_useRegister)
            {
                return;
            }

            RegistryKey regKey = Registry.CurrentUser;

            regKey = regKey.CreateSubKey(RegPath);

            // Чтение значений из реестра
            try
            {
                if (regKey != null)
                {
                    string s = "";
                    s = (string)regKey.GetValue("UninstLocation", s);
                    string[] arr = s.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    if (arr.Length == 2 && Convert.ToInt32(arr[0]) > 0 && Convert.ToInt32(arr[1]) > 0)
                    {
                        paramInfo.UninstLocation = new Point(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]));
                    }

                    s   = "";
                    s   = (string)regKey.GetValue("UninstSize", s);
                    arr = s.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    if (arr.Length == 2)
                    {
                        paramInfo.UninstSize = new Size(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]));
                    }

                    s   = "";
                    s   = (string)regKey.GetValue("UninstColumnsWidth", s);
                    arr = s.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    if (arr.Length > 1)
                    {
                        paramInfo.UninstColumnsWidth = arr;
                    }
                }
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch { }
            // ReSharper restore EmptyGeneralCatchClause
        }