2019-09-08 21:39:04 +02:00
|
|
|
|
using System;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
using System.Diagnostics;
|
2019-09-08 21:39:04 +02:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
2019-11-14 18:53:00 +01:00
|
|
|
|
using System.Reflection;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using UpTool2.DataStructures;
|
|
|
|
|
using UpTool2.Properties;
|
2020-02-28 12:59:59 +01:00
|
|
|
|
using UpTool2.Tool;
|
2019-11-12 21:23:14 +01:00
|
|
|
|
#if DEBUG
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
#endif
|
2019-09-08 21:39:04 +02:00
|
|
|
|
|
|
|
|
|
namespace UpTool2
|
|
|
|
|
{
|
2020-03-16 20:13:41 +01:00
|
|
|
|
public sealed partial class MainForm : Form
|
2019-09-08 21:39:04 +02:00
|
|
|
|
{
|
2020-03-16 20:13:41 +01:00
|
|
|
|
HelpEventHandler help;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
public MainForm()
|
|
|
|
|
{
|
|
|
|
|
GlobalVariables.ReloadElements = ReloadElements;
|
|
|
|
|
InitializeComponent();
|
2020-03-16 20:13:41 +01:00
|
|
|
|
help = MainForm_HelpRequested;
|
|
|
|
|
HelpRequested += help;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
filterBox.DataSource = Enum.GetValues(typeof(Status));
|
|
|
|
|
if (Program.Online)
|
|
|
|
|
{
|
|
|
|
|
RepoManagement.FetchRepos();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Starting in offline mode!");
|
|
|
|
|
controls_reload.Enabled = false;
|
|
|
|
|
filterBox.Enabled = false;
|
|
|
|
|
filterBox.SelectedIndex = 2;
|
|
|
|
|
}
|
|
|
|
|
ReloadElements();
|
|
|
|
|
if (!Directory.Exists(PathTool.appsPath))
|
|
|
|
|
Directory.CreateDirectory(PathTool.appsPath);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 21:39:04 +02:00
|
|
|
|
private void Action_install_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-09-29 16:19:57 +02:00
|
|
|
|
#if !DEBUG
|
2019-09-08 21:39:04 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2019-09-29 16:19:57 +02:00
|
|
|
|
#endif
|
2020-03-16 15:53:14 +01:00
|
|
|
|
AppInstall.Install((App) action_install.Tag);
|
2019-09-29 16:19:57 +02:00
|
|
|
|
#if !DEBUG
|
2019-09-08 21:39:04 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e1)
|
|
|
|
|
{
|
2020-02-28 14:31:52 +01:00
|
|
|
|
if (!GlobalVariables.RelE)
|
2019-09-08 21:39:04 +02:00
|
|
|
|
throw;
|
|
|
|
|
MessageBox.Show(e1.ToString(), "Install failed");
|
|
|
|
|
}
|
2019-09-29 16:19:57 +02:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2019-10-20 15:18:21 +02:00
|
|
|
|
private void Action_remove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
string app = ((App) action_remove.Tag).appPath;
|
2020-02-28 12:59:59 +01:00
|
|
|
|
string tmp = PathTool.tempPath;
|
2019-10-20 15:18:21 +02:00
|
|
|
|
if (Directory.Exists(tmp))
|
|
|
|
|
Directory.Delete(tmp, true);
|
|
|
|
|
Directory.CreateDirectory(tmp);
|
2020-02-28 12:59:59 +01:00
|
|
|
|
ZipFile.ExtractToDirectory(Path.Combine(app, "package.zip"), tmp);
|
2020-02-28 14:26:16 +01:00
|
|
|
|
Process.Start(new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "cmd.exe", Arguments = $"/C \"{Path.Combine(tmp, "Remove.bat")}\"",
|
|
|
|
|
WorkingDirectory = Path.Combine(app, "app")
|
|
|
|
|
}).WaitForExit();
|
2019-10-20 15:18:21 +02:00
|
|
|
|
Directory.Delete(tmp, true);
|
|
|
|
|
Directory.Delete(app, true);
|
2020-02-28 14:26:16 +01:00
|
|
|
|
if (GlobalVariables.RelE)
|
|
|
|
|
ReloadElements();
|
2019-10-20 15:18:21 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e1)
|
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
if (!GlobalVariables.RelE)
|
2019-10-20 15:18:21 +02:00
|
|
|
|
throw;
|
|
|
|
|
MessageBox.Show(e1.ToString(), "Removal failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2019-09-29 16:19:57 +02:00
|
|
|
|
private void controls_upload_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
#if !DEBUG
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#endif
|
2020-03-16 15:53:14 +01:00
|
|
|
|
if (searchPackageDialog.ShowDialog() != DialogResult.OK)
|
|
|
|
|
return;
|
|
|
|
|
Guid id = Guid.NewGuid();
|
|
|
|
|
while (GlobalVariables.Apps.ContainsKey(id) || Directory.Exists(PathTool.GetAppPath(id)))
|
|
|
|
|
id = Guid.NewGuid();
|
|
|
|
|
App appI = new App(AppNameDialog.Show(), "Locally installed package, removal only",
|
|
|
|
|
GlobalVariables.minimumVer, "", true, "", id, Color.Red, Resources.C_64.ToBitmap(), false, "");
|
|
|
|
|
AppInstall.InstallZip(searchPackageDialog.FileName, appI);
|
2019-09-29 16:19:57 +02:00
|
|
|
|
#if !DEBUG
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e1)
|
|
|
|
|
{
|
2020-02-28 14:31:52 +01:00
|
|
|
|
if (!GlobalVariables.RelE)
|
2019-09-29 16:19:57 +02:00
|
|
|
|
throw;
|
|
|
|
|
MessageBox.Show(e1.ToString(), "Install failed");
|
|
|
|
|
}
|
2019-11-09 23:46:49 +01:00
|
|
|
|
#endif
|
2019-09-08 21:39:04 +02:00
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2020-02-28 14:26:16 +01:00
|
|
|
|
private void ReloadElements()
|
2019-10-20 15:18:21 +02:00
|
|
|
|
{
|
|
|
|
|
//remove
|
|
|
|
|
toolTip.RemoveAll();
|
2020-02-28 14:26:16 +01:00
|
|
|
|
ClearSelection();
|
2019-10-20 15:18:21 +02:00
|
|
|
|
infoPanel_Title.Invalidate();
|
|
|
|
|
infoPanel_Description.Invalidate();
|
|
|
|
|
int F = sidebarPanel.Controls.Count;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
for (int i = 0; i < F; i++) sidebarPanel.Controls[0].Dispose();
|
|
|
|
|
GlobalVariables.Apps.Clear();
|
2019-10-20 15:18:21 +02:00
|
|
|
|
//add
|
|
|
|
|
toolTip.SetToolTip(controls_settings, "Settings");
|
|
|
|
|
toolTip.SetToolTip(controls_reload, "Refresh repositories");
|
|
|
|
|
toolTip.SetToolTip(controls_upload, "Install package from disk");
|
|
|
|
|
toolTip.SetToolTip(filterBox, "Filter");
|
|
|
|
|
toolTip.SetToolTip(action_install, "Install");
|
|
|
|
|
toolTip.SetToolTip(action_remove, "Remove");
|
|
|
|
|
toolTip.SetToolTip(action_update, "Update");
|
|
|
|
|
toolTip.SetToolTip(action_run, "Run");
|
2020-02-28 14:26:16 +01:00
|
|
|
|
RepoManagement.GetReposFromDisk();
|
2019-11-11 15:23:14 +01:00
|
|
|
|
int availableUpdates = 0;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
foreach (App app in GlobalVariables.Apps.Values)
|
2019-10-20 15:18:21 +02:00
|
|
|
|
{
|
|
|
|
|
Panel sidebarIcon = new Panel();
|
|
|
|
|
sidebarIcon.Tag = app;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
sidebarIcon.BackColor = app.Color;
|
2019-10-20 15:18:21 +02:00
|
|
|
|
sidebarIcon.Size = new Size(70, 70);
|
2020-02-28 14:26:16 +01:00
|
|
|
|
sidebarIcon.BackgroundImage = app.Icon;
|
2019-10-20 15:18:21 +02:00
|
|
|
|
sidebarIcon.BackgroundImageLayout = ImageLayout.Stretch;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
bool updatable = !app.Local && (app.status & Status.Updatable) == Status.Updatable;
|
|
|
|
|
sidebarIcon.Click += (sender, e) =>
|
2019-10-20 18:25:00 +02:00
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
infoPanel_Title.Text = app.Name;
|
|
|
|
|
infoPanel_Title.ForeColor = app.Local ? Color.Red : Color.Black;
|
|
|
|
|
infoPanel_Description.Text = app.Description;
|
2019-10-20 15:18:21 +02:00
|
|
|
|
action_install.Tag = app;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
action_install.Enabled = !(app.Local || Directory.Exists(app.appPath));
|
2019-10-20 15:18:21 +02:00
|
|
|
|
action_remove.Tag = app;
|
2019-11-12 20:41:57 +01:00
|
|
|
|
action_remove.Enabled = Directory.Exists(app.appPath);
|
2019-10-20 15:18:21 +02:00
|
|
|
|
action_update.Tag = app;
|
2019-11-12 21:23:14 +01:00
|
|
|
|
action_update.Enabled = updatable;
|
2019-10-20 15:18:21 +02:00
|
|
|
|
action_run.Tag = app;
|
2020-03-16 20:13:41 +01:00
|
|
|
|
action_run.Enabled = (app.status & Status.Installed) == Status.Installed && !app.Local && app.Runnable && Directory.Exists(app.appPath);
|
2019-10-20 15:18:21 +02:00
|
|
|
|
};
|
2019-11-12 21:23:14 +01:00
|
|
|
|
if (updatable)
|
2019-11-11 15:23:14 +01:00
|
|
|
|
availableUpdates++;
|
2020-02-28 14:26:16 +01:00
|
|
|
|
toolTip.SetToolTip(sidebarIcon, app.Name);
|
2019-10-20 15:18:21 +02:00
|
|
|
|
sidebarPanel.Controls.Add(sidebarIcon);
|
|
|
|
|
}
|
2020-02-28 14:26:16 +01:00
|
|
|
|
UpdateSidebarV(null, null);
|
|
|
|
|
Text =
|
|
|
|
|
$"UpTool2 {(availableUpdates == 0 ? "(All up-to-date)" : $"({availableUpdates.ToString()} Updates)")}";
|
2019-10-20 15:18:21 +02:00
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2019-11-09 20:51:53 +01:00
|
|
|
|
private void Action_run_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
string path = Path.Combine(((App) action_run.Tag).dataPath, ((App) action_run.Tag).MainFile);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start(
|
|
|
|
|
new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = path,
|
|
|
|
|
WorkingDirectory = ((App) action_run.Tag).dataPath
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e1)
|
|
|
|
|
{
|
2020-03-13 20:16:33 +01:00
|
|
|
|
MessageBox.Show(e1
|
|
|
|
|
#if DEBUG
|
|
|
|
|
+ $"{Environment.NewLine}File was: {path}"
|
|
|
|
|
#endif
|
2020-03-16 15:53:14 +01:00
|
|
|
|
+ "Failed to start!");
|
2020-02-28 14:26:16 +01:00
|
|
|
|
}
|
2019-11-09 20:51:53 +01:00
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2019-10-20 15:18:21 +02:00
|
|
|
|
private void Action_update_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
GlobalVariables.RelE = false;
|
2019-10-20 15:18:21 +02:00
|
|
|
|
Action_remove_Click(sender, e);
|
|
|
|
|
Action_install_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(e1.ToString(), "Install failed");
|
|
|
|
|
}
|
2020-02-28 14:26:16 +01:00
|
|
|
|
ReloadElements();
|
|
|
|
|
GlobalVariables.RelE = true;
|
2019-10-20 15:18:21 +02:00
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2019-10-20 18:25:00 +02:00
|
|
|
|
private void Controls_reload_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
RepoManagement.FetchRepos();
|
|
|
|
|
ReloadElements();
|
2019-10-20 18:25:00 +02:00
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2019-10-21 15:33:09 +02:00
|
|
|
|
private void Controls_settings_Click(object sender, EventArgs e) => new SettingsForms().ShowDialog();
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2020-02-28 14:26:16 +01:00
|
|
|
|
private void ClearSelection()
|
2019-09-10 10:02:24 +02:00
|
|
|
|
{
|
|
|
|
|
action_install.Enabled = false;
|
|
|
|
|
action_remove.Enabled = false;
|
|
|
|
|
action_update.Enabled = false;
|
|
|
|
|
action_run.Enabled = false;
|
|
|
|
|
infoPanel_Title.Text = "";
|
|
|
|
|
infoPanel_Description.Text = "";
|
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2020-02-28 14:26:16 +01:00
|
|
|
|
private void UpdateSidebarV(object sender, EventArgs e)
|
2019-09-09 17:50:33 +02:00
|
|
|
|
{
|
2019-11-09 20:51:53 +01:00
|
|
|
|
#if DEBUG
|
|
|
|
|
if (searchBox.Text == "!DEBUG:PRINT!")
|
2019-09-09 17:50:33 +02:00
|
|
|
|
{
|
2019-11-09 20:51:53 +01:00
|
|
|
|
searchBox.Text = "!DEBUG:PRINT";
|
2020-02-28 14:26:16 +01:00
|
|
|
|
string tmpFile = Path.GetTempFileName();
|
|
|
|
|
File.WriteAllText(tmpFile,
|
|
|
|
|
string.Join("\r\n\r\n",
|
|
|
|
|
GlobalVariables.Apps.Values.Select(app => app.ToString()).Concat(new[]
|
|
|
|
|
{"Assembly version: " + Assembly.GetExecutingAssembly().GetName().Version}).ToArray()));
|
2020-02-28 12:59:59 +01:00
|
|
|
|
new Thread(() =>
|
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
Process.Start("notepad", tmpFile).WaitForExit();
|
|
|
|
|
File.Delete(tmpFile);
|
2019-11-09 20:51:53 +01:00
|
|
|
|
}).Start();
|
2019-09-10 10:02:24 +02:00
|
|
|
|
}
|
2019-11-09 20:51:53 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#endif
|
2020-03-16 15:53:14 +01:00
|
|
|
|
Enum.TryParse(filterBox.SelectedValue.ToString(), out Status status);
|
|
|
|
|
for (int i = 0; i < sidebarPanel.Controls.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Panel sidebarIcon = (Panel) sidebarPanel.Controls[i];
|
|
|
|
|
App app = (App) sidebarIcon.Tag;
|
|
|
|
|
sidebarIcon.Visible = app.Name.Contains(searchBox.Text) &&
|
|
|
|
|
((int) app.status & (int) (Program.Online ? status : Status.Installed)) != 0;
|
|
|
|
|
}
|
|
|
|
|
ClearSelection();
|
2019-11-09 20:51:53 +01:00
|
|
|
|
#if DEBUG
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-09-10 10:02:24 +02:00
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
|
2019-10-20 15:18:21 +02:00
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-02-28 14:26:16 +01:00
|
|
|
|
Program.Splash.Hide();
|
2019-10-20 15:18:21 +02:00
|
|
|
|
BringToFront();
|
|
|
|
|
}
|
2019-11-14 18:53:00 +01:00
|
|
|
|
|
2020-02-28 12:59:59 +01:00
|
|
|
|
private static DateTime GetBuildDateTime(Assembly assembly)
|
2019-11-14 18:53:00 +01:00
|
|
|
|
{
|
2020-03-16 20:13:41 +01:00
|
|
|
|
string location = assembly.Location;
|
|
|
|
|
const int headerOffset = 60;
|
|
|
|
|
const int linkerTimestampOffset = 8;
|
|
|
|
|
byte[] buffer = new byte[2048];
|
|
|
|
|
Stream? stream = null;
|
2019-11-14 18:53:00 +01:00
|
|
|
|
|
2020-03-16 20:13:41 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
stream = new FileStream(location, FileMode.Open, FileAccess.Read);
|
|
|
|
|
stream.Read(buffer, 0, 2048);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (stream != null)
|
2019-11-14 18:53:00 +01:00
|
|
|
|
{
|
2020-03-16 20:13:41 +01:00
|
|
|
|
stream.Close();
|
2019-11-14 18:53:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-16 20:13:41 +01:00
|
|
|
|
|
|
|
|
|
int i = BitConverter.ToInt32(buffer, headerOffset);
|
|
|
|
|
int secondsSince1970 = BitConverter.ToInt32(buffer, i + linkerTimestampOffset);
|
|
|
|
|
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
|
|
|
|
|
dt = dt.AddSeconds(secondsSince1970);
|
|
|
|
|
dt = TimeZoneInfo.ConvertTimeToUtc(dt);
|
|
|
|
|
return dt;
|
2019-11-14 18:53:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainForm_HelpRequested(object sender, HelpEventArgs hlpevent)
|
|
|
|
|
{
|
2020-03-16 20:13:41 +01:00
|
|
|
|
HelpRequested -= help;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime buildTime = GetBuildDateTime(Assembly.GetExecutingAssembly());
|
|
|
|
|
MessageBox.Show($@"UpTool2 by CC24
|
2020-02-28 14:26:16 +01:00
|
|
|
|
Version: {Assembly.GetExecutingAssembly().GetName().Version}
|
|
|
|
|
Build Date: {buildTime:dd.MM.yyyy}", "UpTool2");
|
2020-03-16 20:13:41 +01:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
HelpRequested += help;
|
|
|
|
|
hlpevent.Handled = true;
|
|
|
|
|
}
|
2020-02-28 14:26:16 +01:00
|
|
|
|
}
|
2019-09-08 21:39:04 +02:00
|
|
|
|
}
|
2020-02-28 12:59:59 +01:00
|
|
|
|
}
|