So I coded an autopatcher, not sure if it will work or what. Haven't tested it yet as I'm in college, but if someone would look my coder over and tell me what I could do better or if there is something wrong?
Thanks :D
Thanks :D
Code:
int CurrentVersion = 1001;
string loc = "";
public Form1()
{
InitializeComponent();
}
bool IsDone = false;
private void StartPatching()
{
CurrentVersion++;
WebClient cl = new WebClient();
cl.DownloadFile(loc + "\\" + CurrentVersion + ".exe", Environment.CurrentDirectory + "\\" + CurrentVersion + ".exe");
cl.DownloadProgressChanged += new DownloadProgressChangedEventHandler(HandleProgress);
cl.DownloadFileCompleted += new AsyncCompletedEventHandler(HandleComplete);
}
private void HandleProgress(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value += e.ProgressPercentage;
}
private void HandleComplete(object sender, AsyncCompletedEventArgs e)
{
progressBar1.Value = 0;
IsDone = false;
}
private void Form1_Load(object sender, EventArgs e)
{
IniFile I = new IniFile("Config.ini", "Configuration");
CurrentVersion = I.ReadInt32(I.Section, "Version", 1001);
loc = I.ReadString(I.Section, "PatchingLocation", "");
webBrowser1.Navigate(I.ReadString(I.Section, "News", ""));
try
{
WebClient cl = new WebClient();
int RealVersion = int.Parse(cl.DownloadString(I.ReadString(I.Section, "VersionUrl", "")));
while (RealVersion > CurrentVersion)
{
if (!IsDone)
{
IsDone = true;
StartPatching();
}
}
button1.Enabled = true;
}
catch
{
MessageBox.Show("Could not connect to the autopatching server. Please check your network or settings.");
Environment.Exit(0);
}
}