Add other profiles

This commit is contained in:
Timothy Baldridge 2021-11-05 16:58:08 -06:00
parent b12d927839
commit cec652864e
4 changed files with 74 additions and 5 deletions

View File

@ -8,7 +8,7 @@
x:Class="Wabbajack.App.Screens.CompilerConfigurationView"> x:Class="Wabbajack.App.Screens.CompilerConfigurationView">
<Grid RowDefinitions="40, *, 40" Margin="8"> <Grid RowDefinitions="40, *, 40" Margin="8">
<TextBlock Grid.Row="0" x:Name="StatusText" FontSize="20" FontWeight="Bold">Compiler Configuration</TextBlock> <TextBlock Grid.Row="0" x:Name="StatusText" FontSize="20" FontWeight="Bold">Compiler Configuration</TextBlock>
<Grid Grid.Row="1" ColumnDefinitions="Auto, *" RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto" <Grid Grid.Row="1" ColumnDefinitions="Auto, *" RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto"
Margin="4"> Margin="4">
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right">Title:</Label> <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right">Title:</Label>
<TextBox Grid.Column="1" Grid.Row="0" x:Name="Title" /> <TextBox Grid.Column="1" Grid.Row="0" x:Name="Title" />
@ -29,9 +29,28 @@
</ComboBox> </ComboBox>
<Label Grid.Column="0" Grid.Row="5" HorizontalAlignment="Right">Output Folder:</Label> <Label Grid.Column="0" Grid.Row="5" HorizontalAlignment="Right">Output Folder:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="5" x:Name="OutputFolder" SelectFolder="True" /> <controls:FileSelectionBox Grid.Column="1" Grid.Row="5" x:Name="OutputFolder" SelectFolder="True" />
<Label Grid.Column="0" Grid.Row="6" HorizontalAlignment="Right" VerticalAlignment="Top">Always Enabled:</Label> <Label Grid.Column="0" Grid.Row="6" HorizontalAlignment="Right" VerticalAlignment="Top">Other Profiles:</Label>
<StackPanel Grid.Column="1" Grid.Row="6" Orientation="Vertical"> <StackPanel Grid.Column="1" Grid.Row="6" Orientation="Vertical">
<Button x:Name="AddOtherProfile">
<i:MaterialIcon Kind="AddCircle" />
</Button>
<ItemsControl x:Name="OtherProfilesList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:RemovableListItem />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<Label Grid.Column="0" Grid.Row="7" HorizontalAlignment="Right" VerticalAlignment="Top">Always Enabled:</Label>
<StackPanel Grid.Column="1" Grid.Row="7" Orientation="Vertical">
<Button x:Name="AddAlwaysEnabled"> <Button x:Name="AddAlwaysEnabled">
<i:MaterialIcon Kind="AddCircle" /> <i:MaterialIcon Kind="AddCircle" />
</Button> </Button>
@ -48,6 +67,8 @@
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
</StackPanel> </StackPanel>
</Grid> </Grid>

View File

@ -20,6 +20,7 @@ public partial class CompilerConfigurationView : ScreenBase<CompilerConfiguratio
{ {
InitializeComponent(); InitializeComponent();
AddAlwaysEnabled.Command = ReactiveCommand.Create(() => AddAlwaysEnabled_Command().FireAndForget()); AddAlwaysEnabled.Command = ReactiveCommand.Create(() => AddAlwaysEnabled_Command().FireAndForget());
AddOtherProfile.Command = ReactiveCommand.Create(() => AddOtherProfile_Command().FireAndForget());
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
@ -54,8 +55,27 @@ public partial class CompilerConfigurationView : ScreenBase<CompilerConfiguratio
DeleteCommand = ReactiveCommand.Create(() => { ViewModel?.RemoveAlwaysExcluded(itm); }) DeleteCommand = ReactiveCommand.Create(() => { ViewModel?.RemoveAlwaysExcluded(itm); })
})) }))
.DisposeWith(disposables); .DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.OtherProfiles, view => view.OtherProfilesList.Items,
d => d!.Select(itm => new RemovableItemViewModel
{
Text = itm.ToString(),
DeleteCommand = ReactiveCommand.Create(() => { ViewModel?.RemoveOtherProfile(itm); })
}))
.DisposeWith(disposables);
}); });
} }
private async Task AddOtherProfile_Command()
{
var dialog = new OpenFolderDialog
{
Title = "Select a profile folder"
};
var result = await dialog.ShowAsync(App.MainWindow);
if (!string.IsNullOrWhiteSpace(result))
ViewModel!.AddOtherProfile(result.ToAbsolutePath());
}
private async Task AddAlwaysEnabled_Command() private async Task AddAlwaysEnabled_Command()
{ {

View File

@ -71,6 +71,9 @@ public class CompilerConfigurationViewModel : ViewModelBase
[Reactive] public IEnumerable<RelativePath> AlwaysEnabled { get; set; } = Array.Empty<RelativePath>(); [Reactive] public IEnumerable<RelativePath> AlwaysEnabled { get; set; } = Array.Empty<RelativePath>();
[Reactive]
public string[] OtherProfiles { get; set; } = Array.Empty<string>();
public AbsolutePath SettingsOutputLocation => Source.Combine(Title) public AbsolutePath SettingsOutputLocation => Source.Combine(Title)
.WithExtension(IsMO2Compilation ? Ext.MO2CompilerSettings : Ext.CompilerSettings); .WithExtension(IsMO2Compilation ? Ext.MO2CompilerSettings : Ext.CompilerSettings);
@ -109,10 +112,24 @@ public class CompilerConfigurationViewModel : ViewModelBase
Profile = SelectedProfile, Profile = SelectedProfile,
UseGamePaths = true, UseGamePaths = true,
OutputFile = OutputFolder.Combine(SelectedProfile).WithExtension(Ext.Wabbajack), OutputFile = OutputFolder.Combine(SelectedProfile).WithExtension(Ext.Wabbajack),
AlwaysEnabled = AlwaysEnabled.ToArray() AlwaysEnabled = AlwaysEnabled.ToArray(),
OtherProfiles = OtherProfiles.ToArray()
}; };
} }
public bool AddOtherProfile(AbsolutePath path)
{
if (!path.InFolder(Source.Combine(Consts.MO2Profiles))) return false;
var relative = path.RelativeTo(Source.Combine(Consts.MO2Profiles)).ToString();
OtherProfiles = OtherProfiles.Append(relative).Distinct().ToArray();
return true;
}
public void RemoveOtherProfile(string profile)
{
OtherProfiles = OtherProfiles.Where(p => p != profile).ToArray();
}
public bool AddAlwaysExcluded(AbsolutePath path) public bool AddAlwaysExcluded(AbsolutePath path)
{ {
if (!path.InFolder(Source)) return false; if (!path.InFolder(Source)) return false;
@ -150,6 +167,8 @@ public class CompilerConfigurationViewModel : ViewModelBase
IsMO2Compilation = true; IsMO2Compilation = true;
AlwaysEnabled = Array.Empty<RelativePath>();
// Find Always Enabled mods // Find Always Enabled mods
foreach (var modFolder in mo2Folder.Combine("mods").EnumerateDirectories()) foreach (var modFolder in mo2Folder.Combine("mods").EnumerateDirectories())
{ {
@ -158,12 +177,17 @@ public class CompilerConfigurationViewModel : ViewModelBase
var data = iniFile.LoadIniFile(); var data = iniFile.LoadIniFile();
var generalModData = data["General"]; var generalModData = data["General"];
AlwaysEnabled = Array.Empty<RelativePath>();
if ((generalModData["notes"]?.Contains("WABBAJACK_ALWAYS_ENABLE") ?? false) || if ((generalModData["notes"]?.Contains("WABBAJACK_ALWAYS_ENABLE") ?? false) ||
(generalModData["comments"]?.Contains("WABBAJACK_ALWAYS_ENABLE") ?? false)) (generalModData["comments"]?.Contains("WABBAJACK_ALWAYS_ENABLE") ?? false))
AlwaysEnabled = AlwaysEnabled.Append(modFolder.RelativeTo(mo2Folder)).ToArray(); AlwaysEnabled = AlwaysEnabled.Append(modFolder.RelativeTo(mo2Folder)).ToArray();
} }
var otherProfilesFile = settingsFile.Parent.Combine("otherprofiles.txt");
if (otherProfilesFile.FileExists())
{
OtherProfiles = await otherProfilesFile.ReadAllLinesAsync().ToArray();
}
if (mo2Folder.Depth > 1) if (mo2Folder.Depth > 1)
OutputFolder = mo2Folder.Parent; OutputFolder = mo2Folder.Parent;
@ -173,6 +197,8 @@ public class CompilerConfigurationViewModel : ViewModelBase
} }
} }
private async Task SaveSettingsFile() private async Task SaveSettingsFile()
{ {
await using var st = SettingsOutputLocation.Open(FileMode.Create, FileAccess.Write, FileShare.None); await using var st = SettingsOutputLocation.Open(FileMode.Create, FileAccess.Write, FileShare.None);
@ -189,6 +215,7 @@ public class CompilerConfigurationViewModel : ViewModelBase
{ {
var mo2 = await LoadSettingsFile<MO2CompilerSettings>(path); var mo2 = await LoadSettingsFile<MO2CompilerSettings>(path);
AlwaysEnabled = mo2.AlwaysEnabled; AlwaysEnabled = mo2.AlwaysEnabled;
OtherProfiles = mo2.OtherProfiles;
SelectedProfile = mo2.Profile; SelectedProfile = mo2.Profile;
s = mo2; s = mo2;
} }

View File

@ -7,4 +7,5 @@ public class MO2CompilerSettings : CompilerSettings
{ {
public string Profile { get; set; } = ""; public string Profile { get; set; } = "";
public RelativePath[] AlwaysEnabled { get; set; } = Array.Empty<RelativePath>(); public RelativePath[] AlwaysEnabled { get; set; } = Array.Empty<RelativePath>();
public string[] OtherProfiles { get; set; }
} }