Example #1
0
        internal static async Task MainSafe(CommandSettings args)
        {
            try
            {
                Console.WriteLine(Header);

                if (args.GetVersions)
                {
                    var releases1 = await GetReleases().ConfigureAwait(false);

                    Console.WriteLine("--- AVAILABLE VERSIONS ---");
                    foreach (var r in releases1)
                    {
                        Console.WriteLine(FormatRelease(r, true));
                    }

                    if (args.Exit)
                    {
                        Environment.Exit(0);
                    }
                }

                Console.WriteLine($"AppData folder: {args.AppData.FullName}");

                if (!ValidateServerPath(args.Path.FullName, out var targetFilePath))
                {
                    Console.WriteLine($"Couldn't find '{TARGET_FILE_NAME}' in '{targetFilePath}'");
                    throw new FileNotFoundException("Check the validation of the path parameter");
                }

                if (!(args.GitHubToken is null))
                {
                    Console.WriteLine("Token detected! Using the token...");
                    GitHubClient.Credentials = new Credentials(args.GitHubToken, AuthenticationType.Bearer);
                }

                Console.WriteLine("Receiving releases...");
                Console.WriteLine($"Prereleases included - {args.PreReleases}");
                Console.WriteLine($"Target release version - {(string.IsNullOrEmpty(args.TargetVersion) ? "(null)" : args.TargetVersion)}");

                var releases = await GetReleases().ConfigureAwait(false);

                Console.WriteLine("Searching for the latest release that matches the parameters...");

                if (!TryFindRelease(args, releases, out var targetRelease))
                {
                    Console.WriteLine("--- RELEASES ---");
                    Console.WriteLine(string.Join(Environment.NewLine, releases.Select(FormatRelease)));
                    throw new InvalidOperationException("Couldn't find release");
                }

                Console.WriteLine("Release found!");
                Console.WriteLine(FormatRelease(targetRelease !));

                var exiledAsset = targetRelease !.Assets.FirstOrDefault(a => a.Name.Equals(EXILED_ASSET_NAME, StringComparison.OrdinalIgnoreCase));
                if (exiledAsset is null)
                {
                    Console.WriteLine("--- ASSETS ---");
                    Console.WriteLine(string.Join(Environment.NewLine, targetRelease.Assets.Select(FormatAsset)));
                    throw new InvalidOperationException("Couldn't find asset");
                }

                Console.WriteLine("Asset found!");
                Console.WriteLine(FormatAsset(exiledAsset));

                using var httpClient = new HttpClient
                      {
                          Timeout = TimeSpan.FromSeconds(SecondsWaitForDownload)
                      };
                httpClient.DefaultRequestHeaders.Add("User-Agent", Header);

                using var downloadResult = await httpClient.GetAsync(exiledAsset.BrowserDownloadUrl).ConfigureAwait(false);

                using var downloadArchiveStream = await downloadResult.Content.ReadAsStreamAsync().ConfigureAwait(false);

                using var gzInputStream  = new GZipInputStream(downloadArchiveStream);
                using var tarInputStream = new TarInputStream(gzInputStream);

                TarEntry entry;
                while (!((entry = tarInputStream.GetNextEntry()) is null))
                {
                    entry.Name = entry.Name.Replace('/', Path.DirectorySeparatorChar);
                    ProcessTarEntry(args, targetFilePath, tarInputStream, entry);
                }

                Console.WriteLine("Installation complete");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine("Read the exception message, read the readme, and if you still don't understand what to do, then contact #support in our discord server with the attached screenshot of the full exception");
                if (!args.Exit)
                {
                    Console.Read();
                }
            }

            if (args.Exit)
            {
                Environment.Exit(0);
            }
        }
Example #2
0
 private static void ResolvePath(CommandSettings args, string filePath, out string path)
 {
     path = Path.Combine(args.AppData.FullName, filePath);
 }
Example #3
0
 private static async Task Main(string[] args)
 {
     Console.OutputEncoding = new UTF8Encoding(false, false);
     await CommandSettings.Parse(args).ConfigureAwait(false);
 }
Example #4
0
 private static async Task Main(string[] args)
 {
     await CommandSettings.Parse(args).ConfigureAwait(false);
 }