Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SplashForm.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Concurrent;
5 using System.Collections.Generic;
6 using System.ComponentModel;
7 using System.Data;
8 using System.Drawing;
9 using System.Linq;
10 using System.Reflection;
11 using System.Text;
12 using System.Threading.Tasks;
13 using System.Windows.Forms;
14 using NuGet;
15 using SiliconStudio.Assets;
16 
17 namespace SiliconStudio.LauncherApp
18 {
19  public partial class SplashForm : Form
20  {
21  private string loadingMessage;
22  private int loadingStep;
23  private LauncherApp launcher;
24  private ConcurrentQueue<NugetLogEventArgs> tempLogEvents;
25  private bool isMovingWindow;
26  private Point previousMousePosition;
27  private readonly Timer timer;
28 
29  private bool isInitialized;
30 
31  public SplashForm()
32  {
33  InitializeComponent();
34  tempLogEvents = new ConcurrentQueue<NugetLogEventArgs>();
35  timer = new Timer() { Interval = 200 };
36  launcherVersionLabel.Text = "Launcher Version: " + LauncherApp.Version;
37  ExitOnUserClose = true;
38  }
39 
40  public bool ExitOnUserClose { get; set; }
41 
42  public void Initialize(LauncherApp launcher, string defaultLogText = null)
43  {
44  this.launcher = launcher;
45  logLabel.Text = defaultLogText ?? string.Empty;
46  versionLabel.Text = string.Empty;
47 
48  launcher.Loading += launcher_Loading;
49  launcher.ProgressAvailable += launcher_ProgressAvailable;
50  launcher.LogAvailable += launcher_LogAvailable;
51  timer.Tick += timer_Tick;
52  timer.Start();
53 
54  isInitialized = true;
55  }
56 
57  void launcher_ProgressAvailable(object sender, NuGet.ProgressEventArgs e)
58  {
59  loadingMessage = string.Format("{0} ({1}%)", e.Operation, e.PercentComplete);
60 
61  if (IsDisposed || !launcher.IsDownloading)
62  {
63  return;
64  }
65 
66  tempLogEvents.Enqueue(new NugetLogEventArgs(MessageLevel.Info, loadingMessage));
67  }
68 
69  void launcher_Loading(object sender, LoadingEventArgs e)
70  {
71  tempLogEvents.Enqueue(new NugetLogEventArgs(MessageLevel.Info, "Loading " + e.Package));
72  versionLabel.InvokeSafe(() =>
73  {
74  versionLabel.Text = "Version: " + e.Version;
75  });
76  }
77 
78  private NugetLogEventArgs lastLog;
79 
80  void timer_Tick(object sender, EventArgs e)
81  {
82  NugetLogEventArgs log;
83  while (tempLogEvents.TryDequeue(out log))
84  {
85  lastLog = log;
86  }
87 
88  if (lastLog == null)
89  {
90  return;
91  }
92 
93  var logMessage = lastLog.Message;
94  if (lastLog.Level != MessageLevel.Debug && lastLog.Level != MessageLevel.Info)
95  {
96  logMessage = lastLog.Level + ": " + logMessage;
97  }
98 
99  logLabel.Text = logMessage + string.Concat(Enumerable.Repeat(".", (loadingStep & 3) + 1));
100  loadingStep++;
101  }
102 
103  void launcher_LogAvailable(object sender, NugetLogEventArgs e)
104  {
105  tempLogEvents.Enqueue(e);
106  }
107 
108  private void SplashForm_MouseDown(object sender, MouseEventArgs e)
109  {
110  previousMousePosition = Cursor.Position;
111  isMovingWindow = true;
112  }
113 
114  private void SplashForm_MouseMove(object sender, MouseEventArgs e)
115  {
116  if (isMovingWindow)
117  {
118  var newPosition = Cursor.Position;
119 
120  var delta = new Point(newPosition.X - previousMousePosition.X, newPosition.Y - previousMousePosition.Y);
121  var newWindowPosition = this.Location;
122  newWindowPosition.Offset(delta);
123  this.Location = newWindowPosition;
124 
125  previousMousePosition = newPosition;
126  }
127 
128  }
129 
130  private void SplashForm_MouseUp(object sender, MouseEventArgs e)
131  {
132  isMovingWindow = false;
133  }
134 
135  private void minimizeButton_Click(object sender, EventArgs e)
136  {
137  WindowState = FormWindowState.Minimized;
138  }
139 
140  protected override void OnFormClosing(FormClosingEventArgs e)
141  {
142  if (ExitOnUserClose && e.CloseReason == CloseReason.UserClosing)
143  {
144  Environment.Exit(1);
145  }
146 
147  base.OnFormClosing(e);
148  }
149  }
150 }
override void OnFormClosing(FormClosingEventArgs e)
Definition: SplashForm.cs:140
Operation
Enumeration of the different operations in the new Assimp's material stack.
void Initialize(LauncherApp launcher, string defaultLogText=null)
Definition: SplashForm.cs:42
System.Windows.Point Point
Definition: ColorPicker.cs:15