Changeset 912
- Timestamp:
- 4/28/2009 2:09:09 PM (4 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Eraser/UpdateForm.cs (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Eraser/UpdateForm.cs
r903 r912 33 33 using Eraser.Util; 34 34 using System.Net.Cache; 35 using System.Globalization; 35 36 36 37 namespace Eraser … … 100 101 /// <param name="sender">The object triggering this event/</param> 101 102 /// <param name="e">Event argument.</param> 102 private void updateListDownloader_ProgressChanged(object sender, UpdateManager.ProgressEventArgs e)103 private void updateListDownloader_ProgressChanged(object sender, ProgressEventArgs e) 103 104 { 104 105 if (InvokeRequired) … … 107 108 throw new OperationCanceledException(); 108 109 109 Invoke(new EventHandler< UpdateManager.ProgressEventArgs>(110 Invoke(new EventHandler<ProgressEventArgs>( 110 111 updateListDownloader_ProgressChanged), sender, e); 111 112 return; … … 132 133 { 133 134 if (!(e.Error is OperationCanceledException)) 134 MessageBox.Show(this, e.Error.Message, S._("Eraser"), 135 MessageBoxButtons.OK, MessageBoxIcon.Error); 135 MessageBox.Show(this, e.Error.Message, S._("Eraser"), MessageBoxButtons.OK, 136 MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 137 RightToLeft == RightToLeft.Yes ? MessageBoxOptions.RtlReading : 0); 136 138 137 139 Close(); … … 143 145 144 146 //First list all available mirrors 145 Dictionary<string, UpdateManager.Mirror>.Enumerator iter = 146 updates.Mirrors.GetEnumerator(); 147 Dictionary<string, Mirror>.Enumerator iter = updates.Mirrors.GetEnumerator(); 147 148 while (iter.MoveNext()) 148 149 updatesMirrorCmb.Items.Add(iter.Current.Value); … … 185 186 updatesLv.Groups.Add(group); 186 187 187 foreach (Update Manager.Updateupdate in updates[key])188 foreach (UpdateInfo update in updates[key]) 188 189 { 189 190 //Skip if this update won't work on our current architecture. … … 211 212 { 212 213 MessageBox.Show(this, S._("There are no new updates or plugins available for " + 213 "Eraser."), S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Information); 214 "Eraser."), S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Information, 215 MessageBoxDefaultButton.Button1, 216 RightToLeft == RightToLeft.Yes ? MessageBoxOptions.RtlReading : 0); 214 217 Close(); 215 218 } … … 247 250 updatesPanel.Visible = false; 248 251 downloadingPnl.Visible = true; 249 List<UpdateManager.Update> updatesToInstall = 250 new List<UpdateManager.Update>(); 252 List<UpdateInfo> updatesToInstall = new List<UpdateInfo>(); 251 253 252 254 //Set the mirror 253 updates.SelectedMirror = (UpdateManager.Mirror) 254 updatesMirrorCmb.SelectedItem; 255 updates.SelectedMirror = (Mirror)updatesMirrorCmb.SelectedItem; 255 256 256 257 //Collect the items that need to be installed … … 263 264 downloadingLv.Items.Add(item); 264 265 265 updatesToInstall.Add((Update Manager.Update)item.Tag);266 updatesToInstall.Add((UpdateInfo)item.Tag); 266 267 } 267 268 else 268 uiUpdates.Remove((Update Manager.Update)item.Tag);269 uiUpdates.Remove((UpdateInfo)item.Tag); 269 270 270 271 //Then run the thread if there are updates. … … 285 286 { 286 287 updates.OnProgressEvent += downloader_ProgressChanged; 287 object downloadedUpdates = updates.DownloadUpdates((List<Update Manager.Update>)e.Argument);288 object downloadedUpdates = updates.DownloadUpdates((List<UpdateInfo>)e.Argument); 288 289 e.Result = downloadedUpdates; 289 290 } … … 299 300 /// <param name="sender">The object triggering this event/</param> 300 301 /// <param name="e">Event argument.</param> 301 private void downloader_ProgressChanged(object sender, UpdateManager.ProgressEventArgs e)302 private void downloader_ProgressChanged(object sender, ProgressEventArgs e) 302 303 { 303 304 if (InvokeRequired) … … 306 307 throw new OperationCanceledException(); 307 308 308 Invoke(new EventHandler< UpdateManager.ProgressEventArgs>(downloader_ProgressChanged),309 Invoke(new EventHandler<ProgressEventArgs>(downloader_ProgressChanged), 309 310 sender, e); 310 311 return; 311 312 } 312 313 313 UpdateData update = uiUpdates[(Update Manager.Update)e.UserState];314 315 if (e is UpdateManager.ProgressErrorEventArgs)316 { 317 update.Error = (( UpdateManager.ProgressErrorEventArgs)e).Exception;314 UpdateData update = uiUpdates[(UpdateInfo)e.UserState]; 315 316 if (e is ProgressErrorEventArgs) 317 { 318 update.Error = ((ProgressErrorEventArgs)e).Exception; 318 319 update.LVItem.ImageIndex = 3; 319 320 update.LVItem.SubItems[1].Text = S._("Error"); … … 358 359 if (!(e.Error is OperationCanceledException)) 359 360 MessageBox.Show(this, e.Error.Message, S._("Eraser"), 360 MessageBoxButtons.OK, MessageBoxIcon.Error); 361 MessageBoxButtons.OK, MessageBoxIcon.Error, 362 MessageBoxDefaultButton.Button1, 363 RightToLeft == RightToLeft.Yes ? MessageBoxOptions.RtlReading : 0); 361 364 362 365 Close(); … … 372 375 installingLv.Items.Add(item); 373 376 374 UpdateData update = uiUpdates[(Update Manager.Update)item.Tag];377 UpdateData update = uiUpdates[(UpdateInfo)item.Tag]; 375 378 if (update.Error == null) 376 379 item.SubItems[1].Text = string.Empty; … … 414 417 throw new OperationCanceledException(); 415 418 416 Invoke(new EventHandler< UpdateManager.ProgressEventArgs>(installer_ProgressChanged),419 Invoke(new EventHandler<ProgressEventArgs>(installer_ProgressChanged), 417 420 sender, e); 418 421 return; 419 422 } 420 423 421 UpdateData update = uiUpdates[(Update Manager.Update)e.UserState];422 if (e is UpdateManager.ProgressErrorEventArgs)423 { 424 update.Error = (( UpdateManager.ProgressErrorEventArgs)e).Exception;424 UpdateData update = uiUpdates[(UpdateInfo)e.UserState]; 425 if (e is ProgressErrorEventArgs) 426 { 427 update.Error = ((ProgressErrorEventArgs)e).Exception; 425 428 update.LVItem.ImageIndex = 3; 426 429 update.LVItem.SubItems[1].Text = S._("Error: {0}", update.Error.Message); … … 460 463 /// Maps listview items to the UpdateManager.Update object. 461 464 /// </summary> 462 Dictionary<UpdateManager.Update, UpdateData> uiUpdates = 463 new Dictionary<UpdateManager.Update, UpdateData>(); 465 Dictionary<UpdateInfo, UpdateData> uiUpdates = new Dictionary<UpdateInfo, UpdateData>(); 464 466 465 467 /// <summary> … … 475 477 /// <param name="item">The ListViewItem used for the display of the 476 478 /// update.</param> 477 public UpdateData(Update Manager.Updateupdate, ListViewItem item)479 public UpdateData(UpdateInfo update, ListViewItem item) 478 480 { 479 481 Update = update; … … 485 487 /// of the update. 486 488 /// </summary> 487 public Update Manager.UpdateUpdate;489 public UpdateInfo Update; 488 490 489 491 /// <summary> … … 518 520 public class UpdateManager 519 521 { 520 /// <summary>521 /// Represents a download mirror.522 /// </summary>523 public struct Mirror524 {525 public Mirror(string location, string link)526 : this()527 {528 Location = location;529 Link = link;530 }531 532 /// <summary>533 /// The location where the mirror is at.534 /// </summary>535 public string Location536 {537 get;538 set;539 }540 541 /// <summary>542 /// The URL prefix to utilise the mirror.543 /// </summary>544 public string Link545 {546 get;547 set;548 }549 550 public override string ToString()551 {552 return Location;553 }554 }555 556 /// <summary>557 /// Represents an update available on the server.558 /// </summary>559 public struct Update560 {561 public string Name;562 public Version Version;563 public string Publisher;564 public string Architecture;565 public long FileSize;566 public string Link;567 }568 569 /// <summary>570 /// Specialised progress event argument, containing message describing571 /// current action, and overall progress percentage.572 /// </summary>573 public class ProgressEventArgs : ProgressChangedEventArgs574 {575 public ProgressEventArgs(float progressPercentage, float overallPercentage,576 object userState, string message)577 : base((int)(progressPercentage * 100), userState)578 {579 this.progressPercentage = progressPercentage;580 this.overallProgressPercentage = overallPercentage;581 this.message = message;582 }583 584 /// <summary>585 /// Gets the asynchronous task progress percentage.586 /// </summary>587 public new float ProgressPercentage588 {589 get590 {591 return progressPercentage;592 }593 }594 595 /// <summary>596 /// Gets the asynchronous task overall progress percentage.597 /// </summary>598 public float OverallProgressPercentage599 {600 get601 {602 return overallProgressPercentage;603 }604 }605 606 /// <summary>607 /// Gets the message associated with the current task.608 /// </summary>609 public string Message610 {611 get612 {613 return message;614 }615 }616 617 float progressPercentage;618 float overallProgressPercentage;619 string message;620 }621 622 /// <summary>623 /// Extends the ProgressEventArgs further by allowing for the inclusion of624 /// an exception.625 /// </summary>626 public class ProgressErrorEventArgs : ProgressEventArgs627 {628 /// <summary>629 /// Constructor.630 /// </summary>631 /// <param name="e">The base ProgressEventArgs object.</param>632 /// <param name="ex">The exception</param>633 public ProgressErrorEventArgs(ProgressEventArgs e, Exception ex)634 : base(e.ProgressPercentage, e.OverallProgressPercentage, e.UserState, e.Message)635 {636 this.exception = ex;637 }638 639 /// <summary>640 /// The exception associated with the progress event.641 /// </summary>642 public Exception Exception643 {644 get645 {646 return exception;647 }648 }649 650 private Exception exception;651 }652 653 522 /// <summary> 654 523 /// Retrieves the update list from the server. … … 755 624 /// <param name="rdr">The XML reader object representing the element and its children.</param> 756 625 /// <returns>A list of updates in the category.</returns> 757 private static List<Update > ParseUpdateCategory(XmlReader rdr)758 { 759 List<Update > result = new List<Update>();626 private static List<UpdateInfo> ParseUpdateCategory(XmlReader rdr) 627 { 628 List<UpdateInfo> result = new List<UpdateInfo>(); 760 629 if (!rdr.ReadToDescendant("item")) 761 630 return result; … … 767 636 continue; 768 637 769 Update update = new Update();638 UpdateInfo update = new UpdateInfo(); 770 639 update.Name = rdr.GetAttribute("name"); 771 640 update.Version = new Version(rdr.GetAttribute("version")); 772 641 update.Publisher = rdr.GetAttribute("publisher"); 773 642 update.Architecture = rdr.GetAttribute("architecture"); 774 update.FileSize = Convert.ToInt64(rdr.GetAttribute("filesize")); 643 update.FileSize = Convert.ToInt64(rdr.GetAttribute("filesize"), 644 CultureInfo.InvariantCulture); 775 645 update.Link = rdr.ReadElementContentAsString(); 776 646 … … 787 657 /// <param name="updates">The updates to retrieve and install.</param> 788 658 /// <returns>An opaque object for use with InstallUpdates.</returns> 789 public object DownloadUpdates(ICollection<Update > downloadQueue)659 public object DownloadUpdates(ICollection<UpdateInfo> downloadQueue) 790 660 { 791 661 //Create a folder to hold all our updates. 792 662 DirectoryInfo tempDir = new DirectoryInfo(Path.GetTempPath()); 793 tempDir = tempDir.CreateSubdirectory("eraser" + Environment.TickCount.ToString()); 663 tempDir = tempDir.CreateSubdirectory("eraser" + Environment.TickCount.ToString( 664 CultureInfo.InvariantCulture)); 794 665 795 666 int currUpdate = 0; 796 Dictionary<string, Update > tempFilesMap = new Dictionary<string, Update>();797 foreach (Update update in downloadQueue)667 Dictionary<string, UpdateInfo> tempFilesMap = new Dictionary<string, UpdateInfo>(); 668 foreach (UpdateInfo update in downloadQueue) 798 669 { 799 670 try … … 814 685 byte[] tempBuffer = new byte[16384]; 815 686 string tempFilePath = Path.Combine( 816 tempDir.FullName, string.Format("{0}-{1}", ++currUpdate, 817 Path.GetFileName(reqUri.GetComponents(UriComponents.Path, UriFormat.Unescaped)))); 687 tempDir.FullName, string.Format(CultureInfo.InvariantCulture, "{0}-{1}", 688 ++currUpdate, Path.GetFileName(reqUri.GetComponents(UriComponents.Path, 689 UriFormat.Unescaped)))); 818 690 819 691 using (Stream strm = resp.GetResponseStream()) … … 857 729 public void InstallUpdates(object value) 858 730 { 859 Dictionary<string, Update > tempFiles = (Dictionary<string, Update>)value;860 Dictionary<string, Update >.KeyCollection files = tempFiles.Keys;731 Dictionary<string, UpdateInfo> tempFiles = (Dictionary<string, UpdateInfo>)value; 732 Dictionary<string, UpdateInfo>.KeyCollection files = tempFiles.Keys; 861 733 int currItem = 0; 862 734 … … 865 737 foreach (string path in files) 866 738 { 867 Update item = tempFiles[path];739 UpdateInfo item = tempFiles[path]; 868 740 float progress = (float)currItem++ / files.Count; 869 741 OnProgress(new ProgressEventArgs(0.0f, progress, … … 966 838 /// Retrieves the categories available. 967 839 /// </summary> 968 public Dictionary<string, List<Update >>.KeyCollection Categories840 public Dictionary<string, List<UpdateInfo>>.KeyCollection Categories 969 841 { 970 842 get … … 977 849 /// Retrieves all updates available. 978 850 /// </summary> 979 public Dictionary<string, List<Update >> Updates851 public Dictionary<string, List<UpdateInfo>> Updates 980 852 { 981 853 get … … 990 862 /// <param name="key">The category to retrieve.</param> 991 863 /// <returns>All updates in the given category.</returns> 992 public ICollection<Update > this[string key]864 public ICollection<UpdateInfo> this[string key] 993 865 { 994 866 get … … 1012 884 /// The list of updates downloaded. 1013 885 /// </summary> 1014 private Dictionary<string, List<Update>> updates = 1015 new Dictionary<string, List<Update>>(); 886 private Dictionary<string, List<UpdateInfo>> updates = 887 new Dictionary<string, List<UpdateInfo>>(); 888 } 889 890 /// <summary> 891 /// Represents a download mirror. 892 /// </summary> 893 public struct Mirror 894 { 895 public Mirror(string location, string link) 896 : this() 897 { 898 Location = location; 899 Link = link; 900 } 901 902 /// <summary> 903 /// The location where the mirror is at. 904 /// </summary> 905 public string Location 906 { 907 get; 908 set; 909 } 910 911 /// <summary> 912 /// The URL prefix to utilise the mirror. 913 /// </summary> 914 public string Link 915 { 916 get; 917 set; 918 } 919 920 public override string ToString() 921 { 922 return Location; 923 } 924 } 925 926 /// <summary> 927 /// Represents an update available on the server. 928 /// </summary> 929 public struct UpdateInfo 930 { 931 public string Name { get; set; } 932 public Version Version { get; set; } 933 public string Publisher { get; set; } 934 public string Architecture { get; set; } 935 public long FileSize { get; set; } 936 public string Link { get; set; } 937 } 938 939 /// <summary> 940 /// Specialised progress event argument, containing message describing 941 /// current action, and overall progress percentage. 942 /// </summary> 943 public class ProgressEventArgs : ProgressChangedEventArgs 944 { 945 public ProgressEventArgs(float progressPercentage, float overallPercentage, 946 object userState, string message) 947 : base((int)(progressPercentage * 100), userState) 948 { 949 this.progressPercentage = progressPercentage; 950 this.overallProgressPercentage = overallPercentage; 951 this.message = message; 952 } 953 954 /// <summary> 955 /// Gets the asynchronous task progress percentage. 956 /// </summary> 957 public new float ProgressPercentage 958 { 959 get 960 { 961 return progressPercentage; 962 } 963 } 964 965 /// <summary> 966 /// Gets the asynchronous task overall progress percentage. 967 /// </summary> 968 public float OverallProgressPercentage 969 { 970 get 971 { 972 return overallProgressPercentage; 973 } 974 } 975 976 /// <summary> 977 /// Gets the message associated with the current task. 978 /// </summary> 979 public string Message 980 { 981 get 982 { 983 return message; 984 } 985 } 986 987 float progressPercentage; 988 float overallProgressPercentage; 989 string message; 990 } 991 992 /// <summary> 993 /// Extends the ProgressEventArgs further by allowing for the inclusion of 994 /// an exception. 995 /// </summary> 996 public class ProgressErrorEventArgs : ProgressEventArgs 997 { 998 /// <summary> 999 /// Constructor. 1000 /// </summary> 1001 /// <param name="e">The base ProgressEventArgs object.</param> 1002 /// <param name="ex">The exception</param> 1003 public ProgressErrorEventArgs(ProgressEventArgs e, Exception ex) 1004 : base(e.ProgressPercentage, e.OverallProgressPercentage, e.UserState, e.Message) 1005 { 1006 this.exception = ex; 1007 } 1008 1009 /// <summary> 1010 /// The exception associated with the progress event. 1011 /// </summary> 1012 public Exception Exception 1013 { 1014 get 1015 { 1016 return exception; 1017 } 1018 } 1019 1020 private Exception exception; 1016 1021 } 1017 1022 }
Note: See TracChangeset
for help on using the changeset viewer.
