using System;
using System.Windows.Forms;
using System.Diagnostics;
using CommandLine;
namespace Steam_Desktop_Authenticator
{
static class Program
{
public static Process PriorProcess()
// Returns a System.Diagnostics.Process pointing to
// a pre-existing process with the same name as the
// current one, if any; or null if the current process
// is unique.
{
try
{
Process curr = Process.GetCurrentProcess();
Process[] procs = Process.GetProcessesByName(curr.ProcessName);
foreach (Process p in procs)
{
if ((p.Id != curr.Id) &&
(p.MainModule.FileName == curr.MainModule.FileName))
return p;
}
return null;
}
catch (Exception)
{
return null;
}
}
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
// run the program only once
if (PriorProcess() != null)
{
MessageBox.Show("Another instance of the app is already running.");
return;
}
// Parse command line arguments
CommandLineOptions options = new();
Parser.Default.ParseArguments(args)
.WithParsed(o => options = o);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Manifest man;
try
{
man = Manifest.GetManifest();
}
catch (ManifestParseException)
{
// Manifest file was corrupted, generate a new one.
try
{
MessageBox.Show("Your settings were unexpectedly corrupted and were reset to defaults.", "Steam Desktop Authenticator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
man = Manifest.GenerateNewManifest(true);
}
catch (MaFileEncryptedException)
{
// An maFile was encrypted, we're fucked.
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);
Process.Start(@"https://github.com/Jessecar96/SteamDesktopAuthenticator/wiki/Help!-I'm-locked-out-of-my-account");
return;
}
}
// Warning that this software is no longer supported
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);
if (man.FirstRun)
{
if (man.Entries.Count > 0)
{
// Already has accounts, just run
MainForm mf = new MainForm();
mf.SetEncryptionKey(options.EncryptionKey);
mf.StartSilent(options.Silent);
Application.Run(mf);
}
else
{
// No accounts, run welcome form
Application.Run(new WelcomeForm());
}
}
else
{
MainForm mf = new MainForm();
mf.SetEncryptionKey(options.EncryptionKey);
mf.StartSilent(options.Silent);
Application.Run(mf);
}
}
}
}