'dgalaga music changer
sepfile$="":seppath$=""
SUB SeparateFile(file$)
  SHARED sepfile$,seppath$
  done=0
  ln=LEN(file$)
  FOR backscan=1 TO ln
    bscan=ln-backscan+1
    IF done=0 THEN
      ch$=MID$(file$,bscan,1)
      IF (ch$="/" OR ch$=":") and done=0 THEN            'This part written in ABASIC - Can you tell?
        seppath$=LEFT$(file$,bscan)
        sepfile$=RIGHT$(file$,ln-LEN(seppath$))
        done=1
      END IF
    END IF
  NEXT backscan
  IF done=0 THEN sepfile$=file$
END SUB
Start:
  Skip=0
  style 2:color 2
  ?"Music Select 1.0 ";
  color 1:style 0
  ?"By John Mason"
  open "I",1,"MusicSelectModule"
  if not eof(1) then 'old module exists
    close 1
    if MsgBox("Module found from a previous session!","Delete","Rename") then
      kill "MusicSelectModule"
    else
      Newname$=Ucase$(Inputbox$("Enter a new name for the module"))
      if newname$="" or newname$="MUSICSELECTMODULE" then newname$="NONAME"
      System "Rename MusicSelectModule "+newname$
    end if
  end if
  close 1
  oldmodule=0
  toload$=filebox$("Select A Module","")
  open "I",2,toload$
  if not eof(2) then ' make sure the module exists
    if ucase$(toload$)="GALAGA.MUSIC0" then Skip=1:Goto SkipAll  'Play the existing module
    open "I",1,"GALAGA.MUSIC0"
    if not eof(1) then 'file exists
      command$="Rename Galaga.Music0 MusicSelectModule"
      ?" ** Renaming existing music module! **"
      System command$               '  rename existing
      oldmodule=1
    end if
    close 1
    if ucase$(right$(toload$,4))=".LHA" or ucase$(right$(toload$,4))=".LZH" then 'uh-oh, an lha'ed MOD!
      color 2
      ?"LHA compressed module detected!"
      Color 1
      command$="makedir T:MusicSelect"
      system command$
      system "Assign MS: T:MusicSelect"
      ?"Extracting...";
      system "Lha > NIL: x "+toload$+" MS:"
      files to "T:Ms_Files","MS:"
      open "I",3,"T:Ms_Files"
      line input #3,nil$
      Lhafiles=0
      While eof(3)=0
        line input #3,xtract$
        ++LhaFiles
      Wend
      close 3
      CheckLha:
      if lhafiles>1 then
        lhaload$=filebox$("Multiple files in LHA!","MS:")
        open "I",4,lhaload$
        if eof(4) then close 4:Goto CheckLHA 'File not found
        close 4
        xtract$=lhaload$
      end if
      Kill "T:Ms_Files"
      ?"Moving...";
      if INSTR(ucase$(xtract$),"MOD")=0 then ' no MOD in filename
        if not msgbox (xtract$+": Are you sure this is a module?","Yes","No") then Abort
      end if
      system "Copy > NIL: MS:"+xtract$+" GALAGA.MUSIC0"
      system "Delete > NIL: MS:#? All"
      ?"Cleaning up...";
      system "Assign MS: Remove"
      system "Delete > NIL: T:MusicSelect all"
      color 2
      ?"Done."
      color 1
    else
      if INSTR(ucase$(toload$),"MOD")=0 then ' no MOD in filename
        if not msgbox (toload$+": Are you sure this is a module?","Yes","No") then Abort
      end if
      command$="Copy "+toload$+" to "+chr$(34)+chr$(34) 'copy selected module to current directory
      system command$
      SeparateFile(toload$)
      command$="Rename "+sepfile$+" GALAGA.MUSIC0"
      system command$
    End If
SkipAll:
    system "Galaga"
    if skip=0 then system "Delete > NIL: GALAGA.MUSIC0"
Abort:
    system "Assign > NIL: MS: Remove"
    system "Delete > NIL: T:MusicSelect All"
    system "Delete > NIL: T:MS_Files"
    if oldmodule=1 then
      system "Rename MusicSelectModule GALAGA.MUSIC0"
      ? "Old module has been restored."
    end if
  end if
  close 2
END  