Inproved code quality a bit
This commit is contained in:
parent
0dccd546ee
commit
51e8706bee
|
@ -41,6 +41,5 @@ namespace UpTool2
|
|||
private void progressChanged(object sender, DownloadProgressChangedEventArgs e) => progressBar.Value = e.ProgressPercentage;
|
||||
|
||||
private void DownloadDialog_FormClosing(object sender, FormClosingEventArgs e) => e.Cancel = !close;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,43 +13,20 @@ using System.Xml.Linq;
|
|||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
public static Form splash;
|
||||
public static bool online;
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
splash = new Form
|
||||
{
|
||||
StartPosition = FormStartPosition.CenterScreen,
|
||||
FormBorderStyle = FormBorderStyle.None,
|
||||
ControlBox = false,
|
||||
MaximizeBox = false,
|
||||
MinimizeBox = false,
|
||||
ShowIcon = false,
|
||||
ShowInTaskbar = false,
|
||||
Size = new Size(700, 400),
|
||||
ForeColor = Color.Green,
|
||||
TopMost = true
|
||||
};
|
||||
splash.MaximumSize = splash.Size;
|
||||
splash.MinimumSize = splash.Size;
|
||||
Label splashL = new Label
|
||||
{
|
||||
AutoSize = false,
|
||||
Dock = DockStyle.Fill,
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
Text = "Loading",
|
||||
Font = new Font(FontFamily.GenericSansSerif, 40)
|
||||
};
|
||||
splash.Controls.Add(splashL);
|
||||
splash.Show();
|
||||
splash.BringToFront();
|
||||
showSplash();
|
||||
string appGuid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString();
|
||||
string mutexId = string.Format("Global\\{{{0}}}", appGuid);
|
||||
bool createdNew;
|
||||
|
@ -80,7 +57,60 @@ namespace UpTool2
|
|||
if (!Directory.Exists(dir + @"\Apps"))
|
||||
Directory.CreateDirectory(dir + @"\Apps");
|
||||
string xml = dir + @"\info.xml";
|
||||
fixXML(xml);
|
||||
string metaXml = "https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Meta.xml";
|
||||
online = Ping(metaXml);
|
||||
if (!online || updateCheck(dir, xml, metaXml))
|
||||
Application.Run(new MainForm());
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
MessageBox.Show(e1.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (hasHandle)
|
||||
mutex.ReleaseMutex();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void showSplash()
|
||||
{
|
||||
splash = new Form
|
||||
{
|
||||
StartPosition = FormStartPosition.CenterScreen,
|
||||
FormBorderStyle = FormBorderStyle.None,
|
||||
ControlBox = false,
|
||||
MaximizeBox = false,
|
||||
MinimizeBox = false,
|
||||
ShowIcon = false,
|
||||
ShowInTaskbar = false,
|
||||
Size = new Size(700, 400),
|
||||
ForeColor = Color.Green,
|
||||
TopMost = true
|
||||
};
|
||||
splash.MaximumSize = splash.Size;
|
||||
splash.MinimumSize = splash.Size;
|
||||
Label splashL = new Label
|
||||
{
|
||||
AutoSize = false,
|
||||
Dock = DockStyle.Fill,
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
Text = "Loading",
|
||||
Font = new Font(FontFamily.GenericSansSerif, 40)
|
||||
};
|
||||
splash.Controls.Add(splashL);
|
||||
splash.Show();
|
||||
splash.BringToFront();
|
||||
}
|
||||
|
||||
static void fixXML(string xml)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((!File.Exists(xml)) || XDocument.Load(xml).Element("meta") == null)
|
||||
new XElement("meta", new XElement("Version", 0), new XElement("Repos", new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Repo.xml"))), new XElement("LocalRepo")).Save(xml);
|
||||
else
|
||||
|
@ -100,8 +130,14 @@ namespace UpTool2
|
|||
}
|
||||
x.Save(xml);
|
||||
}
|
||||
online = Ping(metaXml);
|
||||
if (online)
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
new XElement("meta", new XElement("Version", 0), new XElement("Repos", new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Repo.xml"))), new XElement("LocalRepo")).Save(xml);
|
||||
}
|
||||
}
|
||||
|
||||
static bool updateCheck(string dir, string xml, string metaXml)
|
||||
{
|
||||
XElement meta = XDocument.Load(metaXml).Element("meta");
|
||||
int version = int.Parse(meta.Element("Version").Value);
|
||||
|
@ -118,25 +154,9 @@ namespace UpTool2
|
|||
new XElement("meta", new XElement("Version", version)).Save(xml);
|
||||
splash.Hide();
|
||||
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C timeout /t 2 & copy /b/v/y \"" + dir + @"\update.exe" + "\" \"" + Application.ExecutablePath + "\" & \"" + Application.ExecutablePath + "\"", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden });
|
||||
return false;
|
||||
}
|
||||
else
|
||||
Application.Run(new MainForm());
|
||||
}
|
||||
else
|
||||
Application.Run(new MainForm());
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
MessageBox.Show(e1.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (hasHandle)
|
||||
mutex.ReleaseMutex();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Ping(string url)
|
||||
|
@ -158,6 +178,5 @@ namespace UpTool2
|
|||
return false;
|
||||
}
|
||||
}
|
||||
public static bool online;
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user