-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
123 lines (110 loc) · 3.14 KB
/
Program.cs
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
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Samarkin.Caloverlayer
{
class Program
{
static int Main(string[] args)
{
if (args.Length < 1)
{
Usage();
return 1;
}
var settings = new OverlaySettings();
var q = new Queue<string>(args);
while (q.Count > 0)
{
var arg = q.Dequeue();
if (string.IsNullOrWhiteSpace(arg)) continue;
if (arg[0] == '/')
{
if (arg == "/?")
{
Usage();
return 0;
}
if (arg.StartsWith("/font:"))
settings.FontFamily = arg.Substring("/font:".Length);
else if (arg.StartsWith("/culture:"))
settings.Culture = arg.Substring("/culture:".Length);
else if (arg.StartsWith("/workdays:"))
{
var t = arg.Substring("/workdays:".Length);
int x;
if(int.TryParse(t, out x))
settings.WorkDays = x;
}
else if(arg.StartsWith("/offset:"))
{
var t = arg.Substring("/offset:".Length);
int x;
if (int.TryParse(t, out x))
settings.VerticalOffset = x;
}
else if (arg.StartsWith("/year:"))
{
var t = arg.Substring("/year:".Length);
settings.WholeYear = true;
int x;
if (int.TryParse(t, out x))
settings.Year = x;
}
else if (arg.StartsWith("/month:"))
{
var t = arg.Substring("/month:".Length);
if (t == "*")
settings.Month = null;
else
{
int x;
if (int.TryParse(t, out x))
settings.Month = x;
}
}
else if (arg.StartsWith("/out:"))
{
var t = arg.Substring("/out:".Length);
settings.OutputFileName = t;
}
else
{
Log.Warning("Unknown flag: {0}", arg);
}
}
else
{
if (settings.Filename == null)
settings.Filename = arg;
}
}
var overlay = new OverlayCalendar(settings);
try
{
return overlay.Apply();
}
catch (Exception ex)
{
Log.Error(ex);
return 255;
}
}
static void Usage()
{
var version = ((AssemblyFileVersionAttribute)(typeof(Program).Assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true)[0])).Version;
Console.Error.WriteLine("Caloverlayer v" + version +" (c) 2012 Pavel Samarkin");
Console.Error.WriteLine("Usage: Caloverlayer.exe [flags] <filename>");
Console.Error.WriteLine();
Console.Error.WriteLine("Supported flags:");
Console.Error.WriteLine(" /out:<FileName> - output file name");
Console.Error.WriteLine(" /font:<FontFamilyName> - specify font");
Console.Error.WriteLine(" /culture:<CultureName> - culture name abbreviation");
Console.Error.WriteLine(" /workdays:<number> - number of work (non-red) days in a week (0 - 7)");
Console.Error.WriteLine(" /offset:<number> - custom vertical offset relative to image center");
Console.Error.WriteLine(" /year:<number> - year to generate calendar for");
Console.Error.WriteLine(" /month:<number> - month to generate calendar for (1 - 12)");
Console.Error.WriteLine();
}
}
}