public static ApplicationInfo PathToApp(string file, bool allowNonApps, bool allowExcludedNames) { ApplicationInfo ai = new ApplicationInfo(); string fileExt = Path.GetExtension(file); if (allowNonApps || ExecutableExtensions.Contains(fileExt, StringComparer.OrdinalIgnoreCase)) { try { ai.Name = ShellHelper.GetDisplayName(file); ai.Path = file; string target = string.Empty; if (fileExt.Equals(".lnk", StringComparison.OrdinalIgnoreCase)) { Shell.Link link = new Shell.Link(file); target = link.Target; } else { target = file; } ai.Target = target; // remove items that we can't execute. if (!allowNonApps) { if (!string.IsNullOrEmpty(target) && !ExecutableExtensions.Contains(Path.GetExtension(target), StringComparer.OrdinalIgnoreCase)) { ShellLogger.Debug("Not an app: " + file + ": " + target); return(null); } // remove things that aren't apps (help, uninstallers, etc) if (!allowExcludedNames) { foreach (string word in excludedNames) { if (ai.Name.ToLower().Contains(word)) { ShellLogger.Debug("Excluded item: " + file + ": " + target); return(null); } } } } return(ai); } catch (Exception ex) { ShellLogger.Error("Error creating ApplicationInfo object in appgrabber. " + ex.Message, ex); return(null); } } return(null); }
public static void PerformAction(string verb, string fileName) { switch (verb) { case Actions.Open: ShellHelper.StartProcess(fileName); return; case Actions.Delete: string displayName = ShellHelper.GetDisplayName(fileName); CairoMessage.ShowOkCancel(string.Format(Localization.DisplayString.sDesktop_DeleteInfo, displayName), Localization.DisplayString.sDesktop_DeleteTitle, CairoMessageImage.Warning, Localization.DisplayString.sInterface_Delete, Localization.DisplayString.sInterface_Cancel, result => { if (result == true) { ShellHelper.SendToRecycleBin(fileName); } }); return; case Actions.Properties: ShellHelper.ShowFileProperties(fileName); return; case Actions.Copy: StringCollection scPath = new StringCollection(); scPath.Add(fileName); System.Windows.Forms.Clipboard.SetFileDropList(scPath); return; case Actions.AddStack: StacksManager.Instance.AddLocation(fileName); return; case Actions.RemoveStack: StacksManager.Instance.RemoveLocation(fileName); return; case Actions.OpenWithShell: FolderHelper.OpenWithShell(fileName); break; case Actions.Personalize: ShellHelper.StartProcess("Rundll32.exe", "shell32.dll,Control_RunDLL desk.cpl,,2"); break; case Actions.DisplaySettings: ShellHelper.StartProcess("Rundll32.exe", "shell32.dll,Control_RunDLL desk.cpl,,3"); break; default: ShellHelper.StartProcess(fileName, "", verb); break; } }
public static ApplicationInfo PathToApp(string filePath, bool allowNonApps, bool allowExcludedNames) { string fileDisplayName = ShellHelper.GetDisplayName(filePath); if (filePath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) { try { fileDisplayName = FileVersionInfo.GetVersionInfo(filePath).FileDescription; } catch (Exception e) { ShellLogger.Warning($"AppGrabberService: Unable to get file description for {filePath}: {e.Message}"); } } return(PathToApp(filePath, fileDisplayName, allowNonApps, allowExcludedNames)); }
public static void PerformAction(string verb, string fileName) { var desktopManager = CairoApplication.Current.Host.Services.GetService <DesktopManager>(); var settingsUiService = CairoApplication.Current.Host.Services.GetService <ISettingsUIService>(); switch (verb) { case Actions.Open: desktopManager.IsOverlayOpen = false; ShellHelper.StartProcess(fileName); return; case Actions.OpenWith: desktopManager.IsOverlayOpen = false; ShellHelper.ShowOpenWithDialog(fileName); return; case Actions.Delete: string displayName = ShellHelper.GetDisplayName(fileName); CairoMessage.ShowOkCancel(string.Format(Localization.DisplayString.sDesktop_DeleteInfo, displayName), Localization.DisplayString.sDesktop_DeleteTitle, CairoMessageImage.Warning, Localization.DisplayString.sInterface_Delete, Localization.DisplayString.sInterface_Cancel, result => { if (result == true) { ShellHelper.SendToRecycleBin(fileName); } }); return; case Actions.Properties: ShellHelper.ShowFileProperties(fileName); desktopManager.IsOverlayOpen = false; return; case Actions.Copy: StringCollection scPath = new StringCollection(); scPath.Add(fileName); System.Windows.Forms.Clipboard.SetFileDropList(scPath); return; case DirectoryActions.AddStack: StacksManager.Instance.AddLocation(fileName); return; case DirectoryActions.RemoveStack: StacksManager.Instance.StackLocations.Remove(new SystemDirectory(fileName, _dispatcher)); return; case Actions.OpenWithShell: FolderHelper.OpenWithShell(fileName); break; case Actions.Personalize when EnvironmentHelper.IsAppRunningAsShell: settingsUiService?.Show("desktop"); break; case Actions.Personalize: ShellHelper.StartProcess("Rundll32.exe", "shell32.dll,Control_RunDLL desk.cpl,,2"); break; case Actions.DisplaySettings: ShellHelper.StartProcess("Rundll32.exe", "shell32.dll,Control_RunDLL desk.cpl,,3"); break; default: ShellHelper.StartProcess(fileName, "", verb); break; } }
public static ApplicationInfo PathToApp(string filePath, bool allowNonApps, bool allowExcludedNames) { return(PathToApp(filePath, ShellHelper.GetDisplayName(filePath), allowNonApps, allowExcludedNames)); }