From fb17b6daa83c52ebf4d012d2de20bff3554a48fa Mon Sep 17 00:00:00 2001 From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com> Date: Fri, 13 Mar 2020 20:16:33 +0100 Subject: [PATCH] NET Core and some improvements (Build scripts will need to be updated) --- .idea/.idea.UpTool2/.idea/modules.xml | 8 ++ .idea/.idea.UpTool2/riderModule.iml | 7 ++ UpTool build tool/Program.cs | 107 +++++++++++---------- UpTool build tool/UpTool build tool.csproj | 1 + UpTool2/AppNameDialog.Designer.cs | 68 +++++++++++++ UpTool2/AppNameDialog.cs | 25 +++++ UpTool2/AppNameDialog.resx | 61 ++++++++++++ UpTool2/MainForm.cs | 13 +-- UpTool2/Program.cs | 82 ++++++++-------- UpTool2/Tool/AppInstall.cs | 3 + UpTool2/Tool/RepoManagement.cs | 9 +- UpTool2/UpTool2.csproj | 102 +------------------- UpTool2/WindowHelper.cs | 27 ++++++ 13 files changed, 313 insertions(+), 200 deletions(-) create mode 100644 .idea/.idea.UpTool2/.idea/modules.xml create mode 100644 .idea/.idea.UpTool2/riderModule.iml create mode 100644 UpTool2/AppNameDialog.Designer.cs create mode 100644 UpTool2/AppNameDialog.cs create mode 100644 UpTool2/AppNameDialog.resx create mode 100644 UpTool2/WindowHelper.cs diff --git a/.idea/.idea.UpTool2/.idea/modules.xml b/.idea/.idea.UpTool2/.idea/modules.xml new file mode 100644 index 0000000..e9add9e --- /dev/null +++ b/.idea/.idea.UpTool2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.UpTool2/riderModule.iml b/.idea/.idea.UpTool2/riderModule.iml new file mode 100644 index 0000000..1a4e0d9 --- /dev/null +++ b/.idea/.idea.UpTool2/riderModule.iml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/UpTool build tool/Program.cs b/UpTool build tool/Program.cs index fc48f2c..3d1375e 100644 --- a/UpTool build tool/Program.cs +++ b/UpTool build tool/Program.cs @@ -1,11 +1,11 @@ using System; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Reflection; using System.CommandLine; using System.CommandLine.Invocation; using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Reflection; +using CC_Functions.Misc; namespace UpTool_build_tool { @@ -18,15 +18,15 @@ namespace UpTool_build_tool build.AddOption(new Option("--binDir", "Directory to package")); build.AddOption(new Option("--mainBin", "The applications main binary")); build.AddOption(new Option("--packageFile", "Directory to package")); - build.AddOption(new Option("--tempPath", Path.GetTempPath, "Directory to package")); - build.AddOption(new Option("--noShortcuts", "When this is enabled the scripts will not generate a start-menu item")); + build.AddOption(new Option("--noShortcuts", + "When this is enabled the scripts will not generate a start-menu item")); build.AddOption(new Option("--noLogo", "Disables the logo")); - build.Handler = CommandHandler.Create(Build); + build.Handler = CommandHandler.Create(Build); rootCommand.AddCommand(build); return rootCommand.InvokeAsync(args).Result; } - private static void Build(string binDir, string mainBin, string packageFile, string tempPath, bool noLogo, bool noShortcuts) + private static void Build(string binDir, string mainBin, string packageFile, bool noLogo, bool noShortcuts) { Stopwatch watch = Stopwatch.StartNew(); if (!noLogo) @@ -40,56 +40,57 @@ namespace UpTool_build_tool } Console.WriteLine("Parsing arguments..."); packageFile ??= Path.Combine(binDir, "package.zip"); - tempPath = Path.Combine(tempPath, "UpTool2Pkg"); - Console.WriteLine("Removing previous files..."); if (File.Exists(packageFile)) - File.Delete(packageFile); - if (Directory.Exists(tempPath)) - Directory.Delete(tempPath, true); - Directory.CreateDirectory(tempPath); - Console.WriteLine("Copying binary dir..."); - ZipFile.CreateFromDirectory(binDir, Path.Combine(tempPath, "dataDir.zip")); - Directory.CreateDirectory(Path.Combine(tempPath, "Data")); - ZipFile.ExtractToDirectory(Path.Combine(tempPath, "dataDir.zip"), Path.Combine(tempPath, "Data")); - File.Delete(Path.Combine(tempPath, "dataDir.zip")); - Console.WriteLine("Cleaning up .xml and .pdb files..."); - Directory.GetFiles(Path.Combine(tempPath, "Data")) - .Where(s => new[] { ".xml", ".pdb" }.Contains(Path.GetExtension(s))) - .ToList().ForEach(File.Delete); - Console.WriteLine("Creating batch scripts..."); - string installBat = "@echo off\r\necho INSTALL"; - string removeBat = "@echo off\r\necho REMOVE"; - if (string.IsNullOrWhiteSpace(mainBin)) { - string[] tmp = Directory.GetFiles(binDir, "*.exe"); - if (tmp.Length > 0) - mainBin = Directory.GetFiles(binDir, "*.exe")[0]; - if (tmp.Length > 1) + Console.WriteLine("Removing previous package..."); + File.Delete(packageFile); + } + Console.WriteLine("Copying binary dir..."); + using ZipArchive archive = ZipFile.Open(packageFile, ZipArchiveMode.Create); + { + archive.AddDirectory(binDir, "Data", new[] {".xml", ".pdb"}, new[] {packageFile}); + Console.WriteLine("Creating batch scripts..."); + string installBat = "@echo off\r\necho INSTALL"; + string removeBat = "@echo off\r\necho REMOVE"; + if (string.IsNullOrWhiteSpace(mainBin)) { - Console.WriteLine("Detected multiple EXEs. This is not recommended as all processes running in the app folder will need to be terminated for uninstall to succeed"); - Console.WriteLine("Please consider removing unnecessary EXEs or notify me that anyone is actually using this."); + string[] tmp = Directory.GetFiles(binDir, "*.exe"); + if (tmp.Length > 0) + mainBin = Directory.GetFiles(binDir, "*.exe")[0]; + if (tmp.Length > 1) + { + Console.WriteLine( + "Detected multiple EXEs. This is not recommended as all processes running in the app folder will need to be terminated for uninstall to succeed"); + Console.WriteLine( + "Please consider removing unnecessary EXEs or notify me that anyone is actually using this."); + } + } + if (!noShortcuts) + { + 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()"""; + removeBat += "\r\n"; + removeBat += @"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk"""; + } + if (!string.IsNullOrWhiteSpace(mainBin)) + { + removeBat += "\r\n"; + removeBat += $@"taskkill /f /im ""{Path.GetFileNameWithoutExtension(mainBin)}.exe"""; + } + installBat += "\r\ntimeout /t 1"; + removeBat += "\r\ntimeout /t 1"; + using (Stream s = archive.CreateEntry("Install.bat").Open()) + { + using StreamWriter writer = new StreamWriter(s); + writer.Write(installBat); + } + using (Stream s = archive.CreateEntry("Remove.bat").Open()) + { + using StreamWriter writer = new StreamWriter(s); + writer.Write(removeBat); } } - if (!noShortcuts) - { - 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()"""; - removeBat += "\r\n"; - removeBat += @"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk"""; - } - if (!string.IsNullOrWhiteSpace(mainBin)) - { - removeBat += "\r\n"; - removeBat += $@"taskkill /f /im ""{Path.GetFileNameWithoutExtension(mainBin)}.exe"""; - } - installBat += "\r\ntimeout /t 1"; - removeBat += "\r\ntimeout /t 1"; - File.WriteAllText(Path.Combine(tempPath, "Install.bat"), installBat); - File.WriteAllText(Path.Combine(tempPath, "Remove.bat"), removeBat); - Console.WriteLine("Packaging..."); - ZipFile.CreateFromDirectory(tempPath, packageFile); - Console.WriteLine("Cleaning up temp path..."); - Directory.Delete(tempPath, true); watch.Stop(); Console.WriteLine($"Completed package creation in {watch.Elapsed}"); Console.WriteLine($"Output file: {Path.GetFullPath(packageFile)}"); diff --git a/UpTool build tool/UpTool build tool.csproj b/UpTool build tool/UpTool build tool.csproj index 0817d59..075759d 100644 --- a/UpTool build tool/UpTool build tool.csproj +++ b/UpTool build tool/UpTool build tool.csproj @@ -13,6 +13,7 @@ .\pkgtool.exe build --noLogo --noShortcuts --binDir . + \ No newline at end of file diff --git a/UpTool2/AppNameDialog.Designer.cs b/UpTool2/AppNameDialog.Designer.cs new file mode 100644 index 0000000..7bab1b8 --- /dev/null +++ b/UpTool2/AppNameDialog.Designer.cs @@ -0,0 +1,68 @@ +using System.ComponentModel; + +namespace UpTool2 +{ + partial class AppNameDialog + { + /// + /// Required designer variable. + /// + private IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.nameBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // textBox1 + // + this.nameBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.nameBox.Location = new System.Drawing.Point(12, 12); + this.nameBox.Name = "textBox1"; + this.nameBox.Size = new System.Drawing.Size(375, 23); + this.nameBox.TabIndex = 0; + this.nameBox.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + // + // AppNameDialog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(399, 41); + this.Controls.Add(this.nameBox); + this.Name = "AppNameDialog"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.Text = "App Name"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AppNameDialog_FormClosing); + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.AppNameDialog_FormClosed); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox nameBox; + } +} \ No newline at end of file diff --git a/UpTool2/AppNameDialog.cs b/UpTool2/AppNameDialog.cs new file mode 100644 index 0000000..cade47b --- /dev/null +++ b/UpTool2/AppNameDialog.cs @@ -0,0 +1,25 @@ +using System; +using System.Windows.Forms; + +namespace UpTool2 +{ + internal partial class AppNameDialog : Form + { + public string name; + + private AppNameDialog() => InitializeComponent(); + + public static string Show() + { + using AppNameDialog dialog = new AppNameDialog(); + dialog.ShowDialog(); + return dialog.name; + } + + private void AppNameDialog_FormClosed(object sender, FormClosedEventArgs e) => name = nameBox.Text; + + private void AppNameDialog_FormClosing(object sender, FormClosingEventArgs e) => name = nameBox.Text; + + private void textBox1_TextChanged(object sender, EventArgs e) => name = nameBox.Text; + } +} \ No newline at end of file diff --git a/UpTool2/AppNameDialog.resx b/UpTool2/AppNameDialog.resx new file mode 100644 index 0000000..e8ae276 --- /dev/null +++ b/UpTool2/AppNameDialog.resx @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/UpTool2/MainForm.cs b/UpTool2/MainForm.cs index 80e9c4d..8290be0 100644 --- a/UpTool2/MainForm.cs +++ b/UpTool2/MainForm.cs @@ -6,13 +6,13 @@ using System.IO.Compression; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; -using Microsoft.VisualBasic; using UpTool2.DataStructures; using UpTool2.Properties; using UpTool2.Tool; #if DEBUG using System.Threading; using System.Linq; + #endif namespace UpTool2 @@ -91,13 +91,14 @@ namespace UpTool2 #if !DEBUG try { + #endif 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(Interaction.InputBox("Name:"), "Locally installed package, removal only", + 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); #if !DEBUG @@ -184,10 +185,10 @@ namespace UpTool2 } catch (Exception e1) { - MessageBox.Show(e1.ToString() - #if DEBUG - + $"{Environment.NewLine}File was: {path}" - #endif + MessageBox.Show(e1 +#if DEBUG + + $"{Environment.NewLine}File was: {path}" +#endif , "Failed to start!"); } } diff --git a/UpTool2/Program.cs b/UpTool2/Program.cs index 67def00..88bd03a 100644 --- a/UpTool2/Program.cs +++ b/UpTool2/Program.cs @@ -7,14 +7,13 @@ using System.Linq; using System.Net; using System.Reflection; using System.Runtime.InteropServices; -using System.Security.AccessControl; using System.Security.Cryptography; -using System.Security.Principal; using System.Threading; using System.Windows.Forms; using System.Xml; using System.Xml.Linq; using UpTool2.Tool; + #if !DEBUG using Shortcut = UpTool2.Tool.Shortcut; #endif @@ -32,25 +31,24 @@ namespace UpTool2 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ShowSplash(); - string appGuid = ((GuidAttribute) Assembly.GetExecutingAssembly() - .GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value; - string mutexId = string.Format("Global\\{{{0}}}", appGuid); - MutexAccessRule allowEveryoneRule = new MutexAccessRule( - new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, - AccessControlType.Allow); - MutexSecurity securitySettings = new MutexSecurity(); - securitySettings.AddAccessRule(allowEveryoneRule); - using Mutex mutex = new Mutex(false, mutexId, out bool createdNew, securitySettings); + using Mutex mutex = new Mutex(false, + $"Global\\{{{((GuidAttribute) Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value}}}", + out bool _); bool hasHandle = false; #if !DEBUG - try - { + try + { #endif try { hasHandle = mutex.WaitOne(5000, false); if (hasHandle == false) - throw new TimeoutException("Timeout waiting for exclusive access"); + { + Process[] processes = Process.GetProcessesByName("UpTool2"); + if (processes.Length > 0) + WindowHelper.BringProcessToFront(Process.GetProcessesByName("UpTool2")[0]); + Environment.Exit(0); + } } catch (AbandonedMutexException) { @@ -66,39 +64,42 @@ namespace UpTool2 Online = Ping(metaXml); #if !DEBUG - if (Application.ExecutablePath != PathTool.GetRelative("Install", "UpTool2.exe")) - { - if (!Online) - throw new WebException("Could fetch Metadata (are you online?)"); - if (MessageBox.Show(@"Thank you for downloading UpTool2. + if (Application.ExecutablePath != PathTool.GetRelative("Install", "UpTool2.exe")) + { + if (!Online) + throw new WebException("Could fetch Metadata (are you online?)"); + if (MessageBox.Show(@"Thank you for downloading UpTool2. To prevent inconsistent behavior you will need to install this before running. Files will be placed in %appdata%\UpTool2 and %appdata%\Microsoft\Windows\Start Menu\Programs Do you want to continue?", "UpTool2", MessageBoxButtons.YesNo) != DialogResult.Yes) - throw new Exception("Exiting..."); - MessageBox.Show("Installing an Update. Please restart from your start menu!"); - InstallUpdate(XDocument.Load(metaXml).Element("meta")); - Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")); - mutex.ReleaseMutex(); - Environment.Exit(0); - } - if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk"))) - Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")); + throw new Exception("Exiting..."); + MessageBox.Show("Installing an Update. Please restart from your start menu!"); + InstallUpdate(XDocument.Load(metaXml).Element("meta")); + Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"), + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")); + mutex.ReleaseMutex(); + Environment.Exit(0); + } + if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), + "UpTool2.lnk"))) + Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"), + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")); #endif if (!Directory.Exists(PathTool.GetRelative("Apps"))) Directory.CreateDirectory(PathTool.GetRelative("Apps")); if (!Online || UpdateCheck(metaXml)) Application.Run(new MainForm()); #if !DEBUG - } - catch (Exception e1) - { - MessageBox.Show(e1.ToString()); - } - finally - { - if (hasHandle) - mutex.ReleaseMutex(); - } + } + catch (Exception e1) + { + MessageBox.Show(e1.ToString()); + } + finally + { + if (hasHandle) + mutex.ReleaseMutex(); + } #endif } @@ -210,8 +211,8 @@ Do you want to continue?", "UpTool2", MessageBoxButtons.YesNo) != DialogResult.Y Directory.Delete(PathTool.GetRelative("Install", "tmp"), true); Directory.CreateDirectory(PathTool.GetRelative("Install", "tmp")); using (MemoryStream ms = new MemoryStream(dl)) - using (ZipArchive ar = new ZipArchive(ms)) { + using ZipArchive ar = new ZipArchive(ms); ar.Entries.Where(s => !string.IsNullOrEmpty(s.Name)).ToList().ForEach(s => { s.ExtractToFile(PathTool.GetRelative("Install", "tmp", s.Name), true); @@ -231,8 +232,7 @@ Do you want to continue?", "UpTool2", MessageBoxButtons.YesNo) != DialogResult.Y { HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.Timeout = 3000; - request.AllowAutoRedirect = false; - request.Method = "HEAD"; + request.AllowAutoRedirect = true; using WebResponse response = request.GetResponse(); return true; } diff --git a/UpTool2/Tool/AppInstall.cs b/UpTool2/Tool/AppInstall.cs index 3a25a79..84e43ac 100644 --- a/UpTool2/Tool/AppInstall.cs +++ b/UpTool2/Tool/AppInstall.cs @@ -87,6 +87,9 @@ Online: {appI.Hash.ToUpper()}"); } } + //Use + //PowerShell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('Hello World')" + //for message boxes private static void CompleteInstall(App app) => CompleteInstall(app.appPath, app.Name, app.Description, app.Version, app.MainFile); diff --git a/UpTool2/Tool/RepoManagement.cs b/UpTool2/Tool/RepoManagement.cs index a07b072..5879a29 100644 --- a/UpTool2/Tool/RepoManagement.cs +++ b/UpTool2/Tool/RepoManagement.cs @@ -37,7 +37,8 @@ namespace UpTool2.Tool XElement[] tmp_apparray = repo.Element("repo").Elements("app").Where(app => !tmpAppsList.Any(a => a.Element("ID").Value == app.Element("ID").Value) || !tmpAppsList - .Where(a => a.Element("ID").Value == app.Element("ID").Value).Any(a => GetVer(a.Element("Version")) >= app.Element("Version").GetVer())).ToArray() + .Where(a => a.Element("ID").Value == app.Element("ID").Value).Any(a => + GetVer(a.Element("Version")) >= app.Element("Version").GetVer())).ToArray() .Concat(repo.Element("repo").Elements("applink") .Select(s => XDocument.Load(s.Value).Element("app"))).ToArray(); for (int i1 = 0; i1 < tmp_apparray.Length; i1++) @@ -99,7 +100,8 @@ namespace UpTool2.Tool i++; } } - tmpAppsList.Sort((x, y) => string.Compare(x.Element("Name").Value, y.Element("Name").Value, StringComparison.Ordinal)); + tmpAppsList.Sort((x, y) => + string.Compare(x.Element("Name").Value, y.Element("Name").Value, StringComparison.Ordinal)); if (meta.Element("LocalRepo") == null) meta.Add(new XElement("LocalRepo")); XElement repos = meta.Element("LocalRepo"); @@ -146,7 +148,8 @@ namespace UpTool2.Tool #endif }); Directory.GetDirectories(PathTool.appsPath) - .Where(s => Guid.TryParse(Path.GetFileName(s), out Guid guid) && !GlobalVariables.Apps.ContainsKey(guid)).ToList().ForEach(s => + .Where(s => Guid.TryParse(Path.GetFileName(s), out Guid guid) && + !GlobalVariables.Apps.ContainsKey(guid)).ToList().ForEach(s => { Guid tmp = Guid.Parse(Path.GetFileName(s)); try diff --git a/UpTool2/UpTool2.csproj b/UpTool2/UpTool2.csproj index 7c0c4dc..85129a2 100644 --- a/UpTool2/UpTool2.csproj +++ b/UpTool2/UpTool2.csproj @@ -1,115 +1,23 @@ - - - + - Debug - AnyCPU - {C0C1E002-9E13-4E8F-A035-DBDC5128E00E} + netcoreapp3.1 WinExe - UpTool2 - UpTool2 - v4.8 latest - 512 - true false - enable - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 + false + true - AnyCPU none - true - bin\Release\ - TRACE - prompt - 4 UpTool2.Program - - - - - - - - - - - - - - - - - - - - - Form - - - DownloadDialog.cs - - - - Form - - - MainForm.cs - - - - - - - - Form - - - SourcesForm.cs - - - - DownloadDialog.cs - - - MainForm.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - True - - - SourcesForm.cs - - - - - - + - \ No newline at end of file diff --git a/UpTool2/WindowHelper.cs b/UpTool2/WindowHelper.cs new file mode 100644 index 0000000..196b15f --- /dev/null +++ b/UpTool2/WindowHelper.cs @@ -0,0 +1,27 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace UpTool2 +{ + //TODO: This class is Windows-only and can't be used cross-platform. + public static class WindowHelper + { + public static void BringProcessToFront(Process process) + { + IntPtr handle = process.MainWindowHandle; + if (IsIconic(handle)) + ShowWindow(handle, 9); + SetForegroundWindow(handle); + } + + [DllImport("User32.dll")] + private static extern bool SetForegroundWindow(IntPtr handle); + + [DllImport("User32.dll")] + private static extern bool ShowWindow(IntPtr handle, int nCmdShow); + + [DllImport("User32.dll")] + private static extern bool IsIconic(IntPtr handle); + } +} \ No newline at end of file