/// <summary> /// Downloads the common files. /// </summary> /// <param name="pack">The overlay pack to download.</param> /// <param name="destination">The destination path.</param> /// <param name="overwrite">if set to <c>true</c> overwrite existing files.</param> /// <param name="ratio">The ratio to change resolution.</param> /// <param name="messageHandler">The message handler.</param> /// <param name="total">The total number of items.</param> /// <param name="current">The current item number.</param> private async Task DownloadCommon(OverlayBundle pack, string destination, bool overwrite, float ratio, IMessageHandler messageHandler, int total, int current) { if (messageHandler.MustCancel) { return; } if (pack.Common != null && !string.IsNullOrEmpty(pack.Common.Src)) { IEnumerable <string> files = await downloaderService.DownloadFolder(pack.Repository, pack.Common.Src, destination, overwrite, (entry) => { messageHandler.Progress($"downloading {entry.Path}", total, current); }); foreach (var f in files.Where(f => f.EndsWith(".cfg", StringComparison.InvariantCultureIgnoreCase))) { var fi = new FileInfo(f); messageHandler.Progress($"fixing {fi.Name}", total, current); if (overwrite || !fi.Exists) { var content = await File.ReadAllTextAsync(f); content = ChangeResolution(content, ratio); content = FixPaths(content, pack); await File.WriteAllTextAsync(f, content); } } ; } }
/// <summary> /// Fixes the paths in a config. /// </summary> /// <param name="content">The config content.</param> /// <param name="pack">The pack to download.</param> /// <returns> /// The fixed content /// </returns> private static string FixPaths(string content, OverlayBundle pack) { if (ArcadeManagerEnvironment.SettingsOs != pack.BaseOs) { return(content.Replace(pack.Base[pack.BaseOs], pack.Base[ArcadeManagerEnvironment.SettingsOs], StringComparison.InvariantCultureIgnoreCase)); } return(content); }