WelcomeForm.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace Steam_Desktop_Authenticator
  12. {
  13. public partial class WelcomeForm : Form
  14. {
  15. private Manifest man;
  16. public WelcomeForm()
  17. {
  18. InitializeComponent();
  19. man = Manifest.GetManifest();
  20. }
  21. private void btnJustStart_Click(object sender, EventArgs e)
  22. {
  23. // Mark as not first run anymore
  24. man.FirstRun = false;
  25. man.Save();
  26. showMainForm();
  27. }
  28. private void btnImportConfig_Click(object sender, EventArgs e)
  29. {
  30. // Let the user select the config dir
  31. FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
  32. folderBrowser.Description = "Select the folder of your old Steam Desktop Authenticator install";
  33. DialogResult userClickedOK = folderBrowser.ShowDialog();
  34. if (userClickedOK == DialogResult.OK)
  35. {
  36. string path = folderBrowser.SelectedPath;
  37. string pathToCopy = null;
  38. if (Directory.Exists(path + "/maFiles"))
  39. {
  40. // User selected the root install dir
  41. pathToCopy = path + "/maFiles";
  42. }
  43. else if (File.Exists(path + "/manifest.json"))
  44. {
  45. // User selected the maFiles dir
  46. pathToCopy = path;
  47. }
  48. else
  49. {
  50. // Could not find either.
  51. MessageBox.Show("This folder does not contain either a manifest.json or an maFiles folder.\nPlease select the location where you had Steam Desktop Authenticator installed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  52. return;
  53. }
  54. // Copy the contents of the config dir to the new config dir
  55. string currentPath = Manifest.GetExecutableDir();
  56. // Create config dir if we don't have it
  57. if (!Directory.Exists(currentPath + "/maFiles"))
  58. {
  59. Directory.CreateDirectory(currentPath + "/maFiles");
  60. }
  61. // Copy all files from the old dir to the new one
  62. foreach (string newPath in Directory.GetFiles(pathToCopy, "*.*", SearchOption.AllDirectories))
  63. {
  64. File.Copy(newPath, newPath.Replace(pathToCopy, currentPath + "/maFiles"), true);
  65. }
  66. // Set first run in manifest
  67. try
  68. {
  69. man = Manifest.GetManifest(true);
  70. man.FirstRun = false;
  71. man.Save();
  72. }
  73. catch (ManifestParseException)
  74. {
  75. // Manifest file was corrupted, generate a new one.
  76. try
  77. {
  78. MessageBox.Show("Your settings were unexpectedly corrupted and were reset to defaults.", "Steam Desktop Authenticator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  79. man = Manifest.GenerateNewManifest(true);
  80. }
  81. catch (MaFileEncryptedException)
  82. {
  83. // An maFile was encrypted, we're fucked.
  84. 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);
  85. System.Diagnostics.Process.Start(@"https://github.com/Jessecar96/SteamDesktopAuthenticator/wiki/Help!-I'm-locked-out-of-my-account");
  86. this.Close();
  87. return;
  88. }
  89. }
  90. // All done!
  91. MessageBox.Show("All accounts and settings have been imported! Click OK to continue.", "Import accounts", MessageBoxButtons.OK, MessageBoxIcon.Information);
  92. showMainForm();
  93. }
  94. }
  95. private void showMainForm()
  96. {
  97. this.Hide();
  98. new MainForm().Show();
  99. }
  100. }
  101. }