Skip to content

Commit

Permalink
Fix critical issues that may prevent you from updating the suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
Si13n7 committed Jun 21, 2018
1 parent 9d8e7f7 commit 72e138d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
6 changes: 0 additions & 6 deletions src/AppsLauncherUpdater/MainForm.Designer.cs

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

77 changes: 41 additions & 36 deletions src/AppsLauncherUpdater/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@ namespace Updater
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using LangResources;
using Properties;
using SilDev;
using SilDev.Forms;
using SilDev.Investment;
using Timer = System.Windows.Forms.Timer;

public partial class MainForm : Form
{
private static readonly List<string> DownloadMirrors = new List<string>();
private static readonly string HomeDir = PathEx.Combine(PathEx.LocalDir, "..");
private static readonly Guid UpdateGuid = Guid.NewGuid();
private static readonly string UpdateDir = PathEx.Combine(Path.GetTempPath(), $"Port-Able-{{{UpdateGuid}}}");
private readonly NetEx.AsyncTransfer _transfer = new NetEx.AsyncTransfer();
private readonly string _updatePath = Path.Combine(UpdateDir, "Update.7z");
private int _countdown = 100;
private string _hashInfo, _lastFinalStamp, _lastStamp;
private bool _ipv4, _ipv6;

Expand All @@ -32,14 +26,31 @@ public MainForm()
InitializeComponent();
Icon = Resources.Logo;
logoBox.Image = Resources.Changelog;
Language.SetControlLang(this);
changeLogPanel.ResumeLayout(false);
((ISupportInitialize)logoBox).EndInit();
buttonPanel.ResumeLayout(false);
statusTableLayoutPanel.ResumeLayout(false);
statusBarPanel.ResumeLayout(false);
ResumeLayout(false);
}

private void MainForm_Load(object sender, EventArgs e)
{
FormEx.Dockable(this);
private static List<string> DownloadMirrors { get; } = new List<string>();

Language.SetControlLang(this);
private static string HomeDir { get; } = PathEx.Combine(PathEx.LocalDir, "..");

private static Guid UpdateGuid { get; } = Guid.NewGuid();

private static string UpdateDir { get; } = PathEx.Combine(Path.GetTempPath(), $"Port-Able-{{{UpdateGuid}}}");

private NetEx.AsyncTransfer Transferor { get; } = new NetEx.AsyncTransfer();

private string UpdatePath { get; } = Path.Combine(UpdateDir, "Update.7z");

private CounterInvestor<int> Counter { get; } = new CounterInvestor<int>();

private void MainForm_Load(object sender, EventArgs e)
{
// Check internet connection
if (!(_ipv4 = NetEx.InternetIsAvailable()) && !(_ipv6 = NetEx.InternetIsAvailable(true)))
{
Expand Down Expand Up @@ -283,6 +294,7 @@ private void MainForm_Load(object sender, EventArgs e)
changeLog.DeselectAll();
}
ShowInTaskbar = true;
FormEx.Dockable(this);
return;
}

Expand Down Expand Up @@ -365,15 +377,19 @@ private void UpdateBtn_Click(object sender, EventArgs e)
if (!string.IsNullOrWhiteSpace(downloadPath))
try
{
if (_updatePath.ContainsEx(HomeDir))
if (UpdatePath.ContainsEx(HomeDir))
throw new NotSupportedException();
var updDir = Path.GetDirectoryName(UpdateDir);
if (!string.IsNullOrEmpty(updDir))
foreach (var dir in Directory.GetDirectories(updDir, "Port-Able-{*}", SearchOption.TopDirectoryOnly))
Directory.Delete(dir, true);
if (!Directory.Exists(UpdateDir))
Directory.CreateDirectory(UpdateDir);
foreach (var file in new[] { "7z.dll", "7zG.exe" })
foreach (var file in new[]
{
"7z.dll",
"7zG.exe"
})
{
var path = PathEx.Combine(PathEx.LocalDir, "Helper\\7z");
if (Environment.Is64BitOperatingSystem)
Expand All @@ -389,7 +405,7 @@ private void UpdateBtn_Click(object sender, EventArgs e)
}
try
{
_transfer.DownloadFile(downloadPath, _updatePath);
Transferor.DownloadFile(downloadPath, UpdatePath);
checkDownload.Enabled = true;
}
catch (Exception ex)
Expand All @@ -402,19 +418,19 @@ private void CheckDownload_Tick(object sender, EventArgs e)
{
if (!(sender is Timer owner))
return;
statusLabel.Text = _transfer.TransferSpeedAd + @" - " + _transfer.DataReceived;
statusBar.Value = _transfer.ProgressPercentage;
if (!_transfer.IsBusy)
_countdown--;
if (_countdown == 90)
statusLabel.Text = $@"{Transferor.TransferSpeedAd} - {Transferor.DataReceived}";
statusBar.Value = Transferor.ProgressPercentage;
if (Transferor.IsBusy)
return;
if (Counter.Increase(0) == 10)
statusBar.JumpToEnd();
if (_countdown > 0)
if (Counter.GetValue(0) < 100)
return;
owner.Enabled = false;
string helperPath = null;
try
{
helperPath = Path.GetDirectoryName(_updatePath);
helperPath = Path.GetDirectoryName(UpdatePath);
if (string.IsNullOrEmpty(helperPath))
return;
helperPath = Path.Combine(helperPath, "UpdateHelper.bat");
Expand All @@ -432,9 +448,8 @@ private void CheckDownload_Tick(object sender, EventArgs e)
var lastStamp = _lastFinalStamp;
if (string.IsNullOrWhiteSpace(lastStamp))
lastStamp = _lastStamp;
if (!Ini.Read("MD5", lastStamp, _hashInfo).EqualsEx(_updatePath.EncryptFile()))
if (!Ini.Read("MD5", lastStamp, _hashInfo).EqualsEx(UpdatePath.EncryptFile()))
throw new InvalidOperationException();
AppsSuite_CloseAll();
ProcessEx.Start(helperPath, true, ProcessWindowStyle.Hidden);
Application.Exit();
}
Expand All @@ -451,8 +466,8 @@ private void CancelBtn_Click(object sender, EventArgs e)
{
try
{
if (_transfer.IsBusy)
_transfer.CancelAsync();
if (Transferor.IsBusy)
Transferor.CancelAsync();
DirectoryEx.Delete(UpdateDir);
}
catch (Exception ex)
Expand Down Expand Up @@ -496,15 +511,5 @@ private void VirusTotalBtn_Click(object sender, EventArgs e)

private void WebBtn_Click(object sender, EventArgs e) =>
Process.Start(Resources.DevUri);

private void AppsSuite_CloseAll()
{
var fileList = new List<string>();
fileList.AddRange(Directory.GetFiles(HomeDir, "*.exe", SearchOption.TopDirectoryOnly));
fileList.AddRange(Directory.GetFiles(PathEx.LocalDir, "*.exe", SearchOption.AllDirectories).Where(s => !PathEx.LocalPath.EqualsEx(s)));
var taskList = fileList.SelectMany(s => Process.GetProcessesByName(Path.GetFileNameWithoutExtension(s))).ToList();
if (!ProcessEx.Terminate(taskList))
MessageBoxEx.Show(this, Language.GetText(nameof(en_US.InstallErrorMsg)), MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
7 changes: 6 additions & 1 deletion src/AppsLauncherUpdater/Properties/Resources.Designer.cs

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

7 changes: 6 additions & 1 deletion src/AppsLauncherUpdater/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
<value>@echo off
title "{0}"

taskkill /f /im "AppsDownloader.exe" &gt;nul 2&gt;&amp;1
taskkill /f /im "AppsDownloader64.exe" &gt;nul 2&gt;&amp;1
taskkill /f /im "AppsLauncher.exe" &gt;nul 2&gt;&amp;1
taskkill /f /im "AppsLauncher64.exe" &gt;nul 2&gt;&amp;1

cd /d "%~dp0"
7zG.exe x Update.7z -o"{1}\" -y
ping localhost -n 5 &gt;nul
Expand Down Expand Up @@ -158,7 +163,7 @@ exit /b</value>
<value>Port-Able Suite</value>
</data>
<data name="VirusTotalUri" xml:space="preserve">
<value>https://www.virustotal.com/en/file/{0}/analysis</value>
<value>https://www.virustotal.com/#/file/{0}/</value>
</data>
<data name="Changelog" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Changelog.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
Expand Down

0 comments on commit 72e138d

Please sign in to comment.