Program.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Linq;
  5. using Statistics;
  6. /*
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. using System.Text.RegularExpressions;
  19. namespace ObsoleteChecker
  20. {
  21. class MainClass
  22. {
  23. public static int Main (string[] args)
  24. {
  25. try {
  26. if(args.Contains("-l") && args.Length == 1)
  27. {
  28. Console.WriteLine (@"This program is free software: you can redistribute it and/or modify");
  29. Console.WriteLine (@"it under the terms of the GNU General Public License as published by");
  30. Console.WriteLine (@"the Free Software Foundation, either version 3 of the License, or");
  31. Console.WriteLine (@"(at your option) any later version.");
  32. Console.WriteLine ();
  33. Console.WriteLine (@"This program is distributed in the hope that it will be useful,");
  34. Console.WriteLine (@"but WITHOUT ANY WARRANTY; without even the implied warranty of");
  35. Console.WriteLine (@"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
  36. Console.WriteLine (@"GNU General Public License for more details.");
  37. Console.WriteLine ();
  38. Console.WriteLine (@"You should have received a copy of the GNU General Public License");
  39. Console.WriteLine (@"along with this program. If not, see <http://www.gnu.org/licenses/>.");
  40. }
  41. else if (args.Length != 1) {
  42. Console.WriteLine ("Error: Incorrect number of arguments.");
  43. return -1;
  44. } else if (!File.Exists (args [0])) {
  45. Console.WriteLine ("Error: File not found: " + args [0]);
  46. return -1;
  47. }
  48. string readIn = "";
  49. using(Stream stream = File.OpenRead(args[0]))
  50. using(StreamReader reader = new StreamReader(stream))
  51. {
  52. readIn = reader.ReadToEnd();
  53. }
  54. string[] versionDates = new Regex("\n+\\Z").Replace(readIn.Replace("\r", ""), "").Split('\n');
  55. if (versionDates.Length <= 2) {
  56. Console.WriteLine ("Error: Too little versions found in file.");
  57. }
  58. double[] versions = new double[versionDates.Length-1];
  59. for(int i = 1; i < versionDates.Length;i++)
  60. {
  61. versions[i-1] = DateTime.Parse(versionDates[i]).Ticks - DateTime.Parse(versionDates[i - 1]).Ticks;
  62. }
  63. DateTime obsolDate = DateTime.Parse(versionDates[versionDates.Length-1]) + TimeSpan.FromTicks((long)(Quartiles.ThirdQuartile(versions.OrderBy(a => a)) + 1.5*Quartiles.IQR(versions.OrderBy(a => a))));
  64. if(DateTime.UtcNow.Ticks > obsolDate.Ticks)
  65. {
  66. Console.WriteLine("WARNING: This software seems to be no longer developed as of " + obsolDate.ToString("D") + ".");
  67. }
  68. else
  69. {
  70. Console.WriteLine("This software seems to be actively developed.");
  71. Console.WriteLine("However, if an update is not released by " + obsolDate.ToString("D") + ",");
  72. Console.WriteLine("then this software will be considered discontinued.");
  73. }
  74. return 0;
  75. }
  76. catch (Exception e) {
  77. Console.WriteLine ("Error: " + e.GetType().ToString() + " occurred.");
  78. Console.WriteLine ("Description: " + e.Message);
  79. return -1;
  80. }
  81. }
  82. }
  83. }