// 倒数日 - 绿色工具箱 // C# 5.0 语法,零依赖。记生日、纪念日、考试、旅行,算还有多少天 / 已经第几天 // 数据存 %APPDATA%\GreenToolbox\countdown.tsv,纯文本,可以直接备份/手改 using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; using System.Text; using System.Windows.Forms; namespace GreenToolbox { public class CountDownItem { public string Name; public string Date; // 一次性存 yyyy-MM-dd;每年重复存 MM-dd public bool Annual; public bool CountUp; // true = 累计天数(第 N 天),false = 倒数 public int Days; // 计算出来的天数,仅用于排序显示 } // ===== 纯函数区(可自测) ===== public static class CountOps { public static string DataDir() { string b = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); return Path.Combine(Path.Combine(b, "GreenToolbox"), ""); } public static string DataFile() { return Path.Combine(DataDir(), "countdown.tsv"); } // 每年重复的日期只存 MM-dd,一次性的存 yyyy-MM-dd。用段数判断, // 别用长度("1-1" 这种手改出来的也得认) public static bool IsAnnual(string stored) { if (string.IsNullOrEmpty(stored)) return false; string s = stored.Trim(); int n = 0; for (int i = 0; i < s.Length; i++) if (s[i] == '-') n++; return n == 1; } public static bool ParseStored(string stored, out int y, out int m, out int d) { y = 0; m = 0; d = 0; if (string.IsNullOrEmpty(stored)) return false; string[] parts = stored.Trim().Split('-'); if (parts.Length == 2) { if (!int.TryParse(parts[0], out m)) return false; if (!int.TryParse(parts[1], out d)) return false; } else if (parts.Length == 3) { if (!int.TryParse(parts[0], out y)) return false; if (!int.TryParse(parts[1], out m)) return false; if (!int.TryParse(parts[2], out d)) return false; } else return false; if (m < 1 || m > 12) return false; if (d < 1 || d > 31) return false; // 2 月 30 日这种假日期要拦住,否则算天数时会炸 if (d > DateTime.DaysInMonth(y > 0 ? y : 2024, m)) return false; return true; } public static string FormatStored(DateTime dt, bool annual) { if (annual) return string.Format(CultureInfo.InvariantCulture, "{0:00}-{1:00}", dt.Month, dt.Day); return string.Format(CultureInfo.InvariantCulture, "{0:0000}-{1:00}-{2:00}", dt.Year, dt.Month, dt.Day); } public static string DisplayDate(string stored) { int y, m, d; if (!ParseStored(stored, out y, out m, out d)) return stored; if (IsAnnual(stored)) return string.Format(CultureInfo.InvariantCulture, "{0:00} 月 {1:00} 日 · 每年", m, d); return string.Format(CultureInfo.InvariantCulture, "{0:0000} 年 {1:00} 月 {2:00} 日", y, m, d); } // 每年重复:找「今天或之后」最近的那一次 public static DateTime NextAnnual(int m, int d, DateTime today) { DateTime t = today.Date; int year = t.Year; int dd = d; // 2 月 29 日在平年没有,按 2 月 28 日算(国内过生日通常这么处理) if (m == 2 && d == 29 && !DateTime.IsLeapYear(year)) dd = 28; DateTime cand = new DateTime(year, m, dd); if (cand < t) { year++; dd = d; if (m == 2 && d == 29 && !DateTime.IsLeapYear(year)) dd = 28; cand = new DateTime(year, m, dd); } return cand; } // 返回天数:正数=还有几天,0=今天,负数=已过几天 public static int DaysLeft(CountDownItem it, DateTime today) { if (it == null) return 0; int y, m, d; if (!ParseStored(it.Date, out y, out m, out d)) return 0; DateTime t = today.Date; if (it.Annual) { return (NextAnnual(m, d, t) - t).Days; } if (it.CountUp) { // 累计:从那天算到今天第几天(当天算第 1 天) DateTime start = new DateTime(y, m, d); return (t - start).Days + 1; } return (new DateTime(y, m, d) - t).Days; } public static string Label(CountDownItem it, DateTime today) { int days = DaysLeft(it, today); if (it.Annual) return days == 0 ? "就是今天" : "还有 " + days + " 天"; if (it.CountUp) { if (days <= 0) return "还没到"; return "第 " + days + " 天"; } if (days == 0) return "就是今天"; if (days > 0) return "还有 " + days + " 天"; return "已过 " + (-days) + " 天"; } public static string SortKey(CountDownItem it, DateTime today) { int days = DaysLeft(it, today); if (it.CountUp) return "9" + (-days).ToString("000000"); // 累计的排后面 if (it.Annual && days < 0) days = -days; return (days < 0 ? "5" : "0") + Math.Abs(days).ToString("000000"); } public static string EscapeName(string s) { if (s == null) return ""; return s.Replace("\t", " ").Replace("\r", " ").Replace("\n", " ").Trim(); } public static string BuildLine(CountDownItem it) { return EscapeName(it.Name) + "\t" + it.Date + "\t" + (it.Annual ? "1" : "0") + "\t" + (it.CountUp ? "1" : "0"); } public static CountDownItem ParseLine(string line) { if (string.IsNullOrEmpty(line)) return null; string[] p = line.Split('\t'); if (p.Length < 4) return null; CountDownItem it = new CountDownItem(); it.Name = p[0]; it.Date = p[1]; it.Annual = p[2] == "1"; it.CountUp = p[3] == "1"; int y, m, d; if (it.Name.Length == 0 || !ParseStored(it.Date, out y, out m, out d)) return null; return it; } public static List Load(string file) { List list = new List(); try { if (!File.Exists(file)) return list; string[] lines = File.ReadAllLines(file, Encoding.UTF8); for (int i = 0; i < lines.Length; i++) { CountDownItem it = ParseLine(lines[i]); if (it != null) list.Add(it); } } catch { } return list; } public static bool Save(string file, List list) { try { string dir = Path.GetDirectoryName(file); if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir)) Directory.CreateDirectory(dir); StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.Count; i++) sb.AppendLine(BuildLine(list[i])); File.WriteAllText(file, sb.ToString(), new UTF8Encoding(false)); return true; } catch { return false; } } public static string Summary(List list, DateTime today) { if (list == null || list.Count == 0) return "还没有记录。加一个生日或纪念日试试?"; CountDownItem best = null; int bestDays = int.MaxValue; for (int i = 0; i < list.Count; i++) { CountDownItem it = list[i]; if (it.CountUp) continue; int d = DaysLeft(it, today); if (d >= 0 && d < bestDays) { bestDays = d; best = it; } } if (best == null) return "共 " + list.Count + " 条记录"; if (bestDays == 0) return "今天就是「" + best.Name + "」"; return "最近的一个: 「" + best.Name + "」 还有 " + bestDays + " 天"; } } public class CountDownForm : Form { private static readonly Color COL_GREEN = Color.FromArgb(0, 145, 88); private static readonly Color COL_PANEL = Color.FromArgb(245, 249, 246); private static readonly Color COL_GRAY = Color.FromArgb(120, 130, 124); private TextBox txtName; private DateTimePicker dtDate; private CheckBox chkAnnual; private CheckBox chkCountUp; private ListView list; private Label lblSummary; private List items = new List(); public CountDownForm() { InitUi(); items = CountOps.Load(CountOps.DataFile()); RefreshList(); } private void InitUi() { this.Text = "倒数日 - 绿色工具箱"; this.Font = new Font("Microsoft YaHei UI", 9.5f); this.BackColor = Color.White; this.ForeColor = Color.FromArgb(34, 40, 36); this.ClientSize = new Size(720, 470); this.MinimumSize = new Size(660, 430); this.StartPosition = FormStartPosition.CenterScreen; int x = 18, y = 14; Label l0 = new Label(); l0.Text = "记生日、纪念日、考试、旅行:算还有多少天,或者已经第几天。数据存本机,不上传。"; l0.AutoSize = true; l0.ForeColor = COL_GRAY; l0.Location = new Point(x, y); this.Controls.Add(l0); y += 30; txtName = new TextBox(); txtName.Location = new Point(x, y); txtName.Size = new Size(240, 26); txtName.Text = "事情名称,如:妈妈生日"; txtName.ForeColor = COL_GRAY; txtName.GotFocus += delegate { if (txtName.Text == "事情名称,如:妈妈生日") { txtName.Text = ""; txtName.ForeColor = Color.Black; } }; txtName.LostFocus += delegate { if (txtName.Text.Trim().Length == 0) { txtName.Text = "事情名称,如:妈妈生日"; txtName.ForeColor = COL_GRAY; } }; txtName.KeyDown += new KeyEventHandler(OnNameKey); this.Controls.Add(txtName); dtDate = new DateTimePicker(); dtDate.Format = DateTimePickerFormat.Custom; dtDate.CustomFormat = "yyyy 年 M 月 d 日"; dtDate.Location = new Point(x + 250, y - 1); dtDate.Size = new Size(168, 26); dtDate.Value = DateTime.Today; this.Controls.Add(dtDate); chkAnnual = new CheckBox(); chkAnnual.Text = "每年重复"; chkAnnual.AutoSize = true; chkAnnual.Checked = true; chkAnnual.Location = new Point(x + 428, y + 3); chkAnnual.ForeColor = Color.FromArgb(60, 68, 64); this.Controls.Add(chkAnnual); chkCountUp = new CheckBox(); chkCountUp.Text = "算累计"; chkCountUp.AutoSize = true; chkCountUp.Location = new Point(x + 512, y + 3); chkCountUp.ForeColor = Color.FromArgb(60, 68, 64); this.Controls.Add(chkCountUp); y += 40; Button btnAdd = new Button(); btnAdd.Text = "添加"; btnAdd.Location = new Point(x, y); btnAdd.Size = new Size(96, 32); btnAdd.BackColor = COL_GREEN; btnAdd.ForeColor = Color.White; btnAdd.FlatStyle = FlatStyle.Flat; btnAdd.FlatAppearance.BorderSize = 0; btnAdd.Click += new EventHandler(AddClick); this.Controls.Add(btnAdd); Button btnDel = new Button(); btnDel.Text = "删除选中"; btnDel.Location = new Point(x + 106, y); btnDel.Size = new Size(104, 32); btnDel.FlatStyle = FlatStyle.Flat; btnDel.FlatAppearance.BorderColor = Color.FromArgb(200, 120, 120); btnDel.ForeColor = Color.FromArgb(170, 60, 60); btnDel.Click += new EventHandler(DelClick); this.Controls.Add(btnDel); Button btnOpen = new Button(); btnOpen.Text = "打开数据文件"; btnOpen.Location = new Point(x + 220, y); btnOpen.Size = new Size(120, 32); btnOpen.FlatStyle = FlatStyle.Flat; btnOpen.FlatAppearance.BorderColor = Color.FromArgb(200, 206, 202); btnOpen.ForeColor = Color.FromArgb(80, 90, 86); btnOpen.Click += new EventHandler(OpenDataClick); this.Controls.Add(btnOpen); y += 44; list = new ListView(); list.View = View.Details; list.FullRowSelect = true; list.GridLines = false; list.HideSelection = false; list.Location = new Point(x, y); list.Size = new Size(684, 300); list.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom; list.Columns.Add("名称", 220); list.Columns.Add("日期", 190); list.Columns.Add("天数", 150); list.Columns.Add("备注", 110); list.DoubleClick += new EventHandler(ListDoubleClick); this.Controls.Add(list); lblSummary = new Label(); lblSummary.Text = ""; lblSummary.AutoSize = false; lblSummary.Location = new Point(x, y + 308); lblSummary.Size = new Size(684, 24); lblSummary.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; lblSummary.ForeColor = COL_GREEN; this.Controls.Add(lblSummary); // 首次运行不塞示例数据:宁可空着,也不往用户文件里写脏东西 } private void RefreshList() { DateTime today = DateTime.Today; // 按「离今天最近的排前面」排序,倒数完了的沉底 items.Sort(delegate(CountDownItem a, CountDownItem b) { return string.CompareOrdinal(CountOps.SortKey(a, today), CountOps.SortKey(b, today)); }); list.BeginUpdate(); list.Items.Clear(); for (int i = 0; i < items.Count; i++) { CountDownItem it = items[i]; ListViewItem row = new ListViewItem(it.Name); row.SubItems.Add(CountOps.DisplayDate(it.Date)); row.SubItems.Add(CountOps.Label(it, today)); row.SubItems.Add(it.CountUp ? "累计" : (it.Annual ? "每年" : "一次性")); if (it.Annual && CountOps.DaysLeft(it, today) == 0) row.ForeColor = COL_GREEN; else if (!it.CountUp && CountOps.DaysLeft(it, today) < 0) row.ForeColor = COL_GRAY; row.Tag = it; list.Items.Add(row); } list.EndUpdate(); lblSummary.Text = CountOps.Summary(items, today); } private void AddClick(object sender, EventArgs e) { string name = txtName.Text.Trim(); if (name.Length == 0 || name == "事情名称,如:妈妈生日") { MessageBox.Show("先写个名称吧,比如「妈妈生日」。", "还差一步", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } CountDownItem it = new CountDownItem(); it.Name = name; it.Annual = chkAnnual.Checked; it.CountUp = chkCountUp.Checked && !it.Annual; it.Date = CountOps.FormatStored(dtDate.Value, it.Annual); // 同名同日期不重复加,避免手快点两下出现两条 for (int i = 0; i < items.Count; i++) { if (items[i].Name == it.Name && items[i].Date == it.Date) { MessageBox.Show("这条已经记过了。", "重复", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } items.Add(it); CountOps.Save(CountOps.DataFile(), items); txtName.Text = "事情名称,如:妈妈生日"; txtName.ForeColor = COL_GRAY; RefreshList(); } private void DelClick(object sender, EventArgs e) { if (list.SelectedItems.Count == 0) { MessageBox.Show("先在列表里点一行,再删除。", "没选中", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("确定删掉选中的 " + list.SelectedItems.Count + " 条记录?", "确认删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) return; for (int i = list.SelectedItems.Count - 1; i >= 0; i--) { CountDownItem it = list.SelectedItems[i].Tag as CountDownItem; if (it != null) items.Remove(it); } CountOps.Save(CountOps.DataFile(), items); RefreshList(); } private void OpenDataClick(object sender, EventArgs e) { string f = CountOps.DataFile(); try { if (!File.Exists(f)) CountOps.Save(f, items); System.Diagnostics.Process.Start("notepad.exe", "\"" + f + "\""); } catch (Exception ex) { MessageBox.Show("打不开数据文件:" + ex.Message, "出错了", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void ListDoubleClick(object sender, EventArgs e) { if (list.SelectedItems.Count == 0) return; CountDownItem it = list.SelectedItems[0].Tag as CountDownItem; if (it == null) return; MessageBox.Show(it.Name + "\r\n" + CountOps.DisplayDate(it.Date) + "\r\n" + CountOps.Label(it, DateTime.Today), "详情", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void OnNameKey(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { AddClick(null, null); e.SuppressKeyPress = true; } } } public static class CountSelfTest { private static int _pass = 0; private static int _fail = 0; private static List _lines = new List(); private static string Esc(string s) { if (s == null) return ""; return s.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"); } private static void Check(string name, string got, string want) { if (got == null) got = ""; if (want == null) want = ""; if (got == want) { _pass++; _lines.Add(" [ok] " + name); } else { _fail++; _lines.Add(" [!!] " + name + " 期望[" + Esc(want) + "] 实际[" + Esc(got) + "]"); } } private static void CheckTrue(string name, bool ok, string detail) { Check(name, ok ? "yes" : "no", "yes"); if (!ok && detail != null) _lines.Add(" 详情:" + Esc(detail)); } private static CountDownItem Make(string name, string date, bool annual, bool up) { CountDownItem it = new CountDownItem(); it.Name = name; it.Date = date; it.Annual = annual; it.CountUp = up; return it; } public static int Run(string dir) { try { _lines.Add("倒数日 自测"); DateTime today = new DateTime(2026, 10, 19); _lines.Add("固定今天:" + today.ToString("yyyy-MM-dd") + "(保证断言不随运行日期漂移)"); // ── 存储格式判定 ── CheckTrue("2026-12-25 是一次性", !CountOps.IsAnnual("2026-12-25"), null); CheckTrue("12-25 是每年重复", CountOps.IsAnnual("12-25"), null); CheckTrue("手改的 1-1 也认", CountOps.IsAnnual("1-1"), null); CheckTrue("空串不是", !CountOps.IsAnnual(""), null); int y, m, d; CheckTrue("解析一次性日期", CountOps.ParseStored("2026-12-25", out y, out m, out d) && y == 2026 && m == 12 && d == 25, null); CheckTrue("解析每年日期(年份为 0)", CountOps.ParseStored("12-25", out y, out m, out d) && y == 0 && m == 12 && d == 25, null); CheckTrue("2 月 30 日视为非法", !CountOps.ParseStored("2026-02-30", out y, out m, out d), null); CheckTrue("13 月非法", !CountOps.ParseStored("2026-13-01", out y, out m, out d), null); CheckTrue("空串非法", !CountOps.ParseStored("", out y, out m, out d), null); CheckTrue("乱码非法", !CountOps.ParseStored("abc", out y, out m, out d), null); // ── 序列化 ── Check("一次性存储格式", CountOps.FormatStored(new DateTime(2026, 1, 5), false), "2026-01-05"); Check("每年存储格式", CountOps.FormatStored(new DateTime(2026, 1, 5), true), "01-05"); Check("显示文案(一次性)", CountOps.DisplayDate("2026-01-05"), "2026 年 01 月 05 日"); Check("显示文案(每年)", CountOps.DisplayDate("01-05"), "01 月 05 日 · 每年"); // ── 天数计算 ── Check("30 天后", CountOps.DaysLeft(Make("a", "2026-11-18", false, false), today).ToString(), "30"); Check("就是今天", CountOps.DaysLeft(Make("a", "2026-10-19", false, false), today).ToString(), "0"); Check("已过 5 天", CountOps.DaysLeft(Make("a", "2026-10-14", false, false), today).ToString(), "-5"); Check("跨年计算(明年元旦 74 天)", CountOps.DaysLeft(Make("a", "01-01", true, false), today).ToString(), "74"); Check("今年的圣诞 67 天", CountOps.DaysLeft(Make("a", "12-25", true, false), today).ToString(), "67"); Check("每年重复的今天 = 0", CountOps.DaysLeft(Make("a", "10-19", true, false), today).ToString(), "0"); Check("每年重复昨天 → 明年的 10-18(364 天)", CountOps.DaysLeft(Make("a", "10-18", true, false), today).ToString(), "364"); // 2 月 29 日:平年按 2 月 28 日过,不能抛异常 DateTime leap = CountOps.NextAnnual(2, 29, today); Check("2 月 29 日在 2027 平年落到 2 月 28 日", leap.ToString("yyyy-MM-dd"), "2027-02-28"); DateTime leap2 = CountOps.NextAnnual(2, 29, new DateTime(2028, 1, 1)); Check("2028 闰年 2 月 29 日正常", leap2.ToString("yyyy-MM-dd"), "2028-02-29"); // 累计天数:当天算第 1 天 Check("累计当天 = 第 1 天", CountOps.DaysLeft(Make("a", "2026-10-19", false, true), today).ToString(), "1"); Check("累计 10 天前 = 第 11 天", CountOps.DaysLeft(Make("a", "2026-10-09", false, true), today).ToString(), "11"); Check("累计还没开始", CountOps.Label(Make("a", "2026-12-01", false, true), today), "还没到"); // ── 文案 ── Check("倒数文案", CountOps.Label(Make("a", "2026-11-18", false, false), today), "还有 30 天"); Check("今天文案", CountOps.Label(Make("a", "2026-10-19", false, false), today), "就是今天"); Check("已过文案", CountOps.Label(Make("a", "2026-10-14", false, false), today), "已过 5 天"); Check("累计文案", CountOps.Label(Make("a", "2026-10-09", false, true), today), "第 11 天"); Check("每年今天文案", CountOps.Label(Make("a", "10-19", true, false), today), "就是今天"); // ── 排序:近的在前,已过沉底,累计垫最后 ── List arr = new List(); arr.Add(Make("已过", "2026-10-01", false, false)); arr.Add(Make("还有 30 天", "2026-11-18", false, false)); arr.Add(Make("还有 3 天", "2026-10-22", false, false)); arr.Add(Make("累计", "2026-09-01", false, true)); arr.Sort(delegate(CountDownItem a, CountDownItem b) { return string.CompareOrdinal(CountOps.SortKey(a, today), CountOps.SortKey(b, today)); }); string order = ""; for (int i = 0; i < arr.Count; i++) order += (i == 0 ? "" : ",") + arr[i].Name; Check("排序:3 天 → 30 天 → 已过 → 累计", order, "还有 3 天,还有 30 天,已过,累计"); // ── 文本持久化:制表符/回车会破坏 TSV,必须在写之前压掉 ── CountDownItem dirty = Make("带\t制表符\r\n和换行", "2026-12-25", false, false); Check("名称里的制表符被压成空格", CountOps.EscapeName(dirty.Name), "带 制表符 和换行"); string line = CountOps.BuildLine(Make("妈妈生日", "11-08", true, false)); Check("行格式", line, "妈妈生日\t11-08\t1\t0"); CountDownItem back = CountOps.ParseLine(line); CheckTrue("行能原样读回", back != null && back.Name == "妈妈生日" && back.Annual && !back.CountUp, null); CheckTrue("少字段的行被丢弃", CountOps.ParseLine("只有名字\t11-08") == null, null); CheckTrue("空行不崩", CountOps.ParseLine("") == null, null); // ── 落盘读写(真实文件)── Directory.CreateDirectory(dir); string f = Path.Combine(dir, "countdown.tsv"); if (File.Exists(f)) File.Delete(f); List save = new List(); save.Add(Make("妈妈生日", "11-08", true, false)); save.Add(Make("项目上线", "2026-12-01", false, false)); save.Add(Make("在一起", "2024-05-20", false, true)); CheckTrue("保存成功", CountOps.Save(f, save), null); List load = CountOps.Load(f); Check("读回条数", load.Count.ToString(), "3"); Check("读回名称与类型", load[0].Name + "/" + load[0].Annual + "/" + load[2].CountUp, "妈妈生日/True/True"); Check("读回日期", load[1].Date, "2026-12-01"); Check("文件不存在时返回空表", CountOps.Load(Path.Combine(dir, "nope.tsv")).Count.ToString(), "0"); // 坏行不能把整份数据带崩(用户手改文件很常见) File.WriteAllText(f, "妈妈生日\t11-08\t1\t0\r\n坏行没有字段\r\n\r\n项目上线\t2026-12-01\t0\t0\r\n", new UTF8Encoding(false)); List tolerant = CountOps.Load(f); Check("坏行被跳过、好行保留", tolerant.Count.ToString(), "2"); // ── 摘要 ── List emptyList = new List(); Check("空列表提示", CountOps.Summary(emptyList, today), "还没有记录。加一个生日或纪念日试试?"); Check("摘要指向最近的一条", CountOps.Summary(save, today), "最近的一个: 「妈妈生日」 还有 20 天"); List todayOnly = new List(); todayOnly.Add(Make("今天的事", "10-19", true, false)); Check("今天就是那件事", CountOps.Summary(todayOnly, today), "今天就是「今天的事」"); } catch (Exception ex) { _fail++; _lines.Add(" [!!] 自测中途异常:" + ex.GetType().Name + " " + ex.Message); } _lines.Add(""); if (_fail == 0) _lines.Add("结果:共 " + (_pass + _fail) + " 项,全部通过 ✓"); else _lines.Add("结果:共 " + (_pass + _fail) + " 项,通过 " + _pass + ",失败 " + _fail + " ✗"); string all = string.Join("\r\n", _lines.ToArray()); Console.WriteLine(all); try { File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "selftest-countdown.txt"), all, new UTF8Encoding(true)); } catch { } return _fail == 0 ? 0 : 1; } } public static class CountProgram { [STAThread] public static void Main(string[] args) { if (args != null && args.Length > 0 && args[0] == "--selftest") { Environment.Exit(CountSelfTest.Run(args.Length >= 2 ? args[1] : null)); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new CountDownForm()); } } }