/*
    RHWIF.C

Started by DavidW, 1/11/92

Resource file extension to Hwif

*/

#include <appman.g>
#include <wlib.h>
#include <hwif.h>
#include <hwif.g>
#include <epoc.h>
#include <p_gen.h>
#include <s_.rsg>

GLREF_D PR_APPMAN *w_am;
GLREF_D WORD DatLocked;
GLREF_D VOID *DatCommandPtr;


GLDEF_C VOID hDeclareAppRcb(VOID *rcb)
    {
    w_am->appman.rcb=rcb;
    }

GLDEF_C VOID *hInitAppRcb(VOID)
    {               /* create and initialise resource file object */
    INT ret;
    VOID *rcb;      /* resource file object handle */

    rcb=p_new(1,C_RSCFILE);
    ret=p_entersend3(rcb,O_RS_INIT,DatCommandPtr);  /* pass file name */
    if (ret<0)          /* no resource file found */
        p_exit(ret);    /* fatal (programmer) error */
    hDeclareAppRcb(rcb);
    return(rcb);
    }

GLDEF_C INT hSetSystemResLang(INT lang)
    {
    TEXT name[12];  /* eg "ROM::s_.~04" */
    P_INFO junk;
    VOID *srcb;
    INT ret;

    p_atos(&name[0],"ROM::S_.~%02d",lang);
    if (p_finfo(&name[0],&junk))
        return(E_FILE_NXIST);
    srcb=p_new(CAT_HWIF_OLIB,C_RSCFILE);
    if (!srcb)
        return(E_GEN_NOMEMORY);
    ret=p_entersend3(srcb,O_RS_INIT,&name[0]);
    if (!ret)
        {
        p_send2(w_am->appman.srcb,O_DESTROY);
        w_am->appman.srcb=srcb;
        }
    return(ret);
    }

GLDEF_C VOID hRequestReplacePack(VOID *rcb,TEXT *fname)
    {
    TEXT buf[50];

    p_send4(w_am,O_AM_LOAD_RES_BUF,-SYS_REPLACE_DISK,&buf[0]);
    do
        {
        DatLocked++;
        wsAlertW(WS_ALERT_CLIENT,0,&buf[0],0);
        DatLocked--;
        } while (p_entersend3(rcb,O_RS_INIT,fname)<0);
    }
