сделать патчер / скачать и запустить исполняемые файлы беззвучно - PullRequest
0 голосов
/ 22 марта 2012

хорошо, я создал программу, которая должна также исправлять клиента.Вместо того, чтобы загружать каждый файл и перезаписывать, я хотел бы сделать самораспаковывающийся файл WinRAR, затем запустить его в режиме без вывода сообщений и распаковать по указанному пути.до сих пор это то, что, я думаю, мне понадобится

{
  //check for patch(client)(server).txt file
  //download the file
  MessageBox.Show("working", 
                  "Patcher", 
                  MessageBoxButtons.OK, 
                  MessageBoxIcon.Information);
  //check file for needs & write to string
  //delete file
  //implement progress bar steps by files needed
  //find if file is already in directory
  //if not then download
  //finish and show msg (patcher will now extract)
  //msg ok resets progress bar
  //set steps for files needed
  //extract resources    <---
  //overwrite text file
  //finish and show msg (Patch finished)
}

Я могу выполнить все проверки и загрузки, но что касается извлечения ресурсов, я не работаю, также просмотрите и посмотрите, не пропустил ли я какие-либо проверки.

редактировать: я закончил все, кроме кодов извлечения, проверьте для подтверждения

    public void extractrar(string fileneeded)
    {
        string realfileneeded = "ini\\update\\" + fileneeded;

        count++;
    }

    public void extractexe(string fileneeded)
    {
        string realfileneeded = "ini\\update\\" + fileneeded;

        count++;
    }

    public void downloadfile(string fileneeded)
    {
        //find if file is already in directory
            if (!File.Exists("ini\\update\\" + fileneeded))
            {
                webClient.DownloadFile("http://webaddress.com/folder/" + fileneeded, "ini\\update\\" + fileneeded);
                count++;
                progressBar1.PerformStep();
                if (!fileneeded.Contains(".rar") || !fileneeded.Contains(".exe"))
                {
                    File.Move("ini\\update\\" + fileneeded, fileneeded);
                }
            }
            else
            { count++;
progressbar1.performstep();
}



    private void button6_Click(object sender, EventArgs e)//patcher
    {
        progressBar1.Value = 0;
        progressadvance(2); 
            if (File.Exists("version.dat") == true)//check for version file
            {

                TextReader reader1 = File.OpenText("version.dat");
                int x = int.Parse(reader1.ReadLine());
                int clientVer = x;
                reader1.Close();
                progressadvance(2);

                webClient.DownloadFile("http://divinecreation.no-ip.info/patchCO5165/update.dat", "ini\\update.dat");
                progressadvance(2);

                TextReader reader2 = File.OpenText("ini\\update.dat");
                int y = int.Parse(reader2.ReadLine());
                int serverVer = y;
                reader2.Close();
                progressadvance(2);

                File.Delete("ini\\update.dat");
                progressadvance(2);

                if (clientVer < serverVer)
                {
                    string NeedPath = Application.StartupPath + "ini\\update\\patch(" + clientVer + ")(" + serverVer + ").txt";
                    string smallNeedPath = "ini\\update\\patch(" + clientVer + ")(" + serverVer + ").txt";

                    if (MessageBox.Show("Possible patch, Continue?", "Patcher", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.Yes)
                    {
                        progressBar1.Value = 0;
                        //download the file
                        webClient.DownloadFile("http://divinecreation.no-ip.info/patchCO5165/patch(" + clientVer + ")(" + serverVer + ").txt", smallNeedPath);
                        progressadvance(2);

                        //check for patch(client)(server).txt file
                        if (File.Exists(smallNeedPath))
                        {
                            //check file for needs
                            TextReader reader3 = File.OpenText(smallNeedPath);
                            string z = (reader3.ReadLine());
                            string[] bits = z.Split(' ');
                            reader3.Close();
                            progressadvance(2);


                            //delete file
                            File.Delete(smallNeedPath);
                            progressadvance(2);

                            //implement progress steps by files needed
                            progressBar1.Value = 0;
                            progressBar1.Maximum = (3 + bits.Length);

                            //download needed files
                            while (count < bits.Length)
                            {
                                downloadfile(bits[count]);
                            }

                            //reset counter
                            count = 0;
                            progressadvance(1);

                            //finish and show msg (patcher will now extract)
                            //msg ok resets progress bar
                            if (MessageBox.Show("Neccesarry files downloaded, preparing extraction check", "Patcher", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.OK)
                            {

                                //set steps for files needed
                                progressBar1.Value = 0;

                                //find if files needing extraction
                                while (bits[count].Contains(".rar"))
                                {
                                    //extract resources via rar
                                    extractrar(bits[count]);
                                }

                                //find if files needing execution
                                while (bits[count].Contains(".exe"))
                                {
                                    //extract resources via exe
                                    extractexe(bits[count]);
                                }

                                //overwrite text file
                                using (StreamWriter newTask = new StreamWriter("version.dat", false))
                                {
                                    newTask.WriteLine(serverVer.ToString());
                                }

                                //finish and show msg (Patch finished)
                                MessageBox.Show("client patched successfully", "Patcher", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Error during patch [please allow downloaded files]", "Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            progressBar1.Value = 0;

                        }
                    }
                    else
                    {
                        progressBar1.Value = 0;
                    }

                }
                else
                {
                    MessageBox.Show("Your client is already patched", "Patcher", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    progressBar1.PerformStep();
                    progressBar1.PerformStep();
                }
        }
            else if (MessageBox.Show("Please create a Version.dat file with your client version", "Patcher", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Retry)
            {
                progressBar1.Value = 0;
                button6_Click(sender, e);
            }
            else
            {
                progressBar1.Value = 0;
            }

    }
...