C
C#2y ago
gamer50082

✅ making a winform that downloads files from github

need help making the system
31 Replies
gamer50082
gamer50082OP2y ago
the winform button will read a raw github file name version.txt
sibber
sibber2y ago
await HttpClient.GetStringAsync(urlToRawFile)
gamer50082
gamer50082OP2y ago
? using System; using System.IO; using System.Net; class Program { static void Main(string[] args) { // Replace with your own repository URL and file path string repositoryUrl = "https://github.com/username/repository"; string filePath = "path/to/file.txt"; // Replace with your own access token string accessToken = "your_access_token"; // Create a web client and set the access token in the headers WebClient client = new WebClient(); client.Headers.Add("Authorization", "Bearer " + accessToken); // Build the URL for the raw file on GitHub string rawUrl = repositoryUrl.Replace("github.com", "raw.githubusercontent.com") + "/main/" + filePath; // Download the file and save it to disk client.DownloadFile(rawUrl, Path.GetFileName(filePath)); } } oh then i have to make a if else statement but its not a var
sibber
sibber2y ago
what
gamer50082
gamer50082OP2y ago
using System; using System.Net.Http; using System.IO; using System.Windows.Forms; namespace GitHubFileDownloader { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private async void downloadButton_Click(object sender, EventArgs e) { string fileUrl = "https://raw.githubusercontent.com/username/repo/master/path/to/file.txt"; string fileName = "file.txt"; string tempFilePath = Path.GetTempFileName(); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Add("User-Agent", "C# HttpClient"); using (var response = await client.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead)) { response.EnsureSuccessStatusCode(); using (var stream = await response.Content.ReadAsStreamAsync()) { progressBar1.Maximum = (int)response.Content.Headers.ContentLength.GetValueOrDefault(); progressBar1.Value = 0; using (var fileStream = File.Create(tempFilePath)) { byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0) { chat gpt
sibber
sibber2y ago
dont copy stuff you don't understand webclient is deprecated
gamer50082
gamer50082OP2y ago
i know
sibber
sibber2y ago
and you don't need to add custom headers
gamer50082
gamer50082OP2y ago
this is not complete
sibber
sibber2y ago
if all you want is to read the file then just do this
gamer50082
gamer50082OP2y ago
i want the button to read the raw file and download a .js file from another part of the github repo
sibber
sibber2y ago
wdym by find
gamer50082
gamer50082OP2y ago
like a raw .txt tells the exe to go to another link to download the .js file
sibber
sibber2y ago
download as in save to the disk? ah
gamer50082
gamer50082OP2y ago
same repo but diff directory since i dont want to make people reinstall a new exe everytime the file name change
sibber
sibber2y ago
what? im missing some context here
gamer50082
gamer50082OP2y ago
the js file name change on every update
sibber
sibber2y ago
ok so you get the url to the new file from the text file you want to read
gamer50082
gamer50082OP2y ago
the .txt file is just pointing the exe to another link so the exe just read the link and download the file from that link
sibber
sibber2y ago
ok so read the file and get the link
gamer50082
gamer50082OP2y ago
yes and then download the .js file with that link
sibber
sibber2y ago
and you want to save yhe the js file to the disk?
gamer50082
gamer50082OP2y ago
yes is it possible for the exe to make a bin dir
sibber
sibber2y ago
what exe
gamer50082
gamer50082OP2y ago
the program? csharp program i am compiling it to exe
sibber
sibber2y ago
ah we dont usually say exe
gamer50082
gamer50082OP2y ago
so the program create a bin directory on start if its not there
sibber
sibber2y ago
since all an exe does is launch the program anyway sure so what is your question exactly
gamer50082
gamer50082OP2y ago
and when someone downloads the .js the program makes bloxd.io\static\js directories and put the .js after \js when program is executed
Check if bin exist If yes Continue as normal If no Make a bin directory
when user click a button
Check the raw .txt file for url [with https://github.com/user/repo] When .txt returns a link, download the file from that link Create bloxd.io\static\js in bin directory Put the filename.js in bloxd.io\static\js\filename.js
something like this ok^ if possible can u add a intro screen
sibber
sibber2y ago
uh were not going to write the app for you
gamer50082
gamer50082OP2y ago
ok
Want results from more Discord servers?
Add your server