public IniBan(string path) { _filePath = path; Bans = new List<WTuple<string, string>>(); if (!File.Exists(path)) { _file = new DataFile(); _file.Sections.Add(new Section("bans")); return; } _file = new DataFile(path); foreach (var set in _file.GetSettings("bans")) { Bans.Add( new WTuple<string, string>( set.Name, String.Join(", ",set) ) ); } }
/// <summary> /// Initiates the Universe DB. FLPath is the path to the Freelancer directory, not DATA\EXE etc. /// </summary> /// <param name="flPath"></param> /// <param name="log"></param> /// <param name="forceScan"></param> public static bool Parse(string flPath, LogDispatcher.LogDispatcher log, bool forceScan = false) { IsAttached = false; _log = log; Gis.Clear(); if (flPath == "") { _log.NewMessage(LogType.Error, "Universe: Got empty FLPath!"); if (DoneLoading != null) DoneLoading(null, null); return false; } if (StartedLoading != null) StartedLoading(null, null); _log.NewMessage(LogType.Debug, "Universe: Parsing file {0} ...", flPath + @"\DataMaps.ini"); if (!File.Exists(flPath + @"\DataMaps.ini")) { log.NewMessage(LogType.Error, "Universe: Can't find DataMaps.ini!"); if (DoneLoading != null) DoneLoading(null, null); return false; } var dMapIni = new DataFile(flPath + @"\DataMaps.ini"); HpMap.Clear(); foreach (var set in dMapIni.GetSettings("HPMap", "map")) { EquipTypes eqType; if (!Enum.TryParse(set[1], out eqType)) { log.NewMessage(LogType.Error, "Can't parse equipment type in DataMaps.ini: {0} {1}", set[0], set[1]); continue; } HpMap.Add(set[0], eqType); } log.NewMessage(LogType.Debug, "Parsing file {0} ...", flPath + @"\EXE\Freelancer.ini"); if (!File.Exists(flPath + @"\EXE\Freelancer.ini")) { log.NewMessage(LogType.Error, "Universe: Can't find Freelancer.ini!"); if (DoneLoading != null) DoneLoading(null, null); return false; } var flIni = new DataFile(flPath + @"\EXE\Freelancer.ini"); _flDataPath = Path.GetFullPath(Path.Combine(flPath + @"\EXE", flIni.GetSetting("Freelancer", "data path")[0])); // Load the infocard map var ini = new DataFile(_flDataPath + @"\interface\infocardmap.ini"); foreach (var set in ini.Sections.SelectMany(section => section.Settings)) { uint map0, map1; if (!uint.TryParse(set[0], out map0) || !uint.TryParse(set[1], out map1)) { log.NewMessage(LogType.Error, "Can't parse infocard map: {0}", set.String()); continue; } //throw new Exception("Can't parse infocard map: " + set.String()); InfocardMap[map0] = map1; } if (Properties.Settings.Default.FLDataUseCache & !forceScan) { if (File.Exists(flPath + @"/FLSAM_Data.xml")) { _log.NewMessage(LogType.Info, "Universe: Loading game cache..."); Gis.ReadXml(flPath + @"/FLSAM_Data.xml"); IsAttached = true; if (DoneLoading != null) DoneLoading(null, null); _log.NewMessage(LogType.Info, "Universe: Game cache loaded."); return true; } } var bgw = new BackgroundWorker(); bgw.DoWork += _bgw_DoWork; bgw.RunWorkerCompleted += _bgw_RunWorkerCompleted; bgw.RunWorkerAsync(new object[] { flIni,flPath}); return true; }
public static bool SaveCharacter(Character ch, string path) { var oldFile = new DataFile(path); var newFile = new DataFile(); newFile.Sections.Add(new Section("Player")); var pSect = newFile.GetFirstOf("Player"); pSect.Settings.Add(new Setting("description") { oldFile.GetSetting("Player", "description")[0] }); pSect.Settings.Add(new Setting("tstamp") { ((ch.LastOnline.ToFileTime() >> 32) & 0xFFFFFFFF).ToString(CultureInfo.InvariantCulture), (ch.LastOnline.ToFileTime() & 0xFFFFFFFF).ToString(CultureInfo.InvariantCulture) }); //TODO: name pSect.Settings.Add(oldFile.GetSetting("Player","name")); pSect.Settings.Add(new Setting("rank") { ch.Rank.ToString(CultureInfo.InvariantCulture) }); foreach (var set in ch.Reputation.Select(rep => new Setting("house") { String.Format(Nfi, "{0:0.000;-0.000}", rep.Value), rep.Nickname })) { pSect.Settings.Add(set); } pSect.Settings.Add(new Setting("rep_group") { ch.ReputationIFF }); pSect.Settings.Add(new Setting("money") { ch.Money.ToString(CultureInfo.InvariantCulture) }); pSect.Settings.Add(oldFile.GetSetting("Player","num_kills")); pSect.Settings.Add(oldFile.GetSetting("Player", "num_misn_successes")); pSect.Settings.Add(oldFile.GetSetting("Player", "num_misn_failures")); pSect.Settings.Add(oldFile.GetSetting("Player", "voice")); pSect.Settings.Add(oldFile.GetSetting("Player", "com_body")); pSect.Settings.Add(oldFile.GetSetting("Player", "com_head")); pSect.Settings.Add(oldFile.GetSetting("Player", "com_lefthand")); pSect.Settings.Add(oldFile.GetSetting("Player", "com_righthand")); pSect.Settings.Add(oldFile.GetSetting("Player", "body")); pSect.Settings.Add(oldFile.GetSetting("Player", "head")); pSect.Settings.Add(oldFile.GetSetting("Player", "lefthand")); pSect.Settings.Add(oldFile.GetSetting("Player", "righthand")); //TODO: position if in space pSect.Settings.Add(new Setting("system") { ch.System }); if (ch.Base != null) pSect.Settings.Add(new Setting("base") { ch.Base }); else { //in space pSect.Settings.Add(new Setting("pos") { String.Format(Nfi,"{0:0.0}",ch.Position[0]), String.Format(Nfi,"{0:0.0}",ch.Position[1]), String.Format(Nfi,"{0:0.0}",ch.Position[2]) }); pSect.Settings.Add(new Setting("rotate") { "0","0","0" }); } pSect.Settings.Add(new Setting("ship_archetype") { ch.ShipArch.ToString(CultureInfo.InvariantCulture) }); foreach (var eq in ch.EquipmentList) { pSect.Settings.Add(new Setting("equip") { eq.Item1.ToString(CultureInfo.InvariantCulture),eq.Item2,String.Format(Nfi, "{0:0.00}", eq.Item3) }); } foreach (var cg in ch.Cargo.Where(cg => !((cg.Item1 == 0) | (cg.Item2 == 0)))) { pSect.Settings.Add(new Setting("cargo") { cg.Item1.ToString(CultureInfo.InvariantCulture), cg.Item2.ToString(CultureInfo.InvariantCulture), "", "", "0" }); } pSect.Settings.Add(new Setting("last_base") { ch.LastBase }); // base_hull_status pSect.Settings.Add(new Setting("base_hull_status") { String.Format(Nfi, "{0:0.00}", ch.Health) }); //todo: base_collision_group foreach (var eq in ch.EquipmentList) { pSect.Settings.Add(new Setting("base_equip") { eq.Item1.ToString(CultureInfo.InvariantCulture),eq.Item2,String.Format(Nfi, "{0:0.00}", eq.Item3) }); } foreach (var cg in ch.Cargo.Where(cg => !((cg.Item1 == 0) | (cg.Item2 == 0)))) { pSect.Settings.Add(new Setting("base_cargo") { cg.Item1.ToString(CultureInfo.InvariantCulture), cg.Item2.ToString(CultureInfo.InvariantCulture), "", "", "0" }); } pSect.Settings.AddRange(oldFile.GetSettings("Player", "wg")); foreach (var visit in ch.Visits) { pSect.Settings.Add(new Setting("visit") { visit.Key.ToString(CultureInfo.InvariantCulture), visit.Value.ToString(CultureInfo.InvariantCulture) }); } pSect.Settings.Add(oldFile.GetSetting("Player","interface")); //todo: mPlayer, flhook newFile.Sections.Add(oldFile.GetFirstOf("mPlayer")); newFile.Sections.Add(oldFile.GetFirstOf("flhook")); newFile.Save(path); Logger.LogDisp.NewMessage(LogType.Info, "Saved profile {0}: {1}", ch.Name, path); return true; }