From 9b76b0306b9b46716b07979c1104e924a1104278 Mon Sep 17 00:00:00 2001 From: cjmurph Date: Thu, 7 Dec 2017 12:14:28 +0800 Subject: [PATCH] Add menu option for Auxiliary Applications issue #17 Add mapped drives issue #27 Add upnphost as dependency service. some settings layout changes and better window handling (single instance of windows allowed) --- .gitignore | 4 +- PlexService/PlexMediaServerService.cs | 14 +- PlexService/Properties/AssemblyInfo.cs | 4 +- PlexServiceCommon/AuxiliaryApplication.cs | 6 + .../AuxiliaryApplicationMonitor.cs | 5 +- PlexServiceCommon/DriveMap.cs | 98 ++++++ PlexServiceCommon/PlexServiceCommon.csproj | 1 + PlexServiceCommon/Properties/AssemblyInfo.cs | 4 +- PlexServiceCommon/Settings.cs | 7 + PlexServiceInstaller/Product.wxs | 7 +- PlexServiceTray/AboutWindow.xaml.cs | 7 +- .../AuxiliaryApplicationViewModel.cs | 43 +++ PlexServiceTray/DriveMapViewModel.cs | 60 ++++ .../NotifyIconApplicationContext.cs | 52 ++- PlexServiceTray/PlexServiceTray.csproj | 1 + PlexServiceTray/Properties/AssemblyInfo.cs | 4 +- PlexServiceTray/SettingsWindow.xaml | 153 ++++++--- PlexServiceTray/SettingsWindow.xaml.cs | 30 ++ PlexServiceTray/SettingsWindowViewModel.cs | 160 ++++++++- .../Light/Metro.MSControls.Core.Implicit.xaml | 4 + .../Themes/Metro/Light/Styles.WPF.xaml | 314 +++++++++++++++++- PlexServiceWCF/PmsMonitor.cs | 26 +- PlexServiceWCF/Properties/AssemblyInfo.cs | 4 +- 23 files changed, 908 insertions(+), 100 deletions(-) create mode 100644 PlexServiceCommon/DriveMap.cs create mode 100644 PlexServiceTray/DriveMapViewModel.cs diff --git a/.gitignore b/.gitignore index 5ebd21a..bb79496 100644 --- a/.gitignore +++ b/.gitignore @@ -114,7 +114,8 @@ _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML - +# Visual Studio 2015 cache/options directory +.vs/ ############ ## Windows @@ -161,3 +162,4 @@ pip-log.txt # Mac crap .DS_Store +/.vs/PlexMediaServerService/v15/sqlite3/storage.ide diff --git a/PlexService/PlexMediaServerService.cs b/PlexService/PlexMediaServerService.cs index b3dfcd2..78f0bd9 100644 --- a/PlexService/PlexMediaServerService.cs +++ b/PlexService/PlexMediaServerService.cs @@ -88,18 +88,18 @@ protected override void OnStart(string[] args) base.OnStart(args); } - private void startPlex() + private void StartPlex() { //Try and connect to the WCF service and call its start method try { if (_plexService == null) - connect(); + Connect(); if (_plexService != null) { _plexService.Start(); - disconnect(); + Disconnect(); } } catch { } @@ -116,12 +116,12 @@ protected override void OnStop() try { if (_plexService == null) - connect(); + Connect(); if (_plexService != null) { _plexService.Stop(); - disconnect(); + Disconnect(); } } catch { } @@ -141,7 +141,7 @@ protected override void OnStop() /// /// Connect to WCF service /// - private void connect() + private void Connect() { //Create a NetTcp binding to the service and set some appropriate timeouts. //Use reliable connection so we know when we have been disconnected @@ -176,7 +176,7 @@ private void connect() /// /// Disconnect from WCF service /// - private void disconnect() + private void Disconnect() { //try and be nice... if (_plexService != null) diff --git a/PlexService/Properties/AssemblyInfo.cs b/PlexService/Properties/AssemblyInfo.cs index 05e5a47..6fa232a 100644 --- a/PlexService/Properties/AssemblyInfo.cs +++ b/PlexService/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.2.0")] -[assembly: AssemblyFileVersion("1.1.2.0")] +[assembly: AssemblyVersion("1.1.3.0")] +[assembly: AssemblyFileVersion("1.1.3.0")] diff --git a/PlexServiceCommon/AuxiliaryApplication.cs b/PlexServiceCommon/AuxiliaryApplication.cs index 782a016..ee591ca 100644 --- a/PlexServiceCommon/AuxiliaryApplication.cs +++ b/PlexServiceCommon/AuxiliaryApplication.cs @@ -41,6 +41,12 @@ public class AuxiliaryApplication [JsonProperty] public bool KeepAlive { get; set; } + /// + /// A url link to the auxilliary application interface. + /// + [JsonProperty] + public string Url { get; set; } + public AuxiliaryApplication() { Name = string.Empty; diff --git a/PlexServiceCommon/AuxiliaryApplicationMonitor.cs b/PlexServiceCommon/AuxiliaryApplicationMonitor.cs index 1fa7dc5..a2fa598 100644 --- a/PlexServiceCommon/AuxiliaryApplicationMonitor.cs +++ b/PlexServiceCommon/AuxiliaryApplicationMonitor.cs @@ -51,7 +51,6 @@ public void Start() { _stopping = false; - //every time a start attempt is made, check for the existance of the auto start registry key and remove it. if(!string.IsNullOrEmpty(_aux.FilePath) && File.Exists(_aux.FilePath)) { start(); @@ -121,14 +120,14 @@ void auxProcess_Exited(object sender, EventArgs e) #region Start methods /// - /// Start a new/get a handle on existing Plex process + /// Start a new/get a handle on existing process /// private void start() { OnStatusChange(this, new StatusChangeEventArgs("Attempting to start " + _aux.Name)); if (_auxProcess == null) { - //we dont care if this is already running, depending on teh application, this could cause lots of issues but hey... + //we dont care if this is already running, depending on the application, this could cause lots of issues but hey... //Auxiliary process _auxProcess = new Process(); diff --git a/PlexServiceCommon/DriveMap.cs b/PlexServiceCommon/DriveMap.cs new file mode 100644 index 0000000..041769c --- /dev/null +++ b/PlexServiceCommon/DriveMap.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace PlexServiceCommon +{ + public class DriveMap + { + [DllImport("mpr.dll")] private static extern int WNetAddConnection2A(ref NetworkResource netRes, string password, string username, int flags); + [DllImport("mpr.dll")] private static extern int WNetCancelConnection2A(string name, int flags, int force); + + [StructLayout(LayoutKind.Sequential)] + private struct NetworkResource + { + public int Scope; + public int Type; + public int DisplayType; + public int Usage; + public string LocalName; + public string RemoteName; + public string Comment; + public string Provider; + } + + public string ShareName { get; set; } + + public string DriveLetter { get; set; } + + public DriveMap(string shareName, string driveLetter) + { + ShareName = shareName; + DriveLetter = driveLetter; + } + + /// + /// Map network drive + /// + /// do unmap first + public void MapDrive(bool force) + { + if (DriveLetter.Length > 0) + { + var drive = DriveLetter.Substring(0,1) + ":"; + + //create struct data + NetworkResource netRes = new NetworkResource(); + netRes.Scope = 2; + netRes.Type = 0x1; + netRes.DisplayType = 3; + netRes.Usage = 1; + netRes.RemoteName = ShareName; + netRes.LocalName = drive; + //if force, unmap ready for new connection + if (force) + { + try + { + UnMapDrive(true); + } + catch { } + } + //call and return + int i = WNetAddConnection2A(ref netRes, null, null, 0); + + if (i > 0) + throw new System.ComponentModel.Win32Exception(i); + } + else + { + throw new Exception("Invalid drive letter: " + DriveLetter); + } + } + + /// + /// Unmap network drive + /// + /// Specifies whether the disconnection should occur if there are open files or jobs on the connection. If this parameter is FALSE, the function fails if there are open files or jobs. + public void UnMapDrive(bool force) + { + if (DriveLetter.Length > 0) + { + var drive = DriveLetter.Substring(0, 1) + ":"; + + //call unmap and return + int i = WNetCancelConnection2A(drive, 0, Convert.ToInt32(force)); + + if (i > 0) + throw new System.ComponentModel.Win32Exception(i); + } + else + { + throw new Exception("Invalid drive letter: " + DriveLetter); + } + } + } +} diff --git a/PlexServiceCommon/PlexServiceCommon.csproj b/PlexServiceCommon/PlexServiceCommon.csproj index 2369527..9280c30 100644 --- a/PlexServiceCommon/PlexServiceCommon.csproj +++ b/PlexServiceCommon/PlexServiceCommon.csproj @@ -49,6 +49,7 @@ + diff --git a/PlexServiceCommon/Properties/AssemblyInfo.cs b/PlexServiceCommon/Properties/AssemblyInfo.cs index 5c6dbb7..ff84f3f 100644 --- a/PlexServiceCommon/Properties/AssemblyInfo.cs +++ b/PlexServiceCommon/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.2.0")] -[assembly: AssemblyFileVersion("1.1.2.0")] +[assembly: AssemblyVersion("1.1.3.0")] +[assembly: AssemblyFileVersion("1.1.3.0")] diff --git a/PlexServiceCommon/Settings.cs b/PlexServiceCommon/Settings.cs index 20fb27c..6c67070 100644 --- a/PlexServiceCommon/Settings.cs +++ b/PlexServiceCommon/Settings.cs @@ -19,6 +19,12 @@ public class Settings [JsonProperty] public List AuxiliaryApplications { get; set; } + /// + /// Drive mappings to create before starting plex + /// + [JsonProperty] + public List DriveMaps { get; set; } + /// /// port the WCF service should listen on (endpoint port) /// @@ -40,6 +46,7 @@ public class Settings public Settings() { AuxiliaryApplications = new List(); + DriveMaps = new List(); ServerPort = 8787; RestartDelay = 300; } diff --git a/PlexServiceInstaller/Product.wxs b/PlexServiceInstaller/Product.wxs index 1e662a2..d8a7a87 100644 --- a/PlexServiceInstaller/Product.wxs +++ b/PlexServiceInstaller/Product.wxs @@ -1,6 +1,6 @@ - + @@ -21,7 +21,7 @@ - + @@ -87,7 +87,8 @@ Account="[SERVICE_USERNAME]" Password="[SERVICE_PASSWORD]" ErrorControl="normal" > - + + OnGoToUrl(p), (p) => CanGoToUrl(p)); + } + + return _goToUrlCommand; + } + } + + private bool CanGoToUrl(object parameter) + { + return !string.IsNullOrEmpty(Url); + } + + private void OnGoToUrl(object parameter) + { + System.Diagnostics.Process.Start(Url); + } + + #endregion GoToUrlCommand + #region CheckRunningRequest public event EventHandler CheckRunningRequest; diff --git a/PlexServiceTray/DriveMapViewModel.cs b/PlexServiceTray/DriveMapViewModel.cs new file mode 100644 index 0000000..6c398ee --- /dev/null +++ b/PlexServiceTray/DriveMapViewModel.cs @@ -0,0 +1,60 @@ +using PlexServiceCommon; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; + +namespace PlexServiceTray +{ + public class DriveMapViewModel : ObservableObject + { + [Required(ErrorMessage = "Please enter a UNC path to map")] + [RegularExpression(@"^\\\\[a-zA-Z0-9\.\-_]{1,}(\\[a-zA-Z0-9\-_]{1,}[\$]{0,1}){1,}$", ErrorMessage = "Please enter a UNC path to map")] + public string ShareName + { + get + { + return _driveMap.ShareName; + } + set + { + if (_driveMap.ShareName != value) + { + _driveMap.ShareName = value; + OnPropertyChanged("ShareName"); + } + } + } + + [Required(ErrorMessage = "Please enter a single character A-Z")] + [RegularExpression("[a-zA-Z]", ErrorMessage = "Please enter a single character A-Z")] + public string DriveLetter + { + get + { + return _driveMap.DriveLetter; + } + set + { + if (_driveMap.DriveLetter != value) + { + _driveMap.DriveLetter = value; + OnPropertyChanged("DriveLetter"); + } + } + } + + private DriveMap _driveMap; + public DriveMapViewModel(DriveMap driveMap) + { + _driveMap = driveMap; + ValidationContext = this; + } + + public DriveMap GetDriveMap() + { + return _driveMap; + } + } +} diff --git a/PlexServiceTray/NotifyIconApplicationContext.cs b/PlexServiceTray/NotifyIconApplicationContext.cs index ac7419a..9e88563 100644 --- a/PlexServiceTray/NotifyIconApplicationContext.cs +++ b/PlexServiceTray/NotifyIconApplicationContext.cs @@ -30,6 +30,10 @@ class NotifyIconApplicationContext : ApplicationContext private PlexServiceCommon.Interface.ITrayInteraction _plexService; + + private SettingsWindow _settingsWindow; + private ConnectionSettingsWindow _connectionSettingsWindow; + /// /// Clean up any resources being used. /// @@ -179,6 +183,7 @@ void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventAr if (_plexService != null)// && ((ICommunicationObject)_plexService).State == CommunicationState.Opened) { + var settings = Settings.Deserialize(_plexService.GetSettings()); try { var state = _plexService.GetStatus(); @@ -203,7 +208,30 @@ void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventAr } _notifyIcon.ContextMenuStrip.Items.Add("View Logs", null, ViewLogs_Click); _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); - _notifyIcon.ContextMenuStrip.Items.Add("Settings", null, SettingsCommand); + var auxAppsToLink = settings.AuxiliaryApplications.Where(aux => !string.IsNullOrEmpty(aux.Url)).ToList(); + if(auxAppsToLink.Count > 0) + { + var auxAppsItem = new ToolStripMenuItem(); + auxAppsItem.Text = "Auxiliary Applications"; + auxAppsToLink.ForEach(aux => + { + auxAppsItem.DropDownItems.Add(aux.Name, null, (s, a) => + { + try + { + System.Diagnostics.Process.Start(aux.Url); + } + catch(Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Woops!", MessageBoxButtons.OK, MessageBoxIcon.Error); } + }); + }); + _notifyIcon.ContextMenuStrip.Items.Add(auxAppsItem); + _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); + } + var settingsItem = _notifyIcon.ContextMenuStrip.Items.Add("Settings", null, SettingsCommand); + if(_settingsWindow != null) + { + settingsItem.Enabled = false; + } } catch { @@ -218,10 +246,16 @@ void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventAr } _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); - _notifyIcon.ContextMenuStrip.Items.Add("Connection Settings", null, ConnectionSettingsCommand); - _notifyIcon.ContextMenuStrip.Items.Add("About", null, AboutCommand); + var connectionSettingsItem = _notifyIcon.ContextMenuStrip.Items.Add("Connection Settings", null, ConnectionSettingsCommand); + if (_connectionSettingsWindow != null) + connectionSettingsItem.Enabled = false; + var aboutItem = _notifyIcon.ContextMenuStrip.Items.Add("About", null, AboutCommand); + if (AboutWindow.Shown) + aboutItem.Enabled = false; _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); - _notifyIcon.ContextMenuStrip.Items.Add("Exit", null, ExitCommand); + var exitItem = _notifyIcon.ContextMenuStrip.Items.Add("Exit", null, ExitCommand); + if (AboutWindow.Shown || _connectionSettingsWindow != null || _settingsWindow != null) + exitItem.Enabled = false; } /// @@ -274,8 +308,8 @@ private void SettingsCommand(object sender, EventArgs e) requester.Running = _plexService.IsAuxAppRunning(requester.Name); } }; - SettingsWindow settingsWindow = new SettingsWindow(settingsViewModel); - if (settingsWindow.ShowDialog() == true) + _settingsWindow = new SettingsWindow(settingsViewModel); + if (_settingsWindow.ShowDialog() == true) { PlexState status = PlexState.Pending; try @@ -295,6 +329,7 @@ private void SettingsCommand(object sender, EventArgs e) System.Windows.MessageBox.Show("Server port changed! You will need to restart the service from the services snap in for the change to be applied", "Settings changed!", MessageBoxButton.OK, MessageBoxImage.Information); } } + _settingsWindow = null; } } } @@ -306,8 +341,8 @@ private void SettingsCommand(object sender, EventArgs e) /// private void ConnectionSettingsCommand(object sender, EventArgs e) { - ConnectionSettingsWindow connectionSettingsWindow = new ConnectionSettingsWindow(); - if (connectionSettingsWindow.ShowDialog() == true) + _connectionSettingsWindow = new ConnectionSettingsWindow(); + if (_connectionSettingsWindow.ShowDialog() == true) { //if the user saved the settings, then reconnect using the new values try @@ -317,6 +352,7 @@ private void ConnectionSettingsCommand(object sender, EventArgs e) } catch { } } + _connectionSettingsWindow = null; } /// diff --git a/PlexServiceTray/PlexServiceTray.csproj b/PlexServiceTray/PlexServiceTray.csproj index ef9d372..95547a6 100644 --- a/PlexServiceTray/PlexServiceTray.csproj +++ b/PlexServiceTray/PlexServiceTray.csproj @@ -103,6 +103,7 @@ + diff --git a/PlexServiceTray/Properties/AssemblyInfo.cs b/PlexServiceTray/Properties/AssemblyInfo.cs index e70785c..ff263f2 100644 --- a/PlexServiceTray/Properties/AssemblyInfo.cs +++ b/PlexServiceTray/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.2.0")] -[assembly: AssemblyFileVersion("1.1.2.0")] +[assembly: AssemblyVersion("1.1.3.0")] +[assembly: AssemblyFileVersion("1.1.3.0")] diff --git a/PlexServiceTray/SettingsWindow.xaml b/PlexServiceTray/SettingsWindow.xaml index 1519a6b..b5eaf9c 100644 --- a/PlexServiceTray/SettingsWindow.xaml +++ b/PlexServiceTray/SettingsWindow.xaml @@ -5,7 +5,11 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:PlexServiceTray" xmlns:fa="http://schemas.fontawesome.io/icons/" - MinHeight="520" Height="520" MinWidth="450" Width="450" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None" local:DialogCloser.DialogResult="{Binding DialogResult}" Icon="PlexService.ico"> + MinHeight="620" Height="620" MinWidth="500" Width="500" + BorderBrush="{DynamicResource Brush04}" BorderThickness="2" + WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip" AllowsTransparency="True" + TextOptions.TextFormattingMode="Display" UseLayoutRounding="True" WindowStyle="None" + local:DialogCloser.DialogResult="{Binding DialogResult}" Icon="PlexService.ico"> @@ -21,7 +25,8 @@ - + @@ -38,70 +43,116 @@ - + - + - - + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + + + + public partial class SettingsWindow : Window { + private bool _maximiseRequired = false; + public SettingsWindow(SettingsWindowViewModel settingsViewModel) { InitializeComponent(); DataContext = settingsViewModel; } + + private void TitleMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + if (e.ClickCount >= 2) + { + _maximiseRequired = true; + } + else + { + DragMove(); + } + } + + private void TitleMouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + if (_maximiseRequired) + { + _maximiseRequired = false; + if (WindowState == WindowState.Maximized) + { + WindowState = WindowState.Normal; + } + else + { + WindowState = WindowState.Maximized; + } + } + } } } diff --git a/PlexServiceTray/SettingsWindowViewModel.cs b/PlexServiceTray/SettingsWindowViewModel.cs index e7282a7..baa49a2 100644 --- a/PlexServiceTray/SettingsWindowViewModel.cs +++ b/PlexServiceTray/SettingsWindowViewModel.cs @@ -65,6 +65,27 @@ public bool AutoRestart } } + private int _selectedTab; + + public int SelectedTab + { + get + { + return _selectedTab; + } + set + { + if (_selectedTab != value) + { + _selectedTab = value; + OnPropertyChanged("SelectedTab"); + OnPropertyChanged("RemoveToolTip"); + OnPropertyChanged("AddToolTip"); + } + } + } + + private ObservableCollection _auxilaryApplications; /// /// Collection of Auxiliary applications to run alongside plex @@ -104,18 +125,84 @@ public AuxiliaryApplicationViewModel SelectedAuxApplication } } + private ObservableCollection _driveMaps; + + public ObservableCollection DriveMaps + { + get + { + return _driveMaps; + } + set + { + if (_driveMaps != value) + { + _driveMaps = value; + OnPropertyChanged("DriveMaps"); + } + } + } + + private DriveMapViewModel _selectedDriveMap; + + public DriveMapViewModel SelectedDriveMap + { + get + { + return _selectedDriveMap; + } + set + { + if (_selectedDriveMap != value) + { + _selectedDriveMap = value; + OnPropertyChanged("SelectedDriveMap"); + OnPropertyChanged("RemoveToolTip"); + } + } + } + public string RemoveToolTip { get { - if (SelectedAuxApplication != null) + switch (SelectedTab) { - return "Remove " + SelectedAuxApplication.Name; + case 0: + if (SelectedAuxApplication != null) + { + return "Remove " + SelectedAuxApplication.Name; + } + break; + case 1: + if (SelectedDriveMap != null) + { + return "Remove Drive Map " + SelectedDriveMap.DriveLetter + " -> " + SelectedDriveMap.ShareName; + } + break; + default: + break; ; } return "Nothing selected!"; } } + public string AddToolTip + { + get + { + switch (SelectedTab) + { + case 0: + return "Add Auxiliary Application"; + case 1: + return "Add Drive Map"; + default: + return null; + } + } + } + private bool? _dialogResult; public bool? DialogResult @@ -143,6 +230,8 @@ public SettingsWindowViewModel(Settings settings) { WorkingSettings = settings; AuxiliaryApplications = new ObservableCollection(); + DriveMaps = new ObservableCollection(); + WorkingSettings.AuxiliaryApplications.ForEach(x => { var auxApp = new AuxiliaryApplicationViewModel(x, this); @@ -151,6 +240,9 @@ public SettingsWindowViewModel(Settings settings) auxApp.CheckRunningRequest += OnAuxAppCheckRunRequest; AuxiliaryApplications.Add(auxApp); }); + + WorkingSettings.DriveMaps.ForEach(x => DriveMaps.Add(new DriveMapViewModel(x))); + if (AuxiliaryApplications.Count > 0) { AuxiliaryApplications[0].IsExpanded = true; @@ -182,14 +274,27 @@ private bool CanAdd(object parameter) private void OnAdd(object parameter) { - AuxiliaryApplication newAuxApp = new AuxiliaryApplication(); - newAuxApp.Name = "New Auxiliary Application"; - AuxiliaryApplicationViewModel newAuxAppViewModel = new AuxiliaryApplicationViewModel(newAuxApp, this); - newAuxAppViewModel.StartRequest += OnAuxAppStartRequest; - newAuxAppViewModel.StopRequest += OnAuxAppStopRequest; - newAuxAppViewModel.CheckRunningRequest += OnAuxAppCheckRunRequest; - newAuxAppViewModel.IsExpanded = true; - AuxiliaryApplications.Add(newAuxAppViewModel); + switch (SelectedTab) + { + case 0: + AuxiliaryApplication newAuxApp = new AuxiliaryApplication(); + newAuxApp.Name = "New Auxiliary Application"; + AuxiliaryApplicationViewModel newAuxAppViewModel = new AuxiliaryApplicationViewModel(newAuxApp, this); + newAuxAppViewModel.StartRequest += OnAuxAppStartRequest; + newAuxAppViewModel.StopRequest += OnAuxAppStopRequest; + newAuxAppViewModel.CheckRunningRequest += OnAuxAppCheckRunRequest; + newAuxAppViewModel.IsExpanded = true; + AuxiliaryApplications.Add(newAuxAppViewModel); + break; + case 1: + DriveMap newDriveMap = new DriveMap(@"\\computer\share", "Z"); + DriveMapViewModel newDriveMapViewModel = new DriveMapViewModel(newDriveMap); + DriveMaps.Add(newDriveMapViewModel); + break; + default: + break; + } + } #endregion AddCommand @@ -214,14 +319,34 @@ public ICommand RemoveCommand private bool CanRemove(object parameter) { - return SelectedAuxApplication != null; + switch (SelectedTab) + { + case 0: + return SelectedAuxApplication != null; + case 1: + return SelectedDriveMap != null; + default: + return false; + } + } private void OnRemove(object parameter) { - SelectedAuxApplication.StartRequest -= OnAuxAppStartRequest; - SelectedAuxApplication.StopRequest -= OnAuxAppStopRequest; - AuxiliaryApplications.Remove(SelectedAuxApplication); + switch (SelectedTab) + { + case 0: + SelectedAuxApplication.StartRequest -= OnAuxAppStartRequest; + SelectedAuxApplication.StopRequest -= OnAuxAppStopRequest; + AuxiliaryApplications.Remove(SelectedAuxApplication); + break; + case 1: + DriveMaps.Remove(SelectedDriveMap); + break; + default: + break; + } + } #endregion RemoveCommand @@ -246,7 +371,7 @@ public ICommand SaveCommand private bool CanSave(object parameter) { - return ServerPort > 0 && string.IsNullOrEmpty(Error) && !AuxiliaryApplications.Any(a => !string.IsNullOrEmpty(a.Error) || string.IsNullOrEmpty(a.Name)); + return ServerPort > 0 && string.IsNullOrEmpty(Error) && !AuxiliaryApplications.Any(a => !string.IsNullOrEmpty(a.Error) || string.IsNullOrEmpty(a.Name)) && !DriveMaps.Any(dm => !string.IsNullOrEmpty(dm.Error) || string.IsNullOrEmpty(dm.ShareName) || string.IsNullOrEmpty(dm.DriveLetter)); } private void OnSave(object parameter) @@ -256,6 +381,11 @@ private void OnSave(object parameter) { WorkingSettings.AuxiliaryApplications.Add(aux.GetAuxiliaryApplication()); } + WorkingSettings.DriveMaps.Clear(); + foreach(DriveMapViewModel dMap in DriveMaps) + { + WorkingSettings.DriveMaps.Add(dMap.GetDriveMap()); + } DialogResult = true; } diff --git a/PlexServiceTray/Themes/Metro/Light/Metro.MSControls.Core.Implicit.xaml b/PlexServiceTray/Themes/Metro/Light/Metro.MSControls.Core.Implicit.xaml index f7ae177..f0a9318 100644 --- a/PlexServiceTray/Themes/Metro/Light/Metro.MSControls.Core.Implicit.xaml +++ b/PlexServiceTray/Themes/Metro/Light/Metro.MSControls.Core.Implicit.xaml @@ -936,4 +936,8 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PlexServiceWCF/PmsMonitor.cs b/PlexServiceWCF/PmsMonitor.cs index 635d899..2259f12 100644 --- a/PlexServiceWCF/PmsMonitor.cs +++ b/PlexServiceWCF/PmsMonitor.cs @@ -168,10 +168,32 @@ internal void Start() } else { + //load the settings + Settings settings = SettingsHandler.Load(); + OnPlexStatusChange(this, new StatusChangeEventArgs("Plex executable found at " + _executableFileName)); + + //map network drives + if (settings.DriveMaps.Count > 0) + { + OnPlexStatusChange(this, new StatusChangeEventArgs("Mapping Network Drives")); + foreach(DriveMap map in settings.DriveMaps) + { + try + { + map.MapDrive(true); + OnPlexStatusChange(this, new StatusChangeEventArgs(string.Format("Map share {0} to letter '{1}' successful", map.ShareName, map.DriveLetter))); + } + catch(Exception ex) + { + OnPlexStatusChange(this, new StatusChangeEventArgs(string.Format("Unable to map share {0} to letter '{1}': {2}", map.ShareName, map.DriveLetter, ex.Message), EventLogEntryType.Error)); + } + } + } + + StartPlex(); - //load the settings and start a thread that will attempt to bring up all the auxiliary processes - Settings settings = SettingsHandler.Load(); + //stop any running aux apps _auxAppMonitors.ForEach(a => a.Stop()); _auxAppMonitors.Clear(); diff --git a/PlexServiceWCF/Properties/AssemblyInfo.cs b/PlexServiceWCF/Properties/AssemblyInfo.cs index bc2861a..1bbc0c1 100644 --- a/PlexServiceWCF/Properties/AssemblyInfo.cs +++ b/PlexServiceWCF/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.2.0")] -[assembly: AssemblyFileVersion("1.1.2.0")] +[assembly: AssemblyVersion("1.1.3.0")] +[assembly: AssemblyFileVersion("1.1.3.0")]