diff --git a/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj b/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj index e17e9bb32..0af14dff1 100644 --- a/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj +++ b/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj @@ -21,9 +21,9 @@ - - - + + + all diff --git a/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj b/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj index 58f87fc29..a0bb36d5b 100644 --- a/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj +++ b/src/Greenshot.Addon.InternetExplorer/Greenshot.Addon.InternetExplorer.csproj @@ -8,10 +8,10 @@ - 0.8.27 + 0.8.28 - 0.8.27 + 0.8.28 diff --git a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj index c33b14219..f48e2259b 100644 --- a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj +++ b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj @@ -112,11 +112,11 @@ - - + + - - + + all runtime; build; native; contentfiles; analyzers diff --git a/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj b/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj index 09b645c77..4b339a018 100644 --- a/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj +++ b/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj @@ -20,9 +20,9 @@ - - - + + + diff --git a/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj b/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj index 844b3ce58..4bdafdb2f 100644 --- a/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj +++ b/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj @@ -19,9 +19,9 @@ - - - + + + diff --git a/src/Greenshot.Addons/Core/ExplorerHelper.cs b/src/Greenshot.Addons/Core/ExplorerHelper.cs index 8e73a342a..7de72d7ae 100644 --- a/src/Greenshot.Addons/Core/ExplorerHelper.cs +++ b/src/Greenshot.Addons/Core/ExplorerHelper.cs @@ -40,12 +40,19 @@ namespace Greenshot.Addons.Core { return false; } + + try { // Check if path is a directory if (Directory.Exists(path)) { - using (Process.Start(path)) + var processStartInfo = new ProcessStartInfo(path) + { + CreateNoWindow = true, + UseShellExecute = true + }; + using (Process.Start(processStartInfo)) { return true; } @@ -53,8 +60,14 @@ namespace Greenshot.Addons.Core // Check if path is a file if (File.Exists(path)) { + var processStartInfo = new ProcessStartInfo("explorer.exe") + { + Arguments = $"/select,\"{path}\"", + CreateNoWindow = true, + UseShellExecute = true + }; // Start the explorer process and select the file - using (var explorer = Process.Start("explorer.exe", $"/select,\"{path}\"")) + using (var explorer = Process.Start(processStartInfo)) { explorer?.WaitForInputIdle(500); return true; diff --git a/src/Greenshot.Addons/Core/ImageOutput.cs b/src/Greenshot.Addons/Core/ImageOutput.cs index def8c98d7..67763651b 100644 --- a/src/Greenshot.Addons/Core/ImageOutput.cs +++ b/src/Greenshot.Addons/Core/ImageOutput.cs @@ -638,7 +638,7 @@ namespace Greenshot.Addons.Core CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, - UseShellExecute = false + UseShellExecute = true }; using (var process = Process.Start(processStartInfo)) { diff --git a/src/Greenshot.Addons/Greenshot.Addons.csproj b/src/Greenshot.Addons/Greenshot.Addons.csproj index 0e3d62192..9f77e99c0 100644 --- a/src/Greenshot.Addons/Greenshot.Addons.csproj +++ b/src/Greenshot.Addons/Greenshot.Addons.csproj @@ -23,13 +23,13 @@ - 1.2.25 + 1.2.26 - 1.2.25 + 1.2.26 - 1.2.25 + 1.2.26 0.9.18 @@ -41,13 +41,13 @@ 0.9.18 - 0.8.27 + 0.8.28 - 0.8.27 + 0.8.28 - 0.8.27 + 0.8.28 all @@ -57,7 +57,7 @@ 3.0.0-alpha0146 - 2.4.2 + 2.4.3 diff --git a/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs b/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs index 0b84e9f86..36f33ba29 100644 --- a/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs +++ b/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs @@ -126,7 +126,12 @@ namespace Greenshot.Addons.ViewModels if (Information.IsCloudExport) { - Process.Start(Information.Uri); + var processStartInfo = new ProcessStartInfo(Information.Uri) + { + CreateNoWindow = true, + UseShellExecute = true + }; + Process.Start(processStartInfo); } } catch (Exception ex) diff --git a/src/Greenshot.Core/Greenshot.Core.csproj b/src/Greenshot.Core/Greenshot.Core.csproj index 8175b6ffc..c570d48c9 100644 --- a/src/Greenshot.Core/Greenshot.Core.csproj +++ b/src/Greenshot.Core/Greenshot.Core.csproj @@ -8,7 +8,7 @@ - 0.8.27 + 0.8.28 diff --git a/src/Greenshot.Gfx/Greenshot.Gfx.csproj b/src/Greenshot.Gfx/Greenshot.Gfx.csproj index b33c276c8..846887daa 100644 --- a/src/Greenshot.Gfx/Greenshot.Gfx.csproj +++ b/src/Greenshot.Gfx/Greenshot.Gfx.csproj @@ -9,10 +9,10 @@ - 1.2.25 + 1.2.26 - 2.4.2 + 2.4.3 4.5.2 diff --git a/src/Greenshot.Tests/Greenshot.Tests.csproj b/src/Greenshot.Tests/Greenshot.Tests.csproj index 513af4ef1..e1c307f0f 100644 --- a/src/Greenshot.Tests/Greenshot.Tests.csproj +++ b/src/Greenshot.Tests/Greenshot.Tests.csproj @@ -43,10 +43,10 @@ - + - + diff --git a/src/Greenshot/Components/CommandlineParser.cs b/src/Greenshot/Components/CommandlineParser.cs index 424b558e5..4f9e4a72e 100644 --- a/src/Greenshot/Components/CommandlineParser.cs +++ b/src/Greenshot/Components/CommandlineParser.cs @@ -73,7 +73,7 @@ namespace Greenshot.Components if (argument.ToLower().Equals("/help") || argument.ToLower().Equals("/h") || argument.ToLower().Equals("/?")) { // Try to attach to the console - var attachedToConsole = Kernel32Api.AttachConsole(Kernel32Api.ATTACHCONSOLE_ATTACHPARENTPROCESS); + var attachedToConsole = Kernel32Api.AttachConsole(); // If attach didn't work, open a console if (!attachedToConsole) { @@ -186,7 +186,7 @@ namespace Greenshot.Components if (arguments.Length > 0 && arguments[0].ToLower().Equals("/capture")) { // Try to attach to the console - bool attachedToConsole = Kernel32Api.AttachConsole(Kernel32Api.ATTACHCONSOLE_ATTACHPARENTPROCESS); + bool attachedToConsole = Kernel32Api.AttachConsole(); // If attach didn't work, open a console if (!attachedToConsole) { diff --git a/src/Greenshot/Forms/AboutForm.cs b/src/Greenshot/Forms/AboutForm.cs index 60df5a028..3de8f7224 100644 --- a/src/Greenshot/Forms/AboutForm.cs +++ b/src/Greenshot/Forms/AboutForm.cs @@ -158,7 +158,7 @@ namespace Greenshot.Forms pictureBox1.Size = FormDpiHandler.ScaleWithCurrentDpi(new NativeSize(90,90)); }); - var versionInfo = $@"Greenshot {versionProvider.CurrentVersion} {(coreConfiguration.IsPortable ? " Portable" : "")} ({OsInfo.Bits} bit)"; + var versionInfo = $@"Greenshot {versionProvider.CurrentVersion} {(SingleExeHelper.IsRunningAsSingleExe? "SE " : "")}({OsInfo.Bits} bit)"; if (versionProvider.IsUpdateAvailable) { versionInfo += $" latest is: {versionProvider.LatestVersion}"; @@ -247,7 +247,12 @@ namespace Greenshot.Forms try { linkLabel.LinkVisited = true; - Process.Start(linkLabel.Text); + var processStartInfo = new ProcessStartInfo(linkLabel.Text) + { + CreateNoWindow = true, + UseShellExecute = true + }; + Process.Start(processStartInfo); } catch (Exception) { diff --git a/src/Greenshot/Forms/BugReportForm.cs b/src/Greenshot/Forms/BugReportForm.cs index 501143197..d6f092b34 100644 --- a/src/Greenshot/Forms/BugReportForm.cs +++ b/src/Greenshot/Forms/BugReportForm.cs @@ -57,7 +57,12 @@ namespace Greenshot.Forms try { link.LinkVisited = true; - Process.Start(link.Text); + var processStartInfo = new ProcessStartInfo(link.Text) + { + CreateNoWindow = true, + UseShellExecute = true + }; + Process.Start(processStartInfo); } catch (Exception) { diff --git a/src/Greenshot/Forms/MainForm.cs b/src/Greenshot/Forms/MainForm.cs index a782fa855..7dd542be0 100644 --- a/src/Greenshot/Forms/MainForm.cs +++ b/src/Greenshot/Forms/MainForm.cs @@ -801,7 +801,15 @@ namespace Greenshot.Forms /// private void Contextmenu_donateClick(object sender, EventArgs e) { - BeginInvoke((MethodInvoker) delegate { Process.Start("http://getgreenshot.org/support/?version=" + Assembly.GetEntryAssembly().GetName().Version); }); + BeginInvoke((MethodInvoker) delegate + { + var processStartInfo = new ProcessStartInfo("http://getgreenshot.org/support/?version=" + Assembly.GetEntryAssembly()?.GetName().Version) + { + CreateNoWindow = true, + UseShellExecute = true + }; + Process.Start(processStartInfo); + }); } /// diff --git a/src/Greenshot/Greenshot.csproj b/src/Greenshot/Greenshot.csproj index 63594de18..477bc00a1 100644 --- a/src/Greenshot/Greenshot.csproj +++ b/src/Greenshot/Greenshot.csproj @@ -58,25 +58,25 @@ - - - - - + + + + + - - - + + + all runtime; build; native; contentfiles; analyzers - + diff --git a/src/Greenshot/Help/HelpFileLoader.cs b/src/Greenshot/Help/HelpFileLoader.cs index 77c9f9c78..acffd5cf0 100644 --- a/src/Greenshot/Help/HelpFileLoader.cs +++ b/src/Greenshot/Help/HelpFileLoader.cs @@ -36,7 +36,12 @@ namespace Greenshot.Help public static void LoadHelp() { var uri = FindOnlineHelpUrl("en-US");// Language.CurrentLanguage);// ?? Language.HelpFilePath; - Process.Start(uri); + var processStartInfo = new ProcessStartInfo(uri) + { + CreateNoWindow = true, + UseShellExecute = true + }; + Process.Start(processStartInfo); } /// diff --git a/src/Greenshot/Helpers/EnvironmentInfo.cs b/src/Greenshot/Helpers/EnvironmentInfo.cs index 627c78530..773e9a837 100644 --- a/src/Greenshot/Helpers/EnvironmentInfo.cs +++ b/src/Greenshot/Helpers/EnvironmentInfo.cs @@ -18,15 +18,10 @@ // along with this program. If not, see . using System; -using System.ComponentModel; -using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; -using Dapplo.Windows.Kernel32; -using Dapplo.Windows.Kernel32.Enums; -using Dapplo.Windows.Kernel32.Structs; using Dapplo.Windows.User32; namespace Greenshot.Helpers @@ -72,7 +67,11 @@ namespace Greenshot.Helpers public static string EnvironmentToString(bool newline) { var environment = new StringBuilder("Software version: " + Application.ProductVersion); - environment.Append(" (" + OsInfo.Bits + " bit)"); + if (SingleExeHelper.IsRunningAsSingleExe) + { + environment.Append(" SE"); + } + environment.Append(" (" + OsInfo.Bits + " bit)"); if (newline) { @@ -118,16 +117,41 @@ namespace Greenshot.Helpers environment.Append(", "); } - environment.AppendFormat("Location: {0}", Assembly.GetEntryAssembly()?.Location); - if (newline) + if (SingleExeHelper.IsRunningAsSingleExe) { - environment.AppendLine(); + environment.AppendFormat("Exe Location: {0}", SingleExeHelper.SingleExeLocation); + if (newline) + { + environment.AppendLine(); + } + else + { + environment.Append(", "); + } + environment.AppendFormat("Unpacked into: {0}", SingleExeHelper.UnpackPath); + if (newline) + { + environment.AppendLine(); + } + else + { + environment.Append(", "); + } } else { - environment.Append(", "); + environment.AppendFormat("Exe Location: {0}", Assembly.GetEntryAssembly()?.Location); + if (newline) + { + environment.AppendLine(); + } + else + { + environment.Append(", "); + } } + // Get some important information for fixing GDI related Problems environment.AppendFormat("GDI object count: {0}", User32Api.GetGuiResourcesGdiCount()); if (newline) @@ -223,366 +247,4 @@ namespace Greenshot.Helpers return exceptionText.ToString(); } } - - /// - /// Provides detailed information about the host operating system. - /// Code is available at: http://www.csharp411.com/determine-windows-version-and-edition-with-c/ - /// - public static class OsInfo - { - /// - /// Determines if the current application is 32 or 64-bit. - /// - public static int Bits => IntPtr.Size * 8; - - /// - /// Gets the service pack information of the operating system running on this computer. - /// - public static string ServicePack - { - get - { - var servicePack = string.Empty; - var osVersionInfo = OsVersionInfoEx.Create(); - - if (Kernel32Api.GetVersionEx(ref osVersionInfo)) - { - servicePack = osVersionInfo.ServicePackVersion; - } - - return servicePack; - } - } - - private static string _sEdition; - - /// - /// Gets the edition of the operating system running on this computer. - /// - public static string Edition - { - get - { - if (_sEdition != null) - { - return _sEdition; //***** RETURN *****// - } - - var edition = string.Empty; - - var osVersion = Environment.OSVersion; - var osVersionInfo = OsVersionInfoEx.Create(); - if (!Kernel32Api.GetVersionEx(ref osVersionInfo)) - { - _sEdition = edition; - return edition; - } - - var majorVersion = osVersion.Version.Major; - var minorVersion = osVersion.Version.Minor; - var productType = osVersionInfo.ProductType; - var suiteMask = osVersionInfo.SuiteMask; - - if (majorVersion == 4) - { - if (productType.HasFlag(WindowsProductTypes.VER_NT_WORKSTATION)) - { - // Windows NT 4.0 Workstation - edition = "Workstation"; - } - else if (productType.HasFlag(WindowsProductTypes.VER_NT_SERVER)) - { - edition = suiteMask.HasFlag(WindowsSuites.Enterprise) ? "Enterprise Server" : "Standard Server"; - } - } - - else if (majorVersion == 5) - { - if (productType.HasFlag(WindowsProductTypes.VER_NT_WORKSTATION)) - { - if (suiteMask.HasFlag(WindowsSuites.Personal)) - { - // Windows XP Home Edition - edition = "Home"; - } - else - { - // Windows XP / Windows 2000 Professional - edition = "Professional"; - } - } - else if (productType.HasFlag(WindowsProductTypes.VER_NT_SERVER)) - { - if (minorVersion == 0) - { - if (suiteMask.HasFlag(WindowsSuites.DataCenter)) - { - // Windows 2000 Datacenter Server - edition = "Datacenter Server"; - } - else if (suiteMask.HasFlag(WindowsSuites.Enterprise)) - { - // Windows 2000 Advanced Server - edition = "Advanced Server"; - } - else - { - // Windows 2000 Server - edition = "Server"; - } - } - else - { - if (suiteMask.HasFlag(WindowsSuites.DataCenter)) - { - // Windows Server 2003 Datacenter Edition - edition = "Datacenter"; - } - else if (suiteMask.HasFlag(WindowsSuites.Enterprise)) - { - // Windows Server 2003 Enterprise Edition - edition = "Enterprise"; - } - else if (suiteMask.HasFlag(WindowsSuites.Blade)) - { - // Windows Server 2003 Web Edition - edition = "Web Edition"; - } - else - { - // Windows Server 2003 Standard Edition - edition = "Standard"; - } - } - } - } - - else if (majorVersion == 6) - { - if (Kernel32Api.GetProductInfo(majorVersion, minorVersion, osVersionInfo.ServicePackMajor, osVersionInfo.ServicePackMinor, out var ed)) - { - var memberInfo = ed.GetType().GetMember(ed.ToString()).FirstOrDefault(); - - if (memberInfo != null) - { - var descriptionAttribute = (DescriptionAttribute) memberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault(); - edition = descriptionAttribute?.Description ?? "unknown"; - } - } - } - - _sEdition = edition; - return edition; - } - } - - private static string _name; - - /// - /// Gets the name of the operating system running on this computer. - /// - public static string Name - { - get - { - if (_name != null) - { - return _name; //***** RETURN *****// - } - - var name = "unknown"; - - var osVersion = Environment.OSVersion; - var osVersionInfo = OsVersionInfoEx.Create(); - if (!Kernel32Api.GetVersionEx(ref osVersionInfo)) - { - _name = name; - return name; - } - - var majorVersion = osVersion.Version.Major; - var minorVersion = osVersion.Version.Minor; - var productType = osVersionInfo.ProductType; - var suiteMask = osVersionInfo.SuiteMask; - switch (osVersion.Platform) - { - case PlatformID.Win32Windows: - if (majorVersion == 4) - { - var csdVersion = osVersionInfo.ServicePackVersion; - switch (minorVersion) - { - case 0: - if (csdVersion == "B" || csdVersion == "C") - { - name = "Windows 95 OSR2"; - } - else - { - name = "Windows 95"; - } - break; - case 10: - name = csdVersion == "A" ? "Windows 98 Second Edition" : "Windows 98"; - break; - case 90: - name = "Windows Me"; - break; - } - } - break; - case PlatformID.Win32NT: - switch (majorVersion) - { - case 3: - name = "Windows NT 3.51"; - break; - case 4: - switch (productType) - { - case WindowsProductTypes.VER_NT_WORKSTATION: - name = "Windows NT 4.0"; - break; - case WindowsProductTypes.VER_NT_DOMAIN_CONTROLLER: - case WindowsProductTypes.VER_NT_SERVER: - name = "Windows NT 4.0 Server"; - break; - } - break; - case 5: - switch (minorVersion) - { - case 0: - name = "Windows 2000"; - break; - case 1: - switch (suiteMask) - { - case WindowsSuites.Personal: - name = "Windows XP Professional"; - break; - default: - name = "Windows XP"; - break; - } - break; - case 2: - switch (suiteMask) - { - case WindowsSuites.Personal: - name = "Windows XP Professional x64"; - break; - case WindowsSuites.Enterprise: - name = "Windows Server 2003 Enterprise"; - break; - case WindowsSuites.DataCenter: - name = "Windows Server 2003 Data Center"; - break; - case WindowsSuites.Blade: - name = "Windows Server 2003 Web Edition"; - break; - case WindowsSuites.WHServer: - name = "Windows Home Server"; - break; - default: - name = "Windows Server 2003"; - break; - } - break; - } - break; - case 6: - switch (minorVersion) - { - case 0: - switch (productType) - { - case WindowsProductTypes.VER_NT_SERVER: - name = "Windows Server 2008"; - break; - default: - name = "Windows Vista"; - break; - } - break; - case 1: - switch (productType) - { - case WindowsProductTypes.VER_NT_SERVER: - name = "Windows Server 2008 R2"; - break; - default: - name = "Windows 7"; - break; - } - break; - case 2: - name = "Windows 8"; - break; - case 3: - name = "Windows 8.1"; - break; - } - break; - case 10: - name = "Windows 10"; - break; - } - break; - } - - _name = name; - return name; - } - } - - /// - /// Gets the build version number of the operating system running on this computer. - /// - public static int BuildVersion => Environment.OSVersion.Version.Build; - - /// - /// Gets the full version string of the operating system running on this computer. - /// - public static string VersionString - { - get - { - return string.Format("{0}.{1} build {3} revision {2:X}", Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, - Environment.OSVersion.Version.Revision, Environment.OSVersion.Version.Build); - } - } - - /// - /// Gets the full version of the operating system running on this computer. - /// - public static Version Version - { - get { return Environment.OSVersion.Version; } - } - - /// - /// Gets the major version number of the operating system running on this computer. - /// - public static int MajorVersion - { - get { return Environment.OSVersion.Version.Major; } - } - - /// - /// Gets the minor version number of the operating system running on this computer. - /// - public static int MinorVersion - { - get { return Environment.OSVersion.Version.Minor; } - } - - /// - /// Gets the revision version number of the operating system running on this computer. - /// - public static int RevisionVersion - { - get { return Environment.OSVersion.Version.Revision; } - } - } } \ No newline at end of file diff --git a/src/Greenshot/Helpers/OsInfo.cs b/src/Greenshot/Helpers/OsInfo.cs new file mode 100644 index 000000000..a6c5a90d4 --- /dev/null +++ b/src/Greenshot/Helpers/OsInfo.cs @@ -0,0 +1,392 @@ +// Dapplo - building blocks for desktop applications +// Copyright (C) 2019 Dapplo +// +// For more information see: http://dapplo.net/ +// Dapplo repositories are hosted on GitHub: https://github.com/dapplo +// +// This file is part of Greenshot +// +// Greenshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Greenshot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have a copy of the GNU Lesser General Public License +// along with Greenshot. If not, see . + +using System; +using System.ComponentModel; +using System.Linq; +using Dapplo.Windows.Kernel32; +using Dapplo.Windows.Kernel32.Enums; +using Dapplo.Windows.Kernel32.Structs; + +namespace Greenshot.Helpers +{ + /// + /// Provides detailed information about the host operating system. + /// Code is available at: http://www.csharp411.com/determine-windows-version-and-edition-with-c/ + /// + public static class OsInfo + { + /// + /// Determines if the current application is 32 or 64-bit. + /// + public static int Bits => IntPtr.Size * 8; + + /// + /// Gets the service pack information of the operating system running on this computer. + /// + public static string ServicePack + { + get + { + var servicePack = string.Empty; + var osVersionInfo = OsVersionInfoEx.Create(); + + if (Kernel32Api.GetVersionEx(ref osVersionInfo)) + { + servicePack = osVersionInfo.ServicePackVersion; + } + + return servicePack; + } + } + + private static string _sEdition; + + /// + /// Gets the edition of the operating system running on this computer. + /// + public static string Edition + { + get + { + if (_sEdition != null) + { + return _sEdition; //***** RETURN *****// + } + + var edition = string.Empty; + + var osVersion = Environment.OSVersion; + var osVersionInfo = OsVersionInfoEx.Create(); + if (!Kernel32Api.GetVersionEx(ref osVersionInfo)) + { + _sEdition = edition; + return edition; + } + + var majorVersion = osVersion.Version.Major; + var minorVersion = osVersion.Version.Minor; + var productType = osVersionInfo.ProductType; + var suiteMask = osVersionInfo.SuiteMask; + + if (majorVersion == 4) + { + if (productType.HasFlag(WindowsProductTypes.VER_NT_WORKSTATION)) + { + // Windows NT 4.0 Workstation + edition = "Workstation"; + } + else if (productType.HasFlag(WindowsProductTypes.VER_NT_SERVER)) + { + edition = suiteMask.HasFlag(WindowsSuites.Enterprise) ? "Enterprise Server" : "Standard Server"; + } + } + + else if (majorVersion == 5) + { + if (productType.HasFlag(WindowsProductTypes.VER_NT_WORKSTATION)) + { + if (suiteMask.HasFlag(WindowsSuites.Personal)) + { + // Windows XP Home Edition + edition = "Home"; + } + else + { + // Windows XP / Windows 2000 Professional + edition = "Professional"; + } + } + else if (productType.HasFlag(WindowsProductTypes.VER_NT_SERVER)) + { + if (minorVersion == 0) + { + if (suiteMask.HasFlag(WindowsSuites.DataCenter)) + { + // Windows 2000 Datacenter Server + edition = "Datacenter Server"; + } + else if (suiteMask.HasFlag(WindowsSuites.Enterprise)) + { + // Windows 2000 Advanced Server + edition = "Advanced Server"; + } + else + { + // Windows 2000 Server + edition = "Server"; + } + } + else + { + if (suiteMask.HasFlag(WindowsSuites.DataCenter)) + { + // Windows Server 2003 Datacenter Edition + edition = "Datacenter"; + } + else if (suiteMask.HasFlag(WindowsSuites.Enterprise)) + { + // Windows Server 2003 Enterprise Edition + edition = "Enterprise"; + } + else if (suiteMask.HasFlag(WindowsSuites.Blade)) + { + // Windows Server 2003 Web Edition + edition = "Web Edition"; + } + else + { + // Windows Server 2003 Standard Edition + edition = "Standard"; + } + } + } + } + + else if (majorVersion == 6) + { + if (Kernel32Api.GetProductInfo(majorVersion, minorVersion, osVersionInfo.ServicePackMajor, osVersionInfo.ServicePackMinor, out var ed)) + { + var memberInfo = ed.GetType().GetMember(ed.ToString()).FirstOrDefault(); + + if (memberInfo != null) + { + var descriptionAttribute = (DescriptionAttribute) memberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault(); + edition = descriptionAttribute?.Description ?? "unknown"; + } + } + } + + _sEdition = edition; + return edition; + } + } + + private static string _name; + + /// + /// Gets the name of the operating system running on this computer. + /// + public static string Name + { + get + { + if (_name != null) + { + return _name; //***** RETURN *****// + } + + var name = "unknown"; + + var osVersion = Environment.OSVersion; + var osVersionInfo = OsVersionInfoEx.Create(); + if (!Kernel32Api.GetVersionEx(ref osVersionInfo)) + { + _name = name; + return name; + } + + var majorVersion = osVersion.Version.Major; + var minorVersion = osVersion.Version.Minor; + var productType = osVersionInfo.ProductType; + var suiteMask = osVersionInfo.SuiteMask; + switch (osVersion.Platform) + { + case PlatformID.Win32Windows: + if (majorVersion == 4) + { + var csdVersion = osVersionInfo.ServicePackVersion; + switch (minorVersion) + { + case 0: + if (csdVersion == "B" || csdVersion == "C") + { + name = "Windows 95 OSR2"; + } + else + { + name = "Windows 95"; + } + break; + case 10: + name = csdVersion == "A" ? "Windows 98 Second Edition" : "Windows 98"; + break; + case 90: + name = "Windows Me"; + break; + } + } + break; + case PlatformID.Win32NT: + switch (majorVersion) + { + case 3: + name = "Windows NT 3.51"; + break; + case 4: + switch (productType) + { + case WindowsProductTypes.VER_NT_WORKSTATION: + name = "Windows NT 4.0"; + break; + case WindowsProductTypes.VER_NT_DOMAIN_CONTROLLER: + case WindowsProductTypes.VER_NT_SERVER: + name = "Windows NT 4.0 Server"; + break; + } + break; + case 5: + switch (minorVersion) + { + case 0: + name = "Windows 2000"; + break; + case 1: + switch (suiteMask) + { + case WindowsSuites.Personal: + name = "Windows XP Professional"; + break; + default: + name = "Windows XP"; + break; + } + break; + case 2: + switch (suiteMask) + { + case WindowsSuites.Personal: + name = "Windows XP Professional x64"; + break; + case WindowsSuites.Enterprise: + name = "Windows Server 2003 Enterprise"; + break; + case WindowsSuites.DataCenter: + name = "Windows Server 2003 Data Center"; + break; + case WindowsSuites.Blade: + name = "Windows Server 2003 Web Edition"; + break; + case WindowsSuites.WHServer: + name = "Windows Home Server"; + break; + default: + name = "Windows Server 2003"; + break; + } + break; + } + break; + case 6: + switch (minorVersion) + { + case 0: + switch (productType) + { + case WindowsProductTypes.VER_NT_SERVER: + name = "Windows Server 2008"; + break; + default: + name = "Windows Vista"; + break; + } + break; + case 1: + switch (productType) + { + case WindowsProductTypes.VER_NT_SERVER: + name = "Windows Server 2008 R2"; + break; + default: + name = "Windows 7"; + break; + } + break; + case 2: + name = "Windows 8"; + break; + case 3: + name = "Windows 8.1"; + break; + } + break; + case 10: + name = "Windows 10"; + break; + } + break; + } + + _name = name; + return name; + } + } + + /// + /// Gets the build version number of the operating system running on this computer. + /// + public static int BuildVersion => Environment.OSVersion.Version.Build; + + /// + /// Gets the full version string of the operating system running on this computer. + /// + public static string VersionString + { + get + { + return string.Format("{0}.{1} build {3} revision {2:X}", Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, + Environment.OSVersion.Version.Revision, Environment.OSVersion.Version.Build); + } + } + + /// + /// Gets the full version of the operating system running on this computer. + /// + public static Version Version + { + get { return Environment.OSVersion.Version; } + } + + /// + /// Gets the major version number of the operating system running on this computer. + /// + public static int MajorVersion + { + get { return Environment.OSVersion.Version.Major; } + } + + /// + /// Gets the minor version number of the operating system running on this computer. + /// + public static int MinorVersion + { + get { return Environment.OSVersion.Version.Minor; } + } + + /// + /// Gets the revision version number of the operating system running on this computer. + /// + public static int RevisionVersion + { + get { return Environment.OSVersion.Version.Revision; } + } + } +} \ No newline at end of file diff --git a/src/Greenshot/Helpers/SingleExeHelper.cs b/src/Greenshot/Helpers/SingleExeHelper.cs new file mode 100644 index 000000000..1c7e4729c --- /dev/null +++ b/src/Greenshot/Helpers/SingleExeHelper.cs @@ -0,0 +1,88 @@ +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2019 Thomas Braun, Jens Klingen, Robin Krom +// +// For more information see: http://getgreenshot.org/ +// The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 1 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using Dapplo.Windows.Kernel32; + +namespace Greenshot.Helpers +{ + /// + /// This is a helper class to handle the single-exe logic + /// + public static class SingleExeHelper + { + /// + /// Initialize the properties of this static helper, only called when the class is used + /// + static SingleExeHelper() + { + var assemblyLocation = Assembly.GetExecutingAssembly().Location; + if (string.IsNullOrEmpty(assemblyLocation) || assemblyLocation.EndsWith(".dll") != true) + { + return; + } + + // Current process path + string currentProcessPath = null; + try + { + using (var currentProcess = Process.GetCurrentProcess()) + { + currentProcessPath = currentProcess.GetProcessPath(); + } + } + catch + { + // Ignore + } + + if (string.IsNullOrEmpty(currentProcessPath)) + { + return; + } + + if (Path.GetFileName(currentProcessPath).Equals("dotnet.exe", StringComparison.Ordinal)) + { + return; + } + + SingleExeLocation = currentProcessPath; + IsRunningAsSingleExe = true; + UnpackPath = Path.GetDirectoryName(assemblyLocation); + } + + /// + /// Is this process running as a single executable? + /// + public static bool IsRunningAsSingleExe { get; } + + /// + /// Path to where the single exe is extracted + /// + public static string UnpackPath { get; } + + /// + /// Location of the single exe + /// + public static string SingleExeLocation { get; } + } +} diff --git a/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs b/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs index 0cdcbaeac..85570bf52 100644 --- a/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs +++ b/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs @@ -55,7 +55,12 @@ namespace Greenshot.Ui.Notifications.ViewModels { try { - Process.Start(StableDownloadLink); + var processStartInfo = new ProcessStartInfo(StableDownloadLink) + { + CreateNoWindow = true, + UseShellExecute = true + }; + Process.Start(processStartInfo); } catch (Exception ex) {