Example #1
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            _speed_ticks++;
            int speed_prc = StatusBar.Value1 - _speed_last_perc;

            _speed_last_perc = StatusBar.Value1;
            long bytespertick = Convert.ToInt64(Math.Round((Convert.ToDouble(speed_prc) / 100) * update_size.B, 0));

            speed = new bytesconvert(bytespertick * 4);
        }
Example #2
0
        public UpdateForm(GitHubRelease release, Configuration configuration, LauncherForm f)
        {
            rls            = release;
            _configuration = configuration;
            InitializeComponent();
            LoadLocalization();
            update_url  = new Uri(@"https://github.com/dommilosz/MLauncher/releases/download/" + rls.Tag + "/MLauncher.exe");
            newpatch    = Application.ExecutablePath.Replace(".exe", "_" + rls.Tag + ".exe");
            update_size = GetUpdateSize();
            batchURL    = new Uri(@"https://github.com/dommilosz/MLauncher/releases/download/v0.2.0/Update.bat");
            autocheckCheckBox.Checked = _configuration.ApplicationConfiguration.CheckLauncherUpdates;
            Text = $"Found update: {release.Name}";

            changelogBox.Text  = $"Installed Version : {Application.ProductVersion}" + Environment.NewLine;
            changelogBox.Text += $"Latest Version : {rls.Tag}" + Environment.NewLine;
            changelogBox.Text += $"Update Size : {update_size.MB}MB  ({update_size.B} bytes)" + Environment.NewLine;
            changelogBox.Text += $"{release.Description}";
            form = f;
        }
Example #3
0
        public void DownloadUpdates()
        {
            void AppendLOG(string str)
            {
                if (changelogBox.InvokeRequired)
                {
                    changelogBox.Invoke(new Action <string>(AppendLOG), str);
                }
                else
                {
                    changelogBox.AppendText(str);
                }
            }

            void SetProgress(int value)
            {
                if (StatusBar.InvokeRequired)
                {
                    StatusBar.Invoke(new Action <int>(SetProgress), value);
                }
                else
                {
                    StatusBar.Value1 = value;
                }
            }

            void SetStatusText(string str)
            {
                if (StatusBar.InvokeRequired)
                {
                    StatusBar.Invoke(new Action <string>(SetStatusText), str);
                }
                else
                {
                    StatusBar.Text = str;
                }
            }

            void AppStatusText(string str)
            {
                str = StatusBar.Text + str;
                SetStatusText(str);
            }

            string exec    = Application.ExecutablePath.Replace(Application.StartupPath, "");
            string execnew = newpatch.Replace(Application.StartupPath, "");

            exec    = exec.TrimStart(@"\".ToCharArray()[0]);
            execnew = execnew.TrimStart(@"\".ToCharArray()[0]);
            WebClient w = new WebClient();

            w.DownloadProgressChanged += (s, e) =>
            {
                string form_speed = "";
                if (speed.Kb >= 1024)
                {
                    form_speed = ($"{speed.Mb} Mb/s");
                }
                else
                {
                    form_speed = ($"{speed.Kb} Kb/s");
                }
                SetProgress(e.ProgressPercentage);
                SetStatusText($"Downloading    {Math.Round((Convert.ToDouble(e.ProgressPercentage) / 100) * update_size.MB, 2)}/{update_size.MB} MB       {form_speed}");
            };
            w.DownloadFileCompleted += (s, e) =>
            {
                int          download_time = (_speed_ticks * 4);
                bytesconvert speed         = new bytesconvert((update_size.b) / download_time);
                string       speed_form    = "";
                if (speed.Kb >= 1024)
                {
                    speed_form = $"{speed.Mb} Mb/s";
                }
                else
                {
                    speed_form = $"{speed.Kb} Kb/s";
                }
                AppendLOG(Environment.NewLine + $"Average Download Speed : {speed_form}");
                string args = "\"" + execnew + "\" \"" + exec + "\"";
                AppendLOG(Environment.NewLine + $"Downloading Update Installer From : {batchURL}");
                w.DownloadFile(batchURL, Application.StartupPath + "Update.bat");
                AppendLOG(Environment.NewLine + $"Starting Installer : Update.bat WITH ARGS : {args}");
                Thread.Sleep(2000);
                Process.Start(Application.StartupPath + "Update.bat", args);
                Application.Exit();
            };
            AppendLOG(Environment.NewLine + $"Downloading Update From : {update_url}");
            w.DownloadFileAsync(update_url, newpatch);
        }