Browse Source

Download confirm popup with filesize.

master
Alec Murphy 5 years ago
parent
commit
30e0fd52d8
  1. 101
      Uriel.HC
  2. 53
      uriel.py

101
Uriel.HC

@ -2,7 +2,6 @@
#define URIEL_NAVBACK 0x11
#define URIEL_NAVFWD 0x12
#define URIEL_THUMB 0x13
#define URIEL_DOWNLOAD 0x14
#define URIEL_DL_PATH "::/Home/Downloads/"
#define URIEL_THUMB_BMP "/Tmp/UrielThumb.bmp"
@ -54,6 +53,10 @@ U0 U_InsertThumb(U8 *anchor, U8 *indent, U8 *outdent, U8 *url)
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;
@ -67,22 +70,56 @@ U0 U_Browser(U8 *url)
PopUpOk("Bad URL.");
return;
};
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; };
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);
};
Free(cmd);
URIEL_INSTANCE=FALSE;
} else {
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;
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);
};
};
}
@ -107,40 +144,6 @@ U0 U_HistNav(I64 index)
DocTop;
}
U0 U_Download(U8 *url)
{
I64 size;
U8 localfile[StrLen(URIEL_DL_PATH)+28];
U8 msg[128];
StrCpy(localfile,URIEL_DL_PATH);
if (StrLen(StrLastOcc(url,"/")+1)>0) {
StrCpy(localfile+StrLen(localfile), StrLastOcc(url,"/")+1);
} else {
StrCpy(localfile+StrLen(localfile), "Download.OUT");
};
ZeroParamBuf;
HGExec(URIEL_DOWNLOAD);
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size==-1) {
PopUpOk("Bad URL.");
return;
};
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);
}
U0 U_Navigate(U8 *anchor, U8 *url) {
DocAnchorFind(DocPut,anchor);
U_Browser(url);

53
uriel.py

@ -6,7 +6,6 @@ URIEL_NAVBACK = 0x11
URIEL_NAVFWD = 0x12
URIEL_STR_SIZE = 144
URIEL_THUMB = 0x13
URIEL_DOWNLOAD = 0x14
class Uriel:
download_buffer = ''
@ -27,8 +26,6 @@ def uriel(data):
UrielNavFwd()
if data == URIEL_THUMB:
UrielThumb()
if data == URIEL_DOWNLOAD:
UrielDownload()
def UrielGetPage():
global Uriel
@ -89,17 +86,26 @@ def UrielGetPage():
Uriel.download_buffer = pagedata
except:
Uriel.download_buffer = ''
Uriel.nav_index += 1
Uriel.history = Uriel.history[0:Uriel.nav_index]
Uriel.history.append({'url':url, 'filedata':filedata})
ZeroParamBuf()
os.lseek(HGBD,0,os.SEEK_SET)
os.write(HGBD,str(filesize))
os.lseek(HGBD,128,os.SEEK_SET)
os.write(HGBD,str(url)[:URIEL_STR_SIZE])
os.lseek(HGBD,BLK_SIZE,os.SEEK_SET)
os.write(HGBD,filedata)
logger.info("[Uriel] navigate to " + url)
ZeroParamBuf()
os.lseek(HGBD,0,os.SEEK_SET)
os.write(HGBD,str(len(Uriel.download_buffer)))
os.lseek(HGBD,128,os.SEEK_SET)
os.write(HGBD,"download://"+'\x00')
os.lseek(HGBD,BLK_SIZE,os.SEEK_SET)
os.write(HGBD,Uriel.download_buffer)
logger.info("[Uriel] copy to download buffer " + url)
else:
Uriel.nav_index += 1
Uriel.history = Uriel.history[0:Uriel.nav_index]
Uriel.history.append({'url':url, 'filedata':filedata})
ZeroParamBuf()
os.lseek(HGBD,0,os.SEEK_SET)
os.write(HGBD,str(filesize))
os.lseek(HGBD,128,os.SEEK_SET)
os.write(HGBD,str(url)[:URIEL_STR_SIZE])
os.lseek(HGBD,BLK_SIZE,os.SEEK_SET)
os.write(HGBD,filedata)
logger.info("[Uriel] navigate to " + url)
else:
filesize = -1
ZeroParamBuf()
@ -280,25 +286,6 @@ def UrielThumb():
logger.error("[Uriel] error reading url " + url)
conn.send(chr(URIEL_THUMB))
def UrielDownload():
global Uriel
filedata = Uriel.download_buffer
filesize = len(filedata)
if filesize>0:
ZeroParamBuf()
os.lseek(HGBD,0,os.SEEK_SET)
os.write(HGBD,str(filesize))
os.lseek(HGBD,BLK_SIZE,os.SEEK_SET)
os.write(HGBD,filedata)
logger.info("[Uriel] binary, download file")
else:
filesize = -1
ZeroParamBuf()
os.lseek(HGBD,0,os.SEEK_SET)
os.write(HGBD,str(filesize))
logger.error("[Uriel] error downloading file")
conn.send(chr(URIEL_DOWNLOAD))
def UrielPreProcess(htm1, l_url):
title_text = ''
hb_header = '$WW,1$$BLACK$$MA+LIS,"[Close]",LM="U_CloseBrowser;"$ $MA+LIS,"[Back]",LM="U_HistNav(0);"$ $MA+LIS,"[Fwd]",LM="U_HistNav(1);"$ $MA+LIS,"[Go]",LM="U_Browser(GetStr(\\"\nURL> \\"));"$ ' + title_text + '\n\n'

Loading…
Cancel
Save