Esempio n. 1
0
        public void DownloadUpdate(UpdateInfoArgs info, string dstPath)
        {
            try
            {
                // Create tmp file name
                string file = dstPath + ".tmp";

                // Download the file to the tmp path
                Client.DownloadFile(info.UpdateItem, file);

                if (File.Exists(dstPath))
                {
                    // Delete current
                    File.Delete(dstPath);
                }

                // Now that the file has downloaded we need to move it ot the dst path
                File.Move(file, dstPath);

                // Delete temp file
                File.Delete(file);

                // Invoke the update event
                UpdateComplete?.Invoke(this, info, dstPath);
            }
            catch (Exception ex)
            {
                throw new Exception("An error has occured while attempting to update. Please try again.");
            }
        }
Esempio n. 2
0
        public void forceDownload(string dst)
        {
            try
            {
                // Create a new client to download with...
                WebClient c = new WebClient();
                c.Proxy       = null;
                c.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);

                // Get the info for this updater
                string info = c.DownloadString(this.UpdateInfoUrl);

                // Try to get the headers
                string[] headers = info.Split('\n');

                // Create new instance of update info
                UpdateInfoArgs args = new UpdateInfoArgs();
                args.Version = double.Parse(headers[0]);
                args.Type    = headers[1].Replace("\r", "");

                // Get the update item (either database or zip file)
                args.UpdateItem = headers[2];

                // Nowe we have the update information... lets download the file
                if (File.Exists(dst))
                {
                    File.Delete(dst);
                }

                // download the file
                c.DownloadFile(args.UpdateItem, dst);

                // done with web client..
                c.Dispose();

                // Any errors here will cause program to crash... reisntallation is required at this point..
            }
            catch (Exception)
            {
            }
        }
Esempio n. 3
0
        private void Client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                // Try to get the headers
                string[] headers = e.Result.Split('\n');

                // Create new instance of update info
                UpdateInfoArgs args = new UpdateInfoArgs();
                args.Version = double.Parse(headers[0]);
                args.Type    = headers[1].Replace("\r", "");

                // Get the update item (either database or zip file)
                args.UpdateItem = headers[2];

                // Invoke the update found event
                UpdateFound?.Invoke(this, args);
            }
            catch (Exception ex)
            {
                //throw new Exception("Unable to download update information. Server is either down or your computer does not have internet access.");
            }
        }