Skip to content
This repository was archived by the owner on Mar 17, 2018. It is now read-only.

Commit

Permalink
Fixed crashes when installing mod, fixed mods not disappearing after …
Browse files Browse the repository at this point in the history
…delete, added crash reporter for linux
  • Loading branch information
ikkentim committed Apr 28, 2016
1 parent 10f3abf commit 37bd823
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/ParkitectNexus.Client.Base/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public App(IPresenterFactory presenterFactory, IParkitect parkitect, IQueueableT

public static UIImageProvider Images { get; } = new UIImageProvider();


public bool Initialize(ToolkitType type)
{
_log.Open(Path.Combine(AppData.Path, "ParkitectNexusLauncher.log"));
Expand Down Expand Up @@ -76,7 +76,7 @@ public bool Initialize(ToolkitType type)
if (!_parkitect.DetectInstallationPath())
{
if (
!MessageDialog.Confirm("We couldn't detect Parkitect on your machine.\nPlease point me to it!",
!MessageDialog.Confirm("We couldn't automatically detect Parkitect on your machine!\nPlease press OK and manually select the installation folder of Parkitect.",
Command.Ok))
{
_window.Dispose();
Expand Down Expand Up @@ -125,7 +125,6 @@ public void HandleUrl(INexusUrl url)
}
}

// TODO: Replace with simple TCP server configuration
private async void CheckForIpcFile()
{
var ipcPath = Path.Combine(AppData.Path, "ipc.dat");
Expand Down
6 changes: 4 additions & 2 deletions src/ParkitectNexus.Client.Base/Pages/AssetsPageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public AssetsPageView(IParkitect parkitect, AssetType type, IPresenter parent, s

private void Assets_AssetRemoved(object sender, AssetEventArgs e)
{
RefreshTiles();
if (e.Asset.Type == _type)
RefreshTiles();
}

private void Assets_AssetAdded(object sender, AssetEventArgs e)
{
RefreshTiles();
if (e.Asset.Type == _type)
RefreshTiles();
}

protected virtual void PopulateViewBoxWithTitle(VBox vBox, IAsset asset)
Expand Down
12 changes: 6 additions & 6 deletions src/ParkitectNexus.Client.Base/Tiles/LoadableDataTileView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected virtual void ClearTiles()
foreach (var r in _rows)
r.Clear();

_buttons.Clear();
_rows.Clear();
_box.Clear();
PushNewRow();
Expand All @@ -70,14 +71,13 @@ public async void RefreshTiles()
await Task.Delay(1);
}

// Clear controls
ClearTiles();


Spinner spinner = null;

Application.Invoke(() =>
{
// Clear controls
ClearTiles();

Content =
spinner = new Spinner
{
Expand Down Expand Up @@ -139,7 +139,7 @@ public async void RefreshTiles()
}
finally
{
_tokenSource.Dispose();
_tokenSource?.Dispose();
_tokenSource = null;
}
}
Expand All @@ -148,7 +148,7 @@ public void HandleSizeUpdate(float width)
{
if (CalculateButtonsPerRow(width) == _buttonsPerRow)
return;

_buttonsPerRow = CalculateButtonsPerRow(width);
var i = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/ParkitectNexus.Client.Win32/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Main(string[] args)
{
// No matter if the application crashes, we must release the mutex when the app closes. Wrap the app
// logic in a try-finally block.
#if RELEASE
#if !DEBUG
try
{
#endif
Expand Down Expand Up @@ -67,7 +67,7 @@ public static void Main(string[] args)
}

app.Run();
#if RELEASE
#if !DEBUG
}
catch (Exception e)
{
Expand Down
2 changes: 2 additions & 0 deletions src/ParkitectNexus.Data/Reporting/CrashReporterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ private object Generate(string action, IParkitect parkitect, Exception exception
return new WindowsCrashReport(parkitect, action, exception, _log);
case SupportedOperatingSystem.MacOSX:
return new MacOSXCrashReport(parkitect, action, exception, _log);
case SupportedOperatingSystem.Linux:
return new LinuxCrashReport(parkitect, action, exception, _log);
default:
throw new Exception("unsupported operating system " + os);
}
Expand Down
86 changes: 86 additions & 0 deletions src/ParkitectNexus.Data/Reporting/LinuxCrashReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// ParkitectNexusClient
// Copyright 2016 Parkitect, Tim Potze

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using ParkitectNexus.Data.Assets;
using ParkitectNexus.Data.Assets.Modding;
using ParkitectNexus.Data.Game;
using ParkitectNexus.Data.Utilities;

namespace ParkitectNexus.Data.Reporting
{
[JsonObject(MemberSerialization.OptIn)]
public class LinuxCrashReport
{
private readonly ILogger _logger;
private readonly IParkitect _parkitect;

public LinuxCrashReport(IParkitect parkitect, string action, Exception exception, ILogger logger)
{
if (parkitect == null) throw new ArgumentNullException(nameof(parkitect));
if (exception == null) throw new ArgumentNullException(nameof(exception));

_logger = logger;
_parkitect = parkitect;
Action = action;
Exception = exception;
}

[JsonProperty]
public string Action { get; }

[JsonProperty]
public Exception Exception { get; }

[JsonProperty]
public string OS => "Unknown (Linux)";

[JsonProperty]
public int ProcessBits => IntPtr.Size*8;

[JsonProperty]
public IEnumerable<string> Mods
{
get
{
try
{
return _parkitect.Assets[AssetType.Mod].OfType<ModAsset>().Select(
m => $"{m}(Enabled: ???, Directory: {m.InstallationPath})");
}
catch
{
return new[] {"Failed to list"};
}
}
}

[JsonProperty]
public string Log
{
get
{
try
{
if (!_logger.IsOpened)
return "not opened";

var path = _logger.LoggingPath;
_logger.Close();
var result = File.ReadAllText(path);
_logger.Open(path);
return result;
}
catch (Exception e)
{
return "failed to open: " + e.Message;
}
}
}
}
}
102 changes: 101 additions & 1 deletion src/ParkitectNexus.Data/Reporting/MacOSXCrashReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,104 @@ public string Log
}
}
}
}
[JsonObject(MemberSerialization.OptIn)]
public class LinuxCrashReport
{
private readonly ILogger _logger;
private readonly IParkitect _parkitect;

public MacOSXCrashReport(IParkitect parkitect, string action, Exception exception, ILogger logger)
{
if (parkitect == null) throw new ArgumentNullException(nameof(parkitect));
if (exception == null) throw new ArgumentNullException(nameof(exception));

_logger = logger;
_parkitect = parkitect;
Action = action;
Exception = exception;
}

[JsonProperty]
public string Action { get; }

[JsonProperty]
public Exception Exception { get; }

[JsonProperty]
public string OS
{
get
{
try
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "w_vers",
Arguments = "-productVersion",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};

string result = "";
process.Start();
while (!process.StandardOutput.EndOfStream)
{
result += process.StandardOutput.ReadLine();
}
return result;
}
catch
{
return "Unknown (MacOSX)";
}
}
}

[JsonProperty]
public int ProcessBits => IntPtr.Size * 8;

[JsonProperty]
public IEnumerable<string> Mods
{
get
{
try
{
return _parkitect.Assets[AssetType.Mod].OfType<ModAsset>().Select(
m => $"{m}(Enabled: ???, Directory: {m.InstallationPath})");
}
catch
{
return new[] { "Failed to list" };
}
}
}

[JsonProperty]
public string Log
{
get
{
try
{
if (!_logger.IsOpened)
return "not opened";

var path = _logger.LoggingPath;
_logger.Close();
var result = File.ReadAllText(path);
_logger.Open(path);
return result;
}
catch (Exception e)
{
return "failed to open: " + e.Message;
}
}
}
}
}
3 changes: 0 additions & 3 deletions src/ParkitectNexus.Data/Updating/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public UpdateInfo CheckForUpdates<TEntryPoint>()
{
var newestVersion = new Version(updateInfo.Version);

currentVersion = new Version(currentVersion.Major, currentVersion.Minor, currentVersion.Build);
newestVersion = new Version(newestVersion.Major, newestVersion.Minor, newestVersion.Build);

_log.WriteLine($"Server reported newest version is v{updateInfo.Version}.");
if (newestVersion > currentVersion)
{
Expand Down

0 comments on commit 37bd823

Please sign in to comment.