예제 #1
0
        private void UpdateThread(object obj)
        {
            //ThreadParam ap = (ThreadParam)obj;
            Delegate h = new DelegateShowProcess(ShowProcess);

            try
            {
                uint ret;
                if ((bin_filename != null) && (File.Exists(bin_filename)))
                {
                    ret = DeviceInterfaceDll.SR_Update(out uint bin_handle, id, 0, bin_filename);
                    if (ret == DeviceInterfaceDll.RC_OK)
                    {
                        try
                        {
                            int        count = 0;
                            byte[]     bdata = new byte[1024];
                            FileStream fs    = File.OpenRead(bin_filename);
                            if (fs != null)
                            {
                                int rlen;
                                do
                                {
                                    rlen = fs.Read(bdata, 0, bdata.Length);
                                    if (rlen > 0)
                                    {
                                        count += rlen;
                                        DeviceInterfaceDll.SR_UpdateData(bin_handle, bdata, rlen);
                                        this.Invoke(h, bin_filename, (int)(100 * count / fs.Length));
                                    }
                                    //System.Windows.Forms.Application.DoEvents();
                                }while (rlen >= bdata.Length);
                            }
                            fs.Close();
                        }
                        finally
                        {
                            DeviceInterfaceDll.SR_UpdateClose(bin_handle);
                        }
                    }
                }

                Thread.Sleep(500);

                if ((pak_filename != null) && (File.Exists(pak_filename)))
                {
                    ret = DeviceInterfaceDll.SR_Update(out uint pak_handle, id, 1, pak_filename);
                    if (ret == DeviceInterfaceDll.RC_OK)
                    {
                        try
                        {
                            int        count = 0;
                            byte[]     bdata = new byte[1024];
                            FileStream fs    = File.OpenRead(pak_filename);
                            if (fs != null)
                            {
                                int rlen;
                                do
                                {
                                    rlen = fs.Read(bdata, 0, bdata.Length);
                                    if (rlen > 0)
                                    {
                                        count += rlen;
                                        DeviceInterfaceDll.SR_UpdateData(pak_handle, bdata, rlen);
                                        this.Invoke(h, pak_filename, (int)(100 * count / fs.Length));
                                    }
                                }while (rlen >= bdata.Length);

                                //wait update 200
                            }
                            //else
                            //{
                            //    Thread.Sleep(0);
                            //}
                            fs.Close();
                        }
                        finally
                        {
                            DeviceInterfaceDll.SR_UpdateClose(pak_handle);
                        }
                    }
                }

                DeviceInterfaceDll.SR_Apply(id);
            }
            finally
            {
                this.Invoke(h, "", 101);
            }
        }
예제 #2
0
        private void UpdateThread(object obj)
        {
            ThreadParam ap = (ThreadParam)obj;
            Delegate    h  = new DelegateShowProcess(ShowProgress);

            try
            {
                uint ret;
                uint handle;
                ret = DeviceInterfaceDll.SR_Update(out handle, ap.id, 0, ap.bin_filename);
                if (ret == DeviceInterfaceDll.RC_OK)
                {
                    try
                    {
                        int        count = 0;
                        byte[]     bdata = new byte[1024];
                        FileStream fs    = File.OpenRead(ap.bin_filename);
                        if (fs != null)
                        {
                            int rlen;
                            do
                            {
                                rlen = fs.Read(bdata, 0, bdata.Length);
                                if (rlen > 0)
                                {
                                    count += rlen;
                                    DeviceInterfaceDll.SR_UpdateData(handle, bdata, rlen);
                                    this.Invoke(h, ap.bin_filename, (int)(100 * count / fs.Length));
                                }
                            }while (rlen >= bdata.Length);
                        }
                    }
                    finally
                    {
                        DeviceInterfaceDll.SR_UpdateClose(handle);
                        //this.Invoke(h, "", 101);
                    }
                }

                ret = DeviceInterfaceDll.SR_Update(out uint pak_handle, ap.id, 1, ap.pak_filename);
                if (ret == DeviceInterfaceDll.RC_OK)
                {
                    try
                    {
                        int        count = 0;
                        byte[]     bdata = new byte[1024];
                        FileStream fs    = File.OpenRead(ap.pak_filename);
                        if (fs != null)
                        {
                            int rlen;
                            do
                            {
                                rlen = fs.Read(bdata, 0, bdata.Length);
                                if (rlen > 0)
                                {
                                    count += rlen;
                                    DeviceInterfaceDll.SR_UpdateData(pak_handle, bdata, rlen);
                                    this.Invoke(h, ap.pak_filename, (int)(100 * count / fs.Length));
                                }
                            }while (rlen >= bdata.Length);
                        }
                    }
                    finally
                    {
                        DeviceInterfaceDll.SR_UpdateClose(handle);
                    }
                }
            }
            finally
            {
                this.Invoke(h, "", 101);
            }
        }