public static void clearOldLog(Hunt h, int clearMinutes = 10) { var time = DateTime.Now; int hour = time.Hour; int minute = time.Minute; while (clearMinutes > 60) { hour--; clearMinutes -= 60; } if (minute >= clearMinutes) { minute -= clearMinutes; } else { hour--; minute = 60 + (minute - clearMinutes); } int stamp = TimestampManager.getDayStamp(); while (hour < 0) { hour += 24; stamp--; } h.Reset(clearMinutes); HuntManager.SetHuntTime(h, clearMinutes); LootDatabaseManager.DeleteMessagesBefore(h, stamp, hour, minute); SQLiteDataReader reader = LootDatabaseManager.GetHuntMessages(h); Dictionary <string, List <string> > logMessages = new Dictionary <string, List <string> >(); while (reader.Read()) { string line = reader["message"].ToString(); if (line.Length < 15) { continue; } string t = line.Substring(0, 5); if (!(t[0].isDigit() && t[1].isDigit() && t[3].isDigit() && t[4].isDigit() && t[2] == ':')) { continue; //not a valid timestamp } if (!logMessages.ContainsKey(t)) { logMessages.Add(t, new List <string>()); } logMessages[t].Add(line); } Parser.ParseLootMessages(h, logMessages, null, false, false, true); LootDatabaseManager.UpdateLoot(); }
public static void SaveLog(Hunt h, string logPath) { StreamWriter streamWriter = new StreamWriter(logPath); // we load the data from the database instead of from the stored dictionary so it is ordered properly SQLiteDataReader reader = LootDatabaseManager.GetHuntMessages(h); while (reader.Read()) { streamWriter.WriteLine(reader["message"].ToString()); } streamWriter.Flush(); streamWriter.Close(); }
public static void Initialize() { //"Name#DBTableID#Track#Time#Exp#SideHunt#AggregateHunt#ClearOnStartup#Creature#Creature#..." if (!SettingsManager.settingExists("Hunts")) { SettingsManager.setSetting("Hunts", new List <string>() { "New Hunt#True#0#0#False#True" }); } hunts.Clear(); int activeHuntIndex = 0, index = 0; List <int> dbTableIds = new List <int>(); foreach (string str in SettingsManager.getSetting("Hunts")) { SQLiteDataReader reader; Hunt hunt = new Hunt(); string[] splits = str.Split('#'); if (splits.Length >= 7) { hunt.name = splits[0]; if (!int.TryParse(splits[1].Trim(), out hunt.dbtableid)) { continue; } if (dbTableIds.Contains(hunt.dbtableid)) { continue; } dbTableIds.Add(hunt.dbtableid); hunt.totalTime = 0; hunt.trackAllCreatures = splits[2] == "True"; double.TryParse(splits[3], NumberStyles.Any, CultureInfo.InvariantCulture, out hunt.totalTime); long.TryParse(splits[4], out hunt.totalExp); hunt.sideHunt = splits[5] == "True"; hunt.aggregateHunt = splits[6] == "True"; hunt.clearOnStartup = splits[7] == "True"; hunt.temporary = false; string massiveString = ""; for (int i = 8; i < splits.Length; i++) { if (splits[i].Length > 0) { massiveString += splits[i] + "\n"; } } hunt.trackedCreatures = massiveString; // set this hunt to the active hunt if it is the active hunt if (SettingsManager.settingExists("ActiveHunt") && SettingsManager.getSettingString("ActiveHunt") == hunt.name) { activeHuntIndex = index; } refreshLootCreatures(hunt); if (hunt.clearOnStartup) { resetHunt(hunt); } // create the hunt table if it does not exist LootDatabaseManager.CreateHuntTable(hunt); // load the data for the hunt from the database reader = LootDatabaseManager.GetHuntMessages(hunt); while (reader.Read()) { string message = reader["message"].ToString(); Tuple <Creature, List <Tuple <Item, int> > > resultList = Parser.ParseLootMessage(message); if (resultList == null) { continue; } string t = message.Substring(0, 5); if (!hunt.loot.logMessages.ContainsKey(t)) { hunt.loot.logMessages.Add(t, new List <string>()); } hunt.loot.logMessages[t].Add(message); Creature cr = resultList.Item1; if (!hunt.loot.creatureLoot.ContainsKey(cr)) { hunt.loot.creatureLoot.Add(cr, new Dictionary <Item, int>()); } foreach (Tuple <Item, int> tpl in resultList.Item2) { Item item = tpl.Item1; int count = tpl.Item2; if (!hunt.loot.creatureLoot[cr].ContainsKey(item)) { hunt.loot.creatureLoot[cr].Add(item, count); } else { hunt.loot.creatureLoot[cr][item] += count; } } if (!hunt.loot.killCount.ContainsKey(cr)) { hunt.loot.killCount.Add(cr, 1); } else { hunt.loot.killCount[cr] += 1; } } hunts.Add(hunt); index++; } } if (hunts.Count == 0) { Hunt h = new Hunt(); h.name = "New Hunt"; h.dbtableid = 1; hunts.Add(h); resetHunt(h); } activeHunt = hunts[activeHuntIndex]; MainForm.mainForm.InitializeHuntDisplay(activeHuntIndex); }