Ejemplo n.º 1
0
        public bool Load()
        {
            bool createConfigResult = CreateDefaultConfig();

            if (!createConfigResult)
            {
                return(false);
            }

            try
            {
                using (var tempStream = new MemoryStream(File.ReadAllBytes(_configFilePath)))
                {
                    BinaryFormatter bformatter = new BinaryFormatter();
                    BeSafeConfig    tempConfig = (BeSafeConfig)bformatter.Deserialize(tempStream);

                    // Assign loaded config fields to local fields for use
                    this.UserSID          = tempConfig.UserSID;
                    this.SecureVolumePath = tempConfig.SecureVolumePath;
                    this.PluginsPath      = tempConfig.PluginsPath;
                    this.ComponentsState  = tempConfig.ComponentsState;
                }

                return(true);
            }
            catch (Exception ex)
            {
                ex.Log();
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fill setting fields with default values and create default setting file
        /// </summary>
        private bool CreateDefaultConfig()
        {
            // Check if default config exists nothing to do
            if (File.Exists(_configFilePath))
            {
                return(true);
            }

            // Initialize default config
            try
            {
                this.UserSID          = WindowsIdentity.GetCurrent()?.User?.ToString();
                this.SecureVolumePath = PathUtils.BeSafeSecureVolumePath;
                this.PluginsPath      = PathUtils.PluginsPath;
                this.ComponentsState  = new ComponentsEnableState();

                Save();
                return(true);
            }
            catch (Exception ex)
            {
                ex.Log();
                return(false);
            }
        }