Exemplo n.º 1
0
        internal static ClassDB InitDb(string name)
        {
            IDbConnection db;

            if (TShock.Config.StorageType.ToLower() == "sqlite")
            {
                db =
                    new SqliteConnection(string.Format("uri=file://{0},Version=3",
                                                       Path.Combine(TShock.SavePath, name + ".sqlite")));
            }
            else if (TShock.Config.StorageType.ToLower() == "mysql")
            {
                try
                {
                    var host = TShock.Config.MySqlHost.Split(':');
                    db = new MySqlConnection
                    {
                        ConnectionString = string.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4}",
                                                         host[0],
                                                         host.Length == 1 ? "3306" : host[1],
                                                         TShock.Config.MySqlDbName,
                                                         TShock.Config.MySqlUsername,
                                                         TShock.Config.MySqlPassword
                                                         )
                    };
                }
                catch (MySqlException x)
                {
                    TShock.Log.Error(x.ToString());
                    throw new Exception("MySQL not setup correctly.");
                }
            }
            else
            {
                throw new Exception("Invalid storage type.");
            }
            var tempDB = new ClassDB(db);

            return(tempDB);
        }
Exemplo n.º 2
0
 internal ClassUtils()
 {
     class_db = ClassDB.InitDb("Classes");
     class_db.LoadClasses(ref classes);
 }