New plugin downloader based on threads
This commit is contained in:
@@ -47,20 +47,17 @@ public static class Config
|
||||
public class Json<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
{
|
||||
protected IDictionary<TKey, TValue> _dictionary;
|
||||
|
||||
public Json(IDictionary<TKey, TValue> dictionary)
|
||||
{
|
||||
_dictionary = dictionary;
|
||||
}
|
||||
|
||||
private readonly string _file = "";
|
||||
|
||||
public Json(string file)
|
||||
{
|
||||
_dictionary = PrivateReadConfig(file).GetAwaiter().GetResult();
|
||||
this._file = file;
|
||||
}
|
||||
|
||||
public async void Save()
|
||||
{
|
||||
await Functions.SaveToJsonFile("./Data/Resources/config.json", _dictionary);
|
||||
await Functions.SaveToJsonFile(_file, _dictionary);
|
||||
}
|
||||
|
||||
public virtual void Add(TKey key, TValue value)
|
||||
@@ -91,7 +88,7 @@ public static class Config
|
||||
get
|
||||
{
|
||||
if (_dictionary.TryGetValue(key, out TValue value)) return value;
|
||||
return default;
|
||||
throw new Exception("Key not found in dictionary " + key.ToString() + " (Json )" + this.GetType().Name + ")");
|
||||
|
||||
}
|
||||
set
|
||||
|
||||
@@ -15,15 +15,17 @@ public class PluginsManager
|
||||
/// The Plugin Manager constructor
|
||||
/// </summary>
|
||||
/// <param name="link">The link to the file where all plugins are stored</param>
|
||||
public PluginsManager(string link)
|
||||
public PluginsManager(string plink, string vlink)
|
||||
{
|
||||
PluginsLink = link;
|
||||
PluginsLink = plink;
|
||||
VersionsLink = vlink;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The URL of the server
|
||||
/// </summary>
|
||||
public string PluginsLink { get; }
|
||||
public string VersionsLink {get; }
|
||||
|
||||
/// <summary>
|
||||
/// The method to load all plugins
|
||||
@@ -54,7 +56,7 @@ public class PluginsManager
|
||||
display[1] = content[1];
|
||||
display[2] = content[2];
|
||||
display[3] =
|
||||
(await ServerCom.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
(await GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
.ToShortString();
|
||||
data.Add(display);
|
||||
}
|
||||
@@ -67,7 +69,7 @@ public class PluginsManager
|
||||
display[1] = content[1];
|
||||
display[2] = content[2];
|
||||
display[3] =
|
||||
(await ServerCom.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
(await GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
.ToShortString();
|
||||
data.Add(display);
|
||||
}
|
||||
@@ -86,6 +88,25 @@ public class PluginsManager
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
||||
{
|
||||
var data = await ServerCom.ReadTextFromURL(VersionsLink);
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.StartsWith("#"))
|
||||
continue;
|
||||
|
||||
string[] split = item.Split(',');
|
||||
if (split[0] == pakName)
|
||||
{
|
||||
Console.WriteLine("Searched for " + pakName + " and found " + split[1] + " as version.\nUsed url: " + VersionsLink);
|
||||
return new VersionString(split[1]);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The method to get plugin information by its name
|
||||
/// </summary>
|
||||
|
||||
@@ -50,20 +50,4 @@ public static class ServerCom
|
||||
{
|
||||
await DownloadFileAsync(URl, location, progress, null);
|
||||
}
|
||||
|
||||
public static async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
||||
{
|
||||
var url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||
var data = await ReadTextFromURL(url);
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.StartsWith("#"))
|
||||
continue;
|
||||
|
||||
string[] split = item.Split(',');
|
||||
if (split[0] == pakName)
|
||||
return new VersionString(split[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user