Skip to content

Commit

Permalink
Add menu option for Auxiliary Applications issue #17
Browse files Browse the repository at this point in the history
Add mapped drives issue #27
Add upnphost as dependency service.
some settings layout changes and better window handling (single instance of windows allowed)
  • Loading branch information
cjmurph committed Dec 7, 2017
1 parent 09b00f2 commit 9b76b03
Show file tree
Hide file tree
Showing 23 changed files with 908 additions and 100 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ _UpgradeReport_Files/
Backup*/
UpgradeLog*.XML


# Visual Studio 2015 cache/options directory
.vs/

############
## Windows
Expand Down Expand Up @@ -161,3 +162,4 @@ pip-log.txt

# Mac crap
.DS_Store
/.vs/PlexMediaServerService/v15/sqlite3/storage.ide
14 changes: 7 additions & 7 deletions PlexService/PlexMediaServerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Expand All @@ -116,12 +116,12 @@ protected override void OnStop()
try
{
if (_plexService == null)
connect();
Connect();

if (_plexService != null)
{
_plexService.Stop();
disconnect();
Disconnect();
}
}
catch { }
Expand All @@ -141,7 +141,7 @@ protected override void OnStop()
/// <summary>
/// Connect to WCF service
/// </summary>
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
Expand Down Expand Up @@ -176,7 +176,7 @@ private void connect()
/// <summary>
/// Disconnect from WCF service
/// </summary>
private void disconnect()
private void Disconnect()
{
//try and be nice...
if (_plexService != null)
Expand Down
4 changes: 2 additions & 2 deletions PlexService/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
6 changes: 6 additions & 0 deletions PlexServiceCommon/AuxiliaryApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public class AuxiliaryApplication
[JsonProperty]
public bool KeepAlive { get; set; }

/// <summary>
/// A url link to the auxilliary application interface.
/// </summary>
[JsonProperty]
public string Url { get; set; }

public AuxiliaryApplication()
{
Name = string.Empty;
Expand Down
5 changes: 2 additions & 3 deletions PlexServiceCommon/AuxiliaryApplicationMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -121,14 +120,14 @@ void auxProcess_Exited(object sender, EventArgs e)
#region Start methods

/// <summary>
/// Start a new/get a handle on existing Plex process
/// Start a new/get a handle on existing process
/// </summary>
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();
Expand Down
98 changes: 98 additions & 0 deletions PlexServiceCommon/DriveMap.cs
Original file line number Diff line number Diff line change
@@ -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;
}

/// <summary>
/// Map network drive
/// </summary>
/// <param name="force">do unmap first</param>
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);
}
}

/// <summary>
/// Unmap network drive
/// </summary>
/// <param name="force">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.</param>
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);
}
}
}
}
1 change: 1 addition & 0 deletions PlexServiceCommon/PlexServiceCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<ItemGroup>
<Compile Include="AuxiliaryApplication.cs" />
<Compile Include="AuxiliaryApplicationMonitor.cs" />
<Compile Include="DriveMap.cs" />
<Compile Include="Interface\ITrayCallback.cs" />
<Compile Include="Interface\ITrayInteraction.cs" />
<Compile Include="PlexState.cs" />
Expand Down
4 changes: 2 additions & 2 deletions PlexServiceCommon/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
7 changes: 7 additions & 0 deletions PlexServiceCommon/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class Settings
[JsonProperty]
public List<AuxiliaryApplication> AuxiliaryApplications { get; set; }

/// <summary>
/// Drive mappings to create before starting plex
/// </summary>
[JsonProperty]
public List<DriveMap> DriveMaps { get; set; }

/// <summary>
/// port the WCF service should listen on (endpoint port)
/// </summary>
Expand All @@ -40,6 +46,7 @@ public class Settings
public Settings()
{
AuxiliaryApplications = new List<AuxiliaryApplication>();
DriveMaps = new List<DriveMap>();
ServerPort = 8787;
RestartDelay = 300;
}
Expand Down
7 changes: 4 additions & 3 deletions PlexServiceInstaller/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">
<Product Id="*" Name="Plex Service" Language="1033" Version="1.1.2" Manufacturer="cjmurph" UpgradeCode="daa483bb-c7e1-4c79-a4d6-3c2c4c3d9daf">
<Product Id="*" Name="Plex Service" Language="1033" Version="1.1.3" Manufacturer="cjmurph" UpgradeCode="daa483bb-c7e1-4c79-a4d6-3c2c4c3d9daf">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" SummaryCodepage="1252" />
<Binary Id="success_bmp" SourceFile="$(sys.SOURCEFILEDIR)success.bmp" />
<Binary Id="error_bmp" SourceFile="$(sys.SOURCEFILEDIR)error.bmp" />
Expand All @@ -21,7 +21,7 @@
<Condition Message="This application requires .NET Framework 4.0 to run. Please install the .NET Framework then run this installer again.">
<![CDATA[Installed OR NETFRAMEWORK40FULL]]>
</Condition>
<Feature Id="PlexServiceFeature" Title="Plex Service" Description="Plex Service 1.1.2" Level="1" ConfigurableDirectory='INSTALLDIR'>
<Feature Id="PlexServiceFeature" Title="Plex Service" Description="Plex Service 1.1.3" Level="1" ConfigurableDirectory='INSTALLDIR'>
<ComponentRef Id="PlexServiceComponent" />
<ComponentRef Id="PlexServiceWCFComponent" />
<ComponentRef Id="PlexServiceCommonComponent" />
Expand Down Expand Up @@ -87,7 +87,8 @@
Account="[SERVICE_USERNAME]"
Password="[SERVICE_PASSWORD]"
ErrorControl="normal" >
<ServiceDependency Id="LanmanServer"/>
<ServiceDependency Id="LanmanServer"/>
<ServiceDependency Id="upnphost"/>
</ServiceInstall>
<ServiceControl Id="StartService"
Start="install"
Expand Down
7 changes: 6 additions & 1 deletion PlexServiceTray/AboutWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ private void OnOk(object parameter)

#endregion OkCommand

public static bool Shown {get; private set;}

public static bool? ShowAboutDialog()
{
return new AboutWindow().ShowDialog();
Shown = true;
var result = new AboutWindow().ShowDialog();
Shown = false;
return result;
}

private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
Expand Down
43 changes: 43 additions & 0 deletions PlexServiceTray/AuxiliaryApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ public bool Running
}
}

public string Url
{
get
{
return _auxApplication.Url;
}
set
{
if (_auxApplication.Url != value)
{
_auxApplication.Url = value;
OnPropertyChanged("Url");
}
}
}

#endregion Properties

private AuxiliaryApplication _auxApplication;
Expand Down Expand Up @@ -265,6 +281,33 @@ private void OnStop(object parameter)

#endregion StopCommand

#region GoToUrlCommand
RelayCommand _goToUrlCommand = null;
public ICommand GoToUrlCommand
{
get
{
if (_goToUrlCommand == null)
{
_goToUrlCommand = new RelayCommand((p) => 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;
Expand Down
Loading

0 comments on commit 9b76b03

Please sign in to comment.