Last active
August 13, 2023 04:03
-
-
Save Yakov5776/8544660229762c4e5a1481d57603d48d to your computer and use it in GitHub Desktop.
Quick Roblox CDN Hash Downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Win32; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace QuickCDNHashDownloader | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
MainApp().Wait(); | |
} | |
static async Task MainApp() | |
{ | |
Console.Title = "Quick Roblox CDN Downloader | Made by Yakov"; | |
string DownloadsFolder = GetDownloadFolderPath(); | |
string RobloxCDN = Path.Combine(DownloadsFolder, "RobloxCDN"); | |
if (!Directory.Exists(RobloxCDN)) | |
{ | |
WriteLine($"RobloxCDN folder does not exist in \"{RobloxCDN}\", Creating directory...", ConsoleColor.Blue); | |
Directory.CreateDirectory(RobloxCDN); | |
} | |
WriteLine($"Current working download directory: {RobloxCDN}\n", ConsoleColor.Yellow); | |
while (true) | |
{ | |
WriteLine("Please paste CDN hash:", ConsoleColor.Cyan); | |
string hash = Console.ReadLine(); | |
if (hash.Length != 32) | |
{ | |
WriteLine("Hash is not 32 Characters!", ConsoleColor.Red); | |
continue; | |
} | |
HttpClient client = new HttpClient(); | |
bool Success = false; | |
for (int i = 0; i < 8; i++) | |
{ | |
string url = $"https://c{i.ToString()}.rbxcdn.com/{hash}"; | |
WriteLine($"Trying {url}", ConsoleColor.DarkMagenta); | |
var response = await client.GetAsync(url); | |
switch (response.StatusCode) | |
{ | |
case (HttpStatusCode)200: | |
{ | |
WriteLine("Server responded with 200!", ConsoleColor.DarkGreen); | |
WriteLine("\nWhat would you like the file to be named? (Leave blank to use hash)", ConsoleColor.Blue); | |
string RawInput = Console.ReadLine(); | |
string Filename = string.IsNullOrEmpty(RawInput) ? hash : RawInput; | |
string path = Path.Combine(RobloxCDN, Filename); | |
using (var fs = new FileStream(path, FileMode.CreateNew)) | |
{ | |
await response.Content.CopyToAsync(fs); | |
} | |
WriteLine($"Download Successful! (Path: {path})", ConsoleColor.Green); | |
Success = true; | |
goto BreakOutOfLoop; | |
} | |
case (HttpStatusCode)403: | |
continue; | |
default: | |
WriteLine($"Got {(int)response.StatusCode}", ConsoleColor.DarkRed); | |
continue; | |
} | |
} | |
BreakOutOfLoop: | |
if (!Success) | |
{ | |
WriteLine("CDN Server could not be found!", ConsoleColor.Red); | |
} | |
else Success = false; | |
continue; | |
} | |
} | |
// https://stackoverflow.com/questions/10667012/getting-downloads-folder-in-c/21953690 | |
static string GetDownloadFolderPath() | |
{ | |
return Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "{374DE290-123F-4565-9164-39C4925E467B}", String.Empty).ToString(); | |
} | |
static public void WriteLine(string message, ConsoleColor color) | |
{ | |
Console.ForegroundColor = color; | |
Console.WriteLine(message); | |
Console.ResetColor(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment