Skip to content

Commit

Permalink
Add option to force select a mod collection by name
Browse files Browse the repository at this point in the history
  • Loading branch information
bcssov committed Jan 8, 2025
1 parent db7c1ba commit 52d0863
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ***********************************************************************
// Assembly : IronyModManager.Common
// Author : Mario
// Created : 01-08-2025
//
// Last Modified By : Mario
// Last Modified On : 01-08-2025
// ***********************************************************************
// <copyright file="ModCollectionChangeRequestEvent.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using IronyModManager.Models.Common;
using IronyModManager.Shared.MessageBus;

namespace IronyModManager.Common.Events
{
/// <summary>
/// Class ModCollectionChangeRequestEvent.
/// Implements the <see cref="BaseNonAwaitableEvent" />
/// </summary>
/// <seealso cref="BaseNonAwaitableEvent" />
public class ModCollectionChangeRequestEvent : BaseNonAwaitableEvent
{
#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="ModCollectionChangeRequestEvent"/> class.
/// </summary>
/// <param name="modCollection">The mod collection.</param>
public ModCollectionChangeRequestEvent(IModCollection modCollection)
{
ModCollection = modCollection;
}

#endregion Constructors

#region Properties

/// <summary>
/// Gets the mod collection.
/// </summary>
/// <value>The mod collection.</value>
public IModCollection ModCollection { get; private set; }

#endregion Properties
}
}
21 changes: 20 additions & 1 deletion src/IronyModManager/App.xaml.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 : 02-15-2024
// Last Modified On : 01-08-2025
// ***********************************************************************
// <copyright file="App.xaml.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -138,6 +138,25 @@ static void setGame(bool raiseOnlyEvent = false)
}
}
}

if (!string.IsNullOrWhiteSpace(StaticResources.CommandLineOptions.ModCollectionName))
{
var collectionService = DIResolver.Get<IModCollectionService>();
var col = collectionService.Get(StaticResources.CommandLineOptions.ModCollectionName);
if (col != null)
{
if (raiseOnlyEvent)
{
var mbus = DIResolver.Get<Shared.MessageBus.IMessageBus>();
mbus.Publish(new ModCollectionChangeRequestEvent(col));
}
else
{
col.IsSelected = true;
collectionService.Save(col);
}
}
}
}

StaticResources.CommandLineArgsChanged += () =>
Expand Down
10 changes: 9 additions & 1 deletion src/IronyModManager/CommandLineArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
// Created : 02-21-2021
//
// Last Modified By : Mario
// Last Modified On : 10-30-2022
// Last Modified On : 01-08-2025
// ***********************************************************************
// <copyright file="CommandLineArgs.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -39,6 +40,13 @@ public class CommandLineArgs
[Option('g', "game", Required = false, HelpText = "Game:CK3,EU4,HOI4,IR,Stellaris,Vic3")]
public string GameAbrv { get; set; }

/// <summary>
/// Gets or sets the name of the mod collection.
/// </summary>
/// <value>The name of the mod collection.</value>
[Option('c', "collection", Required = false, HelpText = "Mod collection name to preselect")]
public string ModCollectionName { get; set; }

/// <summary>
/// Gets or sets the show fatal error notification.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ***********************************************************************
// Assembly : IronyModManager
// Author : Mario
// Created : 01-08-2025
//
// Last Modified By : Mario
// Last Modified On : 01-08-2025
// ***********************************************************************
// <copyright file="ModCollectionChangeRequestHandler.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using IronyModManager.Common.Events;
using IronyModManager.Shared.MessageBus;

namespace IronyModManager.Implementation.MessageBus.Events
{
/// <summary>
/// Class ModCollectionChangeRequestHandler.
/// Implements the <see cref="IronyModManager.Shared.MessageBus.BaseMessageBusConsumer{IronyModManager.Common.Events.ModCollectionChangeRequestEvent}" />
/// </summary>
/// <seealso cref="IronyModManager.Shared.MessageBus.BaseMessageBusConsumer{IronyModManager.Common.Events.ModCollectionChangeRequestEvent}" />
public class ModCollectionChangeRequestHandler : BaseMessageBusConsumer<ModCollectionChangeRequestEvent>
{
}
}
Loading

0 comments on commit 52d0863

Please sign in to comment.