예제 #1
0
        public override void Load()
        {
            bool result = false;

            FileInfo file = new FileInfo(Path.Combine(FileManager.UoFolderPath, "Prof.txt"));

            if (file.Exists)
            {
                if (file.Length > 0x100000) //1megabyte limit of string file
                {
                    throw new InternalBufferOverflowException($"{file.FullName} exceeds the maximum 1Megabyte allowed size for a string text file, please, check that the file is correct and not corrupted -> {file.Length} file size");
                }

                //what if file doesn't exist? we skip section completely...directly into advanced selection
                TextFileParser read = new TextFileParser(File.ReadAllText(file.FullName), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' });

                while (!read.IsEOF())
                {
                    List <string> strings = read.ReadTokens();

                    if (strings.Count > 0)
                    {
                        if (strings[0].ToLower() == "begin")
                        {
                            result = ParseFilePart(read);

                            if (!result)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            Professions[new ProfessionInfo
                        {
                            Name = "Advanced",
                            Localization = 1061176,
                            Description = 1061226,
                            Graphic = 5545,
                            TopLevel = true,
                            Type = PROF_TYPE.PROFESSION,
                            DescriptionIndex = -1,
                            TrueName = "advanced"
                        }] = null;

            foreach (KeyValuePair <ProfessionInfo, List <ProfessionInfo> > kvp in Professions)
            {
                kvp.Key.Childrens = null;

                if (kvp.Value != null)
                {
                    foreach (ProfessionInfo info in kvp.Value)
                    {
                        info.Childrens = null;
                    }
                }
            }
        }
예제 #2
0
    /// <summary>
    /// Ambience reading is UNFINISHED!
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static Ambience ReadAmbience(string path)
    {
        Ambience amb = new Ambience();

        string[]       s = File.ReadAllLines(path);
        TextFileParser p = new TextFileParser(s);

        p.Skip();
        amb.Name    = p.ReadString();
        amb.TexPath = p.ReadString();

        amb.SunColor         = p.ReadColor();
        amb.MaxSunStrength   = p.ReadFloat();
        amb.SunLightExponent = p.ReadFloat();

        p.Skip(6);

        amb.SunLightVector    = p.ReadVector3();
        amb.SunRotationVector = p.ReadFloat();

        p.Skip(6);

        //skip color ramps
        p.Skip(p.ReadInt());

        p.Skip(4);

        amb.EnvironmentSound = p.ReadString();

        return(amb);
    }
예제 #3
0
파일: Menu.cs 프로젝트: reubene/Civ2-clone
        public static void LoadMenus(Ruleset ruleset)
        {
            _elements = new Dictionary <string, List <MenuElement> >();
            var filePath = Utils.GetFilePath("Menu.txt", ruleset.Paths);

            TextFileParser.ParseFile(filePath, new Menu());
        }
예제 #4
0
        /// <summary>
        /// The Main method serves to launch the application. It validates the input arguments,
        /// calls the IParser responsible for parsing them, and then creates the IEnvironment
        /// which houses all objects necessary for this solution (both the Rover and Grid components).
        /// NOTE: The exception handling method implemented is to throw all Exception to Main's catch
        /// NOTE: block, which will output error information in a friendly way to the user and then exit.
        /// </summary>
        /// <param name="args">The command-line arguments passed to the application</param>
        static void Main(string[] args)
        {
            string strInputFile = "None specified";

            // Do not execute program if arguments are not appropriate
            if (!IsArgsValid(args))
            {
                Console.Out.Write("usage: ThoughtWorksRovers <input_file_path>\n");
                return;
            }

            try
            {
                strInputFile = args[0];
                IParser      textFileParser   = new TextFileParser(strInputFile);
                IEnvironment roverEnvironment = new RoverEnvironment(textFileParser);
            }
            catch (Exception ex)
            {
                Console.Out.Write("An error has been encountered\n");
                Console.Out.Write("\tInput File: " + strInputFile + "\n");
                Console.Out.Write("\tReason: " + ex.Message + "\n");
                System.Environment.Exit(-1);
            }
        }
예제 #5
0
        public static Dictionary <string, List <string> > LoadCityNames(IEnumerable <string> paths)
        {
            var filePath = Utils.GetFilePath("city.txt", paths);
            var loader   = new NameLoader();

            TextFileParser.ParseFile(filePath, loader);
            return(loader.CityNames);
        }
예제 #6
0
        public override void Load()
        {
            bool result = false;

            FileInfo file = new FileInfo(Path.Combine(FileManager.UoFolderPath, "Prof.txt"));

            if (file.Exists)
            {
                //what if file doesn't exist? we skip section completely...directly into advanced selection
                TextFileParser read = new TextFileParser(file, new char[] { ' ', '\t', ',' }, new char[] { '#', ';' }, new char[] { '"', '"' });

                while (!read.IsEOF())
                {
                    List <string> strings = read.ReadTokens();

                    if (strings.Count > 0)
                    {
                        if (strings[0].ToLower() == "begin")
                        {
                            result = ParseFilePart(read);

                            if (!result)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            Professions[new ProfessionInfo()
                        {
                            Name = "Advanced",
                            Localization = 1061176,
                            Description = 1061226,
                            Graphic = 5545,
                            TopLevel = true,
                            Type = PROF_TYPE.PROFESSION,
                            DescriptionIndex = -1,
                            TrueName = "advanced"
                        }] = null;

            foreach (KeyValuePair <ProfessionInfo, List <ProfessionInfo> > kvp in Professions)
            {
                kvp.Key.Childrens = null;
                if (kvp.Value != null)
                {
                    foreach (ProfessionInfo info in kvp.Value)
                    {
                        info.Childrens = null;
                    }
                }
            }
        }
        public void ParseTxtFile()
        {
            var parser   = new TextFileParser();
            var elements = parser.Parse("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\LongFile.txt");

            Assert.IsNotNull(elements);
            Assert.AreEqual(elements.Count, 987386);
            elements = parser.Parse("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\NotSoLongFile.txt");
            Assert.IsNotNull(elements);
            Assert.AreEqual(23945, elements.Count);
        }
 void Awake()
 {
     if (tfp == null)
     {
         DontDestroyOnLoad(gameObject);
         tfp = this;
     }
     else if (tfp != this)
     {
         Destroy(gameObject);
     }
 }
예제 #9
0
        public static void UpdateLabels(Ruleset rules)
        {
            var labelPath = rules != null?Utils.GetFilePath("labels.txt", rules.Paths) : Utils.GetFilePath("labels.txt");

            if (labelPath == _currentPath)
            {
                return;
            }

            _currentPath = labelPath;
            TextFileParser.ParseFile(labelPath, new LabelLoader());
        }
예제 #10
0
        public List <Figure> CreateMazeFromTextFile(string filePath)
        {
            if (filePath.Equals(""))
            {
                filePath = @"E:\StandardFile.txt";
            }
            figureList = new List <Figure>();
            TextFileParser parser      = new TextFileParser();
            bool           isFirstLine = true;

            Dictionary <int, string[]> dict = parser.CreateStringDictionary(filePath);

            if (dict == null)
            {
                return(null);
            }

            for (int i = 0; i < dict.Count; i++)
            {
                if (isFirstLine == true)
                {
                    maze          = mazeTypeConverter[dict[0].First()];
                    factoryObject = mazeList[maze].getInstance();
                    isFirstLine   = false;
                    continue;
                }
                else
                {
                    string[] param = dict[i];
                    if (param[0].Equals("Room"))
                    {
                        factoryObject.AddRoom(param, figureList);
                    }
                    else if (param[0].Equals("Corritage"))
                    {
                        factoryObject.AddCorritage(param, figureList);
                    }
                    else if (param[0].Equals("Key") && maze == MazeType.MAGIC)
                    {
                        KeyCounter++;
                        factoryObject.AddKey(param, figureList);
                    }
                    else if (param[0].Equals("MagicRoom") && maze == MazeType.MAGIC)
                    {
                        factoryObject.AddRoom(param, figureList);
                    }
                }
            }
            return(figureList);
        }
예제 #11
0
        private void bgwTextFileParser_DoWork(object sender, DoWorkEventArgs e)
        {
            string path    = e.Argument.ToString();
            int    retCode = 0;
            List <DataInformation> lstdi = new List <DataInformation>();

            lstdi.Add(new DataInformation()
            {
                Key = "ID", Position = 0
            });
            lstdi.Add(new DataInformation()
            {
                Key = "Via", Position = 1
            });
            lstdi.Add(new DataInformation()
            {
                Key = "Civico", Position = 2
            });
            lstdi.Add(new DataInformation()
            {
                Key = "Esponente", Position = 3
            });
            lstdi.Add(new DataInformation()
            {
                Key = "CAP", Position = 4
            });
            lstdi.Add(new DataInformation()
            {
                Key = "Comune", Position = 5
            });
            lstdi.Add(new DataInformation()
            {
                Key = "Frazione", Position = 6
            });
            lstdi.Add(new DataInformation()
            {
                Key = "Provincia", Position = 7
            });
            TextFileParser       tfp   = new TextFileParser(ContentType.Path, path, lstdi);
            List <DataContainer> lstdc = tfp.ExtractData <DataContainer>(out retCode);
            Result ret = new Result()
            {
                lstdc   = lstdc,
                Logs    = tfp.Logs,
                retCode = retCode
            };

            e.Result = ret;
        }
예제 #12
0
    public static IFileParser GetParser(string fileToParse)
    {
        FileInfo    file           = new FileInfo(fileToParse);
        IFileParser parserToReturn = null;

        switch (file.Extension.ToLower())
        {
        case "csv": parserToReturn = new CSVFileParser(fileToParse);
            break;

        case "txt": parserToReturn = new TextFileParser(fileToParse);
            break;
        }
        return(parserToReturn);
    }
        public void ParseXAMLFile()
        {
            var parser   = new TextFileParser();
            var elements = parser.Parse("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\SearchViewControl.xaml.txt");

            Assert.IsNotNull(elements);
            Assert.AreEqual(205, elements.Count);
            foreach (var element in elements)
            {
                if (element.DefinitionLineNumber == 218)
                {
                    Assert.AreEqual("</UserControl>", element.Name);
                }
            }
        }
예제 #14
0
        public static void Load()
        {
            string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string chair = Path.Combine(path, "chair.txt");

            if (!File.Exists(chair))
            {
                using (StreamWriter writer = new StreamWriter(chair))
                {
                    foreach (var item in _defaultTable)
                    {
                        writer.WriteLine($"{item.Graphic},{item.Direction1},{item.Direction2},{item.Direction3},{item.Direction4},{item.OffsetY},{item.MirrorOffsetY}");
                    }
                }
            }

            TextFileParser chairParse = new TextFileParser(File.ReadAllText(chair), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' });

            while (!chairParse.IsEOF())
            {
                List <string> ss = chairParse.ReadTokens();

                if (ss != null && ss.Count >= 7)
                {
                    ushort.TryParse(ss[0], out ushort graphic);
                    sbyte.TryParse(ss[1], out sbyte d1);
                    sbyte.TryParse(ss[2], out sbyte d2);
                    sbyte.TryParse(ss[3], out sbyte d3);
                    sbyte.TryParse(ss[4], out sbyte d4);
                    sbyte.TryParse(ss[5], out sbyte offsetY);
                    sbyte.TryParse(ss[6], out sbyte mirrorOffsetY);

                    Table.Add(graphic, new SittingInfoData(graphic, d1, d2, d3, d4, offsetY, mirrorOffsetY, false));
                }
            }
        }
        public void Parse_Long_Text()
        {
            string s = " \"a # quoted\tstring\" a non quoted string    #ignoredstring  ";

            char[] delimiters = new char[] { ' ', '\t' };
            char[] comments   = new char[] { '#' };
            char[] quotes     = new char[] { '"', '"' };
            bool   trim       = true;


            ClassicUO.Utility.TextFileParser parser = new TextFileParser(s, delimiters, comments, quotes);

            List <string> tokens = parser.ReadTokens(trim);

            Assert.NotEmpty(tokens);
            Assert.Equal(5, tokens.Count);
            Assert.Equal("a # quoted\tstring", tokens[0]);
            Assert.Equal("a", tokens[1]);
            Assert.Equal("non", tokens[2]);
            Assert.Equal("quoted", tokens[3]);
            Assert.Equal("string", tokens[4]);
        }
예제 #16
0
 static void Main(string[] args)
 {
     try
     {
         string fileText = string.Empty;
         Console.WriteLine("Please enter the file to parse with the complete path");
         string filePath = Console.ReadLine();
         Console.WriteLine("Parsing File");
         IFileParser fileParser = new TextFileParser(new FileSystem());
         fileText = fileParser.ParseFile(filePath);
         Console.WriteLine("File parsed. Counting the number of words");
         IWordCounter   wordCounter       = new WordCounterLogic();
         var            wordCounterOutput = wordCounter.CountWord(fileText);
         ITextFormatter textFormatter     = new TextFormatter.TextFormatter();
         Console.WriteLine("Here is the output");
         Console.WriteLine(textFormatter.FormatText(wordCounterOutput));
         Console.Read();
     }
     catch (ArgumentNullException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (FileNotFoundException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (FileFormatException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (Exception ex)
     {
         //Ideally we should not catch the Base exception class and should not allow the application to run
         //since in case of OutOfMemory or StackOverFlowexception the application/system might not be in a position to run/
         //The Application might be in a corrupted state and should not be allowed to run.
         Console.WriteLine(ex.Message);
     }
 }
예제 #17
0
        static void Main(string[] args)
        {
            //var path = AppDomain.CurrentDomain.BaseDirectory + @"testfiles\test3.txt";
            var path = (AppDomain.CurrentDomain.BaseDirectory + @"Examples\add.gsa").Replace(@"FlowChartBuilder\bin\Debug\netcoreapp3.0\", "");
            var list = TextFileParser.ParseText(path);//.Replace(@"FlowChartBuilder\bin\Debug\netcoreapp3.0\", ""));
            var grid = new BlockDistributor(list);

            grid.PrintGrid();
            grid.RemoveEmptyLines();
            grid.PrintGrid();
            grid.SetNodesPositions();
            grid.PrintGrid();

            var       graph = new GraphMaker(grid.GetNodes(), grid.GetGrid());;
            Stopwatch sw    = new Stopwatch();

            sw.Start();
            graph.LineCreator();
            sw.Stop();
            Console.WriteLine("ElapsedTotal={0}", sw.Elapsed);
            graph.RemoveMiddlePointsFromLines();
            Console.ReadKey();
        }
예제 #18
0
        public static void Load()
        {
            string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string buff = Path.Combine(path, "buff.txt");

            if (File.Exists(buff))
            {
                var tempList = new List <ushort>();

                TextFileParser buffParser = new TextFileParser(File.ReadAllText(buff), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' });

                while (!buffParser.IsEOF())
                {
                    var buffToken = buffParser.ReadTokens();

                    if (buffToken != null && buffToken.Count != 0)
                    {
                        if (ushort.TryParse(buffToken[0], out ushort graphic))
                        {
                            tempList.Add(graphic);
                        }
                    }
                }

                _table = tempList.ToArray();
            }
            else
            {
                _table = _defaultTable;
            }
        }
예제 #19
0
        public static void Load()
        {
            string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string cave       = Path.Combine(path, "cave.txt");
            string vegetation = Path.Combine(path, "vegetation.txt");
            string trees      = Path.Combine(path, "tree.txt");


            if (!File.Exists(cave))
            {
                using (StreamWriter writer = new StreamWriter(cave))
                {
                    for (int i = 0x053B; i < 0x0553 + 1; i++)
                    {
                        if (i != 0x0550)
                        {
                            writer.WriteLine(i);
                        }
                    }
                }
            }

            if (!File.Exists(vegetation))
            {
                using (StreamWriter writer = new StreamWriter(vegetation))
                {
                    ushort[] vegetationTiles =
                    {
                        0x0D45, 0x0D46, 0x0D47, 0x0D48, 0x0D49, 0x0D4A, 0x0D4B, 0x0D4C, 0x0D4D, 0x0D4E, 0x0D4F,
                        0x0D50, 0x0D51, 0x0D52, 0x0D53, 0x0D54, 0x0D5C, 0x0D5D, 0x0D5E, 0x0D5F, 0x0D60, 0x0D61,
                        0x0D62, 0x0D63, 0x0D64, 0x0D65, 0x0D66, 0x0D67, 0x0D68, 0x0D69, 0x0D6D, 0x0D73, 0x0D74,
                        0x0D75, 0x0D76, 0x0D77, 0x0D78, 0x0D79, 0x0D7A, 0x0D7B, 0x0D7C, 0x0D7D, 0x0D7E, 0x0D7F,
                        0x0D80, 0x0D83, 0x0D87, 0x0D88, 0x0D89, 0x0D8A, 0x0D8B, 0x0D8C, 0x0D8D, 0x0D8E, 0x0D8F,
                        0x0D90, 0x0D91, 0x0D93, 0x12B6, 0x12B7, 0x12BC, 0x12BD, 0x12BE, 0x12BF, 0x12C0, 0x12C1,
                        0x12C2, 0x12C3, 0x12C4, 0x12C5, 0x12C6, 0x12C7, 0x0CB9, 0x0CBC, 0x0CBD, 0x0CBE, 0x0CBF,
                        0x0CC0, 0x0CC1, 0x0CC3, 0x0CC5, 0x0CC6, 0x0CC7, 0x0CF3, 0x0CF4, 0x0CF5, 0x0CF6, 0x0CF7,
                        0x0D04, 0x0D06, 0x0D07, 0x0D08, 0x0D09, 0x0D0A, 0x0D0B, 0x0D0C, 0x0D0D, 0x0D0E, 0x0D0F,
                        0x0D10, 0x0D11, 0x0D12, 0x0D13, 0x0D14, 0x0D15, 0x0D16, 0x0D17, 0x0D18, 0x0D19, 0x0D28,
                        0x0D29, 0x0D2A, 0x0D2B, 0x0D2D, 0x0D34, 0x0D36, 0x0DAE, 0x0DAF, 0x0DBA, 0x0DBB, 0x0DBC,
                        0x0DBD, 0x0DBE, 0x0DC1, 0x0DC2, 0x0DC3, 0x0C83, 0x0C84, 0x0C85, 0x0C86, 0x0C87, 0x0C88,
                        0x0C89, 0x0C8A, 0x0C8B, 0x0C8C, 0x0C8D, 0x0C8E, 0x0C93, 0x0C94, 0x0C98, 0x0C9F, 0x0CA0,
                        0x0CA1, 0x0CA2, 0x0CA3, 0x0CA4, 0x0CA7, 0x0CAC, 0x0CAD, 0x0CAE, 0x0CAF, 0x0CB0, 0x0CB1,
                        0x0CB2, 0x0CB3, 0x0CB4, 0x0CB5, 0x0CB6, 0x0C45, 0x0C46, 0x0C49, 0x0C47, 0x0C48, 0x0C4A,
                        0x0C4B, 0x0C4C, 0x0C4D, 0x0C4E, 0x0C37, 0x0C38, 0x0CBA, 0x0D2F, 0x0D32, 0x0D33, 0x0D3F,
                        0x0D40, 0x0CE9
                    };

                    for (int i = 0; i < vegetationTiles.Length; i++)
                    {
                        ushort g = vegetationTiles[i];

                        if (TileDataLoader.Instance.StaticData[g].IsImpassable)
                        {
                            continue;
                        }

                        writer.WriteLine(g);
                    }
                }
            }

            if (!File.Exists(trees))
            {
                using (StreamWriter writer = new StreamWriter(trees))
                    using (StreamWriter writerveg = new StreamWriter(vegetation, true))
                    {
                        ushort[] treeTiles =
                        {
                            0x0CCA, 0x0CCB, 0x0CCC, 0x0CCD, 0x0CD0, 0x0CD3, 0x0CD6, 0x0CD8, 0x0CDA, 0x0CDD, 0x0CE0,
                            0x0CE3, 0x0CE6, 0x0D41, 0x0D42, 0x0D43, 0x0D44, 0x0D57, 0x0D58, 0x0D59, 0x0D5A, 0x0D5B,
                            0x0D6E, 0x0D6F, 0x0D70, 0x0D71, 0x0D72, 0x0D84, 0x0D85, 0x0D86, 0x0D94, 0x0D98, 0x0D9C,
                            0x0DA0, 0x0DA4, 0x0DA8, 0x0C9E, 0x0CA8, 0x0CAA, 0x0CAB, 0x0CC9, 0x0CF8, 0x0CFB, 0x0CFE,
                            0x0D01, 0x12B6, 0x12B7, 0x12B8, 0x12B9, 0x12BA, 0x12BB, 0x12BC, 0x12BD
                        };

                        for (int i = 0; i < treeTiles.Length; i++)
                        {
                            ushort graphic = treeTiles[i];
                            byte   flag    = 1;

                            switch (graphic)
                            {
                            case 0x0C9E:
                            case 0x0CA8:
                            case 0x0CAA:
                            case 0x0CAB:
                            case 0x0CC9:
                            case 0x0CF8:
                            case 0x0CFB:
                            case 0x0CFE:
                            case 0x0D01:
                            case 0x12B6:
                            case 0x12B7:
                            case 0x12B8:
                            case 0x12B9:
                            case 0x12BA:
                            case 0x12BB:
                                flag = 0;

                                break;
                            }

                            if (!TileDataLoader.Instance.StaticData[graphic].IsImpassable)
                            {
                                writerveg.WriteLine(graphic);
                            }
                            else
                            {
                                writer.WriteLine($"{graphic}={flag}");
                            }
                        }
                    }
            }


            TextFileParser caveParser = new TextFileParser
                                            (File.ReadAllText(cave), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' });

            while (!caveParser.IsEOF())
            {
                List <string> ss = caveParser.ReadTokens();

                if (ss != null && ss.Count != 0)
                {
                    if (ushort.TryParse(ss[0], out ushort graphic))
                    {
                        _filteredTiles[graphic] |= STATIC_TILES_FILTER_FLAGS.STFF_CAVE;
                        CaveTiles.Add(graphic);
                    }
                }
            }


            TextFileParser stumpsParser = new TextFileParser
                                              (File.ReadAllText(trees), new[] { ' ', '\t', ',', '=' }, new[] { '#', ';' }, new[] { '"', '"' });

            while (!stumpsParser.IsEOF())
            {
                List <string> ss = stumpsParser.ReadTokens();

                if (ss != null && ss.Count >= 2)
                {
                    STATIC_TILES_FILTER_FLAGS flag = STATIC_TILES_FILTER_FLAGS.STFF_STUMP;

                    if (byte.TryParse(ss[1], out byte f) && f != 0)
                    {
                        flag |= STATIC_TILES_FILTER_FLAGS.STFF_STUMP_HATCHED;
                    }

                    if (ushort.TryParse(ss[0], out ushort graphic))
                    {
                        _filteredTiles[graphic] |= flag;
                        TreeTiles.Add(graphic);
                    }
                }
            }


            TextFileParser vegetationParser = new TextFileParser
                                                  (File.ReadAllText(vegetation), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' });

            while (!vegetationParser.IsEOF())
            {
                List <string> ss = vegetationParser.ReadTokens();

                if (ss != null && ss.Count != 0)
                {
                    if (ushort.TryParse(ss[0], out ushort graphic))
                    {
                        _filteredTiles[graphic] |= STATIC_TILES_FILTER_FLAGS.STFF_VEGETATION;
                    }
                }
            }
        }
예제 #20
0
        public static void BuildContainerFile(bool force)
        {
            string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path = Path.Combine(path, "containers.txt");

            if (!File.Exists(path) || force)
            {
                MakeDefault();

                using (StreamWriter writer = new StreamWriter(File.Create(path)))
                {
                    writer.WriteLine("# FORMAT");

                    writer.WriteLine("# GRAPHIC OPEN_SOUND_ID CLOSE_SOUND_ID LEFT TOP RIGHT BOTTOM ICONIZED_GRAPHIC [0 if not exists] MINIMIZER_AREA_X [0 if not exists] MINIMIZER_AREA_Y [0 if not exists]");

                    writer.WriteLine("# LEFT = X,  TOP = Y,  RIGHT = X + WIDTH,  BOTTOM = Y + HEIGHT");
                    writer.WriteLine();
                    writer.WriteLine();

                    foreach (KeyValuePair <ushort, ContainerData> e in _data)
                    {
                        writer.WriteLine($"{e.Value.Graphic} {e.Value.OpenSound} {e.Value.ClosedSound} {e.Value.Bounds.X} {e.Value.Bounds.Y} {e.Value.Bounds.Width} {e.Value.Bounds.Height} {e.Value.IconizedGraphic} {e.Value.MinimizerArea.X} {e.Value.MinimizerArea.Y}");
                    }
                }
            }

            _data.Clear();

            TextFileParser containersParser = new TextFileParser(File.ReadAllText(path), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' });

            while (!containersParser.IsEOF())
            {
                List <string> ss = containersParser.ReadTokens();

                if (ss != null && ss.Count != 0)
                {
                    if (ushort.TryParse(ss[0], out ushort graphic) && ushort.TryParse(ss[1], out ushort open_sound_id) && ushort.TryParse(ss[2], out ushort close_sound_id) && int.TryParse(ss[3], out int x) && int.TryParse(ss[4], out int y) && int.TryParse(ss[5], out int w) && int.TryParse(ss[6], out int h))
                    {
                        ushort iconized_graphic = 0;
                        int    minimizer_x = 0, minimizer_y = 0;

                        if (ss.Count >= 8 && ushort.TryParse(ss[7], out iconized_graphic))
                        {
                            if (ss.Count >= 9 && int.TryParse(ss[8], out minimizer_x))
                            {
                                if (ss.Count >= 10 && int.TryParse(ss[9], out minimizer_y))
                                {
                                    // nice!
                                }
                            }
                        }

                        _data[graphic] = new ContainerData
                                         (
                            graphic,
                            open_sound_id,
                            close_sound_id,
                            x,
                            y,
                            w,
                            h,
                            iconized_graphic,
                            minimizer_x,
                            minimizer_y
                                         );
                    }
                }
            }
        }
예제 #21
0
        public List <Triangle> ReadAsciiSTL(String filename)
        {
            List <Triangle> mesh = new List <Triangle>();
            bool            init = false;

            if (File.Exists(filename))
            {
                using (TextFileParser parser = new TextFileParser(filename))
                {
                    // Set the parser properties
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(" ");

                    List <double> points = new List <double>();
                    while (!parser.EndOfData)
                    {
                        // Processing row
                        List <string> fields = parser.ReadFiles().ToList();
                        if (fields.Contains("outer"))
                        {
                            init = true;
                            continue;
                        }
                        else if (fields.Contains("endloop"))
                        {
                            init = false;

                            //add the contents to the mesh
                            mesh.Add(new Triangle(new Tuple <double, double, double> (point[0], point[1], point[2]),
                                                  new Tuple <double, double, double> (point[3], point[4], point[5]),
                                                  new Tuple <double, double, double> (point[6], point[7], point[8])));

                            // Clear the points for next traingle
                            points.Clear();
                        }
                        else if (init)
                        {
                            if (fields.Contains("vertex"))
                            {
                                int index = fields.IndexOf("vertex");

                                List <string> coord = new List <string>();
                                foreach (var subIndex in Enumerable.Range(index + 1, fields.Count() - index - 1))
                                {
                                    if (fields[subIndex] != "")
                                    {
                                        coord.Add(fields[subIndex]);
                                    }
                                }

                                double x1 = Convert.ToDouble(coord[0]);
                                double y1 = Convert.ToDouble(coord[1]);
                                double z1 = Convert.ToDouble(coord[2]);

                                points.Add(x1);
                                points.Add(y1);
                                points.Add(z1);
                            }
                        }
                    }
                }
                return(mesh);
            }
            else
            {
                Console.Writeline("Filepath does not exists");
                return(mesh);
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            this.Vectors = new List <VectorModel>();

            BrushesArray = new Brush[80];
            for (int i = 0; i < 80; i++)
            {
                BrushesArray[i] = PickBrush();
            }

            //var path = AppDomain.CurrentDomain.BaseDirectory + @"testfiles\test3.txt";
            var path = (AppDomain.CurrentDomain.BaseDirectory + @"Examples\and.gsa").Replace(@"UI\bin\Debug\netcoreapp3.1\", "");
            var list = TextFileParser.ParseText(path);//.Replace(@"UI\bin\Debug\netcoreapp3.1\", ""));
            var grid = new BlockDistributor(list);

            grid.RemoveEmptyLines();
            grid.PrintGrid();
            grid.SetNodesPositions();

            var       graph = new GraphMaker(grid.GetNodes(), grid.GetGrid());
            Stopwatch sw    = new Stopwatch();

            sw.Start();
            graph.LineCreator();
            sw.Stop();
            Console.WriteLine("ElapsedTotal={0}", sw.Elapsed);

            graph.RemoveMiddlePointsFromLines();

            this.Lines = graph.GetLines();
            this.Nodes = graph.GetNodes();

            int id = 1;

            foreach (var line in Lines)
            {
                var points = line.GetPointsOfLine();
                for (int i = 0; i < points.Count - 1; i++)
                {
                    Vectors.Add(new VectorModel(new Coordinates(points[i].x * _multiplier, points[i].y * _multiplier), new Coordinates(points[i + 1].x * _multiplier, points[i + 1].y * _multiplier), id));
                }
                id++;
            }

            this.Vectors = this.Vectors.Where(x => x.Id <= 100).ToList();
            this.Recheck = new Queue <VectorModel>();
            foreach (var vector in Vectors)
            {
                AddLine(vector);
            }

            while (this.Recheck.Count != 0)
            {
                var recheck = this.Recheck.Dequeue();
                if (recheck.GetChangeNumber() < 5)
                {
                    recheck.AddChange();
                    AddLine(recheck);
                }
            }

            foreach (var vector in Vectors)
            {
                DrawVector(vector);
            }

            foreach (var node in Nodes)
            {
                AddBlock(node.GetPosition().y, node.GetPosition().x, node.GetId(), node.GetType());
            }
        }
예제 #23
0
        private bool ParseFilePart(TextFileParser file)
        {
            List <string> childrens           = new List <string>();
            PROF_TYPE     type                = PROF_TYPE.NO_PROF;
            string        name                = string.Empty;
            string        trueName            = string.Empty;
            int           nameClilocID        = 0;
            int           descriptionClilocID = 0;
            int           descriptionIndex    = 0;
            ushort        gump                = 0;
            bool          topLevel            = false;

            int[,] skillIndex = new int[4, 2] {
                { 0xFF, 0 }, { 0xFF, 0 }, { 0xFF, 0 }, { 0xFF, 0 }
            };
            int[] stats = new int[3] {
                0, 0, 0
            };

            bool exit = false;

            while (!file.IsEOF() && !exit)
            {
                List <string> strings = file.ReadTokens();

                if (strings.Count < 1)
                {
                    continue;
                }

                int code = GetKeyCode(strings[0]);

                switch ((PM_CODE)code)
                {
                case PM_CODE.BEGIN:
                case PM_CODE.END:

                {
                    exit = true;

                    break;
                }

                case PM_CODE.NAME:

                {
                    name = strings[1];

                    break;
                }

                case PM_CODE.TRUENAME:

                {
                    trueName = strings[1];

                    break;
                }

                case PM_CODE.DESC:

                {
                    int.TryParse(strings[1], out descriptionIndex);

                    break;
                }

                case PM_CODE.TOPLEVEL:

                {
                    topLevel = GetKeyCode(strings[1]) == (int)PM_CODE.TRUE;

                    break;
                }

                case PM_CODE.GUMP:

                {
                    ushort.TryParse(strings[1], out gump);

                    break;
                }

                case PM_CODE.TYPE:

                {
                    if (GetKeyCode(strings[1]) == (int)PM_CODE.CATEGORY)
                    {
                        type = PROF_TYPE.CATEGORY;
                    }
                    else
                    {
                        type = PROF_TYPE.PROFESSION;
                    }

                    break;
                }

                case PM_CODE.CHILDREN:

                {
                    for (int j = 1; j < strings.Count; j++)
                    {
                        childrens.Add(strings[j]);
                    }

                    break;
                }

                case PM_CODE.SKILL:

                {
                    if (strings.Count > 2)
                    {
                        int idx = 0;

                        for (int i = 0, len = skillIndex.GetLength(0); i < len; i++)
                        {
                            if (skillIndex[i, 0] == 0xFF)
                            {
                                idx = i;

                                break;
                            }
                        }

                        for (int j = 0; j < SkillsLoader.Instance.SkillsCount; j++)
                        {
                            SkillEntry skill = SkillsLoader.Instance.Skills[j];

                            if (strings[1] == skill.Name || ((SkillEntry.HardCodedName)skill.Index).ToString().ToLower() == strings[1].ToLower())
                            {
                                skillIndex[idx, 0] = j;
                                int.TryParse(strings[2], out skillIndex[idx, 1]);

                                break;
                            }
                        }
                    }

                    break;
                }

                case PM_CODE.STAT:

                {
                    if (strings.Count > 2)
                    {
                        code = GetKeyCode(strings[1]);
                        int.TryParse(strings[2], out int val);

                        if ((PM_CODE)code == PM_CODE.STR)
                        {
                            stats[0] = val;
                        }
                        else if ((PM_CODE)code == PM_CODE.INT)
                        {
                            stats[1] = val;
                        }
                        else if ((PM_CODE)code == PM_CODE.DEX)
                        {
                            stats[2] = val;
                        }
                    }

                    break;
                }

                case PM_CODE.NAME_CLILOC_ID:

                {
                    int.TryParse(strings[1], out nameClilocID);
                    name = ClilocLoader.Instance.GetString(nameClilocID, true, name);

                    break;
                }

                case PM_CODE.DESCRIPTION_CLILOC_ID:

                {
                    int.TryParse(strings[1], out descriptionClilocID);

                    break;
                }
                }
            }

            ProfessionInfo        info = null;
            List <ProfessionInfo> list = null;

            if (type == PROF_TYPE.CATEGORY)
            {
                info = new ProfessionInfo
                {
                    Childrens = childrens
                };
                list = new List <ProfessionInfo>();
            }
            else if (type == PROF_TYPE.PROFESSION)
            {
                info = new ProfessionInfo
                {
                    StatsVal    = stats,
                    SkillDefVal = skillIndex
                };
            }

            bool result = type != PROF_TYPE.NO_PROF;

            if (info != null)
            {
                info.Localization     = nameClilocID;
                info.Description      = descriptionClilocID;
                info.Name             = name;
                info.TrueName         = trueName;
                info.DescriptionIndex = descriptionIndex;
                info.TopLevel         = topLevel;
                info.Graphic          = gump;
                info.Type             = type;

                if (topLevel)
                {
                    Professions[info] = list;
                }
                else
                {
                    foreach (KeyValuePair <ProfessionInfo, List <ProfessionInfo> > kvp in Professions)
                    {
                        if (kvp.Key.Childrens != null && kvp.Value != null && kvp.Key.Childrens.Contains(trueName))
                        {
                            Professions[kvp.Key].Add(info);
                            result = true;

                            break;
                        }
                    }
                }
            }

            return(result);
        }
예제 #24
0
파일: Form1.cs 프로젝트: kLeZ/Gecko
 private void bgwTextFileParser_DoWork(object sender, DoWorkEventArgs e)
 {
     string path = e.Argument.ToString();
     int retCode = 0;
     List<DataInformation> lstdi = new List<DataInformation>();
     lstdi.Add(new DataInformation() { Key = "ID", Position = 0 });
     lstdi.Add(new DataInformation() { Key = "Via", Position = 1 });
     lstdi.Add(new DataInformation() { Key = "Civico", Position = 2 });
     lstdi.Add(new DataInformation() { Key = "Esponente", Position = 3 });
     lstdi.Add(new DataInformation() { Key = "CAP", Position = 4 });
     lstdi.Add(new DataInformation() { Key = "Comune", Position = 5 });
     lstdi.Add(new DataInformation() { Key = "Frazione", Position = 6 });
     lstdi.Add(new DataInformation() { Key = "Provincia", Position = 7 });
     TextFileParser tfp = new TextFileParser(ContentType.Path, path, lstdi);
     List<DataContainer> lstdc = tfp.ExtractData<DataContainer>(out retCode);
     Result ret = new Result()
     {
         lstdc = lstdc,
         Logs = tfp.Logs,
         retCode = retCode
     };
     e.Result = ret;
 }
예제 #25
0
 static void Main(string[] args)
 {
     TextFileParser parser = new TextFileParser();
     var            value  = parser.DictionaryPhilosophy;
 }
예제 #26
0
        //GET AUTO LOOT LIST FROM FILE OR CREATE IT
        public static void LoadFile()
        {
            string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string ALlist    = Path.Combine(path, "ALlist.txt");
            string ALlistlow = Path.Combine(path, "ALlistlow.txt");

            if (!File.Exists(ALlist))
            {
                using (StreamWriter writer = new StreamWriter(ALlist))
                {
                    ushort[] items =
                    {
                        //NOTE - some stuff is commented out, because its above the 0x5780 (22400) LootAboveID
                        //NOTE - some stuff is commented out, because mobs may have them equipped
                        //STRANGELANDS
                        //Drink
                        //0xAD1D, 0xB069,
                        //Food
                        0x1E88, 0x1E89,
                        0x1E90, 0x1E91,
                        //Jars
                        //0xAD20, 0xAD21, 0xAD22, 0xAD23, 0xAD24,
                        //Books
                        0x0FBD, 0x0FBE,
                        0x1C13,
                        0x42BF,
                        //NON STRANGELANDS ----------------------------------------------------------
                        //cores
                        0xf91,
                        //extracts
                        0xefc,
                        //phylactery
                        0x240,
                        //skillscrolls
                        0x227a,
                        //skillballs
                        0x5740,
                        //mcd
                        0x42BF,
                        //-------
                        //backpack dye
                        0xeff,
                        //shield & hair dye
                        0xf03,
                        //furniture dye
                        //0x7161,
                        //headwear dye
                        0xf02,
                        //runebook dye
                        0xefe,
                        //-------
                        //tmap
                        0x14EB, 0x14EC,
                        //deed
                        0x14EF, 0x14F0,
                        //-------
                        //hanging lantern OFF BECAUSE SOME MOBS MAY HAVE EM EQUIPPED
                        //0x0A15, 0x0A16, 0x0A17, 0x0A18,
                        //0x0A1A, 0x0A1B, 0x0A1C, 0x0A1D,
                        //lantern OFF BECAUSE SOME MOBS MAY HAVE EM EQUIPPED
                        //0x0A22, 0x0A23,0x0A24, 0x0A25,
                        //-------
                        //cloth (folded, cut cloth)
                        0x175D, 0x175E, 0x175F, 0x1760, 0x1761, 0x1762, 0x1763, 0x1764, 0x1765, 0x1766, 0x1767, 0x1768,
                        //-------
                        //footwear OFF BECAUSE SOME MOBS MAY HAVE EM EQUIPPED
                        //0x170B, 0x170C, 0x170D, 0x170E, 0x170F, 0x1710, 0x1711, 0x1712,
                        //-------
                        //statue (small)
                        0x42BB,
                        //statue (big)
                        //0xA615,
                        //-------
                        //skull (bossloot)
                        //0xA9B5,
                        ////-------
                        //chain links
                        //0xA8C6,
                    };

                    for (int i = 0; i < items.Length; i++)
                    {
                        ushort graphic = items[i];
                        ushort amount  = 9999;

                        writer.WriteLine($"{graphic}={amount}");
                    }
                }
            }

            if (!File.Exists(ALlistlow))
            {
                using (StreamWriter writer = new StreamWriter(ALlistlow))
                {
                    ushort[] items =
                    {
                        //ADD LOW PRIO STUFF HERE
                        0xeed,                                                  //gold
                        0x4202,0x0E73,  //modded gold
                        0xF7A, 0xF7B, 0xF8C, 0xF8D, 0xF84, 0xF85, 0xF86, 0xF88, //mage reags
                        0xf3f                                                   //arrow
                    };

                    for (int i = 0; i < items.Length; i++)
                    {
                        ushort graphic = items[i];
                        ushort amount  = 9999;

                        writer.WriteLine($"{graphic}={amount}");
                    }
                }
            }

            TextFileParser ALlistParser    = new TextFileParser(File.ReadAllText(ALlist), new[] { ' ', '\t', ',', '=' }, new[] { '#', ';' }, new[] { '"', '"' });
            TextFileParser ALlistParserLow = new TextFileParser(File.ReadAllText(ALlistlow), new[] { ' ', '\t', ',', '=' }, new[] { '#', ';' }, new[] { '"', '"' });

            while (!ALlistParser.IsEOF())
            {
                var ss = ALlistParser.ReadTokens();
                if (ss != null && ss.Count != 0)
                {
                    if (ushort.TryParse(ss[0], out ushort graphic))
                    {
                        ALList.Add(graphic);
                    }

                    if (ushort.TryParse(ss[1], out ushort amount))
                    {
                        ALList.Add(amount);
                    }
                }
            }

            while (!ALlistParserLow.IsEOF())
            {
                var ss = ALlistParserLow.ReadTokens();
                if (ss != null && ss.Count != 0)
                {
                    if (ushort.TryParse(ss[0], out ushort graphic))
                    {
                        ALListLow.Add(graphic);
                    }

                    if (ushort.TryParse(ss[1], out ushort amount))
                    {
                        ALListLow.Add(amount);
                    }
                }
            }
        }
예제 #27
0
        private static void Main(string[] args)
        {
            if (args?.Any() == false)
            {
                return;
            }

            var lineage = new Lineage();
            var family  = lineage.Family;

            var fileParser = new TextFileParser();

            fileParser.ParseFile(args?[0]);

            if (fileParser.Inputs.Count == 0)
            {
                return;
            }

            foreach (var input in fileParser.Inputs)
            {
                try
                {
                    switch (input.Item1)
                    {
                    case Command.ADD_CHILD:
                        AddChildOperation(input);
                        break;

                    case Command.GET_RELATIONSHIP:
                        GetRelationshipOperation(input);
                        break;

                    default:
                        throw new Exception("Invalid Action");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message + Environment.NewLine);
                    //Console.WriteLine(e.StackTrace);
                }
            }

            void AddChildOperation(Tuple <Command, string, string, string> input)
            {
                Enum.TryParse(input.Item4, true, out Gender gender);
                lineage.AddChild(input.Item2, input.Item3, gender);
                Console.WriteLine("CHILD_ADDITION_SUCCEEDED");
            }

            void GetRelationshipOperation(Tuple <Command, string, string, string> input)
            {
                var members = family.FindRelatedMembers(input.Item2, input.Item3);

                if (members == null || !members.Any())
                {
                    Console.WriteLine("None");
                }
                else
                {
                    foreach (var person in members)
                    {
                        Console.Write($"{person.Name} ");
                    }
                    Console.WriteLine();
                }
            }
        }
예제 #28
0
        private static void Main()
        {
            var albumInputUri = InputDirectory + "albumcatalogue.xml";

            var extractor = new XmlCatalogueParser();

            //Task 2
            var artists = extractor.ExtractArtistsAndAlbumCountDom(albumInputUri);

            foreach (var artist in artists)
            {
                Write($"Artist: {artist.Key}, Album Count: {artist.Value}");
            }
            Write(Divider);

            //Task 3
            var xpathArtists = extractor.ExtractArtistsAndAlbumCountXPath(albumInputUri);

            foreach (var artist in xpathArtists)
            {
                Write($"Artist: {artist.Key}, Album Count: {artist.Value}");
            }
            Write(Divider);

            //Task 4
            var filteredDocument = extractor.GetAlbumsWhere(albumInputUri, "price>20");

            filteredDocument.Save(OutputDirectory + "albumcatalogue-filtered.xml");
            Write("Filtered albumcatalogue.xml where price>20 and saved to " + OutputDirectory + "albumcatalogue-filtered.xml");
            Write(Divider);

            //Task 5
            var allSongTitles    = extractor.GetAllSongTitlesByXmlReader(albumInputUri);
            var songTitlesString = string.Join(" | ", allSongTitles);

            Write(songTitlesString);
            Write(Divider);

            //Task 6
            var allSongTitlesByLinq    = extractor.GetAllSongTitlesByXDocumentAndLinq(albumInputUri);
            var songTitlesStringByLinq = string.Join(" | ", allSongTitlesByLinq);

            Write(songTitlesStringByLinq);
            Write(Divider);

            //Task 7
            var personExtractor = new TextFileParser();
            var peopleDoc       = personExtractor.GetPeopleFromFileInXml(InputDirectory + "people.txt");

            peopleDoc.Save(OutputDirectory + "people.xml");
            Write("Extracted people and saved to " + OutputDirectory + "people.xml");
            Write(Divider);

            //Task 8
            extractor.ExtractAlbumAndArtistNames(albumInputUri, OutputDirectory + "albums.xml");
            Write("Extracted albums and artists and saved to " + OutputDirectory + "albums.xml");
            Write(Divider);

            //Task 9-10
            var generator         = new DirectoryXmlStructureGenerator();
            var directoryDocument = generator.GenerateXmlStructure("..\\..\\..\\");

            directoryDocument.Save(OutputDirectory + "project-directory-info.xml");
            Write("Generated folder and file structure for current project and saved to " + OutputDirectory + "project-directory-info.xml");
            Write(Divider);

            //Task 11
            var endYear = DateTime.Now.Year - 5;
            var albums  = extractor.GetAlbumsWhere(albumInputUri, $"year>{endYear}");

            albums.Save(OutputDirectory + "albums-older-than-5.xml");
            Write($"Filtered albumcatalogue.xml where year>{endYear} and saved to " + OutputDirectory + "albums-older-than-5.xml");
            Write(Divider);

            //Task 12
            var oldAlbums = extractor.GetAlbumsOlderThanFiveYears(albumInputUri);

            oldAlbums.Save(OutputDirectory + "albums-older-than-5-linq.xml");
            Write($"Filtered albumcatalogue.xml where year>{endYear} with linq and saved to " + OutputDirectory + "albums-older-than-5-linq.xml");
            Write(Divider);

            //Task 13
            XslCompiledTransform xslt = new XslCompiledTransform();

            xslt.Load(InputDirectory + "albumcatalogue.xsl");
            xslt.Transform(albumInputUri, OutputDirectory + "albumcatalogue.html");
            Write("Transformed albumcatalogue.xml and saved to " + OutputDirectory + "albumcatalogue.html");
            Write(Divider);
        }