Skip to content

Commit

Permalink
Add "check for games updates" to main menu for faster access
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye116477 committed Mar 27, 2024
1 parent 85941ea commit f42bd21
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 40 deletions.
46 changes: 46 additions & 0 deletions src/LegendaryLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;

namespace LegendaryLibraryNS
{
Expand Down Expand Up @@ -546,5 +547,50 @@ public static void ClearCache()
}
}
}

public static void ShowCheckAllGamesUpdatesDialog()
{
IPlayniteAPI playniteAPI = API.Instance;
if (!IsInstalled)
{
playniteAPI.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.LegendaryLauncherNotInstalled));
return;
}

var gamesUpdates = new Dictionary<string, UpdateInfo>();
LegendaryUpdateController legendaryUpdateController = new LegendaryUpdateController();
GlobalProgressOptions updateCheckProgressOptions = new GlobalProgressOptions(ResourceProvider.GetString(LOC.LegendaryCheckingForUpdates), false) { IsIndeterminate = true };
playniteAPI.Dialogs.ActivateGlobalProgress(async (a) =>
{
gamesUpdates = await legendaryUpdateController.CheckAllGamesUpdates();
}, updateCheckProgressOptions);
if (gamesUpdates.Count > 0)
{
var successUpdates = gamesUpdates.Where(i => i.Value.Success).ToDictionary(i => i.Key, i => i.Value);
if (successUpdates.Count > 0)
{
Window window = playniteAPI.Dialogs.CreateWindow(new WindowCreationOptions
{
ShowMaximizeButton = false,
});
window.DataContext = successUpdates;
window.Title = $"{ResourceProvider.GetString(LOC.Legendary3P_PlayniteExtensionsUpdates)}";
window.Content = new LegendaryUpdater();
window.Owner = playniteAPI.Dialogs.GetCurrentAppWindow();
window.SizeToContent = SizeToContent.WidthAndHeight;
window.MinWidth = 600;
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.ShowDialog();
}
else
{
playniteAPI.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.Legendary3P_PlayniteUpdateCheckFailMessage));
}
}
else
{
playniteAPI.Dialogs.ShowMessage(ResourceProvider.GetString(LOC.LegendaryNoUpdatesAvailable));
}
}
}
}
14 changes: 14 additions & 0 deletions src/LegendaryLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -858,5 +858,19 @@ public override IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs
}
}

public override IEnumerable<MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs args)
{
yield return new MainMenuItem
{
Description = ResourceProvider.GetString(LOC.LegendaryCheckForGamesUpdatesButton),
MenuSection = $"@{Instance.Name}",
Icon = "UpdateDbIcon",
Action = (args) =>
{
LegendaryLauncher.ShowCheckAllGamesUpdatesDialog();
}
};
}

}
}
41 changes: 1 addition & 40 deletions src/LegendaryLibrarySettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,46 +564,7 @@ private void ActivateEaBtn_Click(object sender, RoutedEventArgs e)

private void GamesUpdateCheckBtn_Click(object sender, RoutedEventArgs e)
{
if (!LegendaryLauncher.IsInstalled)
{
playniteAPI.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.LegendaryLauncherNotInstalled));
return;
}

var gamesUpdates = new Dictionary<string, UpdateInfo>();
LegendaryUpdateController legendaryUpdateController = new LegendaryUpdateController();
GlobalProgressOptions updateCheckProgressOptions = new GlobalProgressOptions(ResourceProvider.GetString(LOC.LegendaryCheckingForUpdates), false) { IsIndeterminate = true };
playniteAPI.Dialogs.ActivateGlobalProgress(async (a) =>
{
gamesUpdates = await legendaryUpdateController.CheckAllGamesUpdates();
}, updateCheckProgressOptions);
if (gamesUpdates.Count > 0)
{
var successUpdates = gamesUpdates.Where(i => i.Value.Success).ToDictionary(i => i.Key, i => i.Value);
if (successUpdates.Count > 0)
{
Window window = playniteAPI.Dialogs.CreateWindow(new WindowCreationOptions
{
ShowMaximizeButton = false,
});
window.DataContext = successUpdates;
window.Title = $"{ResourceProvider.GetString(LOC.Legendary3P_PlayniteExtensionsUpdates)}";
window.Content = new LegendaryUpdater();
window.Owner = playniteAPI.Dialogs.GetCurrentAppWindow();
window.SizeToContent = SizeToContent.WidthAndHeight;
window.MinWidth = 600;
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.ShowDialog();
}
else
{
playniteAPI.Dialogs.ShowErrorMessage(ResourceProvider.GetString(LOC.Legendary3P_PlayniteUpdateCheckFailMessage));
}
}
else
{
playniteAPI.Dialogs.ShowMessage(ResourceProvider.GetString(LOC.LegendaryNoUpdatesAvailable));
}
LegendaryLauncher.ShowCheckAllGamesUpdatesDialog();
}

private void GamesUpdatesCBo_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down

0 comments on commit f42bd21

Please sign in to comment.