Skip to content

Commit

Permalink
Enhance repairing and layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye116477 committed May 30, 2023
1 parent 0e619b1 commit 163909d
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 20 deletions.
10 changes: 7 additions & 3 deletions src/LegendaryGameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public override void Install(InstallActionArgs args)
}
else
{
window = new Window();
window.Background = System.Windows.Media.Brushes.DodgerBlue;
window = new Window
{
Background = System.Windows.Media.Brushes.DodgerBlue
};
}
window.Title = Game.Name;
window.DataContext = Game.GameId.ToString();
var installProperties = new DownloadProperties { downloadAction = (int)Enums.DownloadAction.Install };
var installData = new DownloadManagerData.Download { gameID = Game.GameId, downloadProperties = installProperties };
window.DataContext = installData;
window.Content = new LegendaryGameInstaller();
window.Owner = playniteAPI.Dialogs.GetCurrentAppWindow();
window.SizeToContent = SizeToContent.WidthAndHeight;
Expand Down
14 changes: 8 additions & 6 deletions src/LegendaryGameInstaller.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<DockPanel Margin="10">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,0,0"
VerticalAlignment="Bottom" Grid.Row="6" Grid.Column="2" DockPanel.Dock="Bottom">
<Button x:Name="RepairBtn" Content="{DynamicResource LOCLegendaryRepair}"
HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,5,0" Visibility="Collapsed" IsEnabled="False" Click="RepairBtn_Click" />
<Button x:Name="ImportBtn" Content="{DynamicResource LOCLegendaryImportEGL}"
HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,5,0"
Click="ImportBtn_Click" />
Expand All @@ -43,10 +45,10 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{DynamicResource LOCGameInstallDirTitle}" Grid.Row="0"></TextBlock>
<DockPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Margin="0,0,0,15">
<DockPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,15" Name="FolderDP">
<TextBlock Text="{DynamicResource LOCGameInstallDirTitle}" VerticalAlignment="Center" Margin="0,0,10,0"></TextBlock>
<Button DockPanel.Dock="Right" Padding="5" Margin="5 0 0 0" Content="&#xec5b;"
Name="ChooseGamePathBtn" Click="ChooseGamePathBtn_Click" FontFamily="{DynamicResource FontIcoFont}"/>
Name="ChooseGamePathBtn" Click="ChooseGamePathBtn_Click" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCSelectDirectoryTooltip}" />
<TextBox Name="SelectedGamePathTxt" Text="" VerticalAlignment="Top" Margin="0,5" />
</DockPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="0">
Expand All @@ -55,7 +57,7 @@
<TextBlock x:Name="DownloadSizeTB" Text="{DynamicResource LOCLoadingLabel}"
VerticalAlignment="Top" Margin="5,0,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0">
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Margin="0,0,0,15">
<TextBlock VerticalAlignment="Top" Text="{DynamicResource LOCLegendaryInstallSize}" />
<TextBlock x:Name="InstallSizeTB" Text="{DynamicResource LOCLoadingLabel}"
VerticalAlignment="Top" Margin="5,0,0,0" />
Expand All @@ -67,7 +69,7 @@
<TextBlock VerticalAlignment="Top" Text="{DynamicResource LOCLoadingLabel}"
Margin="5,0,0,0" Name="SpaceTB" />
</StackPanel>
<Border Grid.Row="4" Grid.Column="0" BorderThickness="2" Style="{DynamicResource HighlightBorder}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0,15,0,0" Grid.ColumnSpan="2" Name="ExtraContentBrd" Visibility="Collapsed">
<Border Grid.Row="4" Grid.Column="0" BorderThickness="2" Style="{DynamicResource HighlightBorder}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Grid.ColumnSpan="2" Name="ExtraContentBrd" Visibility="Collapsed" Margin="0,0,0,5">
<Expander Header="{DynamicResource LOCLegendaryExtraContent}" Margin="2,2,5,2" HorizontalAlignment="Left">
<ListBox BorderThickness="0" Name="ExtraContentLB" SelectionMode="Multiple" SelectionChanged="ExtraContentLB_SelectionChanged" Margin="5,0,5,5">
<ListBox.Resources>
Expand All @@ -84,7 +86,7 @@
</ListBox>
</Expander>
</Border>
<Border Grid.Row="5" Grid.Column="0" BorderThickness="2" Style="{DynamicResource HighlightBorder}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0,5,0,0" Grid.ColumnSpan="2">
<Border Grid.Row="5" Grid.Column="0" BorderThickness="2" Style="{DynamicResource HighlightBorder}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Grid.ColumnSpan="2">
<Expander Header="{DynamicResource LOCLegendaryAdvancedOptions}" Margin="2,2,5,2" HorizontalAlignment="Left" >
<Grid Margin="5">
<Grid.ColumnDefinitions>
Expand Down
77 changes: 75 additions & 2 deletions src/LegendaryGameInstaller.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public LegendaryGameInstaller()

public Window InstallerWindow => Window.GetWindow(this);

public string GameID => DataContext.ToString();
public DownloadManagerData.Download InstallData => (DownloadManagerData.Download)DataContext;
public string GameID => InstallData.gameID;

private void ChooseGamePathBtn_Click(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -161,12 +162,26 @@ private async void ImportBtn_Click(object sender, RoutedEventArgs e)

private async void LegendaryGameInstallerUC_Loaded(object sender, RoutedEventArgs e)
{
if (InstallData.downloadProperties.downloadAction == (int)DownloadAction.Repair)
{
FolderDP.Visibility = Visibility.Collapsed;
ImportBtn.Visibility = Visibility.Collapsed;
InstallBtn.Visibility = Visibility.Collapsed;
RepairBtn.Visibility = Visibility.Visible;
}
var settings = LegendaryLibrary.GetSettings();
SelectedGamePathTxt.Text = settings.GamesInstallationPath;
ReorderingChk.IsChecked = settings.EnableReordering;
MaxWorkersNI.Value = settings.MaxWorkers.ToString();
MaxSharedMemoryNI.Value = settings.MaxSharedMemory.ToString();
UpdateSpaceInfo(SelectedGamePathTxt.Text);
if (!SelectedGamePathTxt.Text.IsNullOrEmpty())
{
UpdateSpaceInfo(SelectedGamePathTxt.Text);
}
else
{
UpdateSpaceInfo(settings.GamesInstallationPath);
}
requiredThings = new List<string>();
var cacheInfoPath = LegendaryLibrary.Instance.GetCachePath("infocache");
var cacheInfoFile = Path.Combine(cacheInfoPath, GameID + ".json");
Expand Down Expand Up @@ -359,6 +374,7 @@ private async void LegendaryGameInstallerUC_Loaded(object sender, RoutedEventArg

}
InstallBtn.IsEnabled = true;
RepairBtn.IsEnabled = true;
}

private void UpdateSpaceInfo(string path)
Expand Down Expand Up @@ -417,5 +433,62 @@ private void SetControlStyles()
Resources.Add(typeof(TextBlock), implicitStyle);
}
}

private async void RepairBtn_Click(object sender, RoutedEventArgs e)
{
var settings = LegendaryLibrary.GetSettings();
int maxWorkers = settings.MaxWorkers;
if (MaxWorkersNI.Value != "")
{
maxWorkers = int.Parse(MaxWorkersNI.Value);
}
int maxSharedMemory = settings.MaxSharedMemory;
if (MaxSharedMemoryNI.Value != "")
{
maxSharedMemory = int.Parse(MaxSharedMemoryNI.Value);
}
bool enableReordering = Convert.ToBoolean(ReorderingChk.IsChecked);
var selectedExtraContent = new List<string>();
if (requiredThings.Count > 0)
{
selectedExtraContent.Add("");
foreach (var requiredThing in requiredThings)
{
selectedExtraContent.Add(requiredThing);
}
}
if (ExtraContentLB.Items.Count > 0)
{
selectedExtraContent.AddMissing("");
foreach (var selectedOption in ExtraContentLB.SelectedItems.Cast<KeyValuePair<string, LegendarySDLInfo>>().ToList())
{
foreach (var tag in selectedOption.Value.Tags)
{
selectedExtraContent.AddMissing(tag);
}
}
}
InstallerWindow.Close();
LegendaryDownloadManager downloadManager = LegendaryLibrary.GetLegendaryDownloadManager();
var wantedItem = downloadManager.downloadManagerData.downloads.FirstOrDefault(item => item.gameID == GameID);
if (wantedItem != null)
{
playniteAPI.Dialogs.ShowMessage(string.Format(ResourceProvider.GetString(LOC.LegendaryDownloadAlreadyExists), wantedItem.name));
}
else
{
playniteAPI.Dialogs.ShowMessage(ResourceProvider.GetString(LOC.LegendaryDownloadManagerWhatsUp));
DownloadProperties downloadProperties = new DownloadProperties()
{
installPath = "",
downloadAction = (int)DownloadAction.Repair,
enableReordering = enableReordering,
maxWorkers = maxWorkers,
maxSharedMemory = maxSharedMemory,
extraContent = selectedExtraContent
};
await downloadManager.EnqueueJob(GameID, InstallerWindow.Title, downloadSize, installSize, downloadProperties);
}
}
}
}
33 changes: 25 additions & 8 deletions src/LegendaryLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,16 +496,33 @@ public override IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs
yield return new GameMenuItem
{
Description = ResourceProvider.GetString(LOC.LegendaryRepair),
Action = async (args) =>
Action = (args) =>
{
DownloadProperties downloadProperties = new DownloadProperties()
Window window = null;
if (PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
{
downloadAction = (int)DownloadAction.Repair,
enableReordering = GetSettings().EnableReordering,
maxWorkers = GetSettings().MaxWorkers,
maxSharedMemory = GetSettings().MaxSharedMemory
};
await GetLegendaryDownloadManager().EnqueueJob(game.GameId, game.Name, "", "", downloadProperties);
window = PlayniteApi.Dialogs.CreateWindow(new WindowCreationOptions
{
ShowMaximizeButton = false,
});
}
else
{
window = new Window
{
Background = System.Windows.Media.Brushes.DodgerBlue
};
}
window.Title = game.Name;
var installProperties = new DownloadProperties { downloadAction = (int)DownloadAction.Repair };
var installData = new DownloadManagerData.Download { gameID = game.GameId, downloadProperties = installProperties };
window.DataContext = installData;
window.Content = new LegendaryGameInstaller();
window.Owner = PlayniteApi.Dialogs.GetCurrentAppWindow();
window.SizeToContent = SizeToContent.WidthAndHeight;
window.MinWidth = 600;
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.ShowDialog();
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/LegendaryLibrarySettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Margin="0,0,0,2"></TextBlock>
<DockPanel Margin="0,0,0,10">
<Button DockPanel.Dock="Right" Padding="5" Margin="5 0 0 0"
Name="ChooseGamePathBtn" Click="ChooseGamePathBtn_Click" Content="&#xec5b;" FontFamily="{DynamicResource FontIcoFont}"/>
Name="ChooseGamePathBtn" Click="ChooseGamePathBtn_Click" Content="&#xec5b;" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCSelectDirectoryTooltip}" />
<TextBox Name="SelectedGamePathTxt"
Text="{Binding Settings.GamesInstallationPath, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center" />
Expand Down

0 comments on commit 163909d

Please sign in to comment.