Autopatcher

09/29/2011 09:52 BaussHacker#1
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

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);
            }
        }
09/29/2011 09:57 12k#2
Looks good to me. Other then not saving the current version, which u may or may not of forgot to do. One thing you may look into is monitoring if the patch is cancelled in the middle or not. I havent seen anyone do it yet, just a idea. Could cause problems otherwise.
09/29/2011 10:00 BaussHacker#3
Quote:
Originally Posted by 12k View Post
Looks good to me. Other then not saving the current version, which u may or may not of forgot to do. One thing you may look into is monitoring if the patch is cancelled in the middle or not. I havent seen anyone do it yet, just a idea. Could cause problems otherwise.
Yeah, not done. Was more the download part/version check, but thanks for the head up ^^
09/29/2011 10:09 12k#4
You just going to use self-extracting archives and run them when their done downloading i take it? Such as

Quote:
private void HandleComplete(object sender, AsyncCompletedEventArgs e)
{
progressBar1.Value = 0;
IsDone = false;
Process.Start(Environment.CurrentDirectory + CurrentVersion + ".exe");
}
09/29/2011 10:15 BaussHacker#5
Quote:
Originally Posted by 12k View Post
You just going to use self-extracting archives and run them when their done downloading i take it? Such as
I have done the other part. If they are closing in the middle of a download, then it will ask them if they are sure they wanna cancel it and if they cancel it, then it will go one patch back. Forgot about that part, thanks ^^