
#include "includes.h"
#include "installergui_data.h"

/********************************************************************
 *
 *  DESCRIPTION
 *
 *  this panel asks the user to insert a specific disk. when the
 *  user presses the "Proceed with install" button, this function
 *  must check for the requested disk and must not return as long
 *  as this requested disk is missing.
 *
 *  IN:  application - pointer to the private application structure
 *       localenv - the local environment of the related ASKDISK function
 *
 *  OUT: -
 *
 */

/********************************************************************
 *
 *  STATIC
 *
 */

/********************************************************************
 *
 *  EXTERN
 *
 */

/********************************************************************
 *
 *  PUBLIC
 *
 */

/********************************************************************
 *
 *  CODE
 *
 */

void __asm igui_AskDisk(register __a0 APTR application,
                        register __a1 struct FunctionEnvironment *localenv)
{
  #ifdef DEBUG
  DEBUG_MAKRO
  #endif

  {
    struct Application *app = (struct Application *) application;

    APTR must;
    APTR obj = GroupObject,
                 Child, TextObject,
                   MUIA_Frame, MUIV_Frame_None,
                   MUIA_Text_Contents, localenv->fe_Prompt.pa_Value,
                   MUIA_Text_SetMin, TRUE,
                   MUIA_Text_PreParse, "\33c",
                 End,
                 Child, GroupObject,
                   MUIA_Group_Horiz, TRUE,
                   Child, HVSpace,
                   Child, GroupObject,
                     Child, HVSpace,
                     Child, must = TextObject,
                       MUIA_Text_Contents, app->app_Texts[MUST_INSERT_DISK],
                       MUIA_Text_SetMin, TRUE,
                       MUIA_Text_PreParse, "\33c",
                       MUIA_ShowMe, FALSE,
                     End,
                     Child, HVSpace,
                   End,
                   Child, HVSpace,
                 End,
               End;

    // maybee BACK (if specified) or respect the swing mode
    if (localenv->fe_Back.pa_Value) { guistuff_SetBackButton(app, TRUE); }
    else if (!app->app_SWING_Mode)  { igui_NameCancel(app, (char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]); }

    // show the panel
    if (guistuff_NewContent(app, obj))
    {
      // wait, until the user does anything
      while (TRUE)
      {
        // wait for the user to do anything
        igui_WaitApp(app);

        //
        if (igui_QuitApp(app)) { break; }
        else
        {
          // where is the requested device/volume?
          if (sav_ExistsDosEntry((char *) localenv->fe_Dest.pa_Value, LDF_VOLUMES|LDF_DEVICES)) { break; }
          if (localenv->fe_Assigns.pa_Value)
          {
            if (sav_ExistsDosEntry((char *) localenv->fe_Dest.pa_Value, LDF_ASSIGNS)) { break; }
          }

          // no correct disk available
          SetAttrs(must, MUIA_ShowMe, TRUE, TAG_DONE);
          DisplayBeep(NULL);
        }
      }
    }
    else { /* NO GUI OBJECT */ }

    //
    if (localenv->fe_Back.pa_Value) { guistuff_SetBackButton(app, FALSE); }

    igui_EmptyPanel(app);
    return;
  }
}

