Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Replace builtin Mod Models with Anno.EasyMod #261

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion ModManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Global
{64ACF7A5-C0DB-4F65-9AF3-F5F549FE3D38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64ACF7A5-C0DB-4F65-9AF3-F5F549FE3D38}.Release|Any CPU.Build.0 = Release|Any CPU
{24688521-C739-4686-8CB4-C2A73BBC44D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24688521-C739-4686-8CB4-C2A73BBC44D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24688521-C739-4686-8CB4-C2A73BBC44D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
Expand Down
4 changes: 1 addition & 3 deletions ModManager/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
<ResourceDictionary Source="Styles/ListBoxStyle.xaml" />
<ResourceDictionary Source="Styles/ToolTipStyle.xaml" />
<ResourceDictionary Source="Styles/SliderStyle.xaml" />

<ResourceDictionary Source="Styles/RichTextBoxStyle.xaml" />
</ResourceDictionary.MergedDictionaries>



<Style TargetType="FlowDocument"
x:Key="DocumentStyle">
<Setter Property="FontFamily"
Expand Down
115 changes: 69 additions & 46 deletions ModManager/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
using System.Windows;
using Imya.UI.Properties;
using Imya.UI.Utils;
using System.Threading.Tasks;
using Imya.Validation;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Imya.Services.Interfaces;
using Imya.Services;
using Imya.Models.Cache;
using Anno.EasyMod.DI;
using Anno.EasyMod.Utils;
using Anno.Utils;
using Imya.GithubIntegration;
using System;
using Imya.Utils;
using Imya.Texts;
using Imya.UI.Views;
using Imya.GithubIntegration.RepositoryInformation;
using Imya.GithubIntegration.StaticData;
using Imya.UI.Models;
using Imya.Models.Options;
using Imya.Models.Attributes.Factories;
using Imya.Models.Attributes.Interfaces;
using Imya.Models.Cache;
using Imya.Models.GameLauncher;
using Imya.Models.Installation.Interfaces;
using Imya.Models.Installation;
using Imya.Models.Mods;
using System.Windows.Forms;
using Imya.Models.Attributes.Interfaces;
using Imya.Models.Attributes.Factories;
using Imya.Models.Installation.Interfaces;
using Imya.Models.ModTweaker.DataModel.Storage;
using Imya.Models.ModTweaker.IO;
using Imya.Models.Options;
using Imya.Services;
using Imya.Services.Interfaces;
using Imya.Texts;
using Imya.UI.Components;
using Imya.Models.ModMetadata;
using Octokit;
using Imya.GithubIntegration.JsonData;
using Imya.GithubIntegration.RepositoryInformation;
using Imya.UI.Models;
using Imya.UI.Properties;
using Imya.UI.Utils;
using Imya.UI.ValueConverters;
using Anno.Utils;
using Newtonsoft.Json.Linq;
using Imya.UI.Views;
using Imya.Utils;
using Imya.Validation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Octokit;
using Serilog;
using Serilog.Sinks.RichTextBox.Themes;
using System;
using System.Windows;

namespace Imya.UI
{
Expand All @@ -49,14 +48,16 @@ public App()
.ConfigureServices((hostContext, services) =>
{
//services
services.ConfigureEasyMod();
services.ConfigureModio(new ModioAuthenticator());
services.AddSingleton<ITextManager, TextManager>();
services.AddSingleton<IGameSetupService, GameSetupService>();
var gameSetup = services.BuildServiceProvider().GetRequiredService<IGameSetupService>();
gameSetup.SetGamePath(Settings.Default.GameRootPath, true);
gameSetup.SetModDirectoryName(Settings.Default.ModDirectoryName);

services.AddSingleton<IImyaSetupService, ImyaSetupService>();
services.AddSingleton<IGameFilesService, GameFileService>();
services.AddSingleton<IGameFilesService, GameFileService>();
services.AddTransient<ICyclicDependencyAttributeFactory, CyclicDependencyAttributeFactory>();
services.AddTransient<IMissingModinfoAttributeFactory, MissingModinfoAttributeFactory>();
services.AddTransient<IModCompabilityAttributeFactory, ModCompabilityAttributeFactory>();
Expand All @@ -67,11 +68,7 @@ public App()
services.AddTransient<ITweakedAttributeFactory, TweakedAttributeFactory>();
services.AddTransient<IContentInSubfolderAttributeFactory, ContentInSubfolderAttributeFactory>();
services.AddTransient<IModAccessIssueAttributeFactory, ModAccessIssueAttributeFactory>();


services.AddSingleton<LocalizedModinfoFactory>();
services.AddSingleton<IModFactory, ModFactory>();
services.AddSingleton<IModCollectionFactory, ModCollectionFactory>();
services.AddTransient<ModTweaksStorageModelLoader>();
services.AddSingleton<ITweakRepository, TweakRepository>();
services.AddSingleton<ModTweaksLoader>();
Expand All @@ -97,6 +94,8 @@ public App()
services.AddTransient<FilenameValidationConverter>();
services.AddTransient<FilepathToImageConverter>();
services.AddTransient<DlcIconConverter>();
services.AddTransient<ByteSizeConverter>();
services.AddTransient<SpeedConverter>();

//game launcher
services.AddSingleton<IGameLauncherFactory, GameLauncherFactory>();
Expand Down Expand Up @@ -145,7 +144,6 @@ public App()
services.AddTransient<ModList>();
services.AddTransient<ModTweaker>();
services.AddTransient<Dashboard>();
services.AddTransient<ConsoleLog>();
services.AddTransient<ModDescriptionDisplay>();
services.AddSingleton<ModActivationView>();
services.AddSingleton<GithubBrowserView>();
Expand All @@ -157,10 +155,28 @@ public App()
services.AddSingleton<MainWindow>();
services.AddSingleton<IMainViewController, MainViewController>();
services.AddSingleton<IAuthenticationController, AuthenticationController>();

services.AddSingleton<System.Windows.Controls.RichTextBox>(sp => {
return new System.Windows.Controls.RichTextBox();
});
services.AddSingleton<RedirectOutput>();

services.AddSingleton<SelfUpdater>();
})
.ConfigureLogging(builder =>
{
builder.ClearProviders();
builder.AddSerilog();
builder.SetMinimumLevel(LogLevel.Trace);
})
.UseSerilog((hostingContext, services, loggerConfiguration)
=> loggerConfiguration
.Enrich.FromLogContext()
.WriteTo.RichTextBox(
services.GetService<System.Windows.Controls.RichTextBox>(),
theme: RichTextBoxConsoleTheme.None,
outputTemplate: "[{Timestamp:HH:mm:ss}] {Message:lj}{NewLine}{Exception}"
)
)
.Build();

var textManager = AppHost.Services.GetRequiredService<ITextManager>();
Expand All @@ -170,17 +186,23 @@ public App()
var settings = AppHost.Services.GetRequiredService<IAppSettings>();
settings.GamePath = Settings.Default.GameRootPath;
settings.ModDirectoryName = Settings.Default.ModDirectoryName;
}

var factory = AppHost.Services.GetRequiredService<IModCollectionFactory>();
var collection = factory.Get(gameSetup.GetModDirectory(), normalize: true);
protected override async void OnStartup(StartupEventArgs e)
{
var gameSetup = AppHost.Services.GetRequiredService<IGameSetupService>();
var imyaSetup = AppHost.Services.GetRequiredService<IImyaSetupService>();
var hooks = AppHost.Services.GetRequiredService<ModCollectionHooks>();

var collection = await AppHost.Services
.GetRequiredService<CollectionBuilder>()
.AddFromLocalSource(gameSetup.GetModDirectory())
.BuildAsync();
imyaSetup.GlobalModCollection = collection;

//subscribe the global mod collection to the gamesetup
//check if this can be moved to OnStartup
var globalMods = imyaSetup.GlobalModCollection;
var hooks = AppHost.Services.GetRequiredService<ModCollectionHooks>();
hooks.HookTo(globalMods);
hooks.HookTo(imyaSetup.GlobalModCollection);
hooks.AddHook(AppHost.Services.GetRequiredService<ModContentValidator>());
hooks.AddHook(AppHost.Services.GetRequiredService<ModCompatibilityValidator>());
hooks.AddHook(AppHost.Services.GetRequiredService<CyclicDependencyValidator>());
Expand All @@ -190,12 +212,6 @@ public App()
hooks.AddHook(AppHost.Services.GetRequiredService<TweakValidator>());
hooks.AddHook(AppHost.Services.GetRequiredService<DlcOwnershipValidator>());
hooks.HookTo(AppHost.Services.GetRequiredService<IAppSettings>());
}

protected override async void OnStartup(StartupEventArgs e)
{
var globalMods = AppHost.Services.GetRequiredService<IImyaSetupService>().GlobalModCollection;
await globalMods.LoadModsAsync();

var appSettings = AppHost.Services.GetRequiredService<IAppSettings>();
appSettings.Initialize();
Expand All @@ -213,12 +229,19 @@ protected override async void OnStartup(StartupEventArgs e)
Resources.Add("DlcTextConverter", AppHost.Services.GetRequiredService<DlcTextConverter>());
Resources.Add("FilepathToImageConverter", AppHost.Services.GetRequiredService<FilepathToImageConverter>());
Resources.Add("FilenameValidationConverter", AppHost.Services.GetRequiredService<FilenameValidationConverter>());
Resources.Add("DlcIconConverter", AppHost.Services.GetRequiredService<DlcIconConverter>());
Resources.Add("DlcIconConverter", AppHost.Services.GetRequiredService<DlcIconConverter>());
Resources.Add("ByteSizeConverter", AppHost.Services.GetRequiredService<ByteSizeConverter>());
Resources.Add("SpeedConverter", AppHost.Services.GetRequiredService<SpeedConverter>());

var redirectedOut = AppHost.Services.GetRequiredService<RedirectOutput>();
Console.SetOut(redirectedOut);
var startupForm = AppHost.Services.GetRequiredService<MainWindow>();
AppHost.Services.GetRequiredService<System.Windows.Controls.RichTextBox>()
.Style = (Style)FindResource("IMYA_RICHTEXTBOX");
startupForm.Show();

base.OnStartup(e);

}

protected override async void OnExit(ExitEventArgs e)
Expand Down
51 changes: 9 additions & 42 deletions ModManager/EmbeddedConsole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -8,51 +9,17 @@

namespace Imya.UI
{
public class EmbeddedConsole : TextWriter
public class RedirectOutput : TextWriter
{
private TextBox TargetTextBox;
private MainWindow Parent;

public override Encoding Encoding => Encoding.Unicode;

public EmbeddedConsole(TextBox t, MainWindow m)
private ILogger<RedirectOutput> _logger;
public RedirectOutput(ILogger<RedirectOutput> logger )
{
TargetTextBox = t;
Parent = m;
_logger = logger;
}

private void WriteTimestamp()
{
TargetTextBox.Dispatcher.BeginInvoke(() =>
TargetTextBox.Text += $"[LOG | { DateTime.Now.ToString("dd.MM.yy | hh:mm:ss")}]: "
);
}

public override void Write(char c)
{
WriteTimestamp();
TargetTextBox.Dispatcher.BeginInvoke(() =>
TargetTextBox.Text += c
);
}

public override void Write(String? s)
{
WriteTimestamp();
TargetTextBox.Dispatcher.BeginInvoke(() =>
TargetTextBox.Text += s
);
}

public override void WriteLine(String? s)
{
WriteTimestamp();
TargetTextBox.Dispatcher.BeginInvoke(() =>
{
TargetTextBox.Text += s;
TargetTextBox.Text += Environment.NewLine;
}
);
}
public override void Write(char c) => _logger.LogInformation(""+c);
public override void Write(String? s) => _logger.LogInformation(s);
public override void WriteLine(String? s) => _logger.LogInformation(s);
}
}
15 changes: 9 additions & 6 deletions ModManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
</Grid.Resources>
<ContentControl Grid.RowSpan="2"
Content="{Binding Dashboard}" />
<ContentControl Grid.Column="1"
Height="100"
Visibility="{Binding Settings.ConsoleVisibility, Converter={StaticResource BoolToVis}, UpdateSourceTrigger=PropertyChanged}"
Grid.Row="1"
Margin="0,0,5,5"
Content="{Binding ConsoleLogTextBox}" />

<ScrollViewer Grid.Column="1"
Height="100"
Style="{StaticResource IMYA_SCROLLVIEWER}"
Grid.Row="1"
Margin="0,0,5,5"
Visibility="{Binding Settings.ConsoleVisibility, Converter={StaticResource BoolToVis}, UpdateSourceTrigger=PropertyChanged}">
<ContentControl Content="{Binding ConsoleLogTextBox}" />
</ScrollViewer>

<ContentControl Grid.Row="0"
Grid.Column="1"
Expand Down
12 changes: 7 additions & 5 deletions ModManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Anno.Utils;
using Imya.Services;
using Imya.Services.Interfaces;
Expand All @@ -29,22 +30,22 @@ public partial class MainWindow : Window
private PopupCreator _popupCreator;

public Dashboard Dashboard { get; set; }
public ConsoleLog ConsoleLogTextBox { get; set; }
public RichTextBox ConsoleLogTextBox { get; set; }

public MainWindow(
IAuthenticator authenticator,
IMainViewController mainViewController,
IGameSetupService gameSetupService,
Dashboard dashboard,
ConsoleLog consoleLog,
RichTextBox TextBox,
PopupCreator popupCreator,
SelfUpdater selfUpdater)
{
_authenticator = authenticator;
_gameSetupService = gameSetupService;
_popupCreator = popupCreator;
Dashboard = dashboard;
ConsoleLogTextBox = consoleLog;
ConsoleLogTextBox = TextBox;

MainViewController = mainViewController;

Expand All @@ -56,6 +57,8 @@ public MainWindow(
MinHeight = Settings.Default.MinWindowHeight;
MinWidth = Settings.Default.MinWindowWidth;



var productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion ?? "?";
Title = $"iModYourAnno - Anno 1800 Mod Manager {productVersion}";

Expand All @@ -76,13 +79,12 @@ public MainWindow(
}

// initialize self-updater
if(!Settings.DevMode)
if (!Settings.DevMode)
selfUpdater.CheckForUpdate("anno-mods", "iModYourAnno");
}

public void SetUpEmbeddedConsole()
{
Console.SetOut(new EmbeddedConsole(ConsoleLogTextBox.Console, this));
}
}
}
Loading
Loading