Пример #1
0
        private void PerformUpdates(string[] updates)
        {
            List <string> updated = new List <string>();

            if (updates.Contains(ExtensionManager) && updates.Length != 2)
            {
                SelfUpdate(updates);
            }

            for (int i = 0; i < updates.Length / 2; i++)
            {
                UpdatesLabel.Invoke((Action)(() => { UpdatesLabel.Text = string.Format("Performing Update {0} of {1}, {2}.", i + 1, updates.Length / 2, updates[i * 2].Substring(updates[i * 2].LastIndexOf('.') + 1)); }));

                try
                {
                    if (IsAdminRole() && i == 0 && !updates[i].ToLowerInvariant().Contains("plugins"))
                    {
                        UpdateApp(updates[i * 2], updates[(i * 2) + 1]);
                    }
                    else
                    {
                        UpdatePackage(updates[i * 2], updates[(i * 2) + 1]);
                    }
                    updated.Insert(0, updates[i * 2]);
                    _add.AddChecked(updated, uxUpdates);
                }
                catch (Exception)
                {
                }
            }

            UpdatesLabel.Invoke((Action)(() => { UpdatesLabel.Text = "All Updates Completed"; }));
        }
Пример #2
0
        private void SelfUpdate(string[] updates)
        {
            List <string> updated    = new List <string>();
            var           updateList = updates.ToList();

            for (int i = 0; i < updates.Length / 2; i++)
            {
                if (updates[i * 2] != ExtensionManager)
                {
                    continue;
                }

                UpdatesLabel.Invoke((Action)(() => { UpdatesLabel.Text = string.Format("Performing Update {0} of {1}, {2}.", 1, 1, updates[i * 2].Substring(updates[i * 2].LastIndexOf('.') + 1)); }));

                try
                {
                    // perform update
                    UpdatePackage(updates[i * 2], updates[(i * 2) + 1]);
                    updated.Insert(0, updates[i * 2]);
                    _add.AddChecked(updated, uxUpdates);

                    // copy new updater to temp location
                    var      updaterPath = Path.GetDirectoryName(_packagePath);
                    string[] files       = Directory.GetFiles(_packagePath, "Updater.exe", SearchOption.AllDirectories);
                    File.Copy(files[0], Path.Combine(updaterPath, "Updater(1).exe"), true);

                    // remove current update and save updates
                    updateList.RemoveRange(i * 2, 2);
                    File.WriteAllLines(Path.Combine(updaterPath, "updates.txt"), updateList);

                    // start new updater
                    Process updater = new Process
                    {
                        StartInfo =
                        {
                            FileName  = Path.Combine(updaterPath, "Updater(1).exe"),
                            Arguments = '"' + _appPath + '"'
                        }
                    };
                    updater.Start();
                    Application.Exit();
                }
                catch (Exception)
                {
                }
            }
        }