Skip to content

Commit

Permalink
Handle cases where manifest.json gets corrupted, and instruct users h…
Browse files Browse the repository at this point in the history
…ow to fix it.
  • Loading branch information
Jessecar96 committed Jun 19, 2018
1 parent 87988b0 commit 25c86df
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Steam Desktop Authenticator/MaFileEncryptedException.cs
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Steam_Desktop_Authenticator
{
class MaFileEncryptedException : Exception
{
}
}
10 changes: 9 additions & 1 deletion Steam Desktop Authenticator/MainForm.cs
Expand Up @@ -47,7 +47,15 @@ public void StartSilent(bool silent)
private void MainForm_Shown(object sender, EventArgs e)
{
this.labelVersion.Text = String.Format("v{0}", Application.ProductVersion);
this.manifest = Manifest.GetManifest();
try
{
this.manifest = Manifest.GetManifest();
}
catch (ManifestParseException)
{
MessageBox.Show("Unable to read your settings. Try restating SDA.", "Steam Desktop Authenticator", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}

// Make sure we don't show that welcome dialog again
this.manifest.FirstRun = false;
Expand Down
18 changes: 9 additions & 9 deletions Steam Desktop Authenticator/Manifest.cs
Expand Up @@ -53,25 +53,24 @@ public static Manifest GetManifest(bool forceLoad = false)

// Find config dir and manifest file
string maDir = Manifest.GetExecutableDir() + "/maFiles/";
string maFile = maDir + "manifest.json";
string manifestFile = maDir + "manifest.json";

// If there's no config dir, create it
if (!Directory.Exists(maDir))
{
_manifest = _generateNewManifest();
_manifest = GenerateNewManifest(false);
return _manifest;
}

// If there's no manifest, create it
if (!File.Exists(maFile))
// If there's no manifest, throw exception
if (!File.Exists(manifestFile))
{
_manifest = _generateNewManifest(true);
return _manifest;
throw new ManifestParseException();
}

try
{
string manifestContents = File.ReadAllText(maFile);
string manifestContents = File.ReadAllText(manifestFile);
_manifest = JsonConvert.DeserializeObject<Manifest>(manifestContents);

if (_manifest.Encrypted && _manifest.Entries.Count == 0)
Expand All @@ -86,11 +85,11 @@ public static Manifest GetManifest(bool forceLoad = false)
}
catch (Exception)
{
return null;
throw new ManifestParseException();
}
}

private static Manifest _generateNewManifest(bool scanDir = false)
public static Manifest GenerateNewManifest(bool scanDir = false)
{
// No directory means no manifest file anyways.
Manifest newManifest = new Manifest();
Expand Down Expand Up @@ -128,6 +127,7 @@ private static Manifest _generateNewManifest(bool scanDir = false)
}
catch (Exception)
{
throw new MaFileEncryptedException();
}
}

Expand Down
12 changes: 12 additions & 0 deletions Steam Desktop Authenticator/ManifestParseException.cs
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Steam_Desktop_Authenticator
{
class ManifestParseException : Exception
{
}
}
24 changes: 23 additions & 1 deletion Steam Desktop Authenticator/Program.cs
Expand Up @@ -78,7 +78,29 @@ static void Main(string[] args)
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Manifest man = Manifest.GetManifest();
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);
System.Diagnostics.Process.Start(@"https://github.com/Jessecar96/SteamDesktopAuthenticator/wiki/Help!-I'm-locked-out-of-my-account");
return;
}
}

if (man.FirstRun)
{
// Install VC++ Redist and wait
Expand Down
Expand Up @@ -157,13 +157,15 @@
<Compile Include="LoginForm.Designer.cs">
<DependentUpon>LoginForm.cs</DependentUpon>
</Compile>
<Compile Include="MaFileEncryptedException.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Manifest.cs" />
<Compile Include="ManifestParseException.cs" />
<Compile Include="PhoneBridge.cs" />
<Compile Include="PhoneExtractForm.cs">
<SubType>Form</SubType>
Expand Down
28 changes: 24 additions & 4 deletions Steam Desktop Authenticator/WelcomeForm.cs
Expand Up @@ -75,12 +75,32 @@ private void btnImportConfig_Click(object sender, EventArgs e)
}

// Set first run in manifest
man = Manifest.GetManifest(true);
man.FirstRun = false;
man.Save();
try
{
man = Manifest.GetManifest(true);
man.FirstRun = false;
man.Save();
}
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);
System.Diagnostics.Process.Start(@"https://github.com/Jessecar96/SteamDesktopAuthenticator/wiki/Help!-I'm-locked-out-of-my-account");
this.Close();
return;
}
}

// All done!
MessageBox.Show("All accounts and settings have been imported! Press OK to continue.", "Import accounts", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("All accounts and settings have been imported! Click OK to continue.", "Import accounts", MessageBoxButtons.OK, MessageBoxIcon.Information);
showMainForm();
}

Expand Down

0 comments on commit 25c86df

Please sign in to comment.