Updated documentation
This commit is contained in:
@@ -13,27 +13,26 @@ namespace PluginManager.Online
|
||||
{
|
||||
public class ServerCom
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Read all lines from a file async
|
||||
/// </summary>
|
||||
/// <param name="link">The link of the file</param>
|
||||
/// <returns></returns>
|
||||
public static async Task<List<string>> ReadTextFromFile(string link)
|
||||
{
|
||||
string response = await OnlineFunctions.DownloadStringAsync(link);
|
||||
string[] lines = response.Split('\n');
|
||||
return lines.ToList();
|
||||
|
||||
|
||||
//[Obsolete]
|
||||
#region old code for reading text from link
|
||||
/*
|
||||
List<string> s = new List<string>();
|
||||
WebClient webClient = new WebClient();
|
||||
var data = await webClient.OpenReadTaskAsync(link);
|
||||
var response = await new StreamReader(data).ReadToEndAsync();
|
||||
s.AddRange(from a in response.Split('\n')
|
||||
where !a.StartsWith("$")
|
||||
select a);
|
||||
return s;*/
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download file from url
|
||||
/// </summary>
|
||||
/// <param name="URL">The url to the file</param>
|
||||
/// <param name="location">The location where to store the downloaded data</param>
|
||||
/// <param name="progress">The <see cref="IProgress{T}"/> to track the download</param>
|
||||
/// <returns></returns>
|
||||
public static async Task DownloadFileAsync(string URL, string location, IProgress<float> progress)
|
||||
{
|
||||
using (var client = new System.Net.Http.HttpClient())
|
||||
@@ -46,50 +45,5 @@ namespace PluginManager.Online
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task DownloadFileAsync(string url, string location, int downloadNumber, int totalToDownload)
|
||||
{
|
||||
|
||||
IProgress<float> progress = new Progress<float>(bytes =>
|
||||
{
|
||||
Console.Title = $"Downloading {MathF.Round(bytes, 2)}% ({downloadNumber}/{totalToDownload})";
|
||||
});
|
||||
|
||||
await DownloadFileAsync(url, location, progress);
|
||||
Console.Title = "ONLINE";
|
||||
return;
|
||||
|
||||
//[Obsolete]
|
||||
#region old download code
|
||||
/*
|
||||
WebClient client = new WebClient();
|
||||
Spinner spinner = new Spinner();
|
||||
Console.Write("Downloading ");
|
||||
spinner.Start();
|
||||
string oldTitle = Console.Title ?? "";
|
||||
client.DownloadProgressChanged += (sender, e) =>
|
||||
{
|
||||
Console.Title = e.BytesReceived + "/" + e.TotalBytesToReceive + " (" + e.ProgressPercentage + "%) (" + downloadNumber + " / " + totalToDownload + ")";
|
||||
};
|
||||
client.DownloadFileCompleted += (sender, e) =>
|
||||
{
|
||||
spinner.Stop(); Console.WriteLine();
|
||||
|
||||
};
|
||||
try
|
||||
{
|
||||
await client.DownloadFileTaskAsync(new Uri(url), location);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.Title = oldTitle;
|
||||
}*/
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user