예제 #1
0
 public void DeletedSelected()
 {
     var wnd = new ChangeSetsProgressDialog("Removing Sets...") { Owner = Program.ClientWindow };
     System.Collections.IList items = lbSetList.SelectedItems;
     ThreadPool.QueueUserWorkItem(_ =>
     {
         int current = 0, max = items.Count;
         wnd.UpdateProgress(current, max, null, false);
         wnd.ShowMessage("Set Removal can take some time. Please be patient.");
         foreach (Set s in items)
         {
             ++current;
             try
             {
                 wnd.ShowMessage(string.Format("Removing '{0}' ...", s.Name));
                 SelectedGame.DeleteSet(s);
                 wnd.UpdateProgress(current, max,
                                    string.Format("'{0}' removed.", s.Name),
                                    false);
             }
             catch (Exception ex)
             {
                 wnd.UpdateProgress(current, max,
                                    string.Format(
                                        "'{0}' an error occured during removal:",
                                        s.Name), true);
                 wnd.UpdateProgress(current, max, ex.Message, true);
             }
         }
     });
     wnd.ShowDialog();
     RefreshList();
 }
예제 #2
0
        public void InstallSets()
        {
            var ofd = new OpenFileDialog
                          {
                              Filter = "Cards set definition files (*.o8s)|*.o8s",
                              Multiselect = true
                          };
            if (ofd.ShowDialog() != true) return;

            //Move the definition file to a new location, so that the old one can be deleted
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Octgn", "Sets");
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            var wnd = new ChangeSetsProgressDialog("Installing Sets...") {Owner = Program.ClientWindow};
            ThreadPool.QueueUserWorkItem(_ =>
                                             {
                                                 int current = 0, max = ofd.FileNames.Length;
                                                 wnd.UpdateProgress(current, max, null, false);
                                                 foreach (string setName in ofd.FileNames)
                                                 {
                                                     ++current;
                                                     string shortName = Path.GetFileName(setName);
                                                     try
                                                     {
                                                         if (shortName != null)
                                                         {
                                                             string copyto = Path.Combine(path, shortName);
                                                             if (setName.ToLower() != copyto.ToLower())
                                                                 File.Copy(setName, copyto, true);
                                                             SelectedGame.InstallSet(copyto);
                                                         }
                                                         wnd.UpdateProgress(current, max,
                                                                            string.Format("'{0}' installed.", shortName),
                                                                            false);
                                                     }
                                                     catch (Exception ex)
                                                     {
                                                         wnd.UpdateProgress(current, max,
                                                                            string.Format(
                                                                                "'{0}' an error occured during installation:",
                                                                                shortName), true);
                                                         wnd.UpdateProgress(current, max, ex.Message, true);
                                                     }
                                                 }
                                             });
            wnd.ShowDialog();
            RefreshList();
        }