31 Replies
the winform button will read a raw github file name version.txt
await HttpClient.GetStringAsync(urlToRawFile)
?
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
what
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
dont copy stuff you don't understand
webclient is deprecated
i know
and you don't need to add custom headers
this is not complete
if all you want is to read the file then just do this
i want the button to read the raw file and download a .js file from another part of the github repo
wdym by find
like a raw .txt tells the exe to go to another link to download the .js file
download as in save to the disk?
ah
same repo but diff directory
since i dont want to make people reinstall a new exe everytime the file name change
what?
im missing some context here
the js file name change on every update
ok so you get the url to the new file from the text file you want to read
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
ok
so read the file and get the link
yes
and then download the .js file with that link
and you want to save yhe the js file to the disk?
yes
is it possible for the exe to make a bin dir
what exe
the program?
csharp program
i am compiling it to exe
ah
we dont usually say exe
so the program create a bin directory on start if its not there
since all an exe does is launch the program
anyway
sure
so what is your question exactly
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 directorywhen 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.jssomething like this ok^ if possible can u add a intro screen
uh were not going to write the app for you
ok