Skip to content

Commit

Permalink
Improve resolving perfomance and conflict solver ui navigation
Browse files Browse the repository at this point in the history
Switch json formatting from indented to none in order to reduce json size
Fixed issue when parsing state overlay message wasn't updated
Switch patch state saving in a background thread to further improve perfomance
Implement signal to prevent app shutdown if a destructive operation is in progress (the app will shutdown once it is completed)
Further reduced the size of state json by excluding code for non relevant objects except conflict history
Export handles not whole text filenames properly (like message_types.txt)
Defines parser handles more complex types now
  • Loading branch information
bcssov committed Apr 20, 2020
1 parent b1cc721 commit 8c543af
Show file tree
Hide file tree
Showing 38 changed files with 927 additions and 194 deletions.
34 changes: 34 additions & 0 deletions src/IronyModManager.Common/Events/ShutdownStateEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ***********************************************************************
// Assembly : IronyModManager.Common
// Author : Mario
// Created : 04-19-2020
//
// Last Modified By : Mario
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="ShutdownStateEventArgs.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;

namespace IronyModManager.Common.Events
{
/// <summary>
/// Class ShutdownStateEventArgs.
/// </summary>
public class ShutdownStateEventArgs
{
#region Properties

/// <summary>
/// Gets or sets a value indicating whether [prevent shutdown].
/// </summary>
/// <value><c>true</c> if [prevent shutdown]; otherwise, <c>false</c>.</value>
public bool PreventShutdown { get; set; }

#endregion Properties
}
}
27 changes: 20 additions & 7 deletions src/IronyModManager.Common/ViewModels/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 01-10-2020
//
// Last Modified By : Mario
// Last Modified On : 03-17-2020
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="BaseViewModel.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -158,13 +158,10 @@ protected virtual void OnSelectedGameChanged(IGame game)
/// <param name="progress">The progress.</param>
protected virtual void TriggerOverlay(bool isVisible, string message = Constants.EmptyParam, string progress = Constants.EmptyParam)
{
var args = new OverlayEventArgs()
Task.Run(() =>
{
IsVisible = isVisible,
Message = message,
MessageProgress = progress
};
MessageBus.Current.SendMessage(args);
TriggerOverlayAsync(isVisible, message, progress).ConfigureAwait(false);
});
}

/// <summary>
Expand All @@ -188,6 +185,22 @@ protected virtual Task TriggerOverlayAsync(bool isVisible, string message = Cons
});
}

/// <summary>
/// Triggers the prevent shutdown.
/// </summary>
/// <param name="cannotShutdown">if set to <c>true</c> [cannot shutdown].</param>
protected virtual void TriggerPreventShutdown(bool cannotShutdown)
{
Task.Run(() =>
{
var args = new ShutdownStateEventArgs()
{
PreventShutdown = cannotShutdown
};
MessageBus.Current.SendMessage(args);
});
}

#endregion Methods
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 04-07-2020
//
// Last Modified By : Mario
// Last Modified On : 04-18-2020
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="JsonDIConverter.cs" company="Mario">
// Mario
Expand All @@ -16,7 +16,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace IronyModManager.DI.JsonConverters
namespace IronyModManager.DI.Json
{
/// <summary>
/// Class JsonDIConverter.
Expand Down
45 changes: 45 additions & 0 deletions src/IronyModManager.DI/Json/WritablePropertiesResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ***********************************************************************
// Assembly : IronyModManager.DI
// Author : Mario
// Created : 04-19-2020
//
// Last Modified By : Mario
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="WritablePropertiesResolver.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace IronyModManager.DI.Json
{
/// <summary>
/// Class WritablePropertiesResolver.
/// Implements the <see cref="Newtonsoft.Json.Serialization.DefaultContractResolver" />
/// </summary>
/// <seealso cref="Newtonsoft.Json.Serialization.DefaultContractResolver" />
public class WritablePropertiesResolver : DefaultContractResolver
{
#region Methods

/// <summary>
/// Creates properties for the given <see cref="T:Newtonsoft.Json.Serialization.JsonContract" />.
/// </summary>
/// <param name="type">The type to create properties for.</param>
/// <param name="memberSerialization">The member serialization mode for the type.</param>
/// <returns>Properties for the given <see cref="T:Newtonsoft.Json.Serialization.JsonContract" />.</returns>
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
IList<JsonProperty> props = base.CreateProperties(type, memberSerialization);
return props.Where(p => p.Writable).ToList();
}

#endregion Methods
}
}
10 changes: 6 additions & 4 deletions src/IronyModManager.DI/JsonDISerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 04-07-2020
//
// Last Modified By : Mario
// Last Modified On : 04-07-2020
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="JsonDISerializer.cs" company="Mario">
// Mario
Expand All @@ -13,7 +13,7 @@
// ***********************************************************************
using System.Collections.Generic;
using System;
using IronyModManager.DI.JsonConverters;
using IronyModManager.DI.Json;
using Newtonsoft.Json;

namespace IronyModManager.DI
Expand Down Expand Up @@ -53,7 +53,7 @@ public static T Deserialize<T>(string text)
/// <returns>System.String.</returns>
public static string Serialize<T>(T model)
{
return JsonConvert.SerializeObject(model, Formatting.Indented, GetSettings(false));
return JsonConvert.SerializeObject(model, Formatting.None, GetSettings(false));
}

/// <summary>
Expand All @@ -68,14 +68,16 @@ private static JsonSerializerSettings GetSettings(bool includeConverter)
return new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new WritablePropertiesResolver(),
Converters = converters
};
}
else
{
return new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new WritablePropertiesResolver()
};
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/IronyModManager.IO.Common/Delegates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ***********************************************************************
// Assembly : IronyModManager.IO.Common
// Author : Mario
// Created : 04-19-2020
//
// Last Modified By : Mario
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="Delegates.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;

namespace IronyModManager.IO.Common
{
/// <summary>
/// Class Delegates.
/// </summary>
public class Delegates
{
#region Delegates

/// <summary>
/// Delegate WriteOperationStateDelegate
/// </summary>
/// <param name="started">if set to <c>true</c> [started].</param>
public delegate void WriteOperationStateDelegate(bool started);

#endregion Delegates
}
}
12 changes: 11 additions & 1 deletion src/IronyModManager.IO.Common/Mods/IModPatchExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 03-31-2020
//
// Last Modified By : Mario
// Last Modified On : 04-06-2020
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="IModPatchExporter.cs" company="Mario">
// Mario
Expand All @@ -15,6 +15,7 @@
using System;
using System.Threading.Tasks;
using IronyModManager.IO.Common.Mods.Models;
using static IronyModManager.IO.Common.Delegates;

namespace IronyModManager.IO.Common.Mods
{
Expand All @@ -23,6 +24,15 @@ namespace IronyModManager.IO.Common.Mods
/// </summary>
public interface IModPatchExporter
{
#region Events

/// <summary>
/// Occurs when [mod definition analyze].
/// </summary>
event WriteOperationStateDelegate WriteOperationState;

#endregion Events

#region Methods

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 04-04-2020
//
// Last Modified By : Mario
// Last Modified On : 04-16-2020
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="BaseDefinitionInfoProvider.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -96,7 +96,11 @@ public virtual string GetFileName(IDefinition definition)
{
EnsureValidType(definition);
var fileName = definition.ValueType == Parser.Common.ValueType.WholeTextFile ? Path.GetFileName(definition.File) : $"{definition.Id}{Path.GetExtension(definition.File)}";
if (FIOSPaths.Any(p => p.EndsWith(definition.ParentDirectory, StringComparison.OrdinalIgnoreCase)))
if (definition.ValueType == Parser.Common.ValueType.WholeTextFile)
{
return definition.File;
}
else if (FIOSPaths.Any(p => p.EndsWith(definition.ParentDirectory, StringComparison.OrdinalIgnoreCase)))
{
return Path.Combine(definition.ParentDirectory, $"{FIOSName}{fileName.GenerateValidFileName()}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/IronyModManager.IO/Mods/ModCollectionExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 03-09-2020
//
// Last Modified By : Mario
// Last Modified On : 04-13-2020
// Last Modified On : 04-19-2020
// ***********************************************************************
// <copyright file="ModCollectionExporter.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -53,7 +53,7 @@ public class ModCollectionExporter : IModCollectionExporter
/// <returns>Task&lt;System.Boolean&gt;.</returns>
public Task<bool> ExportAsync(ModCollectionExporterParams parameters)
{
var content = JsonConvert.SerializeObject(parameters.Mod, Formatting.Indented);
var content = JsonConvert.SerializeObject(parameters.Mod, Formatting.None);
using var zip = ArchiveFactory.Create(ArchiveType.Zip);
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(content));
zip.AddEntry(Common.Constants.ExportedModContentId, stream, false);
Expand Down
Loading

0 comments on commit 8c543af

Please sign in to comment.