Uriel Web Browser for TempleOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

150 lines
4.0 KiB

#define URIEL_GETPAGE 0x10
#define URIEL_NAVBACK 0x11
#define URIEL_NAVFWD 0x12
#define URIEL_THUMB 0x13
#define URIEL_DL_PATH "::/Home/Downloads/"
#define URIEL_THUMB_BMP "/Tmp/UrielThumb.bmp"
#define URIEL_VERSION "Uriel/0.2"
Bool URIEL_INSTANCE=FALSE;
U8 URIEL_USER_AGENT[64];
StrCpy(URIEL_USER_AGENT, URIEL_VERSION);
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), " (");
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), Define("DD_OS_NAME_VERSION"));
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), ")");
U0 U_CloseBrowser()
{
Bool close=FALSE;
close = PopUpCancelOk("Close Uriel Browser?");
if (close) { In("x\n"); };
}
U0 U_InsertThumb(U8 *anchor, U8 *indent, U8 *outdent, U8 *url)
{
DocAnchorFind(DocPut,anchor);
I64 size;
ZeroParamBuf;
StrCpy(HGBD_PARAM_BUF,URIEL_USER_AGENT);
WriteParamBuf;
BlkWrite(HGBD,url,1,(StrLen(url)/BLK_SIZE)+1);
HGExec(URIEL_THUMB);
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size<1) {
PopUpOk("Error loading image.");
return;
};
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
FileWrite(URIEL_THUMB_BMP, HGFS_BUF, size);
DocAnchorFind(DocPut,anchor);
DocBMP(,URIEL_THUMB_BMP);
if (StrCmp(indent,"")!=0) {
DocAnchorFind(DocPut,indent);
DocPrintPartial(DocPut,"$ID,14$");
};
if (StrCmp(indent,"")!=0) {
DocAnchorFind(DocPut,outdent);
DocPrintPartial(DocPut,"$ID,-14$");
};
DocAnchorFind(DocPut,anchor);
}
U0 U_Browser(U8 *url)
{
Bool savefile=FALSE;
U8 localfile[StrLen(URIEL_DL_PATH)+28];
U8 msg[128];
U8 savemsg[1024];
I64 size;
U8 *cmd;
ZeroParamBuf;
StrCpy(HGBD_PARAM_BUF,URIEL_USER_AGENT);
WriteParamBuf;
BlkWrite(HGBD,url,1,(StrLen(url)/BLK_SIZE)+1);
HGExec(URIEL_GETPAGE);
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size<1) {
PopUpOk("Bad URL.");
return;
};
if (StrCmp(HGBD_PARAM_BUF+128,"download://")==0) {
StrCpy(localfile,URIEL_DL_PATH);
if (StrLastOcc(url,"/")>0) {
StrCpy(localfile+StrLen(localfile), StrLastOcc(url,"/")+1);
} else {
StrCpy(localfile+StrLen(localfile),url);
};
StrCpy(savemsg,"Download file: ");
if (StrLastOcc(url,"/")>0) {
StrCpy(savemsg+StrLen(savemsg),StrLastOcc(url,"/")+1);
} else {
StrCpy(savemsg+StrLen(savemsg),url);
};
StrCpy(savemsg+StrLen(savemsg)," (");
StrCpy(savemsg+StrLen(savemsg),HGBD_PARAM_BUF);
StrCpy(savemsg+StrLen(savemsg)," bytes)");
savefile = PopUpCancelOk(savemsg);
if (savefile==TRUE) {
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
if (StrCmp(localfile+StrLen(localfile)-2,".Z")==0) {
U8 uzlocalfile[StrLen(URIEL_DL_PATH)+28];
MemCpy(uzlocalfile,localfile,StrLen(localfile)-2);
uzlocalfile[StrLen(localfile)-1] = 0x0;
FileWrite(uzlocalfile, HGFS_BUF, size);
Move(uzlocalfile, localfile);
} else {
FileWrite(localfile, HGFS_BUF, size);
};
StrCpy(msg, "Downloaded file: ");
StrCpy(msg+StrLen(msg), localfile);
PopUpOk(msg);
};
} else {
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
MemSetU8(ToI64(HGFS_BUF)+size, 0x0, 1);
DocClear;
DocPutS(DocPut,HGFS_BUF);
DocTop;
if (URIEL_INSTANCE==FALSE) {
StrCpy(Fs->task_title, HGBD_PARAM_BUF+128);
URIEL_INSTANCE=TRUE;
while (TRUE) {
cmd = GetStr;
if (StrCmp(cmd,"x")==0) { break; };
};
Free(cmd);
URIEL_INSTANCE=FALSE;
} else {
StrCpy(Fs->parent_task->task_title, HGBD_PARAM_BUF+128);
};
};
}
U0 U_HistNav(I64 index)
{
I64 size;
U8 *cmd;
ZeroParamBuf;
if (index==0) { HGExec(URIEL_NAVBACK); };
if (index==1) { HGExec(URIEL_NAVFWD); };
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size<1) {
PopUpOk("Bad URL.");
return;
};
StrCpy(Fs->parent_task->task_title, HGBD_PARAM_BUF+128);
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
MemSetU8(ToI64(HGFS_BUF)+size, 0x0, 1);
DocClear;
DocPutS(DocPut,HGFS_BUF);
DocTop;
}
U0 U_Navigate(U8 *anchor, U8 *url) {
DocAnchorFind(DocPut,anchor);
U_Browser(url);
}