Beispiel #1
0
        static void ParseLog(string FileName, List<Argument> ArgList)
        {
            string Dir = LogDir;
            string[] MjlogDir = null;
            string Mjlog = null;
            bool Forced = false;
            bool Rewrited;

            foreach (Argument A in ArgList)
            {
                switch (A.Name)
                {
                    case "dir":
                        Dir = A.Value + "/" + LogDir;
                        if (!Directory.Exists(Dir))
                            Directory.CreateDirectory(Dir);
                        break;
                    case "force":
                        Forced = true;
                        break;
                    case "mjlog":
                        {
                            Mjlog = A.Value;
                            if(Directory.Exists(Mjlog)) MjlogDir = Directory.GetFiles(Mjlog, "*.mjlog");
                        }
                        break;
                }
            }

            Console.WriteLine("Parsing games from log: " + FileName);

            if (!File.Exists(FileName))
            {
                Console.Write("Error: Log file " + FileName + " not found!");
                return;
            }

            Tenhou.LogParser Log = new Tenhou.LogParser(FileName);
            List<string> Hashes = Log.HashList.Hashes;

            for (int i = 0; i < Hashes.Count; i++)
            {
                string Hash = Hashes[i];
                string ReplayFileName = Tenhou.LogParser.GetFileName(Hash, Dir);

                Console.Title = String.Format("Parsing {0:d}/{1:d}: {2:s}", i + 1, Hashes.Count, Hash);
                Console.Write(Hash);

                Rewrited = false;

                if (Mahjong.Replay.IsReplayExist(Hash))
                {
                    if (!Forced)
                    {
                        Console.WriteLine(" - exists, skip!");
                        continue;
                    }
                    else
                    {
                        Rewrited = true;
                    }
                }


                string MjLogFile = GetMjlogFilename(MjlogDir, Hash);
                Tenhou.ReplayDecoder R = new Tenhou.ReplayDecoder();

                if (MjLogFile != null)
                {
                    R.OpenGZ(MjLogFile, Hash);
                }
                else
                {
                    if (!File.Exists(ReplayFileName))
                    {
                        Console.WriteLine(" - file not found!");
                        continue;
                    }

                    if (new FileInfo(ReplayFileName).Length == 0)
                    {
                        File.Delete(ReplayFileName);
                        Console.WriteLine(" - zero size, removed!");
                        continue;
                    }

                    R.OpenPlainText(ReplayFileName, Hash);
                }
                // replay (calc shanten, waitings and other) and save result
                Mahjong.Replay Replay = R.R;
                Replay.ReplayGame();
                Replay.Save();

                Console.WriteLine(Rewrited ? " - replaced, ok!" : " - ok!");
            }
        }
Beispiel #2
0
        static void ParseHash(string Hash)
        {
            Console.Write("Parsing game: " + Hash);
            string ReplayFileName = Hash + ".xml";

            Console.Write(Hash);

            if (!File.Exists(ReplayFileName))
            {
                Console.WriteLine(" - file not found!");
                return;
            }

            Tenhou.ReplayDecoder R = new Tenhou.ReplayDecoder();
            R.OpenPlainText(ReplayFileName, Hash);

            // replay (calc shanten, waitings and other) and save result
            Mahjong.Replay Replay = R.R;
            Replay.ReplayGame();
            Replay.Save();

            Console.WriteLine(" - ok!");
        }