public bool SM_ApplySetup(int setupId)
        {
            bool result = false;

            try
            {
                if (!mySurround.apiLoaded)
                {
                    mySurround.Initialize();
                }
                if (NVidia_Surround_Assistant.Properties.Settings.Default.SaveWindowPositions)
                {
                    SM_SaveWindowPositions();
                }
                SurroundConfig config = MainForm.sqlInterface.GetSurroundConfig(setupId);
                if (config != null)
                {
                    mySurround.ApplySetup(config.Config);
                    result = true;
                }
                else
                {
                    MainForm.logger.Info("DM: Application with id {0}, not in list", setupId);
                }
            }
            catch (DisplayManager_Exception ex)
            {
                MainForm.logger.Error("DM: {0}", ex.Message);
            }

            return(result);
        }
        public bool SM_SaveCurrentSetup(string configName, int id)
        {
            bool           result         = false;
            SurroundConfig surroundConfig = new SurroundConfig();

            try
            {
                if (!mySurround.apiLoaded)
                {
                    mySurround.Initialize();
                }
                surroundConfig.Id     = id;
                surroundConfig.Name   = configName;
                surroundConfig.Config = mySurround.SaveSetup();
                if (surroundConfig.Config != null)
                {
                    MainForm.sqlInterface.SetSurroundConfig(surroundConfig);
                    MainForm.logger.Info("DM: Saving to file successful");
                    result = true;
                }
            }
            catch (DisplayManager_Exception ex)
            {
                MessageBox.Show("Display Manager Error: " + ex.Message + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                MainForm.logger.Error("DM: Saving to file Error: {0}", ex.Message);
            }
            return(result);
        }
Exemplo n.º 3
0
        private SurroundConfig ReadSurroundConfig(SQLiteDataReader reader)
        {
            SurroundConfig surroundConfig = null;

            if (reader.VisibleFieldCount > 0 && reader.StepCount > 0)
            {
                while (reader.Read())
                {
                    try
                    {
                        surroundConfig = new SurroundConfig
                        {
                            Id     = reader.GetInt32(reader.GetOrdinal("id")),
                            Name   = (string)reader["Name"],
                            Config = (byte[])reader["ConfigFile"],
                        };
                    }
                    catch (System.InvalidCastException ex)
                    {
                        MainForm.logger.Debug("Invalid Cast: {0}", ex.Message);
                    }
                }
            }
            return(surroundConfig);
        }
        /// <summary>
        /// Initialize NVApi and load the default configs. If there are no configs create them
        /// </summary>
        /// <returns></returns>
        public bool SM_ReadDefaultSurroundConfig()
        {
            try
            {
                defaultConfig         = MainForm.sqlInterface.GetSurroundConfig("Default");
                defaultSurroundConfig = MainForm.sqlInterface.GetSurroundConfig("Default Surround");

                if (defaultConfig == null || defaultSurroundConfig == null)
                {
                    if (!SM_DoInitialSetup())
                    {
                        surroundSetupLoaded = false;
                        return(surroundSetupLoaded);
                    }
                    defaultConfig         = MainForm.sqlInterface.GetSurroundConfig("Default");
                    defaultSurroundConfig = MainForm.sqlInterface.GetSurroundConfig("Default Surround");
                }
                mySurround.LoadSetup(false, defaultConfig.Config);
                mySurround.LoadSetup(true, defaultSurroundConfig.Config);
                surroundSetupLoaded = true;
            }
            catch (DisplayManager_Exception ex)
            {
                MainForm.logger.Error("DM: {0}", ex.Message);
            }
            return(surroundSetupLoaded);
        }
Exemplo n.º 5
0
        public bool DeleteSurroundConfig(SurroundConfig config)
        {
            SQLiteParameter[] parameters = { new SQLiteParameter("@id", config.Id) };

            if (SQL_ExecuteNonQuery("DELETE FROM SurroundConfigs WHERE id = @id", parameters) > 0)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        private bool UpdateSurroundConfig(SurroundConfig editConfig)
        {
            SQLiteParameter[] parameters = { new SQLiteParameter("@id", editConfig.Id), new SQLiteParameter("@name", editConfig.Name), new SQLiteParameter("@config", editConfig.Config) };

            if (SQL_ExecuteNonQuery("UPDATE SurroundConfigs SET Name = @name, ConfigFile = @config WHERE id = @id", parameters) > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        public bool SetSurroundConfig(SurroundConfig newConfig)
        {
            bool result = true;

            if (!SurroundConfigExists(newConfig.Name))
            {
                AddSurroundConfig(newConfig);
            }
            else
            {
                UpdateSurroundConfig(newConfig);
            }
            return(result);
        }
Exemplo n.º 8
0
        public SurroundConfig GetSurroundConfig(int configId)
        {
            SurroundConfig resultConfig = null;

            if (SurroundConfigExists(configId))
            {
                SQLiteDataReader reader = SQL_ExecuteQuery(String.Format("SELECT * FROM SurroundConfigs WHERE id = \"{0}\"", configId));
                if (reader != null)
                {
                    resultConfig = ReadSurroundConfig(reader);
                }
            }

            return(resultConfig);
        }
Exemplo n.º 9
0
        private int AddSurroundConfig(SurroundConfig newConfig)
        {
            SQLiteParameter[] parameters = { new SQLiteParameter("@name", newConfig.Name), new SQLiteParameter("@config", newConfig.Config) };

            if (SQL_ExecuteNonQuery("INSERT INTO SurroundConfigs (Name, ConfigFile) values (@name, @config)", parameters) > 0)
            {
                SQLiteDataReader reader = SQL_ExecuteQuery(String.Format("SELECT * FROM SurroundConfigs WHERE name = \"{0}\"", newConfig.Name));
                if (reader != null)
                {
                    if (reader.VisibleFieldCount > 0 && reader.HasRows)
                    {
                        reader.Read();
                        return(reader.GetInt32(reader.GetOrdinal("id")));
                    }
                }
            }

            return(-1);
        }
        public bool SM_IsSurroundActive(int configID)
        {
            bool result = false;

            try
            {
                if (!mySurround.apiLoaded)
                {
                    mySurround.Initialize();
                }
                SurroundConfig config = MainForm.sqlInterface.GetSurroundConfig(configID);
                if (config != null)
                {
                    result = mySurround.IsSurroundActive(config.Config);
                }
            }
            catch (DisplayManager_Exception ex)
            {
                MainForm.logger.Error("DM: IsSurroundActive Error: {0}", ex.Message);
            }
            return(result);
        }
        //Save current setup to db
        public bool SM_SaveDefaultSurroundSetup()
        {
            bool           result         = false;
            SurroundConfig surroundConfig = new SurroundConfig();

            try
            {
                if (!initConfig)
                {
                    result = SM_SaveCurrentSetup("Default Surround", defaultSurroundConfig.Id);
                    SM_ReadDefaultSurroundConfig();
                }
                else
                {
                    result = SM_SaveCurrentSetup("Default Surround", 1);
                }
            }
            catch (DisplayManager_Exception ex)
            {
                MessageBox.Show("Display Manager Error: " + ex.Message + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                MainForm.logger.Error("DM: Saving to file Error: {0}", ex.Message);
            }
            return(result);
        }