Ejemplo n.º 1
0
        public ResultStatus Upload(string fname, byte[] buff)
        {
            if (this.BeginFileProgress != null)
            {
                this.BeginFileProgress(this, new FileProgressEventArgs(fname, buff.Length, 0));
            }

            this.WriteLine($"f=open('{fname}', 'wb')");
            this.ReadLine();

            int    count = 0;
            string rec   = "";

            for (int i = 0; i < buff.Length;)
            {
                int len = Math.Min(32, buff.Length - i);
                this.WriteLine($"f.write({ BinaryString.BinToString(buff, i, len)})");
                i += len;

                rec = this.ReadLine();
                rec = this.ReadLine();
                int c = 0;
                if (int.TryParse(rec, out c))
                {
                    count += c;
                }
                else
                {
                    string error = this.ReadAllLines();
                    if (this.EndFileProgress != null)
                    {
                        this.EndFileProgress(this, new FileProgressEventArgs(fname, buff.Length, 0));
                    }

                    return(new ResultStatus(ResultStatus.Statuses.Error, error));
                }

                if (this.FileProgress != null)
                {
                    this.FileProgress(this, new FileProgressEventArgs(fname, buff.Length, count));
                }

                //Globals.Terminal.UpdateTerminal("", count.ToString(">>> # bytes written"));
                //Application.DoEvents();
            }

            this.WriteLine("f.flush()");
            rec = this.ReadLine();
            this.WriteLine("f.close()");
            rec = this.ReadLine();

            if (this.EndFileProgress != null)
            {
                this.EndFileProgress(this, new FileProgressEventArgs(fname, buff.Length, count));
            }

            return(new ResultStatus(ResultStatus.Statuses.Success, count.ToString("# bytes written")));
        }