public void stripClasses() //iterates through originalCodeLineList, for every Top Level class creates a new A3Class, //then calls an A3Class.Method to recursively strip top level classes within it //until all classes have been found { //current class object A3Level1Class a3c = new A3Level1Class(); //class gets populated and then added to a3ClassList, then this class gets cleared for //new class int depth = 0; //this is the depth of the current line cursor, only class dec's with a depth of 0 are recorded as //a new class Boolean capped = false; for (int i = 0; i < originalCodeLineList.Count; i++)//iterates through originalCodeList { capped = false; String cursor = originalCodeLineList[i];//value of current index of List //BUGFIX //If variable dec includes a bunch of code, handle and skip line if (cursor.Contains("=") && cursor.Contains(";")) { if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; continue; } //Check if empty class declaration at base level if ((depth == 0) && (cursor.Contains("class")) && (cursor.Contains(";"))) //this is a class that has no contents; { if (cursor.Contains("class")) //found a new class dec { String temp = GenLib.stripFormating(cursor); int loc = temp.IndexOf("class"); //find where in the line the class keyword starts loc += 6; //find the location where the actuall classname starts int end = GenLib.endOfWord(temp, loc); //the point the classname ends int length = end - loc; //the length of the classname a3c = new A3Level1Class(temp.Substring(loc, length)); //grab the className; if (cursor.Contains(":")) //does this class extend a base class { loc = temp.IndexOf(":"); loc = GenLib.startOfNextWord(temp, loc);//find start of baseClass Name end = GenLib.endOfWord(temp, loc); length = end - loc; if (a3c.ExtendedTree != null && a3c.ExtendedTree.Count > 0) { a3c.ExtendedTree.Add(temp.Substring(loc, length));//add originalcode line } else { a3c.ExtendedTree = new List <String> { temp.Substring(loc, length) } }; } capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } if (a3ClassList != null && a3c.OriginalCode.Count > 0) { a3ClassList.Add(a3c);//store class } else { a3ClassList = new List <A3Level1Class> { a3c } }; a3c = new A3Level1Class();//clear class continue; } //Check, has depth increased //Check, is this an open/close statement, then depth as not increased or decreased if (cursor.Contains("{}")) { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } //Check, has depth actually increased else if (cursor.Contains("{")) { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; //Need to handle if multiple opens and closes on a single line(god forbid) if (((Regex.Split(cursor, "{")).Length - 1) > 1) { depth += (Regex.Split(cursor, "{").Length); } else { depth++; } } //check if depth has decreased (can happen on same line) //Check, is this an open/close than depth has not increased or descreased if (cursor.Contains("{}")) { ; } else if (cursor.Contains("}") && (depth > 1)) { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; //Need to handle if multiple opens and closes on a single line(god forbid) if (((Regex.Split(cursor, "}")).Length - 1) > 1) { depth -= (Regex.Split(cursor, "}").Length - 1); } else { depth--; } } //Check, has depth actually descreased else if (cursor.Contains("}"))//if the depth is 1 and closing, that is the end of this class { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; depth--;//decrease depth if (a3c.A3ClassName != null && a3c.A3ClassName != "") { if (a3ClassList != null && a3c.OriginalCode.Count > 0) { a3ClassList.Add(a3c);//store class } else { a3ClassList = new List <A3Level1Class> { a3c } }; a3c = new A3Level1Class();//clear class } continue; } //Check, check for new nonempty class dec at base level if (depth == 0) { if (cursor.Contains("class"))//found a new class dec { String temp = GenLib.stripFormating(cursor); int loc = temp.IndexOf("class"); //find where in the line the class keyword starts loc += 6; //find the location where the actuall classname starts int end = GenLib.endOfWord(temp, loc); //the point the classname ends int length = end - loc; //the length of the classname a3c = new A3Level1Class(temp.Substring(loc, length)); //grab the className; if (cursor.Contains(":")) //does this class extend a base class { loc = temp.IndexOf(":"); loc = GenLib.startOfNextWord(temp, loc);//find start of baseClass Name end = GenLib.endOfWord(temp, loc); length = end - loc; if (a3c.ExtendedTree != null && a3c.ExtendedTree.Count > 0) { a3c.ExtendedTree.Add(temp.Substring(loc, length));//add originalcode line } else { a3c.ExtendedTree = new List <String> { temp.Substring(loc, length) } }; } capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } }/**/ //We need to capture lines of code that are not increased or //decreased to the code and within the content of the current class being captured else if (!capped) { if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } } if (A3ClassList.Count > 0) { foreach (A3Level1Class x in A3ClassList) { x.recursiveParseClasses();//sort all the children classes in each class, recursively } } fillEntireList(); }
public new void recursiveParseClasses() //parses all the children classes in originalcode and tells each child to do the same { //strips only the top level and records contents filterContent(); //current class object if (OriginalCode.Count <= 1) { return; } A3TertiaryClass a3c = new A3TertiaryClass(); //class gets populated and then added to a3ClassList, then this class gets cleared for new class int depth = 0; //this is the depth of the current line cursor, only class dec's with a depth of 0 are recorded as a new class Boolean capped = false; //has cursor been captured if (Content != null) { for (int i = 0; i < Content.Count; i++) //iterates through originalCodeList { String cursor = Content[i]; //value of current index of List capped = false; //BUGFIX //If variable dec includes a bunch of code, handle and skip line if (cursor.Contains("=") && cursor.Contains(";")) { if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; continue; } //Is this an Empty Class if ((depth == 0) && (cursor.Contains("class")) && (cursor.Contains(";"))) //this is a class that has no contents; { if (cursor.Contains("class")) //found a new class dec { String temp = GenLib.stripFormating(cursor); int loc = temp.IndexOf("class"); //find where in the line the class keyword starts loc += 6; //find the location where the actual classname starts int end = GenLib.endOfWord(temp, loc); //the point the classname ends int length = end - loc; //the length of the classname a3c = new A3TertiaryClass(temp.Substring(loc, length)); //grab the className; if (cursor.Contains(":")) //does this class extend a base class { loc = temp.IndexOf(":"); loc = GenLib.startOfNextWord(temp, loc);//find start of baseClass Name end = GenLib.endOfWord(temp, loc); length = end - loc; if (a3c.ExtendedTree != null && a3c.ExtendedTree.Count > 0) { a3c.ExtendedTree.Add(temp.Substring(loc, length));//add originalcode line } else { a3c.ExtendedTree = new List <String> { temp.Substring(loc, length) } }; } capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } if (a3c.A3ClassName != null && a3c.A3ClassName != "") { if (subClasses != null && Content.Count > 0) { subClasses.Add(a3c);//store class } else { subClasses = new List <A3TertiaryClass> { a3c } }; } a3c = new A3TertiaryClass();//clear class continue; } //Has depth increased if (cursor.Contains("{}")) { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } else if (cursor.Contains("{")) { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; //Need to handle if multiple opens and closes on a single line(god forbid) if (((Regex.Split(cursor, "{")).Length - 1) > 1) { depth += (Regex.Split(cursor, "{").Length - 1); } else { depth++; } } //check if depth has decreased (can happen on same line) if (cursor.Contains("{}")) { ; } else if (cursor.Contains("}") && (depth > 1)) { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; //Need to handle if multiple opens and closes on a single line(god forbid) if (((Regex.Split(cursor, "}")).Length - 1) > 1) { depth -= (Regex.Split(cursor, "}").Length - 1); } else { depth--; } } else if (cursor.Contains("}"))//if the depth is 1 and closing, that is the end of this class { capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; depth--;//decrease depth if (a3c.A3ClassName != null && a3c.A3ClassName != "") { if (subClasses != null && Content.Count > 0) { subClasses.Add(a3c);//store class } else { subClasses = new List <A3TertiaryClass> { a3c } }; a3c = new A3TertiaryClass();//clear class } continue; } //if depth is 0, check for new class dec if (depth == 0) { if (cursor.Contains("class"))//found a new class dec { String temp = GenLib.stripFormating(cursor); int loc = temp.IndexOf("class"); //find where in the line the class keyword starts loc += 6; //find the location where the actuall classname starts int end = GenLib.endOfWord(temp, loc); //the point the classname ends int length = end - loc; //the length of the classname a3c = new A3TertiaryClass(temp.Substring(loc, length)); //grab the className; if (cursor.Contains(":")) //does this class extend a base class { loc = temp.IndexOf(":"); loc = GenLib.startOfNextWord(temp, loc);//find start of baseClass Name end = GenLib.endOfWord(temp, loc); length = end - loc; if (a3c.ExtendedTree != null && a3c.ExtendedTree.Count > 0) { a3c.ExtendedTree.Add(temp.Substring(loc, length));//add originalcode line } else { a3c.ExtendedTree = new List <String> { temp.Substring(loc, length) } }; } capped = true; if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } } else if (!capped) { if (a3c.OriginalCode != null && a3c.OriginalCode.Count > 0) { a3c.OriginalCode.Add(cursor);//add originalcode line } else { a3c.OriginalCode = new List <String> { cursor } }; } } } if (subClasses != null) { foreach (A3TertiaryClass x in subClasses) { x.recursiveParseClasses();//sort all the children classes in each class, recursively } } }
private async void btnProcess_Click(object sender, RoutedEventArgs e) { String pboPath = txtPboPath.Text; String binPath = txtBinPath.Text; String cppPath = txtCppPath.Text; String serialPath = txtSerialized.Text; String outputPath = txtOutputPath.Text; List <String> addColumn = new List <String>(); List <String> addToAllRows = new List <String>(); List <String> temp = tbExtraColumns.Text.Split(';').ToList(); if (tbExtraColumns.Text != String.Empty) { foreach (String x in temp) { addColumn.Add(x.Split(':')[0]); addToAllRows.Add(x.Split(':')[1]); } } if (addColumn.Count != addToAllRows.Count) { addColumn = null; addToAllRows = null; } //Extract List <String> binList = new List <String>(); if (cbExtractIsNeeded.IsChecked.Value) { Log("Extracting Files At: " + pboPath); binList = GenLib.extract(pboPath, binPath, txtBankRevPath.Text); Log("Extracted Files To: " + binPath); } //Convert List <String> cppList = new List <String>(); if (cbConvertIsNeeded.IsChecked.Value) { Log("Converting Files At: " + binPath); if (!cbExtractIsNeeded.IsChecked.Value) { binList = GenLib.binList(binPath); } cppList = GenLib.convert(binList, cppPath, txtCfgConvertPath.Text); Log("Converted Files To: " + cppPath); } //Serialize if (cbSerialize.IsChecked.Value) { if (cbConvertIsNeeded.IsChecked.Value) { ; } else { cppList = GenLib.cppList(cppPath); } //Data Grab > Objects ///MultiThread /// //Clear null files for (int i = 0; i < cppList.Count; i++) { if (cppList[i] == null) { cppList.Remove(cppList[i]); i--; } } A3CppFile[] fileArray = new A3CppFile[cppList.Count];//we need the static length of the array to parallelize, the index's must exist beforehand for async assignment Parallel.For(0, (cppList.Count - 1), new ParallelOptions { MaxDegreeOfParallelism = 1 }, a => { A3CppFile tempArray = GenLib.parseFile(cppList[a]); fileArray[a] = tempArray; }); ///SingleThread /// /* * A3CppFile[] fileArray = new A3CppFile[cppList.Count];//we need the static length of the array to parallelize, the index's must exist beforehand for async assignment * for(int i = 0; i < cppList.Count; i++) * { * fileArray[i] = GenLib.parseFile(cppList[i]); * } */ //Serialize Log("Serializing..."); GenLib.serialize(fileArray.ToList(), serialPath); Log("Serialized"); } ///Parse /// if (cbProcess.IsChecked.Value) { Log("Deserializing..."); //Deserialize objects to parse List <A3CppFile> flist = GenLib.deserialize(serialPath); Log("Deserialized"); Log("Parsing..."); //create list of all classes List <A3Class> list = new List <A3Class>(); if (flist != null) { for (int i = 0; i < flist.Count; i++) { if (flist[i] != null) { if (flist[i].A3EntireClassList != null) { foreach (A3Class c in flist[i].A3EntireClassList) { if (list != null) { list.Add(c); } else { list = new List <A3Class> { c } }; } } } } } list = A3Presentation.includeOnlySelected(list, cbShowCfgVehicles.IsChecked.Value, cbShowCfgAmmo.IsChecked.Value, cbShowCfgWeapons.IsChecked.Value, cbShowCfgMagazines.IsChecked.Value, cbShowLvl1.IsChecked.Value, cbShowLvl2.IsChecked.Value, cbShowTertiary.IsChecked.Value, cbShowOtherCfg.IsChecked.Value); //Apply Filters List <String> outputList = new List <String>(); if (txtNotContainPartClass.Text != "") { list = A3Presentation.filterOutClassByPartialName(list, txtNotContainPartClass.Text.Split(';')); } if (txtContainPartClass.Text != "") { list = A3Presentation.filterInClassByPartialName(list, txtContainPartClass.Text.Split(';')); } if (txtHasDirectParent.Text != "") { list = A3Presentation.filterInClassByDirectParent(list, txtHasDirectParent.Text.Split(';')); } if (txtHasParent.Text != "") { list = A3Presentation.filterInClassByAnyParent(list, txtHasParent.Text.Split(';')); } if (txtContainsFields.Text != "") { list = A3Presentation.filterOutClassByVariableName(list, txtContainsFields.Text.Split(';')); } if (txtDisplayFields.Text != "") { outputList = A3Presentation.outputSelectedFields(list, txtDisplayFields.Text.Split(';'), cbShowClassName.IsChecked.Value, cbShowParentClass.IsChecked.Value, cbShowBaseClass.IsChecked.Value, cbOutputSource.IsChecked.Value, addColumn, addToAllRows, cbConfigType.IsChecked.Value); } if (cbDisplayAllFields.IsChecked.Value) { outputList = A3Presentation.outputAllFields(list, cbShowClassName.IsChecked.Value, cbShowParentClass.IsChecked.Value, cbShowBaseClass.IsChecked.Value, cbOutputSource.IsChecked.Value, addColumn, addToAllRows, cbConfigType.IsChecked.Value); } Log("Parsed"); //Build Output Log("Creating File..."); StringBuilder output = new StringBuilder(5000); using (StreamWriter sw = File.CreateText(txtOutputPath.Text)) { foreach (String s in outputList) { if (output.Capacity >= (output.MaxCapacity / 8)) { sw.Write(output); output = new StringBuilder(5000); } else { output.Append(s); } } sw.Write(output); } //Create Output File Log("File Created At: " + txtOutputPath.Text); } //Add code to update tvClassList treeview with classes //if serialized path exists and is valid, load it } }