Skip to content

Commit

Permalink
Add possibility to update EOS Overlay - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye116477 committed Feb 5, 2024
1 parent fc05452 commit 24fc696
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 71 deletions.
5 changes: 5 additions & 0 deletions src/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static string FormatSize(double size, string unit = "B", bool toBits = fa
return finalSize.Replace("i", "");
}

public static double ToBytes(double size, string unit)
{
return ByteSize.Parse($"{size} {unit}").Bytes;
}

public static int TotalRAM
{
get
Expand Down
69 changes: 57 additions & 12 deletions src/LegendaryGameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;

Expand Down Expand Up @@ -398,10 +398,53 @@ public class LegendaryUpdateController
{
private IPlayniteAPI playniteAPI = API.Instance;
private static ILogger logger = LogManager.GetLogger();
public async Task<Dictionary<string, Installed>> CheckGameUpdates(string gameTitle, string gameId)
public async Task<Dictionary<string, UpdateInfo>> CheckGameUpdates(string gameTitle, string gameId)
{
var gamesToUpdate = new Dictionary<string, UpdateInfo>();
if (gameId == "eos-overlay")
{
var cmd = await Cli.Wrap(LegendaryLauncher.ClientExecPath)
.WithArguments(new[] { "eos-overlay", "update" })
.WithStandardInputPipe(PipeSource.FromString("n"))
.WithEnvironmentVariables(LegendaryLauncher.DefaultEnvironmentVariables)
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync();
if (!cmd.StandardError.Contains("is up to date"))
{
double downloadSizeNumber = 0;
double installSizeNumber = 0;
string downloadSizeUnit = "B";
string installSizeUnit = "B";
string[] lines = cmd.StandardError.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var line in lines)
{
var downloadSizeText = "Download size:";
if (line.Contains(downloadSizeText))
{
var downloadSizeSplittedString = line.Substring(line.IndexOf(downloadSizeText) + downloadSizeText.Length).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
downloadSizeNumber = double.Parse(downloadSizeSplittedString[0], CultureInfo.InvariantCulture);
downloadSizeUnit = downloadSizeSplittedString[1];
}
var installSizeText = "Install size:";
if (line.Contains(installSizeText))
{
var installSizeSplittedString = line.Substring(line.IndexOf(installSizeText) + installSizeText.Length).Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
installSizeNumber = double.Parse(installSizeSplittedString[0], CultureInfo.InvariantCulture);
installSizeUnit = installSizeSplittedString[1];
}
}
var updateInfo = new UpdateInfo
{
Version = "",
Title = ResourceProvider.GetString(LOC.LegendaryEOSOverlay),
Download_size = Helpers.ToBytes(downloadSizeNumber, downloadSizeUnit),
Disk_size = Helpers.ToBytes(installSizeNumber, installSizeUnit),
};
gamesToUpdate.Add(gameId, updateInfo);
}
return gamesToUpdate;
}
var newGameInfo = await LegendaryLauncher.GetGameInfo(gameId);
var gamesToUpdate = new Dictionary<string, Installed>();
if (newGameInfo.Game != null)
{
var installedAppList = LegendaryLauncher.GetInstalledAppList();
Expand All @@ -410,11 +453,12 @@ public class LegendaryUpdateController
var oldGameInfo = installedAppList[gameId];
if (oldGameInfo.Version != newGameInfo.Game.Version)
{
var updateInfo = new Installed
var updateInfo = new UpdateInfo
{
Version = newGameInfo.Game.Version,
Title = newGameInfo.Game.Title,
App_name = gameId,
Download_size = newGameInfo.Manifest.Download_size,
Disk_size = newGameInfo.Manifest.Disk_size
};
gamesToUpdate.Add(oldGameInfo.App_name, updateInfo);
}
Expand All @@ -433,11 +477,12 @@ public class LegendaryUpdateController
{
if (oldDlcInfo.Version != newDlcInfo.Game.Version)
{
var updateDlcInfo = new Installed
var updateDlcInfo = new UpdateInfo
{
Version = newDlcInfo.Game.Version,
Title = newDlcInfo.Game.Title,
App_name = dlc.App_name
Download_size = newDlcInfo.Manifest.Download_size,
Disk_size = newDlcInfo.Manifest.Disk_size
};
gamesToUpdate.Add(oldDlcInfo.App_name, updateDlcInfo);
}
Expand All @@ -455,10 +500,10 @@ public class LegendaryUpdateController
return gamesToUpdate;
}

public async Task<Dictionary<string, Installed>> CheckAllGamesUpdates()
public async Task<Dictionary<string, UpdateInfo>> CheckAllGamesUpdates()
{
var appList = LegendaryLauncher.GetInstalledAppList();
var gamesToUpdate = new Dictionary<string, Installed>();
var gamesToUpdate = new Dictionary<string, UpdateInfo>();
foreach (var game in appList.Where(item => item.Value.Is_dlc == false).OrderBy(item => item.Value.Title))
{
var gameID = game.Value.App_name;
Expand All @@ -484,7 +529,7 @@ public class LegendaryUpdateController
return gamesToUpdate;
}

public void UpdateGame(Dictionary<string, Installed> gamesToUpdate, string gameTitle = "", bool silently = false, DownloadProperties downloadProperties = null)
public void UpdateGame(Dictionary<string, UpdateInfo> gamesToUpdate, string gameTitle = "", bool silently = false, DownloadProperties downloadProperties = null)
{
var updateTasks = new List<DownloadManagerData.Download>();
if (gamesToUpdate.Count > 0)
Expand Down Expand Up @@ -528,8 +573,8 @@ public void UpdateGame(Dictionary<string, Installed> gamesToUpdate, string gameT
{
gameID = gameToUpdate.Key,
name = gameToUpdate.Value.Title,
downloadSize = "",
installSize = "",
downloadSize = Helpers.FormatSize(gameToUpdate.Value.Download_size),
installSize = Helpers.FormatSize(gameToUpdate.Value.Disk_size),
downloadProperties = downloadProperties
};
updateTasks.Add(updateTask);
Expand Down
2 changes: 1 addition & 1 deletion src/LegendaryLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public override IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs
throw new Exception(ResourceProvider.GetString(LOC.LegendaryLauncherNotInstalled));
}
LegendaryUpdateController legendaryUpdateController = new LegendaryUpdateController();
var gamesToUpdate = new Dictionary<string, Installed>();
var gamesToUpdate = new Dictionary<string, UpdateInfo>();
GlobalProgressOptions updateCheckProgressOptions = new GlobalProgressOptions(ResourceProvider.GetString(LOC.LegendaryCheckingForUpdates), false) { IsIndeterminate = true };
PlayniteApi.Dialogs.ActivateGlobalProgress(async (a) =>
{
Expand Down
1 change: 1 addition & 0 deletions src/LegendaryLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
<Compile Include="Models\LegendaryGameInfo.cs" />
<Compile Include="Models\LegendaryMetadata.cs" />
<Compile Include="Models\LegendarySDLInfo.cs" />
<Compile Include="Models\UpdateInfo.cs" />
<Compile Include="Models\OauthResponse.cs" />
<Compile Include="EpicMetadataProvider.cs" />
<Compile Include="Models\PlaytimePayload.cs" />
Expand Down
67 changes: 25 additions & 42 deletions src/LegendaryLibrarySettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private async void LegendarySettingsUC_Loaded(object sender, RoutedEventArgs e)
EOSOInstallBtn.Visibility = Visibility.Visible;
EOSOToggleBtn.Visibility = Visibility.Collapsed;
EOSOUninstallBtn.Visibility = Visibility.Collapsed;
EOSOCheckForUpdatesBtn.Visibility = Visibility.Collapsed;
}
else
{
Expand Down Expand Up @@ -572,7 +573,7 @@ private void GamesUpdateCheckBtn_Click(object sender, RoutedEventArgs e)
throw new Exception(ResourceProvider.GetString(LOC.LegendaryLauncherNotInstalled));
}

var gamesUpdates = new Dictionary<string, Installed>();
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) =>
Expand Down Expand Up @@ -618,53 +619,35 @@ private void OpenLogFilesPathBtn_Click(object sender, RoutedEventArgs e)
ProcessStarter.StartProcess("explorer.exe", playniteAPI.Paths.ConfigurationPath);
}

private async void EOSOCheckForUpdatesBtn_Click(object sender, RoutedEventArgs e)
private void EOSOCheckForUpdatesBtn_Click(object sender, RoutedEventArgs e)
{
var cmd = await Cli.Wrap(LegendaryLauncher.ClientExecPath)
.WithArguments(new[] { "eos-overlay", "update" })
.WithStandardInputPipe(PipeSource.FromString("n"))
.WithEnvironmentVariables(LegendaryLauncher.DefaultEnvironmentVariables)
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync();
if (cmd.StandardError.Contains("is up to date"))
LegendaryUpdateController legendaryUpdateController = new LegendaryUpdateController();
var gamesToUpdate = new Dictionary<string, UpdateInfo>();
GlobalProgressOptions updateCheckProgressOptions = new GlobalProgressOptions(ResourceProvider.GetString(LOC.LegendaryCheckingForUpdates), false) { IsIndeterminate = true };
playniteAPI.Dialogs.ActivateGlobalProgress(async (a) =>
{
playniteAPI.Dialogs.ShowMessage(ResourceProvider.GetString(LOC.LegendaryNoUpdatesAvailable), ResourceProvider.GetString(LOC.LegendaryEOSOverlay));
gamesToUpdate = await legendaryUpdateController.CheckGameUpdates(ResourceProvider.GetString(LOC.LegendaryEOSOverlay), "eos-overlay");
}, updateCheckProgressOptions);
if (gamesToUpdate.Count > 0)
{
Window window = playniteAPI.Dialogs.CreateWindow(new WindowCreationOptions
{
ShowMaximizeButton = false,
});
window.DataContext = gamesToUpdate;
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
{
var options = new List<MessageBoxOption>
{
new MessageBoxOption(ResourceProvider.GetString(LOC.Legendary3P_PlayniteUpdaterInstallUpdate)),
new MessageBoxOption(ResourceProvider.GetString(LOC.Legendary3P_PlayniteOKLabel)),
};
var result = playniteAPI.Dialogs.ShowMessage(string.Format(ResourceProvider.GetString(LOC.LegendaryNewVersionAvailable), ResourceProvider.GetString(LOC.LegendaryEOSOverlay), ""), ResourceProvider.GetString(LOC.Legendary3P_PlayniteUpdaterWindowTitle), MessageBoxImage.Information, options);
if (result == options[0])
{
LegendaryDownloadManager downloadManager = LegendaryLibrary.GetLegendaryDownloadManager();
var wantedItem = downloadManager.downloadManagerData.downloads.FirstOrDefault(item => item.gameID == "eos-overlay");
if (wantedItem != null)
{
if (wantedItem.status == DownloadStatus.Completed)
{
downloadManager.downloadManagerData.downloads.Remove(wantedItem);
downloadManager.SaveData();
wantedItem = null;
}
}
if (wantedItem != null)
{
playniteAPI.Dialogs.ShowMessage(string.Format(ResourceProvider.GetString(LOC.LegendaryDownloadAlreadyExists), wantedItem.name), "", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
DownloadProperties downloadProperties = new DownloadProperties()
{
downloadAction = DownloadAction.Update,
};
downloadManager.EnqueueJob("eos-overlay", ResourceProvider.GetString(LOC.LegendaryEOSOverlay), "", "", downloadProperties);
}
}
playniteAPI.Dialogs.ShowMessage(ResourceProvider.GetString(LOC.LegendaryNoUpdatesAvailable), ResourceProvider.GetString(LOC.LegendaryEOSOverlay));
}

}
}
}
23 changes: 7 additions & 16 deletions src/LegendaryUpdater.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace LegendaryLibraryNS
/// </summary>
public partial class LegendaryUpdater : UserControl
{
public Dictionary<string, Installed> UpdatesList => (Dictionary<string, Installed>)DataContext;
public Dictionary<string, UpdateInfo> UpdatesList => (Dictionary<string, UpdateInfo>)DataContext;
public LegendaryUpdater()
{
InitializeComponent();
Expand All @@ -35,24 +35,15 @@ private void UserControl_Loaded(object sender, RoutedEventArgs e)
ReorderingChk.IsChecked = settings.EnableReordering;
}

private async void UpdatesLB_SelectionChanged(object sender, SelectionChangedEventArgs e)
private void UpdatesLB_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
UpdateBtn.IsEnabled = UpdatesLB.SelectedIndex != -1;
double initialDownloadSizeNumber = 0;
double initialInstallSizeNumber = 0;
foreach (var selectedOption in UpdatesLB.SelectedItems.Cast<KeyValuePair<string, Installed>>().ToList())
foreach (var selectedOption in UpdatesLB.SelectedItems.Cast<KeyValuePair<string, UpdateInfo>>().ToList())
{
var manifest = await LegendaryLauncher.GetGameInfo(selectedOption.Key);
bool correctJson = false;
if (manifest != null && manifest.Manifest != null)
{
correctJson = true;
}
if (correctJson)
{
initialDownloadSizeNumber += manifest.Manifest.Download_size;
initialInstallSizeNumber += manifest.Manifest.Disk_size;
}
initialDownloadSizeNumber += selectedOption.Value.Download_size;
initialInstallSizeNumber += selectedOption.Value.Disk_size;
}
var downloadSize = Helpers.FormatSize(initialDownloadSizeNumber);
DownloadSizeTB.Text = downloadSize;
Expand Down Expand Up @@ -97,8 +88,8 @@ private void UpdateBtn_Click(object sender, RoutedEventArgs e)
enableReordering = enableReordering
};
Window.GetWindow(this).Close();
var updatesList = new Dictionary<string, Installed>();
foreach (var selectedOption in UpdatesLB.SelectedItems.Cast<KeyValuePair<string, Installed>>().ToList())
var updatesList = new Dictionary<string, UpdateInfo>();
foreach (var selectedOption in UpdatesLB.SelectedItems.Cast<KeyValuePair<string, UpdateInfo>>().ToList())
{
updatesList.Add(selectedOption.Key, selectedOption.Value);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Models/UpdateInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace LegendaryLibraryNS.Models
{
public class UpdateInfo
{
public string Title { get; set; }
public string Version { get; set; }
public double Disk_size { get; set; }
public double Download_size { get; set; }
public string Title_for_updater { get; set; }
}
}

0 comments on commit 24fc696

Please sign in to comment.