Program.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Diagnostics;
  4. using CommandLine;
  5. namespace Steam_Desktop_Authenticator
  6. {
  7. static class Program
  8. {
  9. public static Process PriorProcess()
  10. // Returns a System.Diagnostics.Process pointing to
  11. // a pre-existing process with the same name as the
  12. // current one, if any; or null if the current process
  13. // is unique.
  14. {
  15. try
  16. {
  17. Process curr = Process.GetCurrentProcess();
  18. Process[] procs = Process.GetProcessesByName(curr.ProcessName);
  19. foreach (Process p in procs)
  20. {
  21. if ((p.Id != curr.Id) &&
  22. (p.MainModule.FileName == curr.MainModule.FileName))
  23. return p;
  24. }
  25. return null;
  26. }
  27. catch (Exception)
  28. {
  29. return null;
  30. }
  31. }
  32. /// <summary>
  33. /// The main entry point for the application.
  34. /// </summary>
  35. [STAThread]
  36. static void Main(string[] args)
  37. {
  38. // run the program only once
  39. if (PriorProcess() != null)
  40. {
  41. MessageBox.Show("Another instance of the app is already running.");
  42. return;
  43. }
  44. // Parse command line arguments
  45. CommandLineOptions options = new();
  46. Parser.Default.ParseArguments<CommandLineOptions>(args)
  47. .WithParsed(o => options = o);
  48. Application.EnableVisualStyles();
  49. Application.SetCompatibleTextRenderingDefault(false);
  50. Manifest man;
  51. try
  52. {
  53. man = Manifest.GetManifest();
  54. }
  55. catch (ManifestParseException)
  56. {
  57. // Manifest file was corrupted, generate a new one.
  58. try
  59. {
  60. MessageBox.Show("Your settings were unexpectedly corrupted and were reset to defaults.", "Steam Desktop Authenticator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  61. man = Manifest.GenerateNewManifest(true);
  62. }
  63. catch (MaFileEncryptedException)
  64. {
  65. // An maFile was encrypted, we're fucked.
  66. MessageBox.Show("Sorry, but SDA was unable to recover your accounts since you used encryption.\nYou'll need to recover your Steam accounts by removing the authenticator.\nClick OK to view instructions.", "Steam Desktop Authenticator", MessageBoxButtons.OK, MessageBoxIcon.Error);
  67. Process.Start(@"https://github.com/Jessecar96/SteamDesktopAuthenticator/wiki/Help!-I'm-locked-out-of-my-account");
  68. return;
  69. }
  70. }
  71. // Warning that this software is no longer supported
  72. MessageBox.Show("Steam Desktop Authenticator is no longer supported and will not receive any more updates. You should only use Steam's official mobile app to login to your account. Using SDA or any other tool is dangerous and puts your account at risk.", "Steam Desktop Authenticator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  73. if (man.FirstRun)
  74. {
  75. if (man.Entries.Count > 0)
  76. {
  77. // Already has accounts, just run
  78. MainForm mf = new MainForm();
  79. mf.SetEncryptionKey(options.EncryptionKey);
  80. mf.StartSilent(options.Silent);
  81. Application.Run(mf);
  82. }
  83. else
  84. {
  85. // No accounts, run welcome form
  86. Application.Run(new WelcomeForm());
  87. }
  88. }
  89. else
  90. {
  91. MainForm mf = new MainForm();
  92. mf.SetEncryptionKey(options.EncryptionKey);
  93. mf.StartSilent(options.Silent);
  94. Application.Run(mf);
  95. }
  96. }
  97. }
  98. }