Skip to content
Permalink
Browse files

[Launcher] Improve log/error message in an attempt to investigate #310

  • Loading branch information
xen2 committed May 2, 2019
1 parent be47e4c commit bbb42daa2a7fef9745f1afe27cfad718ef8ecbaf
@@ -46,10 +46,7 @@ internal static Task SelfUpdate(IViewModelServiceProvider services, NugetStore s
catch (Exception e)
{
dispatcher.Invoke(() => selfUpdateWindow?.ForceClose());
string message = $"An error occurred while updating the launcher. If the problem persists, please reinstall this application.{Environment.NewLine}{Environment.NewLine}Details:{Environment.NewLine}{e}";
await services.Get<IDialogService>().MessageBox(message, MessageBoxButton.OK, MessageBoxImage.Error);
// We do not want our users to use the old launcher when a new one is available.
Environment.Exit(1);
throw;
}
});
}
@@ -40,7 +40,7 @@ internal class LauncherViewModel : DispatcherViewModel, IPackagesLogger, IDispos
private bool isOffline;
private bool isSynchronizing = true;
private string currentToolTip;
private string lastErrorOrWarning;
private List<(DateTime Time, MessageLevel Level, string Message)> logMessages = new List<(DateTime, MessageLevel, string)>();
private bool autoCloseLauncher = LauncherSettings.CloseLauncherAutomatically;
private bool lastActiveVersionRestored;
private AnnouncementViewModel announcement;
@@ -111,7 +111,18 @@ public void Dispose()

public string CurrentToolTip { get { return currentToolTip; } set { SetValue(ref currentToolTip, value); } }

public string LastErrorOrWarning { get { return lastErrorOrWarning; } set { SetValue(ref lastErrorOrWarning, value); } }
public string LogMessages
{
get
{
lock (logMessages)
{
if (logMessages.Count == 0)
return "Empty";
return string.Join(Environment.NewLine, logMessages.Select(x => $"[{x.Time.ToString("HH:mm:ss")}] {x.Level}: {x.Message}"));
}
}
}

public bool AutoCloseLauncher { get { return autoCloseLauncher; } set { SetValue(ref autoCloseLauncher, value, () => LauncherSettings.CloseLauncherAutomatically = value); } }

@@ -135,7 +146,29 @@ private async Task FetchOnlineData()
await Task.Run(async () =>
{
await RetrieveLocalXenkoVersions();
await RunLockTask(() => SelfUpdater.SelfUpdate(ServiceProvider, store));
await RunLockTask(async () =>
{
try
{
await SelfUpdater.SelfUpdate(ServiceProvider, store);
}
catch (Exception e)
{
var message = $@"**An error occurred while updating the launcher. If the problem persists, please reinstall this application.**
### Log
```
{LogMessages}
```
### Exception
```
{e.FormatSummary(false).TrimEnd(Environment.NewLine.ToCharArray())}
```";
await ServiceProvider.Get<IDialogService>().MessageBox(message, MessageBoxButton.OK, MessageBoxImage.Error);
// We do not want our users to use the old launcher when a new one is available.
Environment.Exit(1);
}
});
await RetrieveServerXenkoVersions();
await VsixPackage.UpdateFromStore();
await CheckForFirstInstall();
@@ -298,11 +331,11 @@ private async Task RetrieveServerXenkoVersions()
// Inform the user if we just switched offline
if (IsOffline && !wasOffline)
{
var message = Strings.ErrorOfflineMode;
if (!string.IsNullOrEmpty(LastErrorOrWarning))
{
message += Environment.NewLine + Environment.NewLine + Strings.Details + Environment.NewLine + LastErrorOrWarning;
}
var message = $@"**{Strings.ErrorOfflineMode}**
### Log
```
{LogMessages}
```";
await ServiceProvider.Get<IDialogService>().MessageBox(message, MessageBoxButton.OK, MessageBoxImage.Information);
}

@@ -565,9 +598,9 @@ private void DisplayReleaseAnnouncement()

void IPackagesLogger.Log(MessageLevel level, string message)
{
if (level == MessageLevel.Warning || level == MessageLevel.Error)
lock (logMessages)
{
LastErrorOrWarning = string.Format(message);
logMessages.Add((DateTime.Now, level, message));
}
}

@@ -247,7 +247,16 @@ protected Task Download(bool displayErrorMessage)

if (displayErrorMessage)
{
var message = $"{InstallErrorMessage}{Environment.NewLine}{Environment.NewLine}{Launcher.LastErrorOrWarning?.Replace(Environment.NewLine, Environment.NewLine + Environment.NewLine) ?? string.Empty}{Environment.NewLine}{e.FormatSummary(true)}";
var message = $@"**{InstallErrorMessage}**
### Log
```
{Launcher.LogMessages}
```
### Exception
```
{e.FormatSummary(false).TrimEnd(Environment.NewLine.ToCharArray())}
```";
await ServiceProvider.Get<IDialogService>().MessageBox(message, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
@@ -28,7 +28,7 @@
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>

<!-- Assembly version for the launcher, used to generate the appropriate nuget package -->
<InformationalVersion>3.0.6</InformationalVersion>
<InformationalVersion>3.0.7</InformationalVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>Xenko.Launcher</id>
<version>3.0.6</version>
<version>3.0.7</version>
<authors>Xenko</authors>
<owners>Xenko</owners>
<licenseUrl>http://xenko.com/license.txt</licenseUrl>

0 comments on commit bbb42da

Please sign in to comment.
You can’t perform that action at this time.