/* */
parse arg eMail Password

Data = ""
Error = ""
Status = ""
AccountKey = ""

select
      when eMail = "update" then
           do
             '@boinc_cmd.exe --project http://boinc.gorlaeus.net update'
             exit
           end
      when eMail = "detach" then
           do
             '@boinc_cmd.exe --project http://boinc.gorlaeus.net detach'
             exit
           end
      when eMail = "suspend" then
           do
             '@boinc_cmd.exe --project http://boinc.gorlaeus.net suspend'
             exit
           end
      when eMail = "resume" then
           do
             '@boinc_cmd.exe --project http://boinc.gorlaeus.net resume'
             exit
           end
      otherwise
               do
if eMail = "" then
   do
     say "Project http://boinc.gorlaeus.net:"
     say ""
     say "Options:"
     say "leidenclassical.cmd <Username> <Password> for project attach"
     say "leidenclassical.cmd update for project update"
     say "leidenclassical.cmd detach for project detach"
     say "leidenclassical.cmd suspend for project suspending"
     say "leidenclassical.cmd resume for project resuming"
     exit
   end
if Password = "" then
   do
     say "Project http://boinc.gorlaeus.net:"
     say ""
     say "Options:"
     say "leidenclassical.cmd <Username> <Password> for project attach"
     say "leidenclassical.cmd update for project update"
     say "leidenclassical.cmd detach for project detach"
     say "leidenclassical.cmd suspend for project suspending"
     say "leidenclassical.cmd resume for project resuming"
     exit
   end
               end
end

'@boinc_cmd.exe --lookup_account http://boinc.gorlaeus.net ' || eMail || ' ' || Password || ' | RXQUEUE'
do queued()
    Data = linein("QUEUE:")
    Status = substr(Data,1,12)
    if Status = "account key:" then
       do
         AccountKey = substr(Data,13)
         '@boinc_cmd.exe --project_attach http://boinc.gorlaeus.net ' ||  AccountKey
       end
       else
           Error = Data
end

if Status = "account key:" then
   do
     say "Project http://boinc.gorlaeus.net:"
     say ""
     say "successfull attach to project http://boinc.gorlaeus.net!"
     say "account key is: " || AccountKey
     say "now copying OS/2 application into project directory..."
     '@copy ClassicalDynamics_i386-pc-os2-emx.exe projects\boinc.gorlaeus.net'
     '@copy ..\leidenclassical_app_info.xml projects\boinc.gorlaeus.net\app_info.xml'
     say "Remember to change all occurence of <min_rpc_time> to 0.00 in client_state.xml"
     say "for immediate download of WorkUnit."
  end
  else
      do
        say "Project http://boinc.gorlaeus.net:"
        say ""
        say "Unable to attach..."
        say "error: " || Error
        exit
      end
