End of gcode finder

So we are in the process of switching from mach3 to uccnc and one function I made was a macro that found the end of a gcode file's line number so that it can be used to calculate the percentage of the file ran, but I'm struggling to find any way to convert this to C# with uccnc's context. I've already figured out how to write the percentage itself but this little bit of code stumps me.
Mach3 code (Visual Basic):
Anyone with any ideas on how to do this in uccnc?
Mach3 code (Visual Basic):
- Code: Select all
DoOemButton(216)
Dim I
Dim textLine
Open FileName For Input As #1
//loads file and increments through each line until the end of file is found
While Not EOF(1)
Line Input #1, textLine
I = I + 1
SetuserDro(1202, I)
Wend
Close #1
//writes the end line number to a user dro to be used and displayed elsewhere
Call SetUserDRO(1200,I)
Anyone with any ideas on how to do this in uccnc?