'===========================================================================
' Subject: SPLIT BIG FILES                    Date: 10-16-99 (19:56)       
'  Author: David Drake                        Code: LB                     
'  Origin: drake@apexmail.com               Packet: LIBERTY.ABC
'===========================================================================
'This splits big files into smaller pieces then
'writes a batch file that combines them together
'again.
'By David Drake
'Needs:  Make a version for Win3.1 as well.

nomainwin

[create.main.window]

    directory$="c:\temp\"
    size=1440000
    dim info$(10,10)

    UpperLeftX=50
    UpperLeftY=50
    WindowWidth = 264
    WindowHeight = 310

    nomainwin

    textbox #main.filetosplit, 22, 43, 160, 18
    textbox #main.directory, 22, 118, 160, 18
    textbox #main.sizeotherbox, 135, 184, 72, 18

    button #main.selectfile, "Browse", [select.file], UL, 190, 43, 58, 20
    button #main.browse, "Browse", [select.directory], UL, 190, 118, 58, 20
    button #main.ok, "Split File",[split.file],UL,22,255,88,20
    button #main.help, "Help",[help],UL,125,255,50,20
    button #main.cancel, "Quit",[end.it],UL,190,255,58,20

    radiobutton #main.size144, "", [size.144mb], [radiobutton8Reset], 22, 186, 15, 15
    radiobutton #main.size365kb, "", [size.365kb], [radiobutton9Reset], 22, 211, 15, 15
    radiobutton #main.sizeother, "", [size.other], [radiobutton10Reset], 118, 186, 15, 15

    open "File Splitter for LB" for graphics_nsb_nf as #main

    blue=256
    print #main, "down; size 5"

    for y = 0 to 310 step 5
        blue=blue - 5:if blue<0 then blue=0
        print #main, "color 0 0 ";str$(blue)
        y$=str$(y)
        line$="line 0 "+y$+" 264 "+y$ 
        print #main, line$ 
    next y
    print #main, "flush"

    print #main.size144, "set"
    print #main, "trapclose [end.it]"
    print #main, "font Times_New_Roman_Bold 6 14"
    print #main.filetosplit, "!font Times_New_Roman 5 14"
    print #main.directory, "!font Times_New_Roman 5 14"
    print #main.sizeotherbox, "!font Times_New_Roman 5 14"
    print #main.directory,directory$ 
    print #main, "color white; backcolor darkblue;"
    print #main, "up; goto 21 38; down; backcolor blue"
    print #main, "\File to split:"
    print #main, "up; goto 21 110; down; backcolor darkblue"
    print #main, "\Destination directory:"
    print #main, "up; goto 21 175; down; backcolor black"
    print #main, "\Select split file size:"
    print #main, "up; goto 39 195; down; backcolor black"
    print #main, "\1.44 MB"
    print #main, "up; goto 39 220; down;backcolor black"
    print #main, "\365 KB"
    print #main, "flush"

[input.loop]
    input a$ 
    goto [input.loop]


[select.file]
    filedialog "Select file to split into 1.44MB pieces:","c:\temp\*.*",file.to.split$ 
    if file.to.split$="" then goto [input.loop]
    file.to.split$=lower$(file.to.split$)
    print #main.filetosplit, file.to.split$ 
    goto [input.loop]

[size.144mb]
    size=1440000
    goto [input.loop]

[size.365kb]
    size=365000
    goto [input.loop]

[size.other]
    prompt "Other file size:"+chr$(13)+"Enter file size in KB:";size$ 
    if size$="" then goto [input.loop]
    size=val(size$)
    if size=0 then size=1440000: print #main.size144, "set": goto [input.loop]
    size=size*1000
    print #main.sizeotherbox,str$(size/1000);" KB"
    goto [input.loop]

[select.directory]
    directory$="c:\temp\"
    filedialog "Select destination directory:","join.bat",dirinput$ 
    if dirinput$="" then goto [input.loop]
    directory$=lower$(mid$(dirinput$,1,len(dirinput$)-8))
    print #main.directory,directory$ 
    goto [input.loop]

[split.file]

    print #main.directory,"!contents?"
    input #main.directory,directory$ 
    print #main.filetosplit,"!contents?"
    input #main.filetosplit,file.to.split$ 

    if file.to.split$="" then notice "File Error"+chr$(13)+"No file specified!":goto [input.loop]
    if directory$="" then notice "Directory Error"+chr$(13)+"No directory specified!":goto [input.loop]

    [get.file.name]
        x=len(file.to.split$)
        z = z+1
            test$=mid$(file.to.split$,x-z,1)
            if test$="\" then goto [continue.splitting]
            goto [get.file.name]
    [continue.splitting]
            name$=right$(file.to.split$,z)
            source.directory$=left$(file.to.split$,x-z)

    gosub [check.directory]
        if errorflag=1 then errorflag=0: goto [input.loop]
    gosub [check.file.to.split]
        if errorflag=1 then errorflag=0: goto [input.loop]
    z=-1

    open file.to.split$ for input as #1
    length=lof(#1)
    divisions=int(length/size)
    lastbit=length-divisions*size
    if length<size then notice "It is already less than the specified size!":close #1:goto [input.loop]

    WindowWidth=300
    WindowHeight=100
    UpperLeftX = 100
    UpperLeftY = 100
    open "Progress" for graphics_nsb_nf as #progress
    print #progress, "fill blue; flush"
    print #progress, "color yellow;backcolor blue;goto 10 50; down"

    open directory$+"assemble.bat" for output as #2
    print #2, "@ECHO OFF"
    print #2, "rem **All lbx files must be in the same directory"
    print #2, "rem **as this batch file."
    print #2, "COPY ";

    for a = 1 to divisions
            print #progress, "fill blue; up; goto 10 25; down;\Parsing file ";str$(a);" of ";str$(divisions+1)
        piece$=input$(#1,size)
        split.file$=str$(a)+".lbx"
        open split.file$ for output as #3
            print #progress, "fill blue; up; goto 10 25; down;\Creating file ";str$(a);" of ";str$(divisions+1)
        print #3, piece$;
        close #3
        print #2," ";split.file$;"/B";
        if a<divisions then print #2, "+";
    next a

    if lastbit=0 then goto [continue]
            print #progress, "fill blue; up; goto 10 25; down;\Parsing file ";str$(a);" of ";str$(divisions+1)
        piece$=input$(#1,lastbit)
        split.file$=str$(a)+".lbx"
        open split.file$ for output as #3
            print #progress, "fill blue; up; goto 10 25; down;\Creating file ";str$(a);" of ";str$(divisions+1)
        print #3, piece$;
        close #3
        print #2,"+";split.file$;"/B ";

    [continue]
        print #2, " ";name$ 
        print #2, "ECHO Merge Complete"
        close #1
        close #2
        close #progress
        notice "Done"
        goto [input.loop]

[check.directory]
    files directory$, info$(
    If val(info$(0, 0)) <= 0 then notice "Directory Error"+chr$(13)+"Destination directory does not exist!":errorflag=1
    return

[check.file.to.split]
    files source.directory$,name$, info$(
    If val(info$(0, 0)) <= 0 then notice "File Error"+chr$(13)+"Source file does not exist!":errorflag=1
    return

[help]
    WindowWidth=500
    WindowHeight=400
    UpperLeftX=10
    UpperLeftY=10
    open "Splitter for LB Help" for graphics as #help
        bigfont$="font Ariel_Bold 12 27"
        smallfont$="font Ariel 5 15"

    print #help, "goto 10 30;color blue;down"
    print #help, bigfont$ 
    print #help, "\Splitter for LB Help"
    print #help, smallfont$ 
    print #help, "color black"
    print #help, "\"
    print #help, "\Thank you for using File Splitter for Liberty Basic."
    print #help, "\"
    print #help, "\File Splitter does just that... It splits large files into smaller files so that you"
    print #help, "\can store them on floppies."
    print #help, "\"
    print #help, "\How to use File Splitter:"
    print #help, "\"
    print #help, "\1. Key in or browse to find the file to split."
    print #help, "\2. Key in or browse to find the destination directory for split files."
    print #help, "\3. Select a split file size, or specify your own."
    print #help, "\4. Click on Split File."
    print #help, "\"
    print #help, "\File Splitter will create a series of *.lbx files (the split files) and one batch"
    print #help, "\file called ASSEMBLE.BAT.  The batch file will automatically merge the split files"
    print #help, "\into the original file, provided that the lbx files and the ASSEMBLE.BAT are in"
    print #help, "\the same directory."
    print #help, "\"
    print #help, "\Thanks again.  Please send any bugs, suggestions, etc. to:"
    print #help, "\David Drake"
    print #help, "\drake@apexmail.com"
    print #help, "\"
    print #help, "\Note: Even though this program has been well tested, the author is not responsible"
    print #help, "\for any damage to files, equipment, etc. that this program may cause."
    print #help, "flush"

    print #help, "trapclose [close.help]"
    goto [input.loop]

    [close.help]
    close #help
    goto [input.loop]

[end.it]
    close #main
