Exemple #1
0
        public static int UpdateConfig(this MainForm main, CoreConfig config, string configname = "ServiceCore.dll.config")
        {
            string xmlfile = PathHelper.Combine(config.BinPath, configname);

            if (!File.Exists(xmlfile))
            {
                //	return -5;
            }
            string connStr  = config.ConnectionString;
            string gamecode = config.GameCode;
            int    i;

            if (!int.TryParse(gamecode, out i))
            {
                //查sql
                string db3 = PathHelper.Combine(config.GamePath, "sql/heroes.db3");
                if (!File.Exists(db3))
                {
                    db3 = PathHelper.Combine(config.BinPath, "heroesContents.db3");
                    if (!File.Exists(db3))
                    {
                        return(-3);
                    }
                }
                SQLiteHelper db = new SQLiteHelper(db3);
                if (!db.Open())
                {
                    return(-3);
                }
                using (DbDataReader reader = db.GetReader("select \"" + gamecode + "\" from featurematrix where feature='GameCode';")){
                    if (reader != null && reader.HasRows && reader.Read())
                    {
                        string _code = reader.GetString(0);
                        if (gamecode == _code)
                        {
                            return(-4);
                        }
//						System.Windows.Forms.MessageBox.Show(gamecode);
//						return -3;
                    }
                    else
                    {
                        return(-4);
                    }
                }
            }
            XmlDocument doc = new XmlDocument();

            doc.Load(xmlfile);
            XmlNodeList list = doc.SelectNodes("//configuration//connectionStrings//add");

            if (list != null)
            {
                foreach (XmlNode _node in list)
                {
                    Console.WriteLine(_node.Attributes["name"].Value);
                    //Console.WriteLine(node.Attributes["connectionString"].Value);
                    string dbname = GetDbName(_node.Attributes["connectionString"].Value);
                    //Initial Catalog=;
                    string connectionString = GetConnectionString(connStr, dbname);
                    _node.Attributes["connectionString"].Value = connectionString;
                    Console.WriteLine(connectionString);
                }
            }
            else
            {
                return(-1);
            }
            XmlNode node = doc.SelectSingleNode("//configuration//applicationSettings//UnifiedNetwork.Properties.Settings" +
                                                "//setting[@name='GameCode']");

            if (node != null)
            {
                SetValue(node, "" + gamecode);
            }
            else
            {
                return(-2);
            }
            XmlNodeList Properties = doc.SelectNodes("//configuration//applicationSettings//ServiceCore.Properties.Settings//setting");

            if (Properties != null)
            {
                foreach (XmlNode x in Properties)
                {
                    XmlAttribute attr = x.Attributes["name"];
                    if (attr == null)
                    {
                        continue;
                    }
                    if ("DSExecPath".Equals(attr.Value, StringComparison.OrdinalIgnoreCase))
                    {
                        SetValue(x, PathHelper.Combine(config.GamePath, "srcds.exe"));
                    }
                    else if ("VersionMatchUpToDateFile".Equals(attr.Value, StringComparison.OrdinalIgnoreCase))
                    {
                        SetValue(x, PathHelper.Combine(config.GamePath, "CurrentInfo.txt"));
                    }
                }
            }
            else
            {
                return(-3);
            }
            doc.Save(xmlfile);
            return(0);
        }