| 1 import "dart:html" as s;class qB{static const rB="Chrome";static const sB="Fir
efox";static const tB="Internet Explorer";static const uB="Safari";final TB;f
inal minimumVersion;const qB(this.TB,[this.minimumVersion]);}class vB{const vB(
);}class wB{final name;const wB(this.name);}class xB{const xB();}class yB{const
yB();}class RB{var LB;var n;var NB;var OB;var KB;var JB;var AB;var EB;var versi
on='0.0.1';var PB=['default','cream'];var history=[] ;var v=0;var u;RB(this.NB,t
his.OB,this.KB){EB=s.document.query(NB);JB=s.document.query(OB);AB=s.document.qu
ery(KB);s.window.onClick.listen((g)=>EB.focus());EB.onClick.listen((g)=>AB.value
=AB.value);EB.onKeyDown.listen(cB);EB.onKeyDown.listen(iB);} cB( g){var j="";var
h=38;var i=40;if(g.keyCode==h||g.keyCode==i){g.preventDefault();if(v<history.le
ngth){history[v]=AB.value;}else{j=AB.value;}}if(g.keyCode==h){v-- ;if(v<0){v=0;}
}else if(g.keyCode==i){v++ ;if(v>=history.length){v=history.length-1;}}if(g.keyC
ode==h||g.keyCode==i){AB.value=history[v]!=null?history[v]:j;}} iB( o){var BB=13
;var t=9;if(o.keyCode==t){o.preventDefault();}else if(o.keyCode==BB){if(!AB.valu
e.isEmpty){history.add(AB.value);v=history.length;}var i=AB.parent.parent.clone(
true);i.attributes.remove('id');i.classes.add('line');var j=i.query(KB);j.attrib
utes.remove('id');j.autofocus=false;j.readOnly=true;JB.children.add(i);var l=AB.
value;AB.value="";var h;var g="";if(!l.isEmpty){l.trim();h=k(l).split(' ');g=h[0
];h.removeRange(0,1);}if(u[g] is Function){u[g](g,h);}else{m('${k(g)}: command n
ot found');}s.window.scrollTo(0,s.window.innerHeight);}} dB( h, g){u={'clear':WB
,'help':bB,'version':oB,'cat':UB,'cd':VB,'date':YB,'ls':eB,'mkdir':fB,'mv':gB,'c
p':XB,'open':hB,'pwd':jB,'rm':lB,'rmdir':mB,'theme':nB,'who':pB};m('<div>Welcome
to ${k(s.document.title)}! (v${version})</div>');m(new DateTime.now().toLocal()
.toString());m('<p>Documentation: type "help"</p>');s.window.requestFileSystem(g
,persistent:h).then(ZB,onError:q);} CB( g, h){m('<div>${k(g)}: not available sin
ce filesystem was not initialized</div>');} ZB( i){LB=i;if(LB is s.FileSystem){n
=LB.root;}else{u['cat']=CB;u['cd']=CB;u['ls']=CB;u['mkdir']=CB;u['mv']=CB;u['cp'
]=CB;u['open']=CB;u['pwd']=CB;u['rm']=CB;u['rmdir']=CB;}n.createDirectory('testq
uotaforfsfolder').then(( h){h.remove().then((CC){});},onError:(g){if(g.code==s.F
ileError.QUOTA_EXCEEDED_ERR){m('ERROR: Write access to the filesystem is ' 'unav
ailable. Are you running Google Chrome with ' '--unlimited-quota-for-files?');}e
lse{q(g);}});} q(h){var g='';switch (h.code){case s.FileError.QUOTA_EXCEEDED_ERR
:g='QUOTA_EXCEEDED_ERR';break;case s.FileError.NOT_FOUND_ERR:g='NOT_FOUND_ERR';b
reak;case s.FileError.SECURITY_ERR:g='SECURITY_ERR';break;case s.FileError.INVAL
ID_MODIFICATION_ERR:g='INVALID_MODIFICATION_ERR';break;case s.FileError.INVALID_
STATE_ERR:g='INVALID_STATE_ERR';break;case s.FileError.TYPE_MISMATCH_ERR:g='TYPE
_MISMATCH_ERR';break;default:g='FileError = ${h.code}: Error not handled';break;
}m('<div>Error: ${k(g)}</div>');} FB( i, g, h){switch (i.code){case s.FileError.
NOT_FOUND_ERR:m('${k(g)}: ${k(h)}: No such file or directory<br>');break;case s.
FileError.INVALID_STATE_ERR:m('${k(g)}: ${k(h)}: Not a directory<br>');break;cas
e s.FileError.INVALID_MODIFICATION_ERR:m('${k(g)}: ${k(h)}: File already exists<
br>');break;default:q(i);break;}} MB([ g='default']){if(g==null||g=='default'){s
.window.localStorage.remove('theme');s.document.body.classes.clear();}else{s.doc
ument.body.classes.add(g);s.window.localStorage['theme']=g;}} SB( j){j.forEach((
g){n.createFile(g.name,exclusive:true).then(( i){i.createWriter().then(( h){h.on
Error.listen(q);h.write(g);},onError:q);},onError:q);});} kB( j, h,var t){n.getF
ile(h).then(( l){l.file().then((o){var g=new s.FileReader();g.onLoadEnd.listen((
BB)=>t(g.result));g.readAsText(o);},onError:q);},onError:(i){if(i.code==s.FileE
rror.INVALID_STATE_ERR){m('${k(j)}: ${k(h)}): is a directory<br>');}else if(i.co
de==s.FileError.NOT_FOUND_ERR){m('${k(j)}: ${k(h)}: No such file or directory<br
>');}else{q(i);}});} WB( g, h){JB.innerHtml='';} bB( i, j){var g=new StringBuffe
r();g.write('<div class="ls-files">');u.keys.forEach((h)=>g.write('${h}<br>'));g
.write('</div>');g.write('<p>Add files by dragging them from your desktop.</p>')
;m(g.toString());} oB( g, h){m("${version}");} UB( g, h){if(h.length>=1){var i=h
[0];kB(g,i,(j)=>m('<pre>${k(j)}</pre>'));}else{m('usage: ${k(g)} filename');}} V
B( i, j){var g=j.join(' ').trim();if(g.isEmpty){g='/';}n.getDirectory(g).then((
h){n=h;m('<div>${k(h.fullPath)}</div>');},onError:( l){FB(l,i,g);});} YB( g,var
h){m(new DateTime.now().toLocal().toString());} aB( g){var h=g[0].name;g.forEach
((i){if(i.name.length>h.length){h=i.name;}});var l=g.length<=3?'height: ${g.leng
th}em;':'${g.length~/3}em';var o="${h.length}em";var j=new StringBuffer();j.writ
e('<div class="ls-files" style="-webkit-column-width: ${o}; height: ${l}">');ret
urn j;} eB( AC, BC){ GB( g){if(g.length!=0){var h=aB(g);g.forEach((j){var HB=j.i
sDirectory?'folder':'file';var BB='<span class="${HB}">${k(j.name)}</span><br>';
h.write(BB);});h.write('</div>');m(h.toString());}}var i=[] ;var t=n.createReade
r(); l(){t.readEntries().then(( o){if(o.length==0){GB(i);}else{i.addAll(o);l();}
},onError:q);}l();} IB( t, g,[ j="", l=""]){if(g.length==0){return;}if(j.isEmpty
){t.createDirectory(g[0]).then((h){if(g.length!=0){g.removeAt(0);IB(h,g);}},onEr
ror:q);}else{var o=n.fullPath;n.getDirectory(j).then(( h){n=h;IB(n,g);n.getDirec
tory(o).then(( h)=>n=h,onError:( i)=>FB(i,l,o));},onError:( i)=>FB(i,l,j));}} fB
( j, h){var o=false;var t=h.indexOf('-p');if(t!=-1){h.removeAt(t);o=true;}if(h.l
ength==0){m('usage: ${k(j)} [-p] directory<br>');return;}for(int l=0;l<h.length;
l++ ){var i=h[l];if(o){var g=i.split('/');if(g[0]=='.'||g[0]==''){g.removeAt(0);
}if(i[0]=="/"){IB(n,g,i[0],j);}else{IB(n,g);}}else{n.createDirectory(i,exclusive
:true).then((CC){},onError:( BB){FB(BB,j,i);});}}} QB( l, h, j){if(h.length!=2){
m('usage: ${k(l)} source target<br>' '
${k(l)}' ' source directory/');return;}var o=h[0];var g=h[1];if(g[g.length-1].en
dsWith('/')){n.getDirectory(o).then(( t){var HB=['.','./','..','../','/'].indexO
f(g)!=-1?false:true;if(HB){n.createDirectory(g).then(( i)=>j(t,i),onError:q);}el
se{n.getDirectory(g).then(( i)=>j(t,i),onError:q);}},onError:q);}else{n.getFile(
o).then(( BB){BB.getParent().then(( GB)=>j(BB,GB,g),onError:q);},onError:q);}} X
B( j, l){QB(j,l,(h,g,[i=""]){if(i.isEmpty){h.copyTo(g);}else{h.copyTo(g,i);}});}
gB( j, l){QB(j,l,(h,g,[i=""]){if(i.isEmpty){h.moveTo(g);}else{h.moveTo(g,i);}})
;} hB( g, i){if(i.length==0){m('usage: ${k(g)} [filenames]');return;}i.forEach((
h){open(g,h,( j){s.window.open(j.toUrl(),'${h}');});});} open( i, g,j){n.getFile
(g).then(j,onError:(h){if(h.code==s.FileError.NOT_FOUND_ERR){m('${k(i)}: ${k(g)}
: No such file or directory<br>');}else{q(h);}});} jB( g, h){m(k(n.fullPath));}
lB( t, g){var o=false;var BB=['-r','-f','-rf','-fr'];BB.forEach((l){var h=g.inde
xOf(l);if(h!=-1){while (h!=-1){g.removeAt(h);h=g.indexOf(l);}o=true;}});g.forEac
h((i){n.getFile(i).then((GB){GB.remove().then((CC){},onError:q);},onError:(j){if
(o&&j.code==s.FileError.TYPE_MISMATCH_ERR){n.getDirectory(i).then(( HB)=>HB.remo
veRecursively().then((CC){},onError:q),onError:q);}else if(j.code==s.FileError.I
NVALID_STATE_ERR){m('${k(t)}: ${k(i)}: is a directory<br>');}else{q(j);}});});}
mB( i, j){j.forEach((h){n.getDirectory(h).then((l){l.remove().then((CC){},onErro
r:(g){if(g.code==s.FileError.INVALID_MODIFICATION_ERR){m('${k(i)}: ${k(h)}: Dire
ctory not empty<br>');}else{q(g);}});},onError:(g)=>FB(g,i,h));});} nB( h, i){va
r g=i.join(' ').trim();if(g.isEmpty){m('usage: ${k(h)} ${k(PB.toString())}');}el
se{if(PB.contains(g)){MB(g);}else{m('Error - Unrecognized theme used');}}} pB( g
, h){m('${k(s.document.title)}' ' - By: Eric Bidelman <ericbidelman@chromium
.org>,' ' Adam Singer <financeCoding@gmail.com>');} m( g){JB.insertAdja
centHtml('beforeEnd',g);}}class zB{var DB; run(){DB=new RB('#input-line','#outpu
t','#cmdline');DB.dB(false,1024*1024);if(!s.window.location.hash.isEmpty){var h=
s.window.location.hash.substring(1,s.window.location.hash.length).split('=')[1];
DB.MB(h);}else if(s.window.localStorage.containsKey('theme')){DB.MB(s.window.loc
alStorage['theme']);}var g=s.document.body;g.onDragEnter.listen(onDragEnter);g.o
nDragOver.listen(onDragOver);g.onDrop.listen(onDrop);} onDragEnter( g){g.stopPro
pagation();g.preventDefault();var h=g.target;h.classes.add('dropping');} onDragO
ver( g){g.stopPropagation();g.preventDefault();g.dataTransfer.dropEffect='copy';
} onDrop( g){g.stopPropagation();g.preventDefault();var h=g.target;h.classes.rem
ove('dropping');DB.SB(g.dataTransfer.files);DB.m('<div>File(s) added!</div>');}}
main(){new zB().run();} k( g){return g.replaceAll("&","&").replaceAll("<","
<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'");
} |