blob: e5aa189d1640e2b32aeaa5f775a31793742162e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
using System;
using System.Linq;
using System.Threading;
namespace WarframeClock
{
class Program
{
public static readonly string VersionString = "Warframe Clock Overlay 2019-01-22";
public static readonly bool UseWorldStatePhp = true;
private static Timer worldStateFetchTimer;
private static System.Windows.Forms.NotifyIcon notifyIcon;
private static OverlayWindow overlayWindow;
[STAThread]
static void Main(string[] args)
{
try
{
if (UseWorldStatePhp)
StartWorldStateFetch();
StartNotifyIcon();
StartOverlay();
}
catch (Exception ex)
{
Console.WriteLine($"Main: Uncaught exception: {ex.Message}");
Console.WriteLine(ex.StackTrace);
System.Windows.Forms.MessageBox.Show($"Main: Uncaught exception: {ex.Message}\n{ex.StackTrace}");
Terminate();
}
}
private static void StartWorldStateFetch()
{
worldStateFetchTimer = new Timer(state =>
{
try
{
var worldState = WorldState.Fetch();
var cetusSyndicate = worldState.SyndicateMissions.FirstOrDefault(mi => mi.Tag == "CetusSyndicate");
if (cetusSyndicate == null)
{
Console.WriteLine("WorldState: CetusSyndicate missions not found");
return;
}
var cetusExpiry = cetusSyndicate.Expiry.Date.NumberLong;
Console.WriteLine($"WorldState: CetusSyndicate missions expire at {cetusExpiry}");
Clock.CetusExpiry = cetusExpiry;
}
catch (Exception ex)
{
Console.WriteLine($"WorldState: Failed to fetch or parse worldState.php: {ex.ToString()}");
Console.WriteLine(ex.StackTrace);
}
}, null, 0, 10 * 60 * 1000 /* 10 minutes */);
}
private static void StartNotifyIcon()
{
var iconMenu = new System.Windows.Forms.ContextMenu();
notifyIcon = new System.Windows.Forms.NotifyIcon()
{
Text = "Warframe Clock",
ContextMenu = iconMenu,
Icon = Properties.Resources.TrayIcon
};
iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem(VersionString) { Enabled = false });
iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Quit", (_, __) => Terminate()));
notifyIcon.Visible = true;
}
private static void StartOverlay()
{
overlayWindow = new OverlayWindow();
overlayWindow.Start();
}
private static void Terminate()
{
notifyIcon.Dispose();
overlayWindow.Close();
worldStateFetchTimer.Change(Timeout.Infinite, Timeout.Infinite);
Environment.Exit(0);
}
}
}
|