{
//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;
}
}