Ejemplo n.º 1
0
            private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    if (!TryNextURL((int)e.UserState))
                    {
                        InvokeUpdateInfoCallbacksAndClear(null, null);
                    }
                }
                else
                {
                    AppInfo info = AppInfo.FromJson(e.Result);
                    if (info == null)
                    {
                        if (!TryNextURL((int)e.UserState))
                        {
                            InvokeUpdateInfoCallbacksAndClear(null, null);
                        }
                        return;
                    }

                    if (!LauncherSettings.AppID.Equals(info.appId))
                    {
                        MessageBox.Show("Invalid update mirror: appID does not match local value!", "An error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        if (!TryNextURL((int)e.UserState))
                        {
                            InvokeUpdateInfoCallbacksAndClear(null, null);
                        }
                        return;
                    }
                    InvokeUpdateInfoCallbacksAndClear(info, UpdateHost.GetUpdateHosts()[(int)e.UserState]);
                }
            }
Ejemplo n.º 2
0
 public UpdateInfoDownloadHelper(Action <UpdateInfo, UpdateHost, int> callback, UpdateHost appInfoSource, double[] version, int i)
 {
     this.multiUpdateCallback = callback;
     this.appInfoSource       = appInfoSource;
     this.versions            = version;
     this.index = i;
 }
Ejemplo n.º 3
0
        private List <UpdateTask> GetOldFileTasks(AppInfo appInfo, UpdateInfo info, UpdateHost updateInfoSource, FileIndex index)
        {
            List <UpdateTask> updateTasks = new List <UpdateTask>();

            for (int i = 0; i < index.files.Count; i++)
            {
                string curFile      = index.files[i];
                string curLocalFile = InstallationSettings.InstallationFolder + '/' + curFile;

                if (info.fileChecksums.ContainsKey(curFile))
                {
                    if (File.Exists(curLocalFile))
                    {
                        string curHash = FileHasher.GetFileChecksum(curLocalFile);
                        string updatedHash;
                        info.fileChecksums.TryGetValue(curFile, out updatedHash);

                        if (!curHash.Equals(updatedHash))
                        {
                            updateTasks.Add(new UpdateTask(TaskType.DownloadReplacementFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                        }
                    }
                    else
                    {
                        updateTasks.Add(new UpdateTask(TaskType.DownloadNewFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                    }
                }
                else
                {
                    updateTasks.Add(new UpdateTask(TaskType.DeleteFile, curLocalFile));
                }
            }
            return(updateTasks);
        }
Ejemplo n.º 4
0
 public void RetrieveUpdateInfo(AppInfo appInfo, UpdateHost appInfoSource, double version, Action <UpdateInfo, UpdateHost> callback)
 {
     if (client.IsBusy)
     {
         throw new Exception("Cannot execute multiple updateinfo requests at once.");
     }
     client.DownloadStringAsync(appInfoSource.GetVersionInfoURL(appInfo, version), new UpdateInfoDownloadHelper(callback, appInfoSource, version));
 }
Ejemplo n.º 5
0
 private void InvokeUpdateInfoCallbacksAndClear(AppInfo result, UpdateHost uri)
 {
     foreach (Action <AppInfo, UpdateHost> callback in appInfoCallbacks)
     {
         callback.Invoke(result, uri);
     }
     appInfoCallbacks.Clear();
 }
Ejemplo n.º 6
0
        private UpdateTask[] GetUpdaterTasks(AppInfo appInfo, UpdateInfo info, UpdateHost updateInfoSource, FileIndex index)
        {
            List <UpdateTask> updateTasks = new List <UpdateTask>();

            updateTasks.AddRange(GetOldFileTasks(appInfo, info, updateInfoSource, index));
            updateTasks.AddRange(GetNewFileTasks(appInfo, info, updateInfoSource, index));
            return(updateTasks.ToArray());
        }
Ejemplo n.º 7
0
 public void InvokeCallback(UpdateInfo info, UpdateHost source)
 {
     if (IsSingleUpdate)
     {
         singleUpdateCallback.Invoke(info, source);
     }
     else
     {
         multiUpdateCallback.Invoke(info, source, index);
     }
 }
Ejemplo n.º 8
0
            private bool TryNextURL(int currentIndex)
            {
                int nextIndex = (currentIndex) + 1;

                if (nextIndex < UpdateHost.GetUpdateHosts().Length)
                {
                    client.DownloadStringAsync(UpdateHost.GetUpdateHosts()[nextIndex].AppInfoURL, nextIndex);
                    return(true);
                }
                return(false);
            }
Ejemplo n.º 9
0
        public void ApplyUpdate(AppInfo appInfo, UpdateInfo info, UpdateHost updateInfoSource)
        {
            string lockFile = InstallationSettings.InstallationFolder + "/Updater.lock";

            if (File.Exists(lockFile))
            {
                throw new Exception("Could not update: the application folder is already locked by another updater instance.");
            }
            else
            {
                File.Create(lockFile).Close();
            }

            TriggerProgressEvent(0, "Calculating updater tasks");

            FileIndex index = FileIndex.Deserialize(InstallationSettings.InstallationFolder + "/UpdateIndex.dat");

            UpdateTask[]      tasks       = GetUpdaterTasks(appInfo, info, updateInfoSource, index);
            List <UpdateTask> failedTasks = RunTasks(tasks, true, 10);

            TriggerProgressEvent(percentageDone, "Retrying failed tasks");
            for (int i = 0; i < failedTasks.Count; i++)
            {
                UpdateTask task = failedTasks[i];
                try {
                    task.Run();
                } catch (WebException ex) {
                    if (MessageBox.Show("Updater could not download file: " + ex.Message + "\r\n(" + ex.Data["Target"] + ")", "Failed to download file", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error).Equals(DialogResult.Retry))
                    {
                        i--; //Retry
                    }
                    else
                    {
                        Application.Exit();
                    }
                } catch (UnauthorizedAccessException ex) {
                    if (MessageBox.Show("Updater could access file or folder: " + ex.Message + "\r\n(" + ex.Data["Target"] + ")", "Failed to download file", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error).Equals(DialogResult.Retry))
                    {
                        i--; //Retry
                    }
                    else
                    {
                        Application.Exit();
                    }
                }
            }
            TriggerProgressEvent(98, "Updating local file index");

            index = new FileIndex(index.appID);
            index.applicationVersion = info.version;
            index.files.AddRange(info.fileChecksums.Keys);
            index.Serialize(InstallationSettings.InstallationFolder + "/UpdateIndex.dat");
            File.Delete(lockFile);
        }
        public SingleUpdateDetailsForm(Updater updater, AppInfo appInfo, UpdateHost updateHost, double targetVersion)
        {
            this.updater       = updater;
            this.appInfo       = appInfo;
            this.updateHost    = updateHost;
            this.targetVersion = targetVersion;
            InitializeComponent();

            this.Text           = LauncherLocale.Current.Get("Updater.Single.Title");
            detailsTextBox.Text = LauncherLocale.Current.Get("Updater.Single.NotesPlaceholder");
            cancelButton.Text   = LauncherLocale.Current.Get("Updater.Single.CancelButton");
            updateButton.Text   = LauncherLocale.Current.Get("Updater.Single.ApplyButton");
        }
Ejemplo n.º 11
0
 public void RetrieveUpdateInfos(AppInfo appInfo, UpdateHost appInfoSource, double[] versions, Action <UpdateInfo, UpdateHost, int> callback)
 {
     if (client.IsBusy)
     {
         throw new Exception("Cannot execute multiple updateinfo requests at once.");
     }
     for (int i = 0; i < versions.Length; i++)
     {
         WebClient curClient = new WebClient();
         curClient.DownloadStringCompleted += client_DownloadStringCompleted;
         curClient.DownloadStringAsync(appInfoSource.GetVersionInfoURL(appInfo, versions[i]), new UpdateInfoDownloadHelper(callback, appInfoSource, versions, i));
     }
 }
Ejemplo n.º 12
0
        public MultiUpdateDetailsForm(Updater updater, AppInfo appInfo, UpdateHost hostURL, double[] targetVersions)
        {
            this.updater        = updater;
            this.appInfo        = appInfo;
            this.hostURL        = hostURL;
            this.targetVersions = targetVersions;
            updateInfos         = new UpdateInfo[targetVersions.Length];
            InitializeComponent();

            this.Text      = LauncherLocale.Current.Get("Updater.Multi.Title");
            infoLabel.Text = LauncherLocale.Current.Get("Updater.Multi.InfoLabel");
            updateNotesDropdownLabel.Text = LauncherLocale.Current.Get("Updater.Multi.NotesDropDownLabel");
            updateNotesComboBox.Items.AddRange(targetVersions.ToList().ConvertAll <string>(d => VersionFormatter.ToString(d)).ToArray());
            detailsTextBox.Text = LauncherLocale.Current.Get("Updater.Multi.NotesPlaceholder");
            cancelButton.Text   = LauncherLocale.Current.Get("Updater.Multi.CancelButton");
            updateButton.Text   = LauncherLocale.Current.Get("Updater.Multi.ApplyButton").Replace("${updateCount}", targetVersions.Length.ToString());
        }
Ejemplo n.º 13
0
        private List <UpdateTask> GetNewFileTasks(AppInfo appInfo, UpdateInfo info, UpdateHost updateInfoSource, FileIndex index)
        {
            List <UpdateTask> updateTasks = new List <UpdateTask>();

            for (int i = 0; i < info.fileChecksums.Keys.Count; i++)
            {
                string curFile      = info.fileChecksums.Keys.ElementAt(i);
                string curLocalFile = InstallationSettings.InstallationFolder + '/' + curFile;

                if (index.files.Contains(curFile))
                {
                    //Already handled file
                    continue;
                }

                if (File.Exists(curLocalFile))
                {
                    //File exists but is missing in index?
                    string curHash = FileHasher.GetFileChecksum(curLocalFile);
                    string updatedHash;
                    info.fileChecksums.TryGetValue(curFile, out updatedHash);
                    if (updatedHash.Equals(curHash))
                    {
                        continue;
                    }
                    else
                    {
                        updateTasks.Add(new UpdateTask(TaskType.DownloadReplacementFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                    }
                }
                else
                {
                    updateTasks.Add(new UpdateTask(TaskType.DownloadNewFile, updateInfoSource.GetFileURL(appInfo, info, curFile), curLocalFile));
                }
            }
            return(updateTasks);
        }
Ejemplo n.º 14
0
 public UpdateInfoDownloadHelper(Action <UpdateInfo, UpdateHost> callback, UpdateHost appInfoSource, double version)
 {
     this.singleUpdateCallback = callback;
     this.appInfoSource        = appInfoSource;
     this.versions             = new double[] { version };
 }
Ejemplo n.º 15
0
 public void RetrieveUpdateInfos(AppInfo appInfo, UpdateHost appInfoSource, double[] version, Action <UpdateInfo, UpdateHost, int> callback)
 {
     updateInfoHelper.RetrieveUpdateInfos(appInfo, appInfoSource, version, callback);
 }
Ejemplo n.º 16
0
 public void RetrieveAppInfo(Action <AppInfo, UpdateHost> callback)
 {
     client.DownloadStringCompleted += client_DownloadStringCompleted;
     appInfoCallbacks.Add(callback);
     client.DownloadStringAsync(UpdateHost.GetUpdateHosts()[0].AppInfoURL, 0);
 }