Well, imma be honest, i'm pretty proud of this script. But here's what it does;
For when someone wants to show you an image, but you've already closed the inernet, or your just generally too lazy to flick alt + tab,
This works using sockets to download the image file, picwins to display it, then the image being scrapped, so it doesn't clogg any memory/cache space.
Hope you enjoy and give positive feedback, rate !
Thanks to Lindrian for his help with the socket :]
~Jonesy
menu * {
Image Viewer: imgviewer
}
alias imgviewer {
dialog -m imgviewer imgviewer
}
dialog imgviewer {
size -1 -1 200 100
title "Image Viewer Console"
option dbu
edit "", 1, 2 2 140 10, autohs
button "View Image", 2, 144 2 54 10
edit "", 3, 2 14 196 10, read autohs center
text "History", 4, 2 30 100 10
list 5, 2 37 196 70
}
on *:DIALOG:imgviewer:init:*: {
refresh.histimgs
}
on *:DIALOG:imgviewer:sclick:*: {
if ($did == 2) {
getimg $did(1).text
if (!$read(imghistory.dat, w, $did(1).text)) {
write imghistory.dat $did(1).text
}
refresh.histimgs
}
if ($did == 5) {
did -r imgviewer 3
}
}
on *:DIALOG:imgviewer:dclick:*: {
if ($did == 5) {
write -ds $+ $did(5).seltext imghistory.dat
write imghistory.dat $did(5).seltext
did -ra imgviewer 1 $did(5).seltext
getimg $did(5).seltext
refresh.histimgs
}
}
alias refresh.histimgs {
var %x = 1
did -r imgviewer 5
while (%x <= $lines(imghistory.dat)) {
did -i imgviewer 5 1 $read(imghistory.dat, %x)
inc %x 1
}
}
alias getimg {
dialog $iif($dialog(imgviewer),-v,-m) imgviewer imgviewer
if (% isin $1-) {
did -ra imgviewer 3 Please remove any "%" from the URL
halt
}
if ($right($1-,4) == .jpg || $right($1-,4) == .gif || $right($1-,4) == .png) {
did -r imgviewer 3
window -paoCzdk0 +tnbL @image.download -1 -1 600 50
clear @image.download
drawtext @image.download 14 5 5 Downloading Temporary Image: 0KB
img.download $1-
}
else {
did -ra imgviewer 3 Unsupported Image format: $right($1-,4)
halt
}
}
alias img.download {
var %r $remove($1,http://),%y $ticks,%1 $gettok(%r,1,47),%o $pos(%r,/),%2 $mid(%r,%o,$calc(1+$pos(%r,/,$count(%r,/))-%o)),%u $remove(%r,%1,%2),%4 $iif($count(%u,.),$gettok(%u,$calc(1+$v1),46)),%3 $remove(%u,%4),%i %3 $+ %4
sockopen imgdload. $+ %y %1 80
sockmark imgdload. $+ %y %1 %2 %3 %4
}
on *:sockopen:imgdload.*:{
if ($sockerr) echo -a Socket error: $sock($sockname).wsmsg
else {
tokenize 32 $sock($sockname).mark
sockwrite $sockname $+(GET $2,$3,$4 $chr(32) HTTP/1.1,$lf,Host: $1,$lf,$lf)
}
}
on *:sockread:imgdload.*:{
if (!$sockerr) {
var %a 1,%v $numtok($sock($sockname).mark,32)
while %a && %v > 2 {
sockread %a
if ($regex(%a,/Content\-Type: .*?\/([^\s;]+)/i)) var %t $iif($regml(1) != plain,$v1)
if ($regex(%a,/Content\-Length: (\d+)/i)) var %l $regml(1)
}
if (%v > 2) sockmark $sockname $gettok($sock($sockname).mark,3,32) $+ %t %l $gettok($sock($sockname).mark,5-,32)
tokenize 32 $sock($sockname).mark
while $sock($sockname).rq {
clear @image.download
drawtext @image.download 14 5 5 Downloading Temporary Image: $bytes($2).suf
sockread &b
bwrite $1 -1 -1 &b
}
if ($lof($1) >= $2) {
clear @image.download
drawtext @image.download 14 5 5 File Image Download Complete: $bytes($2).suf
window -paoCzdk0 @image.( $+ $1 $+ ) -1 -1 $calc($pic($1).width + 20) $calc($pic($1).height + 50)
/drawfill @image.( $+ $1 $+ ) 0 0 1 1
drawpic @image.( $+ $1 $+ ) 5 5 $1
.remove $1
.sockclose $sockname
}
}
else .sockclose $sockname
unset %dl.dir
}
on *:CLOSE:@image*: {
if ($window(@image.download)) {
window -c @image.download
}
}