Downlaoder läd größere Dateien nicht.

  • C#
  • .NET (FX) 4.5–4.8

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von rikau87.

    Downlaoder läd größere Dateien nicht.

    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

    C#-Quellcode

    1. private void Download_Mods_DoWork(object sender, DoWorkEventArgs e)
    2. {
    3. if (counter == 0)
    4. {
    5. WebClient webClient = new WebClient();
    6. webClient.DownloadFile(ftp + file_modslist, appdata + file_modslist);
    7. // Read modslist file
    8. if (!File.Exists(appdata + file_modslist))
    9. {
    10. if (!Erreur_Msg.IsBusy)
    11. {
    12. error_code = 402;
    13. Erreur_Msg.RunWorkerAsync();
    14. }
    15. return;
    16. }
    17. }
    18. // Read the file and display it line by line.
    19. string[] lines = File.ReadAllLines(appdata + file_modslist);
    20. line = lines[counter];
    21. counter_total = lines.Length;
    22. HttpWebRequest wrq = (HttpWebRequest)WebRequest.Create(ftp + dest_mods + "/" + line);
    23. //You should be getting only the response header
    24. wrq.Method = "HEAD";
    25. // Set label info
    26. Label_modsdeal.Text = Trans_Deal + ": " + counter + " / " + counter_total;
    27. // Load Local size
    28. using (var wrs = (HttpWebResponse)wrq.GetResponse())
    29. {
    30. //Do something logic here...
    31. wrs_1 = wrs.ContentLength.ToString();
    32. }
    33. // Create new FileInfo object and get the Length.
    34. if (File.Exists(dest_arma + modsname + "\\addons\\" + line))
    35. {
    36. byte[] array = File.ReadAllBytes(dest_arma + modsname + "\\addons\\" + line);
    37. wrs_2 = array.Length.ToString();
    38. }
    39. if (wrs_1 != wrs_2) {
    40. // Downlaod the mods
    41. Label_mods.Text = Trans_Download + ": " + line;
    42. // the URL to download the file from
    43. string sUrlToReadFileFrom = ftp + dest_mods + "/"+ line;
    44. // the path to write the file to
    45. string sFilePathToWriteFileTo = dest_arma + modsname + "\\addons\\" + line;
    46. // first, we need to get the exact size (in bytes) of the file we are downloading
    47. Uri url = new Uri(sUrlToReadFileFrom);
    48. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    49. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    50. response.Close();
    51. // gets the size of the file in bytes
    52. Int64 iSize = response.ContentLength;
    53. // keeps track of the total bytes downloaded so we can update the progress bar
    54. Int64 iRunningByteTotal = 0;
    55. // use the webclient object to download the file
    56. using (WebClient client = new WebClient())
    57. {
    58. // open the file at the remote URL for reading
    59. using (Stream streamRemote = client.OpenRead(new Uri(sUrlToReadFileFrom)))
    60. {
    61. // using the FileStream object, we can write the downloaded bytes to the file system
    62. using (Stream streamLocal = new FileStream(sFilePathToWriteFileTo, FileMode.Create, FileAccess.Write, FileShare.None))
    63. {
    64. // loop the stream and get the file into the byte buffer
    65. int iByteSize = 0;
    66. byte[] byteBuffer = new byte[iSize];
    67. while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
    68. {
    69. // write the bytes to the file system at the file path specified
    70. streamLocal.Write(byteBuffer, 0, iByteSize);
    71. iRunningByteTotal += iByteSize;
    72. // calculate the progress out of a base "100"
    73. double dIndex = (double)(iRunningByteTotal);
    74. double dTotal = (double)byteBuffer.Length;
    75. double dProgressPercentage = (dIndex / dTotal);
    76. int iProgressPercentage = (int)(dProgressPercentage * 100);
    77. // update the progress bar
    78. Download_Mods.ReportProgress(iProgressPercentage);
    79. if ((int)dIndex < 1048576)
    80. {
    81. int total = (int)dIndex / 1024;
    82. bytes = total.ToString() + " KB";
    83. int total_d = (int)dTotal / 1024;
    84. bytes_d = total_d.ToString() + " KB";
    85. }
    86. else
    87. {
    88. int total = (int)dIndex / 1048576;
    89. bytes = total.ToString() + " MB";
    90. int total_d = (int)dTotal / 1048576;
    91. bytes_d = total_d.ToString() + " MB";
    92. }
    93. }
    94. // clean up the file stream
    95. streamLocal.Close();
    96. }
    97. // close the connection to the remote server
    98. streamRemote.Close();
    99. }
    100. }
    101. }
    102. }


    Ich hoffe mal das mir hier jemand helfen kann.