The Free Software Media System - Server Backend & API
update shortcut handling
Luke Pulverenti02f749c654a5
diff --git a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.csindex 55a63b4e5d..b791311f9f 100644--- a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs+++ b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs@@ -74,21 +74,21 @@ namespace Emby.Server.Implementations.Library.Resolvers.Moviesif (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)){- return ResolveVideos<MusicVideo>(parent, files, directoryService, false);+ return ResolveVideos<MusicVideo>(parent, files, directoryService, false, collectionType);}if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) ||string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase)){- return ResolveVideos<Video>(parent, files, directoryService, false);+ return ResolveVideos<Video>(parent, files, directoryService, false, collectionType);}- if (string.IsNullOrEmpty(collectionType))+ if (string.IsNullOrWhiteSpace(collectionType)){// Owned items should just use the plain video typeif (parent == null){- return ResolveVideos<Video>(parent, files, directoryService, false);+ return ResolveVideos<Video>(parent, files, directoryService, false, collectionType);}if (parent is Series || parent.GetParents().OfType<Series>().Any())@@ -96,18 +96,18 @@ namespace Emby.Server.Implementations.Library.Resolvers.Moviesreturn null;}- return ResolveVideos<Movie>(parent, files, directoryService, false);+ return ResolveVideos<Movie>(parent, files, directoryService, false, collectionType);}if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase)){- return ResolveVideos<Movie>(parent, files, directoryService, true);+ return ResolveVideos<Movie>(parent, files, directoryService, true, collectionType);}return null;}- private MultiItemResolverResult ResolveVideos<T>(Folder parent, IEnumerable<FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, bool suppportMultiEditions)+ private MultiItemResolverResult ResolveVideos<T>(Folder parent, IEnumerable<FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, bool suppportMultiEditions, string collectionType)where T : Video, new(){var files = new List<FileSystemMetadata>();@@ -117,6 +117,16 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies// Loop through each child file/folder and see if we find a videoforeach (var child in fileSystemEntries){+ // This is a hack but currently no better way to resolve a sometimes ambiguous situation+ if (string.IsNullOrWhiteSpace(collectionType))+ {+ if (string.Equals(child.Name, "tvshow.nfo", StringComparison.OrdinalIgnoreCase) ||+ string.Equals(child.Name, "season.nfo", StringComparison.OrdinalIgnoreCase))+ {+ return null;+ }+ }+if (child.IsDirectory){leftOver.Add(child);@@ -408,7 +418,8 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies!string.Equals(collectionType, CollectionType.Photos) &&!string.Equals(collectionType, CollectionType.MusicVideos);- var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, supportsMultiVersion);+ var result = ResolveVideos<T>(parent, fileSystemEntries, directoryService, supportsMultiVersion, collectionType) ??+ new MultiItemResolverResult();if (result.Items.Count == 1){diff --git a/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs b/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.csindex 91ff7033ee..b4a87b9b48 100644--- a/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs+++ b/MediaBrowser.ServerApplication/Native/LnkShortcutHandler.cs@@ -1,6 +1,7 @@using System;using System.IO;using System.Runtime.InteropServices;+using System.Runtime.InteropServices.ComTypes;using System.Security;using System.Text;using MediaBrowser.Model.IO;@@ -52,7 +53,7 @@ namespace MediaBrowser.ServerApplication.Native/// <summary>/// The STG m_ READ/// </summary>- public const uint STGM_READ = 0;+ public const int STGM_READ = 0;}/// <summary>@@ -319,72 +320,6 @@ namespace MediaBrowser.ServerApplication.Native}- /// <summary>- /// Interface IPersist- /// </summary>- [ComImport, Guid("0000010c-0000-0000-c000-000000000046"),- InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]- public interface IPersist- {- /// <summary>- /// Gets the class ID.- /// </summary>- /// <param name="pClassID">The p class ID.</param>- [PreserveSig]- void GetClassID(out Guid pClassID);- }-- /// <summary>- /// Interface IPersistFile- /// </summary>- [ComImport, Guid("0000010b-0000-0000-C000-000000000046"),- InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]- public interface IPersistFile : IPersist- {- /// <summary>- /// Gets the class ID.- /// </summary>- /// <param name="pClassID">The p class ID.</param>- new void GetClassID(out Guid pClassID);- /// <summary>- /// Determines whether this instance is dirty.- /// </summary>- [PreserveSig]- int IsDirty();-- /// <summary>- /// Loads the specified PSZ file name.- /// </summary>- /// <param name="pszFileName">Name of the PSZ file.</param>- /// <param name="dwMode">The dw mode.</param>- [PreserveSig]- void Load([In, MarshalAs(UnmanagedType.LPWStr)]- string pszFileName, uint dwMode);-- /// <summary>- /// Saves the specified PSZ file name.- /// </summary>- /// <param name="pszFileName">Name of the PSZ file.</param>- /// <param name="remember">if set to <c>true</c> [remember].</param>- [PreserveSig]- void Save([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName,- [In, MarshalAs(UnmanagedType.Bool)] bool remember);-- /// <summary>- /// Saves the completed.- /// </summary>- /// <param name="pszFileName">Name of the PSZ file.</param>- [PreserveSig]- void SaveCompleted([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName);-- /// <summary>- /// Gets the cur file.- /// </summary>- /// <param name="ppszFileName">Name of the PPSZ file.</param>- [PreserveSig]- void GetCurFile([In, MarshalAs(UnmanagedType.LPWStr)] string ppszFileName);- }-// CLSID_ShellLink from ShlGuid.h/// <summary>/// Class ShellLinkdiff --git a/MediaBrowser.ServerApplication/WindowsAppHost.cs b/MediaBrowser.ServerApplication/WindowsAppHost.csindex c2cdb9ab01..398d21f329 100644--- a/MediaBrowser.ServerApplication/WindowsAppHost.cs+++ b/MediaBrowser.ServerApplication/WindowsAppHost.cs@@ -3,6 +3,7 @@ using System.Collections.Generic;using System.Diagnostics;using System.IO;using System.Reflection;+using System.Runtime.InteropServices.ComTypes;using Emby.Server.Core;using Emby.Server.Implementations;using Emby.Server.Implementations.EntryPoints;@@ -93,21 +94,30 @@ namespace MediaBrowser.ServerApplicationprotected override void ConfigureAutoRunInternal(bool autorun){- var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");-var startupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);- if (autorun)+ if (autorun && !MainStartup.IsRunningAsService){//Copy our shortut into the startup folder for this user- var targetPath = Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk");- FileSystemManager.CreateDirectory(Path.GetDirectoryName(targetPath));- File.Copy(shortcutPath, targetPath, true);+ var targetPath = Path.Combine(startupPath, "Emby Server.lnk");++ IShellLinkW link = (IShellLinkW)new ShellLink();++ var appPath = Process.GetCurrentProcess().MainModule.FileName;++ // setup shortcut information+ link.SetDescription(Name);+ link.SetPath(appPath);+ link.SetWorkingDirectory(Path.GetDirectoryName(appPath));++ // save it+ IPersistFile file = (IPersistFile)link;+ file.Save(targetPath, false);}else{//Remove our shortcut from the startup folder for this user- FileSystemManager.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));+ FileSystemManager.DeleteFile(Path.Combine(startupPath, "Emby Server.lnk"));}}