func init // adds using namespace sys.add_use('System.IO') sys.add_use('System.Text') sys.add_use('Mozilla.CharDet') // adds widget assembly sys.add_assembly('CharDet', 'CharDet.dll') // initialize instance sys.add_object(this.codename, 'UniversalDetector') // makes implementation of methods as properties sys._mtd_as_prop_init('UniversalDetector') this.setfield('bytes', 'bytes' + this.id) this.setfield('enc', 'enc' + this.id) this.setfield('reader', 'reader' + this.id) end func doDetect(data) blk.println(this.codename, '.Reset();') .println('byte[] ', this.bytes, ' = File.ReadAllBytes(', d("FileName"), ');') .println('if (', this.codename, '.HandleData(', this.bytes, ') == 0) {').inc() .println(this.codename, '.DataEnd();') .println('string ', this.enc, ' = ', this.codename, '.DetectedCharsetName;') .println('if (!String.IsNullOrEmpty(', this.enc, ')) {').inc() event("onResult", 'Encoding.GetEncoding(' + this.enc + ')') blk.dec().println('} else {').inc() .println('using (StreamReader ', this.reader, ' = new StreamReader(', d("FileName"), ', true)) {').inc() .println(this.reader, '.Peek();') event("onResult", this.reader + '.CurrentEncoding') blk.dec().println('}') .dec().println('}') .dec().println('}') end