Hallo,
wir/ich sind dabei einen eigenen Launcher/downloader für unseren Server zu erstellen.
Ich habe auch schon etwas erfahrung im C# Programmieren.
Hab mich im Internet darüber informiert wie man am besten so einen Downloader erstellt für mehrere Datein und hab dazu auch was gefunden,
also den Code dazu hab ich gefunden.
Das Problem is jetzt das der Downloader größere Dateien irgendwie nicht laden will, ich denken so ab einer größe von 400-500MB und größer gibt es die Probleme.
Also im Downloader sieht man das er den Datei Namen anzeigt aber die größe der Datei ist auf 0,
er vergleich ja dann die Dateigrößen vom Download Server und vom PC und dadurch das bei 0 sind läd er Sie ja dann nicht runter.
Habe mir den Downloader Code auch schon angesehen aber ich kann den Fehler einfach nicht finden.
Hier der code des downloaders:
Spoiler anzeigen
Ich hoffe mal das mir hier jemand helfen kann.
wir/ich sind dabei einen eigenen Launcher/downloader für unseren Server zu erstellen.
Ich habe auch schon etwas erfahrung im C# Programmieren.
Hab mich im Internet darüber informiert wie man am besten so einen Downloader erstellt für mehrere Datein und hab dazu auch was gefunden,
also den Code dazu hab ich gefunden.
Das Problem is jetzt das der Downloader größere Dateien irgendwie nicht laden will, ich denken so ab einer größe von 400-500MB und größer gibt es die Probleme.
Also im Downloader sieht man das er den Datei Namen anzeigt aber die größe der Datei ist auf 0,
er vergleich ja dann die Dateigrößen vom Download Server und vom PC und dadurch das bei 0 sind läd er Sie ja dann nicht runter.
Habe mir den Downloader Code auch schon angesehen aber ich kann den Fehler einfach nicht finden.
Hier der code des downloaders:
C#-Quellcode
- private void Download_Mods_DoWork(object sender, DoWorkEventArgs e)
- {
- if (counter == 0)
- {
- WebClient webClient = new WebClient();
- webClient.DownloadFile(ftp + file_modslist, appdata + file_modslist);
- // Read modslist file
- if (!File.Exists(appdata + file_modslist))
- {
- if (!Erreur_Msg.IsBusy)
- {
- error_code = 402;
- Erreur_Msg.RunWorkerAsync();
- }
- return;
- }
- }
- // Read the file and display it line by line.
- string[] lines = File.ReadAllLines(appdata + file_modslist);
- line = lines[counter];
- counter_total = lines.Length;
- HttpWebRequest wrq = (HttpWebRequest)WebRequest.Create(ftp + dest_mods + "/" + line);
- //You should be getting only the response header
- wrq.Method = "HEAD";
- // Set label info
- Label_modsdeal.Text = Trans_Deal + ": " + counter + " / " + counter_total;
- // Load Local size
- using (var wrs = (HttpWebResponse)wrq.GetResponse())
- {
- //Do something logic here...
- wrs_1 = wrs.ContentLength.ToString();
- }
- // Create new FileInfo object and get the Length.
- if (File.Exists(dest_arma + modsname + "\\addons\\" + line))
- {
- byte[] array = File.ReadAllBytes(dest_arma + modsname + "\\addons\\" + line);
- wrs_2 = array.Length.ToString();
- }
- if (wrs_1 != wrs_2) {
- // Downlaod the mods
- Label_mods.Text = Trans_Download + ": " + line;
- // the URL to download the file from
- string sUrlToReadFileFrom = ftp + dest_mods + "/"+ line;
- // the path to write the file to
- string sFilePathToWriteFileTo = dest_arma + modsname + "\\addons\\" + line;
- // first, we need to get the exact size (in bytes) of the file we are downloading
- Uri url = new Uri(sUrlToReadFileFrom);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- response.Close();
- // gets the size of the file in bytes
- Int64 iSize = response.ContentLength;
- // keeps track of the total bytes downloaded so we can update the progress bar
- Int64 iRunningByteTotal = 0;
- // use the webclient object to download the file
- using (WebClient client = new WebClient())
- {
- // open the file at the remote URL for reading
- using (Stream streamRemote = client.OpenRead(new Uri(sUrlToReadFileFrom)))
- {
- // using the FileStream object, we can write the downloaded bytes to the file system
- using (Stream streamLocal = new FileStream(sFilePathToWriteFileTo, FileMode.Create, FileAccess.Write, FileShare.None))
- {
- // loop the stream and get the file into the byte buffer
- int iByteSize = 0;
- byte[] byteBuffer = new byte[iSize];
- while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
- {
- // write the bytes to the file system at the file path specified
- streamLocal.Write(byteBuffer, 0, iByteSize);
- iRunningByteTotal += iByteSize;
- // calculate the progress out of a base "100"
- double dIndex = (double)(iRunningByteTotal);
- double dTotal = (double)byteBuffer.Length;
- double dProgressPercentage = (dIndex / dTotal);
- int iProgressPercentage = (int)(dProgressPercentage * 100);
- // update the progress bar
- Download_Mods.ReportProgress(iProgressPercentage);
- if ((int)dIndex < 1048576)
- {
- int total = (int)dIndex / 1024;
- bytes = total.ToString() + " KB";
- int total_d = (int)dTotal / 1024;
- bytes_d = total_d.ToString() + " KB";
- }
- else
- {
- int total = (int)dIndex / 1048576;
- bytes = total.ToString() + " MB";
- int total_d = (int)dTotal / 1048576;
- bytes_d = total_d.ToString() + " MB";
- }
- }
- // clean up the file stream
- streamLocal.Close();
- }
- // close the connection to the remote server
- streamRemote.Close();
- }
- }
- }
- }
Ich hoffe mal das mir hier jemand helfen kann.