Ejemplo n.º 1
0
        private void Work()
        {
            while (!queue.IsEmpty)
            {
                Item f;
                if (queue.TryDequeue(out f))
                {
                    FileInfo file = new FileInfo(this.form.txtNWNInstall.Text.Substring(0, (this.form.txtNWNInstall.Text.Length - 10)) + "\\" + f._file);
                    string addr = (repo.Address +  f._file).Replace('\\', '/');

                    if (File.Exists(file.FullName))
                    {
                        //prepare the check.
                        CRC32 crcCheck = new CRC32();

                        //assign the status.
                        f.row.Cells[1].Value = "Checking";

                        //create the string for the hash.
                        string hash = "";

                        //open the file
                        using (Stream reader = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
                        {
                            //calculate the hash and go though each return byte.
                            foreach (byte b in crcCheck.ComputeHash(reader))
                            {
                                //foreach bye add the value to the string.
                                hash += b.ToString("x2").ToLower();
                            }
                        }

                        //check if the hash matches
                        if (hash == f._crc)
                        {
                            f.row.Cells[1].Value = "Not Updated";
                        }
                        //if the file dosen't match add it to download.
                        else
                        {
                            //assign the status.
                            f.row.Cells[1].Value = "Downloading";

                            //mark the file for download.
                            this.download(file, addr, f);
                        }
                    }
                    else
                    {
                        //assign the status.
                        f.row.Cells[1].Value = "Downloading";

                        //mark the file for download.
                        this.download(file, addr, f);
                    }

                }
            }

            if (queue.IsEmpty && threads.FindAll(Thread => Thread.IsAlive).Count == 1)
            {
                this.form.BeginInvoke((MethodInvoker)delegate()
                {
                    this.form.btnUpdate.Enabled = true;
                    this.form.checkedListBox1.Enabled = true;
                    this.form.btnToggleWindow.Enabled = true;
                });
            }
        }