Some fixes

This commit is contained in:
CreepyCrafter24 2020-03-16 20:13:41 +01:00
parent 50d56aa638
commit 723ae1ce7f
4 changed files with 46 additions and 54 deletions

View File

@ -70,14 +70,14 @@ namespace UpTool_build_tool
{
installBat += "\r\n";
installBat +=
$@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{programName}.exe';$s.Save()""";
$@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{mainBin}.exe';$s.Save()""";
removeBat += "\r\n";
removeBat += $@"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk""";
}
if (!string.IsNullOrWhiteSpace(mainBin))
{
removeBat += "\r\n";
removeBat += $@"taskkill /f /im ""{programName}.exe""";
removeBat += $@"taskkill /f /im ""{Path.GetFileName(mainBin)}""";
}
installBat += "\r\ntimeout /t 1";
removeBat += "\r\ntimeout /t 1";

View File

@ -1,6 +1,6 @@
namespace UpTool2
{
partial class MainForm
sealed partial class MainForm
{
/// <summary>
/// Required designer variable.
@ -143,8 +143,7 @@
// infoPanel_Title
//
this.infoPanel_Title.AutoSize = true;
this.infoPanel_Title.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (0)));
this.infoPanel_Title.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F);
this.infoPanel_Title.Location = new System.Drawing.Point(2, 1);
this.infoPanel_Title.Name = "infoPanel_Title";
this.infoPanel_Title.Size = new System.Drawing.Size(0, 31);
@ -190,7 +189,7 @@
this.controls_upload.Anchor =
((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Right)));
this.controls_upload.Location = new System.Drawing.Point(283, 6);
this.controls_upload.Location = new System.Drawing.Point(284, 6);
this.controls_upload.Name = "controls_upload";
this.controls_upload.Size = new System.Drawing.Size(27, 27);
this.controls_upload.TabIndex = 4;
@ -208,7 +207,7 @@
this.filterBox.FormattingEnabled = true;
this.filterBox.Location = new System.Drawing.Point(68, 7);
this.filterBox.Name = "filterBox";
this.filterBox.Size = new System.Drawing.Size(208, 23);
this.filterBox.Size = new System.Drawing.Size(209, 23);
this.filterBox.TabIndex = 3;
this.filterBox.SelectedIndexChanged += new System.EventHandler(this.UpdateSidebarV);
//
@ -220,7 +219,7 @@
System.Windows.Forms.AnchorStyles.Right)));
this.searchBox.Location = new System.Drawing.Point(3, 38);
this.searchBox.Name = "searchBox";
this.searchBox.Size = new System.Drawing.Size(306, 23);
this.searchBox.Size = new System.Drawing.Size(307, 23);
this.searchBox.TabIndex = 2;
this.searchBox.TextChanged += new System.EventHandler(this.UpdateSidebarV);
//
@ -267,7 +266,6 @@
this.ShowIcon = false;
this.Text = "UpTool 2";
this.Load += new System.EventHandler(this.MainForm_Load);
this.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.MainForm_HelpRequested);
this.infoPanel.ResumeLayout(false);
this.infoPanel.PerformLayout();
this.splitContainer.Panel1.ResumeLayout(false);

View File

@ -4,26 +4,26 @@ using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using UpTool2.DataStructures;
using UpTool2.Properties;
using UpTool2.Tool;
#if DEBUG
using System.Threading;
using System.Linq;
#endif
namespace UpTool2
{
public partial class MainForm : Form
public sealed partial class MainForm : Form
{
HelpEventHandler help;
public MainForm()
{
GlobalVariables.ReloadElements = ReloadElements;
InitializeComponent();
help = MainForm_HelpRequested;
HelpRequested += help;
filterBox.DataSource = Enum.GetValues(typeof(Status));
if (Program.Online)
{
@ -154,7 +154,7 @@ namespace UpTool2
action_update.Tag = app;
action_update.Enabled = updatable;
action_run.Tag = app;
action_run.Enabled = !app.Local && app.Runnable && Directory.Exists(app.appPath);
action_run.Enabled = (app.status & Status.Installed) == Status.Installed && !app.Local && app.Runnable && Directory.Exists(app.appPath);
};
if (updatable)
availableUpdates++;
@ -264,54 +264,48 @@ namespace UpTool2
private static DateTime GetBuildDateTime(Assembly assembly)
{
string path = assembly.GetName().CodeBase;
if (File.Exists(path))
{
byte[] buffer = new byte[Math.Max(Marshal.SizeOf(typeof(_IMAGE_FILE_HEADER)), 4)];
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
fileStream.Position = 0x3C;
fileStream.Read(buffer, 0, 4);
fileStream.Position = BitConverter.ToUInt32(buffer, 0); // COFF header offset
fileStream.Read(buffer, 0, 4); // "PE\0\0"
fileStream.Read(buffer, 0, buffer.Length);
}
GCHandle pinnedBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
_IMAGE_FILE_HEADER coffHeader =
(_IMAGE_FILE_HEADER) Marshal.PtrToStructure(pinnedBuffer.AddrOfPinnedObject(),
typeof(_IMAGE_FILE_HEADER));
string location = assembly.Location;
const int headerOffset = 60;
const int linkerTimestampOffset = 8;
byte[] buffer = new byte[2048];
Stream? stream = null;
return TimeZone.CurrentTimeZone.ToLocalTime(
new DateTime(1970, 1, 1) + new TimeSpan(coffHeader.TimeDateStamp * TimeSpan.TicksPerSecond));
}
finally
try
{
stream = new FileStream(location, FileMode.Open, FileAccess.Read);
stream.Read(buffer, 0, 2048);
}
finally
{
if (stream != null)
{
pinnedBuffer.Free();
stream.Close();
}
}
return new DateTime();
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;
}
private void MainForm_HelpRequested(object sender, HelpEventArgs hlpevent)
{
DateTime buildTime = GetBuildDateTime(Assembly.GetExecutingAssembly());
_ = MessageBox.Show($@"UpTool2 by CC24
HelpRequested -= help;
try
{
DateTime buildTime = GetBuildDateTime(Assembly.GetExecutingAssembly());
MessageBox.Show($@"UpTool2 by CC24
Version: {Assembly.GetExecutingAssembly().GetName().Version}
Build Date: {buildTime:dd.MM.yyyy}", "UpTool2");
hlpevent.Handled = true;
}
private struct _IMAGE_FILE_HEADER
{
public ushort Machine;
public ushort NumberOfSections;
public uint TimeDateStamp;
public uint PointerToSymbolTable;
public uint NumberOfSymbols;
public ushort SizeOfOptionalHeader;
public ushort Characteristics;
}
finally
{
HelpRequested += help;
hlpevent.Handled = true;
}
}
}
}

View File

@ -118,9 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
<value>184, 17</value>
</metadata>
<metadata name="searchPackageDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>107, 17</value>
<value>17, 17</value>
</metadata>
</root>