-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
114 lines (107 loc) · 5.35 KB
/
Program.cs
File metadata and controls
114 lines (107 loc) · 5.35 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using CommandLine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.Drawing.Text;
using System.IO.MemoryMappedFiles;
using System.Security.Permissions;
using System.Security.Policy;
using System.Text;
namespace StreamStartingTimer
{
class Options {
[Option('s', "seconds", Required = false, HelpText = "Run clock for this number of seconds")] public int? Seconds { get; set; }
[Option('m', "minutes", Required = false, HelpText = "Run clock for this number of minutes")] public int? Minutes { get; set; }
[Option('p', "past", Required = false, HelpText = "Run clock until time is this many minutes past the hour")] public int? Past { get; set; }
[Option('e', "events", Required = false, HelpText = "Load the startup events from this file instead of default")] public string? Events { get; set; }
[Option('c', "config", Required = false, HelpText = "Load the clock configuation from this file instead of default")] public string? Config { get; set; }
[Option('a', "alter", Required = false, HelpText = "Alter the timer of an already running copy of this program")] public bool Alter { get; set; }
}
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args) {
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
int StartTime = 0;
bool AdjustingTime = false;
string ConfigFile = Application.StartupPath + "DefaultConfig.json";
string EventsFile = Application.StartupPath + "DefaultEvents.json";
Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>(o => {
if (o.Alter ) {
Console.WriteLine("edit");
StartTime = (int)Shared.SecondsToGo;
Console.WriteLine("Clock is currently at " + StartTime.ToString() + " seconds");
AdjustingTime = true;
} else {
Console.WriteLine("Non-edit");
StartTime = 0;
}
if (o.Events != null) {
EventsFile = o.Events;
}
if (o.Config != null) {
ConfigFile = o.Config;
}
if (o.Past != null) {
DateTime dateTime = DateTime.Now;
DateTime trgTime;
trgTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, (int)o.Past, 0, 0);
if (trgTime < dateTime) {
trgTime = trgTime.AddHours(1);
}
StartTime = (int)(trgTime - DateTime.Now).TotalSeconds;
}
if (o.Seconds != null) {
if (AdjustingTime || o.Seconds >= 0) {
StartTime += (int)o.Seconds;
} else {
MessageBox.Show("Seconds cannot be negative, unless -a is used");
}
}
if (o.Minutes != null) {
if (AdjustingTime || o.Minutes >= 0) {
StartTime += (int)o.Minutes * 60;
} else {
MessageBox.Show("Minutes cannot be negative, unless -a is used");
}
}
}
);
if (AdjustingTime) {
Shared.SecondsToGo = StartTime;
} else {
while (!Shared.IsSingleInstance()) {
if (MessageBox.Show("Another copy of this program is already running", "Mutex Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel) {
return;
}
}
Shared.CurSettings = new CSettings();
if (!File.Exists(ConfigFile)) {
if (MessageBox.Show("This appears to be the first time you have run this program. Would you like to view the instructions", "Welcome", MessageBoxButtons.YesNo) == DialogResult.Yes) {
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = "https://github.com/LumKitty/StreamStartingTimer/blob/master/README.md";
myProcess.Start();
myProcess.Dispose();
}
} else {
Shared.CurSettings.LoadConfig(ConfigFile);
}
if (File.Exists(EventsFile)) {
Shared.TimerEvents = Shared.LoadEvents(EventsFile);
}
Shared.frmClock = new Clock(StartTime, EventsFile);
Application.Run(Shared.frmClock);
}
}
}
}