B4J Question [B4X] [SOLVED] The right way to read (and edit) a .b4j or .b4a file...?

Magma

Expert
Licensed User
Longtime User
Well I am updating my lazy code Generator (EasyCode)... and try to figure the right way to read/write a project file (.b4j), and bas files too...

So tried to use the following code to read the lines into a list (but i think is wrong)

B4X:
    Dim allcode As List=File.ReadList(expdir & "/B4J","B4JProject.b4j")
    Dim allcode2 As List
    allcode2.Initialize
    For k=0 To 6
        allcode2.Add(allcode.Get(k))
    Next
    Dim n As Int = 5
    For k=0 To lviews.Size-1   'For example i want to auto add/sync the new files will be added to a B4J Project
        If File.Exists(seldir,lfile(k)) Then
            n=n+1
            Dim s As String=n
            allcode2.Add("File" & s.Trim & "=" & lfile(k))
        End If
        If File.Exists(seldir,lfile(k).Replace(".view",".json")) Then
            n=n+1
            Dim s As String=n
            allcode2.Add(("File" & s.Trim & "=" & lfile(k).Replace(".view",".json") ))
        End If
        If File.Exists(seldir,lfile(k).Replace(".view",".json")) Then
            n=n+1
            Dim s As String=n
            allcode2.Add(("File" & s.Trim & "=" & lfile(k).Replace(".view",".html") ))
        End If
    Next
...
...
    File.WriteList(expdir & "/B4J","B4JProject.b4j",allcode2)

... Seems good .. but if check the output... more find that the new output has only LF.. and no CRLF at the end of lines... so B4J IDE can't open the new project...

May be need to read line by line as string... input stream? anyone tried to read/write/edit b4j files?
 

Mashiane

Expert
Licensed User
Longtime User
Interesting, I had to do something similar when I was working with the BVAD3 package manager as some files had to be removed after the package manager compares and tree shakes the project.

There is a "variable" on the file that keeps a record of the number of modules and other things. After your "auto-sync", does that have any effect or one can just leave that and it will auto-update itself?
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
There is a "variable" on the file that keeps a record of the number of modules and other things. After your "auto-sync", does that have any effect or one can just leave that and it will auto-update itself?
I have seen that variable... and already changed with number of files... I thought if it is there, needed...
 
Upvote 0
Top