Skip to content

Commit

Permalink
Added update checker to standalone Encrypt and Decrypt forms and fixe…
Browse files Browse the repository at this point in the history
…d a typo in the Settings panel
  • Loading branch information
mullak99 committed Oct 19, 2020
1 parent 760e260 commit 4a288d2
Show file tree
Hide file tree
Showing 10 changed files with 6,613 additions and 29 deletions.
8 changes: 8 additions & 0 deletions FileAES/DecryptForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace FAES_GUI
{
public partial class DecryptForm : Form
{
private UpdateForm _updateForm;

public DecryptForm(FAES_File faesFile)
{
InitializeComponent();
Expand All @@ -17,6 +19,12 @@ public DecryptForm(FAES_File faesFile)
decryptPanel.LockFileSelect(true);
decryptPanel.setCloseAfterOperationSuccessful(true);
decryptPanel.SetFileToDecrypt(faesFile);

if (!Program.programManager.GetSkipUpdates())
{
_updateForm = new UpdateForm();
_updateForm.CheckForUpdate();
}
}

private void titleBar_Paint(object sender, PaintEventArgs e)
Expand Down
9 changes: 9 additions & 0 deletions FileAES/EncryptForm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using FAES;
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace FAES_GUI
{
public partial class EncryptForm : Form
{
private UpdateForm _updateForm;

public EncryptForm(FAES_File faesFile)
{
InitializeComponent();
Expand All @@ -17,6 +20,12 @@ public EncryptForm(FAES_File faesFile)
encryptPanel.LockFileSelect(true);
encryptPanel.setCloseAfterOperationSuccessful(true);
encryptPanel.SetFileToEncrypt(faesFile);

if (!Program.programManager.GetSkipUpdates())
{
_updateForm = new UpdateForm();
_updateForm.CheckForUpdate();
}
}

private void titleBar_Paint(object sender, PaintEventArgs e)
Expand Down
13 changes: 11 additions & 2 deletions FileAES/FileAES.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
<Compile Include="CustomControls\TextProgressBar.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UpdateForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UpdateForm.Designer.cs">
<DependentUpon>UpdateForm.cs</DependentUpon>
</Compile>
<Compile Include="DevForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -158,6 +164,9 @@
<EmbeddedResource Include="CustomControls\SubMenuButton.resx">
<DependentUpon>SubMenuButton.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UpdateForm.resx">
<DependentUpon>UpdateForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DevForm.resx">
<DependentUpon>DevForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -229,7 +238,7 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" />
<Error Condition="!Exists('..\packages\Fody.6.2.6\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.2.6\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.6.3.0\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.3.0\build\Fody.targets'))" />
</Target>
<Import Project="..\packages\Fody.6.2.6\build\Fody.targets" Condition="Exists('..\packages\Fody.6.2.6\build\Fody.targets')" />
<Import Project="..\packages\Fody.6.3.0\build\Fody.targets" Condition="Exists('..\packages\Fody.6.3.0\build\Fody.targets')" />
</Project>
4 changes: 2 additions & 2 deletions FileAES/MenuPanels/SettingsPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 48 additions & 23 deletions FileAES/MenuPanels/aboutPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class aboutPanel : UserControl
private string _latestVersion, _lastCheckedBranch;
private bool _updateThreadRunning = false;
private bool _updateUI = false;
private bool _isUpdate = false;

private Action _onIsUpdateAction;

Expand All @@ -26,9 +27,7 @@ public aboutPanel()

miscVersionLabel.Text = String.Format("FAES Version: {0}\n\rSSM Version: {1}", ConvertVersionToFormatted(FAES.FileAES_Utilities.GetVersion()), ConvertVersionToFormatted(SimpleSettingsManager.SSM.GetVersion()));
GetCurrentVersion();
CheckForUpdate();
}

public enum UpdateStatus
{
ServerError,
Expand All @@ -37,6 +36,11 @@ public enum UpdateStatus
AppNewer
};

public bool IsUpdate()
{
return _isUpdate;
}

private void GetCurrentVersion()
{
currentVerLabel.Text = Program.GetVersion();
Expand Down Expand Up @@ -69,6 +73,7 @@ private void UpdateUI()
reinstallCurrentButton.Enabled = true;
updateDescLabel.Text = "You are on the latest version!";
latestVerLabel.Text = latestVersion;
_isUpdate = false;

Logging.Log(String.Format("FAES_GUI(AboutPanel): UpdateUI set to AppLatest."), Severity.DEBUG);
}
Expand All @@ -82,6 +87,7 @@ private void UpdateUI()
reinstallCurrentButton.Enabled = false;
updateDescLabel.Text = "You are on a private build.";
latestVerLabel.Text = latestVersion;
_isUpdate = false;

Logging.Log(String.Format("FAES_GUI(AboutPanel): UpdateUI set to AppNewer."), Severity.DEBUG);
}
Expand All @@ -95,6 +101,7 @@ private void UpdateUI()
reinstallCurrentButton.Enabled = false;
updateDescLabel.Text = "Unable to connect to the update server.";
latestVerLabel.Text = "SERVER ERROR!";
_isUpdate = false;

Logging.Log(String.Format("FAES_GUI(AboutPanel): UpdateUI set to ServerError."), Severity.DEBUG);
}
Expand All @@ -108,6 +115,7 @@ private void UpdateUI()
reinstallCurrentButton.Enabled = true;
updateDescLabel.Text = "An update is available!";
latestVerLabel.Text = latestVersion;
_isUpdate = true;

Logging.Log(String.Format("FAES_GUI(AboutPanel): UpdateUI set to AppOutdated."), Severity.DEBUG);
}
Expand Down Expand Up @@ -161,32 +169,45 @@ private bool DoesVersionExist(string version, string branch)

public void CheckForUpdate()
{
if (!_updateThreadRunning)
try
{
_updateThreadRunning = true;

Thread threaddedUpdateCheck = new Thread(() =>
if (!_updateThreadRunning)
{
string updateVersion;
_updateThreadRunning = true;

Logging.Log(String.Format("Checking for update..."), Severity.DEBUG);
UpdateStatus updateInfo = GetUpdateStatus(out updateVersion);
Thread threaddedUpdateCheck = new Thread(() =>
{
try
{
string updateVersion;
if (updateVersion != "v0.0.0")
Logging.Log(String.Format("Latest FAES_GUI version: {0}", updateVersion), Severity.DEBUG);
else
Logging.Log(String.Format("Update check failed!"), Severity.WARN);
Logging.Log(String.Format("Checking for update..."), Severity.DEBUG);
UpdateStatus updateInfo = GetUpdateStatus(out updateVersion);
_appUpdateStatus = updateInfo;
_latestVersion = updateVersion;
_lastCheckedBranch = Program.programManager.GetBranch();
_updateUI = true;
_updateThreadRunning = false;
if (updateVersion != "v0.0.0")
Logging.Log(String.Format("Latest FAES_GUI version: {0}", updateVersion), Severity.DEBUG);
else
Logging.Log(String.Format("Update check failed!"), Severity.WARN);
if (_appUpdateStatus == UpdateStatus.AppOutdated && !Program.programManager.GetSkipUpdates()) DoIsUpdateAction();
});
threaddedUpdateCheck.Start();
_appUpdateStatus = updateInfo;
_latestVersion = updateVersion;
_lastCheckedBranch = Program.programManager.GetBranch();
_updateUI = true;
_updateThreadRunning = false;
if (_appUpdateStatus == UpdateStatus.AppOutdated && !Program.programManager.GetSkipUpdates()) DoIsUpdateAction();
}
catch { } // Hacky solution to stop VS2019 crashing when viewing some forms...
});
threaddedUpdateCheck.Start();
}
}
catch { } // Hacky solution to stop VS2019 crashing when viewing some forms...
}

public bool IsUpdateCheckRunning()
{
return _updateThreadRunning;
}

public void SetIsUpdateAction(Action action)
Expand Down Expand Up @@ -427,8 +448,12 @@ private static void RunAsAdmin()

private void Runtime_Tick(object sender, EventArgs e)
{
if (_updateThreadRunning || _updateUI) UpdateUI();
if (Program.programManager.GetBranch() != _lastCheckedBranch) CheckForUpdate();
try
{
if (_updateThreadRunning || _updateUI) UpdateUI();
if (Program.programManager.GetBranch() != _lastCheckedBranch) CheckForUpdate();
}
catch { } // Hacky solution to stop VS2019 crashing when viewing some forms...
}

private void UpdatePanel_Paint(object sender, PaintEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion FileAES/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace FAES_GUI
static class Program
{
private const string devAppendTag = "";
private const string betaAppendTag = "BETA 6";
private const string betaAppendTag = "BETA 7";

private static bool _verbose = false;
private static bool _purgeTemp = false;
Expand Down
151 changes: 151 additions & 0 deletions FileAES/UpdateForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a288d2

Please sign in to comment.