Exemple #1
0
        public static bool scanLogFile(String logFile, ref WurmDateTime cur, ref WurmDateTimeStamp stamp, DateTime maxDate)
        {
            bool foundMatch = false;

            System.Diagnostics.Debug.WriteLine(logFile);

            FileStream   stream = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader reader = new StreamReader(stream);

            Regex LoggingStarted = new Regex(@"^Logging started (\d{4}-\d{2}-\d{2})$");
            Regex LogEntry       = new Regex(@"^\[(\d\d):(\d\d):(\d\d)] (.*)$");

            DateTime lastLogDate = new DateTime();

            while (!reader.EndOfStream)
            {
                String line  = reader.ReadLine();
                Match  match = LoggingStarted.Match(line);
                if (match.Success)
                {
                    lastLogDate = DateTime.Parse(match.Groups[1].Value);
                    continue;
                }
                match = LogEntry.Match(line);
                if (match.Success)
                {
                    DateTime currentLogDate = new DateTime(
                        lastLogDate.Year, lastLogDate.Month, lastLogDate.Day,
                        Int16.Parse(match.Groups[1].Value),
                        Int16.Parse(match.Groups[2].Value),
                        Int16.Parse(match.Groups[3].Value),
                        DateTimeKind.Local);
                    while (currentLogDate < lastLogDate)
                    {
                        currentLogDate = currentLogDate.AddDays(1); // Handle day wrap around
                    }
                    lastLogDate = currentLogDate;

                    if (currentLogDate > maxDate)
                    {
                        System.Diagnostics.Debug.WriteLine(currentLogDate + " > " + maxDate + ". Exiting");
                        break;
                    }

                    if (parseDateTime(match.Groups[4].Value, ref cur))
                    {
                        System.Diagnostics.Debug.WriteLine(lastLogDate + ": new Date " + match.Groups[4].Value);
                        stamp.wurm = cur;
                        stamp.real = lastLogDate;

                        foundMatch = true;
                    }
                }
            }

            reader.Close();
            stream.Close();

            return(foundMatch);
        }
Exemple #2
0
        public static bool parseDateTime(String date, ref WurmDateTime cur)
        {
            string[] days = { "day of the Ant",
                              "Luck day",
                              "day of the Wurm",
                              "Wrath day",
                              "day of Tears",
                              "day of Sleep",
                              "day of Awakening" };
            string[] starfalls = { "the starfall of Diamonds",
                                   "the starfall of the Saw",
                                   "the starfall of the Digging",
                                   "the starfall of the Leaf",
                                   "the Bear's starfall",
                                   "the Snake's starfall",
                                   "the White Shark starfall",
                                   "the starfall of Fires",
                                   "the Raven's starfall",
                                   "the starfall of Dancers",
                                   "the starfall of Omens",
                                   "the starfall of Silence" };
            Regex    TimeEntry = new Regex(@"^It is (\d\d):(\d\d):(\d\d) on (.*) in week (\d) of (.*) in the year of (\d*).$");

            Match match = TimeEntry.Match(date);

            if (match.Success)
            {
                int day      = Array.IndexOf(days, match.Groups[4].Value);
                int week     = Int16.Parse(match.Groups[5].Value);
                int starfall = Array.IndexOf(starfalls, match.Groups[6].Value);
                int year     = Int16.Parse(match.Groups[7].Value);

                int hour   = Int16.Parse(match.Groups[1].Value);
                int minute = Int16.Parse(match.Groups[2].Value);
                int second = Int16.Parse(match.Groups[3].Value);

                if (day == -1 || week == -1 || starfall == -1 || year == -1 || hour == -1 || minute == -1 || second == -1)
                {
                    System.Diagnostics.Debug.WriteLine("Parse Error " + match.Groups[0] + String.Format(" {0} {1} {2} {3}", day, week, starfall, year));
                    return(false);
                }

                cur.Day      = day + 7 * week - 7;
                cur.Starfall = starfall;
                cur.Time     = hour * 60 * 60 + minute * 60 + second;
                return(true);
            }
            return(false);
        }
Exemple #3
0
        public static bool scanLogFile(String logFile, ref WurmDateTime cur, ref WurmDateTimeStamp stamp, DateTime maxDate)
        {
            bool foundMatch = false;

            System.Diagnostics.Debug.WriteLine(logFile);

            FileStream stream = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader reader = new StreamReader(stream);

            Regex LoggingStarted = new Regex(@"^Logging started (\d{4}-\d{2}-\d{2})$");
            Regex LogEntry = new Regex(@"^\[(\d\d):(\d\d):(\d\d)] (.*)$");

            DateTime lastLogDate = new DateTime();
            while (!reader.EndOfStream)
            {
                String line = reader.ReadLine();
                Match match = LoggingStarted.Match(line);
                if (match.Success)
                {
                    lastLogDate = DateTime.Parse(match.Groups[1].Value);
                    continue;
                }
                match = LogEntry.Match(line);
                if (match.Success)
                {
                    DateTime currentLogDate = new DateTime(
                        lastLogDate.Year, lastLogDate.Month, lastLogDate.Day,
                        Int16.Parse(match.Groups[1].Value),
                        Int16.Parse(match.Groups[2].Value),
                        Int16.Parse(match.Groups[3].Value),
                        DateTimeKind.Local);
                    while (currentLogDate < lastLogDate)
                        currentLogDate = currentLogDate.AddDays(1); // Handle day wrap around
                    lastLogDate = currentLogDate;

                    if (currentLogDate > maxDate)
                    {
                        System.Diagnostics.Debug.WriteLine(currentLogDate + " > " + maxDate + ". Exiting");
                        break;
                    }

                    if (parseDateTime(match.Groups[4].Value, ref cur))
                    {
                        System.Diagnostics.Debug.WriteLine(lastLogDate + ": new Date " + match.Groups[4].Value);
                        stamp.wurm = cur;
                        stamp.real = lastLogDate;

                        foundMatch = true;
                    }
                }
            }

            reader.Close();
            stream.Close();

            return foundMatch;
        }
Exemple #4
0
        public static bool parseDateTime(String date, ref WurmDateTime cur)
        {
            string[] days = { "day of the Ant",
                              "Luck day",
                              "day of the Wurm",
                              "Wrath day",
                              "day of Tears",
                              "day of Sleep",
                              "day of Awakening" };
            string[] starfalls = { "the starfall of Diamonds",
                                   "the starfall of the Saw",
                                   "the starfall of the Digging",
                                   "the starfall of the Leaf",
                                   "the Bear's starfall",
                                   "the Snake's starfall",
                                   "the White Shark starfall",
                                   "the starfall of Fires",
                                   "the Raven's starfall",
                                   "the starfall of Dancers",
                                   "the starfall of Omens",
                                   "the starfall of Silence" };
            Regex TimeEntry = new Regex(@"^It is (\d\d):(\d\d):(\d\d) on (.*) in week (\d) of (.*) in the year of (\d*).$");

            Match match = TimeEntry.Match(date);
            if (match.Success)
            {
                int day = Array.IndexOf(days, match.Groups[4].Value);
                int week = Int16.Parse(match.Groups[5].Value);
                int starfall = Array.IndexOf(starfalls, match.Groups[6].Value);
                int year = Int16.Parse(match.Groups[7].Value);

                int hour = Int16.Parse(match.Groups[1].Value);
                int minute = Int16.Parse(match.Groups[2].Value);
                int second = Int16.Parse(match.Groups[3].Value);

                if (day == -1 || week == -1 || starfall == -1 || year == -1 || hour == -1 || minute == -1 || second == -1)
                {
                    System.Diagnostics.Debug.WriteLine("Parse Error " + match.Groups[0] + String.Format(" {0} {1} {2} {3}", day, week, starfall, year));
                    return false;
                }

                cur.Day = day + 7 * week - 7;
                cur.Starfall = starfall;
                cur.Time = hour * 60 * 60 + minute * 60 + second;
                return true;
            }
            return false;
        }