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.
 
 

136 lines
3.8 KiB

#define URIEL_BINARY_EOF "*[U_EOF]"
#define URIEL_BINARY_SOF "*[U_SOF]"
#define URIEL_FCMD_GET "*[U_GET]"
#define URIEL_FCMD_PUT "*[U_PUT]"
#define URIEL_PORT 2
#include "::/Doc/Comm"
U8 UrielPageBuf[2097152];
U8 UrielFileBuf[2097152];
I64 UrielFileBufSize=0;
CComm *c=CommInit8n1(URIEL_PORT,115200);
U0 Get(U8 *remote_file, U8 *local_file="file") {
Bool load=FALSE;
I64 b=0;
UrielFileBufSize=0;
CommPutS(URIEL_PORT, URIEL_FCMD_GET);
CommPutS(URIEL_PORT, remote_file);
CommPutS(URIEL_PORT, "|");
CommPutS(URIEL_PORT, Define("DD_OS_NAME_VERSION"));
CommPutS(URIEL_PORT, "^");
progress1_max=100;
progress1=0;
StrCpy(progress1_desc, "Receiving file");
while (!load) {
Sleep(0);
while (FifoU8Rem(c->RX_fifo,&b)) {
if (b != 0x00) {
UrielFileBuf[UrielFileBufSize] = b;
UrielFileBufSize++;
progress1++;
if (progress1>progress1_max) { progress1=0; };
}
else {
if (StrCmp(UrielFileBuf+(UrielFileBufSize-8), URIEL_BINARY_EOF)==0) {
UrielFileBufSize -= 8;
load=TRUE;
break;
}
else {
UrielFileBuf[UrielFileBufSize] = b;
UrielFileBufSize++;
progress1++;
if (progress1>progress1_max) { progress1=0; };
}
}
}
}
FileWrite(local_file, UrielFileBuf, UrielFileBufSize);
ProgressBarsRst;
}
U0 Send(U8 *local_file, U8 *remote_file="") {
CDirEntry *d_file = FilesFind(local_file);
U8 *s_file = FileRead(d_file->full_name, d_file->size);
I64 f_pos=0;
CommPutS(URIEL_PORT, URIEL_FCMD_PUT);
CommPutS(URIEL_PORT, local_file);
CommPutS(URIEL_PORT, "|");
CommPutS(URIEL_PORT, remote_file);
CommPutS(URIEL_PORT, URIEL_BINARY_SOF);
progress1_max=d_file->size;
progress1=0;
StrCpy(progress1_desc, "Sending file");
for (f_pos=0;f_pos<d_file->size;f_pos++) {
Sleep(0);
progress1=f_pos;
CommPutChar(URIEL_PORT, s_file[f_pos]);
}
CommPutS(URIEL_PORT, URIEL_BINARY_EOF);
ProgressBarsRst;
Free(s_file);
Free(d_file);
}
U0 CloseBrowser() {
Bool close=FALSE;
close = PopUpCancelOk("Close Browser?");
if (close) { In("x\n"); };
}
U0 Browser(U8 *url)
{
WinMax;
U8 *Cmd;
I64 UrielPageBufSize=0;
I64 UrielPageBufPos=0;
CommPutS(URIEL_PORT, url);
CommPutS(URIEL_PORT, "|");
CommPutS(URIEL_PORT, Define("DD_OS_NAME_VERSION"));
CommPutS(URIEL_PORT, "^");
CDoc *UrielPage = DocNew();
I64 b=0;
Bool load=FALSE;
Bool proc=FALSE;
Bool pad=TRUE;
progress1_max=100;
progress1=0;
StrCpy(progress1_desc, "Request sent, waiting for response");
while (!load) {
if (InU8(0x60)==0x01) { UrielPageBufSize=0; break; };
Sleep(0);
while (FifoU8Rem(c->RX_fifo,&b)) {
if (b == 0xFF && !pad) { load=TRUE; break; };
if (b != 0xFF && pad) { pad=FALSE; };
if (b != 0xFF && !pad) {
if (!proc) { proc=TRUE; StrCpy(progress1_desc, "Processing DolDoc"); };
UrielPageBuf[UrielPageBufSize] = b;
UrielPageBufSize++;
progress1++;
if (progress1>progress1_max) { progress1=0; };
}
}
}
ProgressBarsRst;
while (UrielPageBufPos<UrielPageBufSize) {
DocPrintPartial(UrielPage, "%c", UrielPageBuf[UrielPageBufPos]);
UrielPageBufPos++;
}
DocClear;
DocInsDoc(DocPut, UrielPage);
DocTop;
DocDel(UrielPage);
while (TRUE) {
Cmd = GetStr;
if(StrCmp(Cmd, "x")==0) { break; };
}
Free(Cmd);
DocBottom;
}