private static int Mount(IServiceProvider provider, MountOptions options, CancellationToken token) { provider.GetRequiredService <WorkshopMounter>() .Mount(token) .GetAwaiter() .GetResult(); ConsoleHelpers.WaitBeforeExiting(TimeSpan.FromSeconds(5), PrimaryCancellationSource.Token) .GetAwaiter() .GetResult(); return(0); }
public async Task Mount(CancellationToken token) { var gameInfo = _gameInfoRepository.FindGameInfo(); var items = await _workshopRepository.GetUserSubscribedItems(token); if (items.Length == 0) { ConsoleHelpers.WriteLine($"No workshop items found. To subscribe to items, head over to the workshop!", ConsoleColor.Yellow); ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine($"https://steamcommunity.com/app/{Constants.AppId}/workshop/", ConsoleColor.Blue); return; } var itemsToMount = new List <Item>(); ConsoleHelpers.WriteLine($"Found {items.Length} workshop item(s) in total:", ConsoleColor.Yellow); ConsoleHelpers.WriteLine(); foreach (var item in items) { ConsoleHelpers.Write("\t- ", ConsoleColor.DarkGray); ConsoleHelpers.Write(item.Title, ConsoleColor.White); if (item.Installed) { ConsoleHelpers.Write(" (will be mounted)", ConsoleColor.Gray); itemsToMount.Add(item); } else { ConsoleHelpers.Write(" (won't be mounted - not installed)", ConsoleColor.DarkGray); } ConsoleHelpers.WriteLine(); } var itemDirectories = items.Where(x => x.Installed).Select(x => x.Directory).ToArray(); await _gameInfoRepository.SetWorkshopSearchPaths(gameInfo, itemDirectories); ConsoleHelpers.WriteLine(); if (itemsToMount.Count > 0) { ConsoleHelpers.WriteLine($"You can now run the game and play your new content!", ConsoleColor.Green); } else { ConsoleHelpers.WriteLine($"No items found to mount. Looks like they are still installing.", ConsoleColor.Yellow); } }
public static void FatalError(string error) { Console.WriteLine(); WriteLine("FATAL ERROR", ConsoleColor.Red); Console.WriteLine(); WriteLine(error, ConsoleColor.Red); Console.WriteLine(); ConsoleHelpers.WriteLine($"If you keep seeing this error, you may want to report it:", ConsoleColor.Yellow); ConsoleHelpers.WriteLine($"- https://steamcommunity.com/app/{Constants.AppId}/discussions/", ConsoleColor.Yellow); ConsoleHelpers.WriteLine($"- https://discord.gg/estranged", ConsoleColor.Yellow); Program.PrimaryCancellationSource.Cancel(); WaitBeforeExiting(TimeSpan.FromSeconds(5), CancellationToken.None).GetAwaiter().GetResult(); }
public void OpenBrowser(string url) { ConsoleHelpers.WriteLine($"See: {url}", ConsoleColor.Cyan); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Process.Start(new ProcessStartInfo("cmd", $"/c start {url}")); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Process.Start("xdg-open", url); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Process.Start("open", url); } }
public async Task <Editor> UpdateItem(Item item, DirectoryInfo uploadDirectory, CancellationToken token) { Editor editor; if (item == null) { editor = _client.Workshop.CreateItem(ItemType.Community); editor.Title = "New Item"; editor.Description = "Edit me"; } else { editor = _client.Workshop.EditItem(item.Id); } var previewExtensions = new[] { ".png", ".jpeg", ".jpg" }; var preview = uploadDirectory.EnumerateFiles() .Where(x => previewExtensions.Contains(x.Extension.ToLower())) .Where(x => x.Length < 1024 * 1024) .FirstOrDefault(); editor.WorkshopUploadAppId = _client.AppId; editor.Folder = uploadDirectory.FullName; editor.PreviewImage = preview?.FullName; editor.Publish(); ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine($"Publishing workshop item... this might take a little while."); while (editor.Publishing) { await Task.Delay(TimeSpan.FromMilliseconds(20), token); } if (editor.NeedToAgreeToWorkshopLegal) { ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine("Please agree to the Steam Workshop legal agreement.", ConsoleColor.Yellow); _browserOpener.OpenBrowser("http://steamcommunity.com/sharedfiles/workshoplegalagreement"); } return(editor); }
internal async Task Upload(DirectoryInfo uploadDirectory, ulong?existingItemId, CancellationToken token) { if (!uploadDirectory.Exists) { ConsoleHelpers.FatalError($"Directory doesn't exist: {uploadDirectory.FullName}"); } Item existingItem = null; if (existingItemId.HasValue) { existingItem = await _workshopRepository.GetItem(existingItemId.Value, token); if (existingItem == null) { ConsoleHelpers.FatalError($"Item {existingItemId.Value} was not found."); } ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine($"Updating existing item '{existingItem.Title}'"); } var item = await _workshopRepository.UpdateItem(existingItem, uploadDirectory, token); if (item.Error == null) { ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine("Item uploaded successfully!", ConsoleColor.Green); ConsoleHelpers.WriteLine(); _browserOpener.OpenBrowser($"https://steamcommunity.com/sharedfiles/filedetails/?id={item.Id}"); ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine("You can edit the title, description, preview images and more from the item page.", ConsoleColor.Green); } else { ConsoleHelpers.FatalError($"Item upload failed. The error from Steam was: {item.Error}"); } }
public static void Main(string[] args) { ConsoleHelpers.OverrideColors(); ConsoleHelpers.WriteLine(@" ___ ___ _____ ___ _ _ _ ___ ___ ___ "); ConsoleHelpers.WriteLine(@"| __/ __|_ _| _ \ /_\ | \| |/ __| __| \ "); ConsoleHelpers.WriteLine(@"| _|\__ \ | | | / / _ \| .` | (_ | _|| |) |"); ConsoleHelpers.WriteLine(@"|___|___/ |_| |_|_\/_/ \_\_|\_|\___|___|___/ "); ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine("ACT I WORKSHOP TOOL", ConsoleColor.White); ConsoleHelpers.WriteLine(); Console.ForegroundColor = ConsoleColor.White; var arguments = Parser.Default.ParseArguments <MountOptions, UploadOptions>(args); ConsoleHelpers.OverrideColors(); Console.CancelKeyPress += (sender, ev) => { ev.Cancel = true; PrimaryCancellationSource.Cancel(); ConsoleHelpers.WriteLine(); ConsoleHelpers.WriteLine("Cancelling...", ConsoleColor.Yellow); }; var services = new ServiceCollection() .AddSingleton <WorkshopMounter>() .AddSingleton <WorkshopRepository>() .AddSingleton <WorkshopUploader>() .AddSingleton <GameInfoRepository>() .AddSingleton <BrowserOpener>(); using (var steam = new Client(Constants.AppId)) using (var tick = Task.Run(() => TickSteamClient(steam, PrimaryCancellationSource.Token))) using (var provider = services.AddSingleton(steam).BuildServiceProvider()) { // Add newlines after the Steam SDK spam ConsoleHelpers.WriteLine(); if (steam.IsValid) { try { arguments.MapResult((MountOptions options) => Mount(provider, options, PrimaryCancellationSource.Token), (UploadOptions options) => Upload(provider, options, PrimaryCancellationSource.Token), errors => 1); } catch (OperationCanceledException) { // Expected } } else { ConsoleHelpers.FatalError("Failed to connect to Steam."); } PrimaryCancellationSource.Cancel(); try { tick.GetAwaiter().GetResult(); } catch (OperationCanceledException) { // Expected } } }