Skip to content

Instantly share code, notes, and snippets.

@Yakov5776
Created February 7, 2021 00:03
Show Gist options
  • Save Yakov5776/125a17f9809c32c17417184a7c6a3543 to your computer and use it in GitHub Desktop.
Save Yakov5776/125a17f9809c32c17417184a7c6a3543 to your computer and use it in GitHub Desktop.
Multi-threaded download utility (for downloading all versions of an uncopylocked game)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Multithreaded_game_downloader
{
class Program
{
static int NextJob = 1;
static string GameId;
static void Main(string[] args)
{
Console.Title = "Multithreaded game downloader";
Console.WriteLine("Enter ID of place:");
GameId = Console.ReadLine();
for (int i = 0; i < 10; i++)
{
Thread thread = new Thread(() => assetworker(i));
thread.IsBackground = true;
thread.Start();
}
while (true) { }
}
static void assetworker(int ThreadID)
{
Console.WriteLine($"[Thread {ThreadID.ToString()}] Has Started!");
WebClient client = new WebClient();
if (!Directory.Exists(GameId)) Directory.CreateDirectory(GameId);
int Job = NextJob++;
back:
try
{
while (true)
{
Console.WriteLine($"[Thread {ThreadID.ToString()}] Download started for {Job.ToString()}");
client.DownloadFile($"https://assetdelivery.roblox.com/v1/asset?id={GameId}&version={Job.ToString()}", $"{GameId}\\{Job.ToString()}.rbxl");
Console.WriteLine($"[Thread {ThreadID.ToString()}] Download completed for {Job.ToString()}");
Job = NextJob++;
}
}
catch (WebException e)
{
switch (e.Status)
{
case (WebExceptionStatus)404:
return; //Kill Thread
case (WebExceptionStatus)403:
Job = NextJob++;
goto back;
default:
Console.WriteLine($"[Thread {ThreadID.ToString()}] Failed to fetch ID {GameId} with version {Job.ToString()} Error Code: {e.Status.ToString()}, Retrying...");
goto back;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment