TaskListBar.xaml 的互動邏輯
Inheritance: System.Windows.Controls.Button, IDisposable
 public TaskDetail(Grid parent, TaskListBar task)
     : this()
 {
     this.parent = parent;
     this.task = task;
     string uri = ((BitmapImage)task.ImgSrc).UriSource.OriginalString;
     ImgSrc = new BitmapImage(new Uri(uri.Replace("-banner", "")));
     lblName.Content = task.TaskName;
     lblState.Content = task.TaskStatus;
     task.OnLogUpdate += TaskBarLogUpdate;
     task.OnStateUpdate += TaskBarNameUpdate;
 }
Exemple #2
0
 private void butDLPack_Click(object sender, RoutedEventArgs e)
 {
     TaskListBar task = new TaskListBar() { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/download-banner.jpg")) };
     var thDL = new Thread(new ThreadStart(delegate
     {
         try
         {
             MeCore.Invoke(new System.Windows.Forms.MethodInvoker(() =>
             {
                 Uri url = new Uri(MeCore.Config.Server.ServerPackUrl);
                 if (url == null | string.IsNullOrWhiteSpace(url.AbsoluteUri))
                 {
                     throw new InvalidOperationException("url");
                 }
                 var downer = new WebClient();
                 downer.Headers.Add("User-Agent", "MTMCL" + MeCore.version);
                 var filename = "pack.zip";
                 var filecount = 0;
                 while (File.Exists(filename))
                 {
                     ++filecount;
                     filename = "pack-" + filecount + ".zip";
                 }
                 downer.DownloadProgressChanged += delegate (object sender1, DownloadProgressChangedEventArgs e1)
                 {
                     MeCore.Invoke(new Action(() => task.setTaskStatus(string.Format(LangManager.GetLangFromResource("SubTaskDLModPack"), e1.ProgressPercentage))));
                 };
                 downer.DownloadFileCompleted += delegate (object sender1, AsyncCompletedEventArgs e1)
                 {
                     MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("SubTaskExtractModPack"))));
                     new Threads.ModPackProcesser().install(filename);
                     File.Delete(filename);
                     MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("TaskFinish"))));
                     task.noticeFinished();
                 };
                 MeCore.Invoke(new Action(() => task.setTaskStatus(string.Format(LangManager.GetLangFromResource("SubTaskDLModPack"), 0))));
                 downer.DownloadFileAsync(url, filename);
             }));
         }
         catch (Exception ex)
         {
             MeCore.Invoke(new Action(() => MeCore.MainWindow.addNotice(new Notice.CrashErrorBar(string.Format(LangManager.GetLangFromResource("ErrorNameFormat"), DateTime.Now.ToLongTimeString()), ex.ToWellKnownExceptionString()) { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/error-banner.jpg"))})));
             MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("TaskFail"))));
             task.noticeFailed();
         }
     }));
     MeCore.MainWindow.addTask("dl-modpack", task.setThread(thDL).setTask(LangManager.GetLangFromResource("TaskDLModPack")).setDetectAlive(false));
     MeCore.MainWindow.addBalloonNotice(new Notice.NoticeBalloon(LangManager.GetLangFromResource("Download"), string.Format(LangManager.GetLangFromResource("BalloonNoticeSTTaskFormat"), LangManager.GetLangFromResource("TaskDLModPack"))));
 }
Exemple #3
0
 private void butInstallF_Click(object sender, RoutedEventArgs e)
 {
     TaskListBar task = new TaskListBar() { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/download-banner.jpg")) };
     var thDL = new Thread(new ThreadStart(delegate
     {
         try
         {
             string a = "";
             Dispatcher.Invoke(new Action(() => a = txtPathF.Text));
             MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("SubTaskInstallForge"))));
             new ForgeInstaller().install(a);
             MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("TaskFinish"))));
             task.noticeFinished();
         }
         catch (Exception ex)
         {
             MeCore.Invoke(new Action(() => MeCore.MainWindow.addNotice(new Notice.CrashErrorBar(string.Format(LangManager.GetLangFromResource("ErrorNameFormat"), DateTime.Now.ToLongTimeString()), ex.ToWellKnownExceptionString()) { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/error-banner.jpg")) })));
             Logger.log(ex);
             task.noticeFailed();
         }
     }));
     MeCore.MainWindow.addTask("instl-forgeclient", task.setThread(thDL).setTask(LangManager.GetLangFromResource("TaskInstallForge")).setDetectAlive(false));
     MeCore.MainWindow.addBalloonNotice(new Notice.NoticeBalloon(LangManager.GetLangFromResource("Download"), string.Format(LangManager.GetLangFromResource("BalloonNoticeSTTaskFormat"), LangManager.GetLangFromResource("TaskInstallForge"))));
 }
 private void DownloadForge(ForgeVersion ver)
 {
     TaskListBar task = new TaskListBar() { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/download-banner.jpg")) };
     var thDL = new Thread(new ThreadStart(delegate
     {
         bool universalInstead = !ver.urls.ContainsKey("installer");
         bool clientInstead = universalInstead & !ver.urls.ContainsKey("universal");
         var url = new Uri(clientInstead ? ver.urls["client"] : universalInstead ? ver.urls["universal"] : ver.urls["installer"]);
         var downer = new WebClient();
         downer.Headers.Add("User-Agent", "MTMCL" + MeCore.version);
         var filename = !universalInstead ? "forge.jar" : "forge.zip";
         var filecount = 0;
         while (File.Exists(filename))
         {
             ++filecount;
             filename = "forge-" + filecount + (!universalInstead ? ".jar" : ".zip");
         }
         downer.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e)
         {
             MeCore.Invoke(new Action(() => task.setTaskStatus(string.Format(LangManager.GetLangFromResource("SubTaskDLForge"), e.ProgressPercentage))));
         };
         downer.DownloadFileCompleted += delegate (object sender, AsyncCompletedEventArgs e)
         {
             try
             {
                 task.log(Logger.HelpLog("Trying to install forge"));
                 MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("SubTaskInstallForge"))));
                 if (universalInstead) new ForgeInstaller().installOld(filename, ver.mcversion, "forge-" + ver.mcversion + "-" + ver.version + (!string.IsNullOrWhiteSpace(ver.branch) ? "-" + ver.branch : ""));
                 else new ForgeInstaller().install(filename);
                 File.Delete(filename);
                 task.log(Logger.HelpLog("Installation finished"));
                 MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("TaskFinish"))));
                 task.noticeFinished();
             }
             catch (Exception ex)
             {
                 task.log(Logger.HelpLog("Installation failed"));
                 Logger.log(ex);
                 task.noticeFailed();
             }
         };
         task.log(Logger.HelpLog("Start downloading forge installer"));
         MeCore.Invoke(new Action(() => task.setTaskStatus(string.Format(LangManager.GetLangFromResource("SubTaskDLForge"), "0"))));
         downer.DownloadFileAsync(url, filename);
     }));
     MeCore.MainWindow.addTask("dl-instl-forgeclient-" + ver, task.setThread(thDL).setTask(LangManager.GetLangFromResource("TaskInstallForge")).setDetectAlive(false));
     MeCore.MainWindow.addBalloonNotice(new Notice.NoticeBalloon(LangManager.GetLangFromResource("Download"), string.Format(LangManager.GetLangFromResource("BalloonNoticeSTTaskFormat"), LangManager.GetLangFromResource("TaskInstallMC"))));
 }
        private void downloadVVer(RemoteVerType ver)
        {
            if (ver == null)
            {
                MessageBox.Show(LangManager.GetLangFromResource("RemoteVerErrorNoVersionSelect"));
                return;
            }
                TaskListBar taskbar = new TaskListBar() { ImgSrc = new BitmapImage(new Uri("pack://*****:*****@"\versions\");
                    downpath.Append(selectver).Append("\\");
                    downpath.Append(selectver).Append(".jar");
                    if (MeCore.IsServerDedicated)
                    {
                        if (!string.IsNullOrWhiteSpace(MeCore.Config.Server.ClientPath))
                        {
                            downpath.Replace(MeCore.Config.MCPath, Path.Combine(MeCore.BaseDirectory, MeCore.Config.Server.ClientPath));
                        }
                    }
                    var downer = new WebClient();
                    downer.Headers.Add("User-Agent", "MTMCL" + MeCore.version);
                    var downurl = new StringBuilder(MTMCL.Resources.UrlReplacer.getDownloadUrl());
                    downurl.Append(@"versions\");
                    downurl.Append(selectver).Append("\\");
                    downurl.Append(selectver).Append(".jar");
            #if DEBUG
                    MessageBox.Show(downpath + "\n" + downurl);
            #endif
                    if (!Directory.Exists(Path.GetDirectoryName(downpath.ToString())))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(downpath.ToString()));
                    }
                    string downjsonfile = downurl.ToString().Substring(0, downurl.Length - 4) + ".json";
                    if (!string.IsNullOrWhiteSpace(ver.url) & MeCore.Config.DownloadSource == 0)
                    {
                        downjsonfile = ver.url;
                    }
                    string downjsonpath = downpath.ToString().Substring(0, downpath.Length - 4) + ".json";
                    try
                    {
                        downer.DownloadFileCompleted += delegate (object sender, AsyncCompletedEventArgs e)
                        {
                            taskbar.log(Logger.HelpLog("Success to download client file."));
                            taskbar.noticeFinished();
                        };
                        downer.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e)
                        {
                            Dispatcher.Invoke(new Action(() => taskbar.setTaskStatus(e.ProgressPercentage + "%")));
                        };
                        taskbar.log(Logger.HelpLog("Start download file from url " + downjsonfile));
                        try
                        {
                            downer.DownloadFile(new Uri(downjsonfile), downjsonpath);
                        }
                        catch (Exception)
                        {
                            taskbar.noticeFailed();
                            return;
                        }
                        taskbar.log(Logger.HelpLog("Finish downloading file " + downjsonfile));
                        await TaskEx.Delay(TimeSpan.FromMilliseconds(500));
                        taskbar.log(Logger.HelpLog(string.Format("Start reading json of version {0} for further downloading", selectver)));
                        var sr = new StreamReader(downjsonpath);
                        VersionJson verjson = JsonConvert.DeserializeObject<VersionJson>(sr.ReadToEnd());
                        sr.Close();
                        var sw = new StreamWriter(downjsonpath);
                        sw.Write(JsonConvert.SerializeObject(verjson.Simplify(), Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }));
                        sw.Close();
                        if (verjson.downloads != null)
                        {
                            if (verjson.downloads.client != null)
                            {
                                if (verjson.downloads.client.url != null)
                                {
                                    downurl.Clear().Append(verjson.downloads.client.url);
                                }
                            }

                        }
                        taskbar.log(Logger.HelpLog("Start download file from url " + downurl.ToString()));
                        downer.DownloadFileAsync(new Uri(downurl.ToString()), downpath.ToString());
                    }
                    catch (Exception ex)
                    {
                        Dispatcher.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                        {
                            Dispatcher.Invoke(new Action(() => MeCore.MainWindow.addNotice(new Notice.CrashErrorBar(string.Format(LangManager.GetLangFromResource("ErrorNameFormat"), DateTime.Now.ToLongTimeString()), ex.ToWellKnownExceptionString()) { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/error-banner.jpg")) })));
                            taskbar.noticeFailed();
                        }));
                    }
                }));
                MeCore.MainWindow.addTask("dl-mcclient-" + ver.id, taskbar.setThread(task).setTask(LangManager.GetLangFromResource("TaskDLMC")).setDetectAlive(false));
                MeCore.MainWindow.addBalloonNotice(new Notice.NoticeBalloon(LangManager.GetLangFromResource("Download"), string.Format(LangManager.GetLangFromResource("BalloonNoticeSTTaskFormat"), LangManager.GetLangFromResource("TaskDLMC"))));
        }
Exemple #6
0
 private void putTaskBarLater(TaskListBar t)
 {
     t.Click += TaskBar_Click;
     panelTask.Children.Add(t);
     gridNullth.Visibility = Visibility.Collapsed;
 }
 private void butRDLAsset_Click(object sender, RoutedEventArgs e)
 {
     TaskListBar task = new TaskListBar() { ImgSrc = new BitmapImage(new Uri("pack://*****:*****@"\assets\objects\" + entity.Value.hash.Substring(0, 2) + "\\" + entity.Value.hash;
             if (MeCore.IsServerDedicated)
             {
                 if (!string.IsNullOrWhiteSpace(MeCore.Config.Server.ClientPath))
                 {
                     file = file.Replace(MeCore.Config.MCPath, Path.Combine(MeCore.BaseDirectory, MeCore.Config.Server.ClientPath));
                 }
             }
             FileHelper.CreateDirectoryForFile(file);
             try
             {
                 if (FileHelper.IfFileVaild(file, entity.Value.size))
                 {
                     task.log(Logger.HelpLog(string.Format("{0} exists, delete it", entity.Key)));
                     File.Delete(file);
                 }
                 task.log(Logger.HelpLog(string.Format("Start downloading {0}", entity.Key)));
                 _downer.DownloadFile(new Uri(url), file);
                 task.log(Logger.HelpLog(string.Format("Finish downloading {0}, Progress {1}", entity.Key, i.ToString(CultureInfo.InvariantCulture) + "/" + assets.objects.Count.ToString(CultureInfo.InvariantCulture))));
                 //Logger.log(i.ToString(CultureInfo.InvariantCulture), "/", assets.objects.Count.ToString(CultureInfo.InvariantCulture), file.Substring(MeCore.Config.MCPath.Length), "下载完毕");
                 if (i == assets.objects.Count)
                 {
                     Dispatcher.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                     {
                         task.log(Logger.HelpLog("Finish redownloading assets"));
                         //Logger.log("assets重新下载完毕");
                     }));
                 }
             }
             catch (WebException ex)
             {
                 Dispatcher.Invoke(new System.Windows.Forms.MethodInvoker(delegate
                 {
                     Logger.log(ex.Response.ResponseUri.ToString());
                     Logger.error(ex);
                 }));
             }
         }
     }));
     MeCore.MainWindow.addTask("dl-assets", task.setThread(thGet).setTask(LangManager.GetLangFromResource("TaskRDLAssets")));
 }
Exemple #8
0
 private void butInstallLL_Click(object sender, RoutedEventArgs e)
 {
     TaskListBar task = new TaskListBar() { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/download-banner.jpg")) };
     var thDL = new Thread(new ThreadStart(delegate
     {
         try
         {
             string a = "", b = "";
             bool c = false;
             Dispatcher.Invoke(new Action(() => { a = txtPathLL.Text; b = comboIVer.SelectedItem as string; c = (bool)toggleWF.IsChecked; }));
             MeCore.Invoke(new Action(() => task.setTaskStatus(string.Format(LangManager.GetLangFromResource("SubTaskInstallMod"), "LiteLoader"))));
             new LiteLoaderInstaller(c, b).install(a);
             MeCore.Invoke(new Action(() => task.setTaskStatus(LangManager.GetLangFromResource("TaskFinish"))));
             task.noticeFinished();
         }
         catch (Exception ex)
         {
             MeCore.Invoke(new Action(() => MeCore.MainWindow.addNotice(new Notice.CrashErrorBar(string.Format(LangManager.GetLangFromResource("ErrorNameFormat"), DateTime.Now.ToLongTimeString()), ex.ToWellKnownExceptionString()) { ImgSrc = new BitmapImage(new Uri("pack://application:,,,/Resources/error-banner.jpg")) })));
             Logger.log(ex);
             task.noticeFailed();
         }
     }));
     MeCore.MainWindow.addTask("instl-liteloader", task.setThread(thDL).setTask(string.Format(LangManager.GetLangFromResource("TaskInstallMod"), "LiteLoader")).setDetectAlive(false));
     MeCore.MainWindow.addBalloonNotice(new Notice.NoticeBalloon(LangManager.GetLangFromResource("Download"), string.Format(LangManager.GetLangFromResource("BalloonNoticeSTTaskFormat"), string.Format(LangManager.GetLangFromResource("TaskInstallMod"), "LiteLoader"))));
 }
 public void removeTask(string s, TaskListBar task)
 {
     taskdict.Remove(s);
     butTask.Count = taskdict.Where(n => !n.Value.isFinished()).Count() > 0 ? taskdict.Where(n => !n.Value.isFinished()).Count().ToString() : "";
 }
Exemple #10
0
 public void addTask(string identifier, TaskListBar task)
 {
     if (taskdict.ContainsKey(identifier))
     {
         if (taskdict[identifier].isFinished())
         {
             string _identifier = identifier + "_";
             int ie = 0;
             while (taskdict.ContainsKey(_identifier))
             {
                 ie++;
                 _identifier = identifier + ie;
             }
             identifier = _identifier;
         }
         else
         {
             task.noticeExisted();
             string _identifier = identifier + "exist";
             int i = 0;
             while (taskdict.ContainsKey(_identifier))
             {
                 i++;
                 _identifier = identifier + "exist" + i;
             }
         identifier = _identifier;
         }
     }
     task.Margin = new Thickness(0);
     taskdict.Add(identifier, task);
     OnTaskAdded?.Invoke(task);
     butTask.Count = taskdict.Where(n => !n.Value.isFinished()).Count() > 0 ? taskdict.Where(n => !n.Value.isFinished()).Count().ToString() : "";
 }