1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Changed run-as-admin method to work with Squirrel

This commit is contained in:
SpoinkyNL 2016-08-21 23:34:20 +02:00
parent 53c016ffdd
commit 2abe4ec93b
14 changed files with 112 additions and 144 deletions

View File

@ -1,8 +1,6 @@
using System;
using System.Security.Principal;
using System.Windows;
using System.Windows.Threading;
using Artemis.Utilities;
using NLog;
using WpfExceptionViewer;
@ -13,28 +11,25 @@ namespace Artemis
/// </summary>
public partial class App : Application
{
protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
Environment.Exit(0);
}
public App()
{
if (!IsRunAsAdministrator())
GeneralHelpers.RunAsAdministrator();
//using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/SpoinkyNL/Artemis"))
//using (var mgr = new UpdateManager("C:\\Users\\Robert\\Desktop\\Artemis builds\\squirrel_test"))
//{
// SquirrelAwareApp.HandleEvents(
// onInitialInstall: v => mgr.CreateShortcutForThisExe(),
// onAppUpdate: v => Updater.AppUpdate(mgr),
// onAppUninstall: v => Updater.AppUninstall(mgr));
//}
InitializeComponent();
}
public bool DoHandle { get; set; }
private static bool IsRunAsAdministrator()
protected override void OnExit(ExitEventArgs e)
{
var wi = WindowsIdentity.GetCurrent();
var wp = new WindowsPrincipal(wi);
return wp.IsInRole(WindowsBuiltInRole.Administrator);
base.OnExit(e);
Environment.Exit(0);
}
private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

View File

@ -39,8 +39,8 @@
<SupportUrl>https://github.com/SpoinkyNL/Artemis/wiki/Frequently-Asked-Questions-%28FAQ%29</SupportUrl>
<ProductName>Artemis</ProductName>
<PublisherName>Artemis</PublisherName>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.2.3.1</ApplicationVersion>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.3.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
@ -73,7 +73,7 @@
<ManifestKeyFile>Artemis_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
@ -120,6 +120,12 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<ItemGroup>
<Reference Include="Caliburn.Micro, Version=3.0.1.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.Core.3.0.1\lib\net45\Caliburn.Micro.dll</HintPath>
@ -628,6 +634,9 @@
</Compile>
<EmbeddedResource Include="Modules\Games\UnrealTournament\Resources\ut-plugin.zip" />
<EmbeddedResource Include="Modules\Games\Witcher3\Resources\witcher3-mod.zip" />
<None Include="app.manifest">
<SubType>Designer</SubType>
</None>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -12,6 +13,7 @@ using Artemis.ViewModels;
using Caliburn.Micro;
using Newtonsoft.Json;
using Ninject;
using LogManager = NLog.LogManager;
namespace Artemis
{

View File

@ -49,10 +49,7 @@ namespace Artemis.DeviceProviders.Logitech
"Artemis couldn't enable your Logitech keyboard, because the required files are not in place.\n\n" +
"This happens when you run The Division and shut down Artemis before shutting down The Division\n" +
"It can be fixed automatically by clicking OK, but to avoid this message in the future please\n" +
"shut down The Division before shutting down Artemis.\n\n" +
"Click OK to fix the issue and restart Artemis");
GeneralHelpers.RunAsAdministrator();
"shut down The Division before shutting down Artemis.");
}
public override void Enable()

View File

@ -1,12 +0,0 @@
<Window x:Class="Artemis.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Artemis"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Artemis
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

View File

@ -52,6 +52,6 @@ using System.Windows;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.1")]
[assembly: AssemblyFileVersion("1.3.0.1")]
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]
[assembly: AssemblyVersion("1.3.0.2")]
[assembly: AssemblyFileVersion("1.3.0.2")]
//[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]

View File

@ -1,30 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Artemis.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

View File

@ -1,7 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows;
using Microsoft.Win32;
using Newtonsoft.Json;
using static System.String;
@ -13,31 +11,6 @@ namespace Artemis.Utilities
{
public static class GeneralHelpers
{
public static void RunAsAdministrator()
{
var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase)
{
UseShellExecute = true,
Verb = "runas"
};
// The following properties run the new process as administrator
// Start the new process
try
{
System.Diagnostics.Process.Start(processInfo);
}
catch (Exception)
{
// The user did not allow the application to run as administrator
MessageBox.Show("Sorry, this application must be run as Administrator.");
}
// Shut down the current process
Environment.Exit(0);
}
/// <summary>
/// Perform a deep Copy of the object, using Json as a serialisation method.
/// </summary>
@ -61,7 +34,7 @@ namespace Artemis.Utilities
return null;
var value = prop.GetValue(o, null);
if (propertyNames.Length == 1 || value == null)
if ((propertyNames.Length == 1) || (value == null))
return value;
return GetPropertyValue(value, path.Replace(propertyNames[0] + ".", ""));
}

View File

@ -6,46 +6,45 @@ using Artemis.DAL;
using Artemis.Settings;
using Artemis.Utilities.Memory;
using Newtonsoft.Json;
using NLog;
using Squirrel;
namespace Artemis.Utilities
{
public static class Updater
{
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
public static async void UpdateApp()
{
// Only update if the user allows it
if (!SettingsProvider.Load<GeneralSettings>().AutoUpdate)
return;
_logger.Info("Checking for updates...");
// TODO: Remove prerelease before releasing
// using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/SpoinkyNL/Artemis", null, null, null,true))
// {
// // Replace / remove the autorun shortcut
// SquirrelAwareApp.HandleEvents(onAppUpdate: v => AppUpdate(mgr.Result),
// onAppUninstall: v => AppUninstall(mgr.Result));
//
// await mgr.Result.UpdateApp();
// }
//using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/SpoinkyNL/Artemis", null, null, null, true))
//{
// await mgr.Result.UpdateApp();
//}
using (var mgr = new UpdateManager("C:\\Users\\Robert\\Desktop\\Artemis builds\\squirrel_test"))
{
// Replace / remove the autorun shortcut
SquirrelAwareApp.HandleEvents(onAppUpdate: v => AppUpdate(mgr), onAppUninstall: v => AppUninstall(mgr));
await mgr.UpdateApp();
}
}
private static void AppUpdate(IUpdateManager mgr)
public static void AppUpdate(IUpdateManager mgr)
{
_logger.Info("Running AppUpdate");
var settings = new GeneralSettings();
settings.ApplyAutorun();
mgr.CreateShortcutForThisExe();
}
private static void AppUninstall(IUpdateManager mgr)
public static void AppUninstall(IUpdateManager mgr)
{
_logger.Info("Running AppUninstall");
// Use GeneralSettings to get rid of the autorun shortcut
var fakeSettings = new GeneralSettings {Autorun = false};
fakeSettings.ApplyAutorun();

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 KiB