/// <summary> /// Adds a base item to the project-file manager /// </summary> /// <param name="theme">The item to add</param> /// <returns>true, if successful - false, otherwise</returns> public bool AddDB(IDB db) { if (!DBs.Contains(db)) { DBs.Add(db); return(true); } return(false); }
/// <summary> /// Loads all databases. UnloadDBs must be called between calls to LoadDBs. /// </summary> public static void LoadDBs() { if (!Directory.Exists(FileSystem.DbPath)) { Directory.CreateDirectory(FileSystem.DbPath); } var alldbs = Program.DatabaseConfig.Databases; for (int i = 0; i < alldbs.Count; i++) { var db = alldbs[i]; try{ string path = db.Filename; if (!Path.IsPathRooted(path)) { path = System.IO.Path.Combine(FileSystem.DbPath, path); } if (!File.Exists(path)) { MessageBox.Show("The database " + Path.GetFileName(path) + " was not found and can not be loaded."); } else { var loadedDB = ClrMameProParser.ParseDAT(db, File.ReadAllText(path), db.Platforms); loadedDB.AssociatedConfigEntry = db; DBs.Add(loadedDB); for (int j = 0; j < db.MiscPlatforms.Count; j++) { var platformName = db.MiscPlatforms[j]; loadedDB.MiscPlatforms.Add(db.MiscPlatforms[j]); // Only add unique strings. Case-insensitive if (_AllMiscPlatforms.Find(s => platformName.Equals(s, StringComparison.OrdinalIgnoreCase)) == null) { _AllMiscPlatforms.Add(platformName); } } } }catch (ClrMameProParser.CmpDocumentException ex) { var rslt = MessageBox.Show("A database could not be loaded (" + db.Filename + "). Additional errors will be ignored. Show details?", "Error", MessageBoxButtons.YesNo); if (rslt == DialogResult.Yes) { using (var frm = new frmError()) { frm.SetError(ex); frm.ShowDialog(); } } } } }
private void LoadConf() { log.WriteFileLog("加载配置文件"); XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(conf); XmlElement root = xmldoc.DocumentElement; // 读取显示属性 XmlNode xn; try { xn = root.SelectSingleNode("encry_str"); keystr = xn.Attributes["key"].InnerText; } catch (Exception ex) { keystr = string.Empty; } // 读取Ssh连接配置 xn = root.SelectSingleNode("DBBase"); XmlNodeList xnl = xn.ChildNodes; XmlNodeList xll; foreach (XmlNode x in xnl) { // 跳过注释,否则格式不对,会报错 if (x.NodeType == XmlNodeType.Comment) { continue; } DBConf d = new DBConf(x.Attributes["dbtns"].InnerText, x.Attributes["note"].InnerText); xll = x.ChildNodes; foreach (XmlNode xx in xll) { DBUser u = new DBUser(xx.Attributes["name"].InnerText, xx.Attributes["pass"].InnerText, xx.Attributes["note"].InnerText); u.file = xx.Attributes["file"].InnerText; d.Users.Add(u); } DBs.Add(d); } log.WriteFileLog("配置初始化完成"); }
private void AddDB(string name, string path) { if (name == null || path == null) { return; } int count = DBs.Where(db => { return(db.DBPath == path); }).Count(); if (count != 0) { return; } DBViewModel newDB = new DBViewModel(name, path); DBs.Add(newDB); ActiveDB = newDB; }