Add project files.

This commit is contained in:
Wizzy69
2022-01-07 20:26:10 +02:00
parent 8b8d4c7147
commit 84ee5c6235
53 changed files with 3544 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using PluginManager.Items;
namespace PluginManager.Online
{
public class Downloader
{
public bool isWorking { get; private set; }
public int percent { get; private set; }
private string fileName;
private string downloadLink;
public Downloader(string fileName, string fileLink)
{
this.downloadLink = fileLink;
this.fileName = fileName;
}
public async Task DownloadFileAsync(string location = @"./Downloads/", string? pluginType = null)
{
Directory.CreateDirectory(location);
if (isWorking) return;
isWorking = true;
percent = 0;
Spinner s = new Spinner();
Console.Write("Downloading:\t\t");
s.Start();
#pragma warning disable SYSLIB0014
WebClient client = new WebClient();
#pragma warning restore SYSLIB0014
client.DownloadFileCompleted += (sender, args) =>
{
isWorking = false;
s.Stop();
var c = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write("OK");
Console.ForegroundColor = c;
Console.Write(" !\n");
//Console.WriteLine("Your plugin has been successfully downloaded !");
if (pluginType == "Event/Command" || pluginType == "Command/Event")
{
File.Copy(location + fileName, location + "Commands/" + fileName, true);
File.Move(location + fileName, location + "Events/" + fileName, true);
}
};
string l = "";
if (pluginType == "Command")
l = location + "Commands/" + fileName;
else if (pluginType == "Event")
l = location + "Events/" + fileName;
else l = location + fileName;
try
{
await client.DownloadFileTaskAsync(new Uri(this.downloadLink), l);
}
catch
{
var c = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("FAIL");
Console.ForegroundColor = c;
Console.Write(" !\n");
}
}
}
}

View File

@@ -0,0 +1,75 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Net;
using System.Collections.Generic;
using PluginManager.Others;
namespace PluginManager.Online
{
public class LanguageManager
{
private string link;
public LanguageManager(string link) => this.link = link;
public async Task ListAllLanguages()
{
try
{
#pragma warning disable SYSLIB0014
WebClient client = new WebClient();
#pragma warning restore SYSLIB0014
Stream data = await client.OpenReadTaskAsync(link);
string[] lines = (await new StreamReader(data).ReadToEndAsync()).Split('\n');
List<string[]> info = new List<string[]>();
info.Add(new string[] { "-", "-" });
info.Add(new string[] { "Language Name", "File Size" });
info.Add(new string[] { "-", "-" });
foreach (var line in lines)
{
if (line.Length <= 2) continue;
string[] d = line.Split(',');
if (d[3].Contains("cp") || d[3].Contains("CrossPlatform"))
info.Add(new string[] { d[0], d[1] });
}
info.Add(new string[] { "-", "-" });
Functions.FormatAndAlignTable(info);
}
catch (Exception exception)
{
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
Others.Functions.WriteErrFile(exception.ToString());
}
}
public async Task<string[]?> GetDownloadLink(string langName)
{
try
{
#pragma warning disable SYSLIB0014
WebClient client = new WebClient();
#pragma warning restore SYSLIB0014
Stream data = await client.OpenReadTaskAsync(link);
string[] lines = (await new StreamReader(data).ReadToEndAsync()).Split('\n');
foreach (var line in lines)
{
if (line.Length <= 2) continue;
string[] d = line.Split(',');
if (d[0].Equals(langName) && (d[3].Contains("cp") || d[3].Contains("CrossPlatform")))
return new string[] { d[2], d[3] };
}
}
catch (Exception exception)
{
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
Others.Functions.WriteErrFile(exception.ToString());
}
return null;
}
}
}

View File

@@ -0,0 +1,108 @@
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using System.Collections.Generic;
using PluginManager.Others;
namespace PluginManager.Online
{
public class PluginsManager
{
public string PluginsLink { get; private set; }
public PluginsManager(string link)
{
PluginsLink = link;
}
public async Task ListAvailablePlugins()
{
try
{
#pragma warning disable SYSLIB0014
WebClient client = new WebClient();
#pragma warning restore SYSLIB0014
Stream s = await client.OpenReadTaskAsync(PluginsLink);
string text = await new StreamReader(s).ReadToEndAsync();
List<string[]> data = new List<string[]>();
var op = Functions.GetOperatinSystem();
string[] lines = text.Split('\n');
int len = lines.Length;
string[] titles = { "Name", "Description", "Plugin Type" };
data.Add(new string[] { "-", "-", "-" });
data.Add(titles);
data.Add(new string[] { "-", "-", "-" });
for (int i = 0; i < len; i++)
{
if (lines[i].Length <= 2) continue;
string[] content = lines[i].Split(',');
string[] display = new string[3];
if (op == PluginManager.Others.OperatingSystem.WINDOWS)
{
if (content[4].Contains("Windows"))
{
display[0] = content[0];
display[1] = content[1];
display[2] = content[2];
data.Add(display);
continue;
}
}
else if (op == PluginManager.Others.OperatingSystem.LINUX)
{
if (content[4].Contains("Linux"))
{
display[0] = content[0];
display[1] = content[1];
display[2] = content[2];
data.Add(display);
continue;
}
}
}
data.Add(new string[] { "-", "-", "-" });
Functions.FormatAndAlignTable(data);
}
catch (Exception exception)
{
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
Others.Functions.WriteErrFile(exception.ToString());
}
}
public async Task<string[]> GetPluginLinkByName(string name)
{
try
{
#pragma warning disable SYSLIB0014
WebClient client = new WebClient();
#pragma warning restore SYSLIB0014
Stream s = await client.OpenReadTaskAsync(PluginsLink);
string text = await new StreamReader(s).ReadToEndAsync();
string[] lines = text.Split('\n');
int len = lines.Length;
for (int i = 0; i < len; i++)
{
string[] contents = lines[i].Split(',');
if (contents[0] == name)
return new string[] { contents[2], contents[3] };
}
}
catch (Exception exception)
{
Console.WriteLine("Failed to execute command: listlang\nReason: " + exception.Message);
Others.Functions.WriteErrFile(exception.ToString());
}
return new string[] { null!, null! };
}
}
}