Skip to content

Commit 6ba6edd

Browse files
committed
Added more error messages
1 parent e792950 commit 6ba6edd

File tree

7 files changed

+55
-18
lines changed

7 files changed

+55
-18
lines changed

LiveWriterPluginManager/App.xaml.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,6 @@ private void OnStartup(object sender, StartupEventArgs e)
2222
{
2323
AppHelper.CreatePluginDirectory();
2424
}
25-
else
26-
{
27-
// TODO: Display some kind of message prompt
28-
}
29-
30-
AppDomain myDomain = Thread.GetDomain();
31-
32-
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
33-
WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
34-
if (!myPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
35-
{
36-
// TODO: Show a message that it's not in administrator
37-
MessageBox.Show("Not running as adming");
38-
var i = 0;
39-
}
4025
}
4126
}
4227
}

LiveWriterPluginManager/Controls/RemovePluginControl.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}"
4444
Height="30"
4545
Width="30"
46-
Command="{Binding DeletePluginCommand}">
46+
Command="{Binding DeletePluginCommand}"
47+
IsEnabled="{Binding CanRemove}">
4748
<Viewbox Stretch="Uniform"
4849
StretchDirection="DownOnly"
4950
Width="20"

LiveWriterPluginManager/Helpers/AppHelper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Linq;
5+
using System.Security.Principal;
6+
using System.Threading;
57

68
namespace LiveWriterPluginManager.Helpers
79
{
@@ -41,5 +43,14 @@ public static bool IsLiveWriterRunning()
4143
var process = Process.GetProcessesByName("OpenLiveWriter");
4244
return process.Any();
4345
}
46+
47+
public static bool IsRunningAsAdmin()
48+
{
49+
var myDomain = Thread.GetDomain();
50+
51+
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
52+
var myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
53+
return myPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
54+
}
4455
}
4556
}

LiveWriterPluginManager/MainWindow.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
xmlns:dragablz="http://dragablz.net/winfx/xaml/dragablz"
88
xmlns:local="clr-namespace:LiveWriterPluginManager.Controls"
99
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
10+
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
11+
xmlns:command="http://www.galasoft.ch/mvvmlight"
1012
mc:Ignorable="d"
1113
Title="Live Writer Plugin Manager"
1214
Height="350"
@@ -19,6 +21,11 @@
1921
Background="{DynamicResource MaterialDesignPaper}"
2022
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
2123
DataContext="{Binding Main, Source={StaticResource Locator}}">
24+
<i:Interaction.Triggers>
25+
<i:EventTrigger EventName="Loaded">
26+
<command:EventToCommand Command="{Binding LoadedCommand}" />
27+
</i:EventTrigger>
28+
</i:Interaction.Triggers>
2229
<materialDesign:DialogHost>
2330
<Grid>
2431
<dragablz:TabablzControl TextElement.Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window}, Path=(TextElement.Foreground)}"

LiveWriterPluginManager/ViewModel/AddPluginViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public AddPluginViewModel(IZipService zipService, IFileService fileService, ILiv
3131
_zipService = zipService;
3232
_fileService = fileService;
3333
_liveWriterService = liveWriterService;
34-
CanAdd = AppHelper.LiveWriterInstalled;
34+
CanAdd = AppHelper.LiveWriterInstalled && AppHelper.IsRunningAsAdmin();
3535
}
3636

3737
public bool CanAdd { get; set; }
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1-
using GalaSoft.MvvmLight;
1+
using System.Net.Mime;
2+
using System.Windows;
3+
using GalaSoft.MvvmLight;
4+
using GalaSoft.MvvmLight.Command;
5+
using LiveWriterPluginManager.Helpers;
6+
using LiveWriterPluginManager.Services;
27

38
namespace LiveWriterPluginManager.ViewModel
49
{
510
public class MainViewModel : ViewModelBase
611
{
12+
private readonly IMessageService _messageService;
13+
public MainViewModel(IMessageService messageService)
14+
{
15+
_messageService = messageService;
16+
}
17+
18+
public RelayCommand LoadedCommand
19+
{
20+
get
21+
{
22+
return new RelayCommand(() =>
23+
{
24+
if (!AppHelper.LiveWriterInstalled)
25+
{
26+
_messageService.ShowErrorAsync("It doesn't look like you have Live Writer installed, please go to http://openlivewriter.org to download and install it.");
27+
Application.Current.Shutdown();
28+
return;
29+
}
30+
31+
if (!AppHelper.IsRunningAsAdmin())
32+
{
33+
_messageService.ShowErrorAsync("In order for this app to add/remove plugins, it needs to run as Administrator, please restart the app with higher privileges");
34+
}
35+
});
36+
}
37+
}
738
}
839
}

LiveWriterPluginManager/ViewModel/PluginViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public PluginViewModel(Plugin plugin, ILiveWriterService liveWriterService, IMes
2020

2121
public Plugin Plugin { get; set; }
2222

23+
public bool CanRemove => AppHelper.IsRunningAsAdmin();
24+
2325
public RelayCommand DeletePluginCommand
2426
{
2527
get

0 commit comments

Comments
 (0)