Skip to content

Commit

Permalink
Merge branch 'release/1.0.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
canton7 committed Apr 13, 2015
2 parents 3df1732 + 463ba99 commit 152ca2e
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 64 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

v1.0.13
-------

- Fix crash if 'Show tray icon only on close' is checked (#45)
- Fix undocumented REST API change in Syncthing 0.11 (#46)
- Check for updates on resume from sleep
- Ensure SyncTrayzor is started as original user after auto-update

v1.0.12
-------

Expand Down
2 changes: 1 addition & 1 deletion installer/x64/installer-x64.iss
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Name: "{commondesktop}\{#AppName}"; Filename: "{app}\{#AppExeName}"; Tasks: desk

[Run]
Filename: "{tmp}\dotNet451Setup.exe"; Parameters: "/passive /promptrestart"; Check: FrameworkIsNotInstalled; StatusMsg: "Microsoft .NET Framework 4.5.1 is being installed. Please wait..."
Filename: "{app}\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall
Filename: "{app}\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[Code]
function FrameworkIsNotInstalled: Boolean;
Expand Down
2 changes: 1 addition & 1 deletion installer/x86/installer-x86.iss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Name: "{commondesktop}\{#AppName}"; Filename: "{app}\{#AppExeName}"; Tasks: desk

[Run]
Filename: "{tmp}\dotNet451Setup.exe"; Parameters: "/passive /promptrestart"; Check: FrameworkIsNotInstalled; StatusMsg: "Microsoft .NET Framework 4.5.1 is being installed. Please wait..."
Filename: "{app}\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall
Filename: "{app}\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[Code]
function FrameworkIsNotInstalled: Boolean;
Expand Down
24 changes: 13 additions & 11 deletions server/version_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

set_error_handler('error_handler');
date_default_timezone_set('UCT');
header('Content-Type: application/json');

function error_handler($severity, $message, $filename, $lineno)
{
Expand All @@ -64,20 +65,21 @@ function get_with_wildcard($src, $value, $default = null)
}

$versions = [
// '1.0.12' => [
// 'installed' => [
// 'direct_download_url' => [
// 'x64' => 'https://github.com/canton7/SyncTrayzor/releases/download/v1.0.11/SyncTrayzorSetup-x64.exe',
// 'x86' => 'https://github.com/canton7/SyncTrayzor/releases/download/v1.0.11/SyncTrayzorSetup-x86.exe'
// ],
// ],
// 'release_page_url' => 'https://github.com/canton7/SyncTrayzor/releases/tag/v1.0.11',
// 'release_notes' => "These\nare some release notes",
// ],
'1.0.13' => [
// No direct_download_url, as it turns out the 1.0.12 auto-upgrader is a bit broken (will restart SyncTrayzor as admin)
// 'installed' => [
// 'direct_download_url' => [
// 'x64' => 'https://github.com/canton7/SyncTrayzor/releases/download/v1.0.13/SyncTrayzorSetup-x64.exe',
// 'x86' => 'https://github.com/canton7/SyncTrayzor/releases/download/v1.0.13/SyncTrayzorSetup-x86.exe'
// ],
// ],
'release_page_url' => 'https://github.com/canton7/SyncTrayzor/releases/tag/v1.0.13',
'release_notes' => "- Fix crash if 'Show tray icon only on close' is checked (#45)\n- Fix undocumented REST API change in Syncthing 0.11 (#46)\n- Check for updates on resume from sleep\n- Ensure SyncTrayzor is started as original user after auto-update",
],
];

$upgrades = [
// '1.0.11' => ['to' => '1.0.12', 'formatter' => '1'],
'1.0.12' => ['to' => '1.0.13', 'formatter' => '1'],
];

$response_formatters = [
Expand Down
36 changes: 33 additions & 3 deletions src/InstallerRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -12,14 +13,39 @@ class Program
{
private const int ERROR_CANCELLED = 1223;

static int Main(string[] args)
static int Main(string[] argsIn)
{
if (args.Length == 0)
var args = new List<string>(argsIn);

string launch = null;
var indexOfLaunch = args.IndexOf("-launch");
if (indexOfLaunch > -1)
{
if (indexOfLaunch >= args.Count - 1)
{
Console.Error.WriteLine("Must provide an argument to -launch");
return 1;
}

launch = args[indexOfLaunch + 1];
args.RemoveAt(indexOfLaunch + 1);
args.RemoveAt(indexOfLaunch);
}

if (args.Count == 0)
{
Console.Error.WriteLine("Must provide at least one command-line argument");
return 1;
}

if (!File.Exists(args[0]))
{
Console.Error.WriteLine("Could not find {0}", args[0]);
return 4;
}

Console.WriteLine(String.Join(", ", args));

var startInfo = new ProcessStartInfo()
{
FileName = args[0],
Expand All @@ -30,7 +56,11 @@ static int Main(string[] args)

try
{
Process.Start(startInfo);
var process = Process.Start(startInfo);
process.WaitForExit();

if (!String.IsNullOrWhiteSpace(launch))
Process.Start(launch);
}
catch (Win32Exception e)
{
Expand Down
4 changes: 3 additions & 1 deletion src/SyncTrayzor/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ protected override void Configure()
autostartProvider.UpdatePathToSelf();
}

// Needs to be done before ConfigurationApplicator is run
this.Container.Get<IApplicationWindowState>().Setup((ShellViewModel)this.RootViewModel);

this.Container.Get<ConfigurationApplicator>().ApplyConfiguration();

this.Container.Get<MemoryUsageLogger>().Enabled = true;
Expand All @@ -118,7 +121,6 @@ protected override void Configure()
{ MessageBoxResult.Yes, Localizer.Translate("Generic_Dialog_Yes") },
};

this.Container.Get<IApplicationWindowState>().Setup((ShellViewModel)this.RootViewModel);
this.Container.Get<IApplicationState>().ApplicationStarted();
}

Expand Down
4 changes: 2 additions & 2 deletions src/SyncTrayzor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.12.0")]
[assembly: AssemblyFileVersion("1.0.12.0")]
[assembly: AssemblyVersion("1.0.13.0")]
[assembly: AssemblyFileVersion("1.0.13.0")]
10 changes: 8 additions & 2 deletions src/SyncTrayzor/Services/ProcessStartProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IProcessStartProvider
void Start(string filename);
void Start(string filename, string arguments);
void StartDetached(string filename);
void StartElevatedDetached(string filename, string arguments);
void StartElevatedDetached(string filename, string arguments, string launchAfterFinished = null);
}

public class ProcessStartProvider : IProcessStartProvider
Expand Down Expand Up @@ -50,8 +50,14 @@ public void StartDetached(string filename)
Process.Start(startInfo);
}

public void StartElevatedDetached(string filename, string arguments)
public void StartElevatedDetached(string filename, string arguments, string launchAfterFinished = null)
{
if (arguments == null)
arguments = String.Empty;

if (launchAfterFinished != null)
arguments += String.Format(" -launch \"{0}\"", launchAfterFinished);

var startInfo = new ProcessStartInfo()
{
FileName = Path.Combine(Path.GetDirectoryName(this.exeDir), installerRunner),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ public class InstalledUpdateVariantHandler : IUpdateVariantHandler
{
private readonly IUpdateDownloader updateDownloader;
private readonly IProcessStartProvider processStartProvider;
private readonly IAssemblyProvider assemblyProvider;

private string installerPath;

public string VariantName { get { return "installed"; } }
public bool CanAutoInstall { get; private set; }

public InstalledUpdateVariantHandler(IUpdateDownloader updateDownloader, IProcessStartProvider processStartProvider)
public InstalledUpdateVariantHandler(IUpdateDownloader updateDownloader, IProcessStartProvider processStartProvider, IAssemblyProvider assemblyProvider)
{
this.updateDownloader = updateDownloader;
this.processStartProvider = processStartProvider;
this.assemblyProvider = assemblyProvider;
}

public async Task<bool> TryHandleUpdateAvailableAsync(VersionCheckResults checkResult)
Expand Down Expand Up @@ -48,7 +50,7 @@ public void AutoInstall()
if (this.installerPath == null)
throw new InvalidOperationException("TryHandleUpdateAvailableAsync returned false: cannot call AutoInstall");

this.processStartProvider.StartElevatedDetached(this.installerPath, "/SILENT");
this.processStartProvider.StartElevatedDetached(this.installerPath, "/SILENT", this.assemblyProvider.Location);
}
}
}
76 changes: 42 additions & 34 deletions src/SyncTrayzor/Services/UpdateManagement/UpdateDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,58 @@ public UpdateDownloader(IApplicationPathsProvider pathsProvider, IFilesystemProv

public async Task<string> DownloadUpdateAsync(string url, Version version)
{
var downloadPath = Path.Combine(this.downloadsDir, String.Format(downloadFileName, version.ToString(3)));
try
{
var downloadPath = Path.Combine(this.downloadsDir, String.Format(downloadFileName, version.ToString(3)));

// Just in case...
this.filesystemProvider.CreateDirectory(this.downloadsDir);
// Just in case...
this.filesystemProvider.CreateDirectory(this.downloadsDir);

bool download = true;
bool download = true;

// Someone downloaded it already? Oh good. Let's see if it's corrupt or not...
if (this.filesystemProvider.Exists(downloadPath))
{
logger.Info("Skipping download as file {0} already exists", downloadPath);
if (this.installerVerifier.Verify(downloadPath))
{
download = false;
// Touch the file, so we (or someone else!) doesn't delete when cleaning up
this.filesystemProvider.SetLastAccessTimeUtc(downloadPath, DateTime.UtcNow);
}
else
// Someone downloaded it already? Oh good. Let's see if it's corrupt or not...
if (this.filesystemProvider.Exists(downloadPath))
{
logger.Info("Actually, it's corrupt. Re-downloading");
this.filesystemProvider.Delete(downloadPath);
logger.Info("Skipping download as file {0} already exists", downloadPath);
if (this.installerVerifier.Verify(downloadPath))
{
download = false;
// Touch the file, so we (or someone else!) doesn't delete when cleaning up
this.filesystemProvider.SetLastAccessTimeUtc(downloadPath, DateTime.UtcNow);
}
else
{
logger.Info("Actually, it's corrupt. Re-downloading");
this.filesystemProvider.Delete(downloadPath);
}
}
}

// House-keeping. Do this now, after SetLastAccessTimeUTc has been called, but before we start hitting the early-exits
this.CleanUpUnusedFiles();

if (download)
{
bool downloaded = await this.TryDownloadToFileAsync(downloadPath, url);
if (!downloaded)
return null;

logger.Info("Verifying...");
// House-keeping. Do this now, after SetLastAccessTimeUTc has been called, but before we start hitting the early-exits
this.CleanUpUnusedFiles();

if (!this.installerVerifier.Verify(downloadPath))
if (download)
{
logger.Warn("Download verification failed. Deleting {0}", downloadPath);
this.filesystemProvider.Delete(downloadPath);
return null;
bool downloaded = await this.TryDownloadToFileAsync(downloadPath, url);
if (!downloaded)
return null;

logger.Info("Verifying...");

if (!this.installerVerifier.Verify(downloadPath))
{
logger.Warn("Download verification failed. Deleting {0}", downloadPath);
this.filesystemProvider.Delete(downloadPath);
return null;
}
}
}

return downloadPath;
return downloadPath;
}
catch (Exception e)
{
logger.Error("Error in DownloadUpdateAsync", e);
return null;
}
}

private async Task<bool> TryDownloadToFileAsync(string downloadPath, string url)
Expand Down
11 changes: 11 additions & 0 deletions src/SyncTrayzor/Services/UpdateManagement/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public UpdateManager(
// We'll also check when the application is restored from tray

this.applicationState.Startup += this.ApplicationStartup;
this.applicationState.ResumeFromSleep += this.ResumeFromSleep;
this.applicationWindowState.RootWindowActivated += this.RootWindowActivated;
}

Expand All @@ -118,6 +119,12 @@ private async void ApplicationStartup(object sender, EventArgs e)
await this.CheckForUpdatesAsync();
}

private async void ResumeFromSleep(object sender, EventArgs e)
{
if (this.UpdateCheckDue())
await this.CheckForUpdatesAsync();
}

private async void RootWindowActivated(object sender, ActivationEventArgs e)
{
if (this.toastCts != null)
Expand Down Expand Up @@ -232,6 +239,10 @@ private async Task CheckForUpdatesAsync()
break;
}
}
catch (Exception e)
{
logger.Error("Error in UpdateManager.CheckForUpdatesAsync", e);
}
finally
{
this.versionCheckLock.Release();
Expand Down
17 changes: 10 additions & 7 deletions src/SyncTrayzor/SyncThing/ApiClient/ItemStartedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public class ItemStartedEventDetails
[JsonProperty("Modified")]
public long Modified { get; set; } // Is this supposed to be a DateTime?

[JsonProperty("Version")]
public long Version { get; set; }
// This changed in 0.11 beta, but it's not yet clear what do
// Since we don't use it anyway currently...
//[JsonProperty("Version")]
//public List<long> Version { get; set; }

[JsonProperty("LocalVersion")]
public long LocalVersion { get; set; }
// This changed in 0.11 beta, but it's not yet clear what do
// Since we don't use it anyway currently...
//[JsonProperty("LocalVersion")]
//public List<long> LocalVersion { get; set; }

[JsonProperty("NumBlocks")]
public long NumBlocks { get; set; }
Expand Down Expand Up @@ -52,9 +56,8 @@ public override void Visit(IEventVisitor visitor)

public override string ToString()
{
return String.Format("<ItemStarted ID={0} Time={1} Item={2} Folder={3} Name={4} Flags={5} Modified={6} Version={7} LocalVersion={8} NumBlocks={9}>",
this.Id, this.Time, this.Data.Item, this.Data.Folder, this.Data.Details.Name, this.Data.Details.Flags, this.Data.Details.Modified,
this.Data.Details.Version, this.Data.Details.LocalVersion, this.Data.Details.NumBlocks);
return String.Format("<ItemStarted ID={0} Time={1} Item={2} Folder={3} Name={4} Flags={5} Modified={6} NumBlocks={7}>",
this.Id, this.Time, this.Data.Item, this.Data.Folder, this.Data.Details.Name, this.Data.Details.Flags, this.Data.Details.Modified, this.Data.Details.NumBlocks);
}
}
}

0 comments on commit 152ca2e

Please sign in to comment.