(procedure P_DEVICEINFO
  (cat #dev (getenv "TSTDEV_DEVICE") "\n" 
       #unit (getenv "TSTDEV_UNIT") "\n"
       #devtype (getenv "TSTDEV_DEVICETYPE") "\n"
       #commandset (getenv "TSTDEV_COMMANDSET") "\n"
       #vendor (getenv "TSTDEV_VENDOR") "\n"
       #product (getenv "TSTDEV_PRODUCT") "\n"
       #revision (getenv "TSTDEV_REVISION")
  )
)

(procedure P_FINDBYVOLUME userlevel
  (if (= userlevel 0)
    (set #ret (run "testdevice CD0: volume setvar"))
    (set #ret (run (cat "testdevice " (askstring (prompt #entercdname) (help @askstring-help) (default "CD0:")) " volume setvar")))
  )

  (if (= #ret 0)
    (if (= (getenv "TSTDEV_DEVICETYPE") "CD-ROM")
      (if (< userlevel 2)
        (set #goon 1)
        (set #goon 
          (askbool 
            (prompt
              (cat #found "\n\n" (P_DEVICEINFO) "\n\n\n" #isok)
            )
            (help @askbool-help)
            (default 1)
          )
        )
      )  
      (if (= userlevel 0)
        (set #goon 0)
        (set #goon
          (askbool 
            (prompt
              (cat #foundnotcd "\n\n" (P_DEVICEINFO) "\n\n\n" #isok)
            )
            (help @askbool-help)
            (default 1)
          )
        )  
      )
    )
    ((set #goon 0) (message #notfound (all)))
  )
)

(procedure P_FINDBYDEVICE
  (
    (set #name
      (cat "testdevice NAME=" 
        (askstring (prompt #findbydev) (help @askstring-help)
        (default "atapi.device"))
        " "
        (askstring (prompt #unitnum) (help @askstring-help)
        (default ""))
        " setvar"
      )
    )
    (working #search)
    (set #ret (run #name))
    (if (= #ret 0)
      (if (< @user-level 2)
        (set #goon 1)
        (set #goon 
          (askbool 
            (prompt
              (cat #found "\n\n" (P_DEVICEINFO) "\n\n\n" #isok)
            )
            (help @askbool-help)
            (default 1)
          )
        )  
      )
      (set #goon 0)
    )
  )
)

(procedure P_CONFIGURECD
  (working #search)

  (P_FINDBYVOLUME @user-level)

  (if (= #goon 0)
    (if (= @user-level 0)
      (P_FINDBYVOLUME 1)
    )
  )

  (if (= #goon 0)
    (P_FINDBYDEVICE)
  )

  (if (= #goon 0) (abort #notfound))
  
  (tooltype
    (dest (tackon @default-dest "MUI_CD_Player"))
    (settooltype "DEVICE" (getenv "TSTDEV_DEVICE"))
    (settooltype "UNIT" (getenv "TSTDEV_UNIT"))
    (settooltype "LIBRARY"
      (if (= (getenv "TSTDEV_COMMANDSET") "CD32") "CDPlayers/cddevplay.library" "CDPlayers/atapiplay.library")
    )
  )
)

(set #language 
  (if (= @language "polski") 1 
    (if (= @language "deutsch") 2
      (if (= @language "italiano") 3 0
    )
  )
)

(select #language

; English translation

  (
    (set #search "Searching for CD-ROM...")
    (set #found "Found a CD-ROM drive:")
    (set #dev "Device: ")
    (set #unit "Unit: ")
    (set #vendor "Vendor: ")
    (set #product "Product: ")
    (set #revision "Revision: ")
    (set #devtype "Device type: ")
    (set #commandset "Command set: ")
    (set #foundnotcd "Found a device which is probably not a CD-ROM:")
    (set #isok "Use this device ?")
    (set #notfound "Could not find a CD-ROM")
    (set #entercdname "Enter the name of your CD-ROM\n(eg. CD0, CD1, CDR etc.)")
    (set #findbydev "Let's try to find the CD-ROM differently.\nEnter the device name:")
    (set #unitnum "Enter unit number:\n(or leave it empty if you don't know the number)")
  )

; Polish translation

  (
    (set #search "Szukam CD-ROMu...")
    (set #found "Znalazīem CD-ROM:")
    (set #dev "Urzādzenie: ")
    (set #unit "Nr: ")
    (set #vendor "Producent: ")
    (set #product "Produkt: ")
    (set #revision "Wersja: ")
    (set #devtype "Typ urzādzenia: ")
    (set #commandset "Zestaw komend: ")
    (set #foundnotcd "Znalazīem urzādzenie, które prawdopodobnie nie jest CD-ROMem:")
    (set #isok "Czy mam uūyź tych danych ?")
    (set #notfound "Nie mogė znaleśź CD-ROMu")
    (set #entercdname "Wpisz nazwė CD-ROMu\(czyli np. CD0, CD1, CDR itp.)")
    (set #findbydev "Spróbujmy znaleśź CD-ROM w inny sposób.\nWpisz nazwė urzādzenia:")
    (set #unitnum "Wpisz numer urzādzenia:\n(albo pozostaw to pole puste jeōli nie znasz numeru)")
  )

; German translation

  (
    (set #search "Suche nach einem CD-ROM...")
    (set #found "Es wurde ein CD-ROM Laufwerk gefunden:")
    (set #dev "Device: ")
    (set #unit "Unit: ")
    (set #vendor "Hersteller: ")
    (set #product "Produkt: ")
    (set #revision "Revision: ")
    (set #devtype "Geräte-Typ: ")
    (set #commandset "Befehlssatz: ")
    (set #foundnotcd "Es wurde ein Gerät gefunden, das vermutlich kein CD-ROM ist:")
    (set #isok "Dieses Gerät verwenden?")
    (set #notfound "Ein CD-ROM konnte nicht gefunden werden")
    (set #entercdname "Geben Sie den Namen Ihres CD-ROM ein\n(z.B. CD0, CD1, CDR etc.)")
    (set #findbydev "Wir versuchen jetzt, das CD-ROM auf eine andere Weise zu finden.\nGeben Sie den Device-Namen ein:")
    (set #unitnum "Geben Sie die Unit-Nummer ein:\n(oder lassen Sie das Feld leer, falls Sie die Nummer nicht wissen)")
  )

; Italian translation

    (set #search "Ricerco il tuo CD-ROM...")
    (set #found "Trovato drive CD-ROM :")
    (set #dev "Dispositivo: ")
    (set #unit "Unita`: ")
    (set #vendor "Venditore: ")
    (set #product "Prodotto: ")
    (set #revision "Revisione: ")
    (set #devtype "Tipo Dispositivo: ")
    (set #commandset "Comandi disponibili: ")
    (set #foundnotcd "Il dispositivo trovato probabilmente non e` un CD-ROM:")
    (set #isok "Devo usare questo dispositivo ?")
    (set #notfound "Non riesco a trovare un CD-ROM")
    (set #entercdname "Digita il nome del tuo CD-ROM\n(es. CD0, CD1, CDR ecc.)")
    (set #findbydev "Cerco di trovare il CD-ROM in altro modo.\nDigita nome dispositivo:")
    (set #unitnum "Digita numero unita`:\n(o lascialo vuoto se non lo conosci !)")
  )
)

(set @default-dest "")

(P_CONFIGURECD)

(exit)
