16 private Builder _builder;
17#pragma warning disable 649
19 private Gtk.TextView textBox;
21 private Gtk.Button upBut;
22#pragma warning restore 649
28 public string Name {
get;
set; }
29 public string Path {
get;
set; }
30 public string Sha {
get;
set; }
31 public int Size {
get;
set; }
32 public string Url {
get;
set; }
33 public string HtmlUrl {
get;
set; }
34 public string GitUrl {
get;
set; }
35 public string DownloadUrl {
get;
set; }
36 public string Type {
get;
set; }
37 public Links _Links {
get;
set; }
42 [JsonProperty(
"self")]
43 public string Self {
get;
set; }
46 public string Git {
get;
set; }
48 [JsonProperty(
"html")]
49 public string Html {
get;
set; }
53 #region Constructors / Destructors
61 Builder builder =
new Builder(
new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) +
"/" +
"Glade/Updater.glade", FileMode.Open));
62 return new Updater(builder, builder.GetObject(
"updater").Handle);
66 protected Updater(Builder builder, IntPtr handle) : base(handle)
69 builder.Autoconnect(
this);
70 this.DeleteEvent += Updater_DeleteEvent;
71 upBut.ButtonPressEvent += UpButton_ButtonPressEvent;
72 string st =
BioLib.Settings.GetSettings(
"UpdateSites");
75 string[] ups = st.Split(
',');
76 for(
int i = 0; i < ups.Length; i++)
78 if (i < ups.Length - 1)
79 textBox.Buffer.Text += ups[i] + Environment.NewLine;
81 textBox.Buffer.Text += ups[i];
84 App.ApplyStyles(
this);
87 private void UpButton_ButtonPressEvent(
object o, ButtonPressEventArgs args)
90 if (textBox.Buffer.Text.Contains(
'\n'))
91 sts = textBox.Buffer.Text.Split(
'\n');
93 sts =
new string[] { textBox.Buffer.Text };
94 foreach (
string s
in sts)
97 if (!s.EndsWith(
"/contents/"))
99 if (!s.Contains(
"api"))
100 st = st.Replace(
"github.com",
"api.github.com/repos");
101 string j = GetHtmlContentAsync(st).Result;
102 var gitHubFile = JsonConvert.DeserializeObject<GitHubFile[]>(j);
103 foreach (var item
in gitHubFile)
105 if(item.Name.EndsWith(
".dll"))
107 string url = s.Replace(
"github.com",
"raw.githubusercontent.com") +
"/main/" + item.Name;
108 DownloadFileAsync(url, System.IO.Path.GetDirectoryName(Environment.ProcessPath) +
"/Plugins/" + item.Name).Wait();
114 private void Updater_DeleteEvent(
object o, DeleteEventArgs args)
116 string[] sts = textBox.Buffer.Text.Split(Environment.NewLine);
118 for (
int i = 0; i < sts.Length; i++)
125 BioLib.Settings.AddSettings(
"UpdateSites", ups);
128 public static async Task DownloadFileAsync(
string fileUrl,
string savePath)
133 byte[] fileBytes = await fileUrl.WithHeader(
"User-Agent",
"BioGTK").GetBytesAsync().ConfigureAwait(
false);
136 await File.WriteAllBytesAsync(savePath, fileBytes);
137 Console.WriteLine($
"File downloaded successfully and saved to {savePath}");
139 catch (FlurlHttpException e)
142 Console.WriteLine($
"Failed to download the file. HTTP Error: {e.Message}");
147 Console.WriteLine($
"An error occurred: {e.Message}");
151 public static async Task<string> GetHtmlContentAsync(
string url)
156 string htmlContent = await url.WithHeader(
"User-Agent",
"BioGTK").GetStringAsync().ConfigureAwait(
false);
159 catch (FlurlHttpException e)
162 Console.WriteLine($
"HTTP Request Failed: {e.Message}");