private static Win32Program ExeProgram(string path) { try { var program = CreateWin32Program(path); var info = FileVersionInfoWrapper.GetVersionInfo(path); if (!string.IsNullOrEmpty(info?.FileDescription)) { program.Description = info.FileDescription; } return(program); } catch (Exception e) when(e is SecurityException || e is UnauthorizedAccessException) { ProgramLogger.LogException( $"|Win32|ExeProgram|{path}" + $"|Permission denied when trying to load the program from {path}", e); return(new Win32Program() { Valid = false, Enabled = false }); } }
private static Win32Program ExeProgram(string path) { try { var program = CreateWin32Program(path); var info = FileVersionInfoWrapper.GetVersionInfo(path); if (!string.IsNullOrEmpty(info?.FileDescription)) { program.Description = info.FileDescription; } return(program); } catch (Exception e) when(e is SecurityException || e is UnauthorizedAccessException) { ProgramLogger.Warn($"|Permission denied when trying to load the program from {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path); return(InvalidProgram); } catch (FileNotFoundException e) { ProgramLogger.Warn($"|Unable to locate exe file at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path); return(InvalidProgram); } catch (Exception e) { ProgramLogger.Exception($"|An unexpected error occurred in the calling method ExeProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path); return(InvalidProgram); } }
private static Win32Program LnkProgram(string path) { try { var program = CreateWin32Program(path); string target = ShellLinkHelper.RetrieveTargetPath(path); if (!string.IsNullOrEmpty(target)) { if (!(File.Exists(target) || Directory.Exists(target))) { // If the link points nowhere, consider it invalid. return(InvalidProgram); } program.LnkResolvedPath = program.FullPath; program.LnkResolvedExecutableName = Path.GetFileName(target); // Using CurrentCulture since this is user facing program.FullPath = Path.GetFullPath(target).ToLowerInvariant(); program.Arguments = ShellLinkHelper.Arguments; // A .lnk could be a (Chrome) PWA, set correct AppType program.AppType = program.IsWebApplication() ? ApplicationType.WebApplication : GetAppTypeFromPath(target); var description = ShellLinkHelper.Description; if (!string.IsNullOrEmpty(description)) { program.Description = description; } else { var info = FileVersionInfoWrapper.GetVersionInfo(target); if (!string.IsNullOrEmpty(info?.FileDescription)) { program.Description = info.FileDescription; } } } return(program); } catch (System.IO.FileLoadException e) { ProgramLogger.Warn($"Couldn't load the link file at {path}. This might be caused by a new link being created and locked by the OS.", e, MethodBase.GetCurrentMethod().DeclaringType, path); return(InvalidProgram); } // Only do a catch all in production. This is so make developer aware of any unhandled exception and add the exception handling in. // Error caused likely due to trying to get the description of the program catch (Exception e) { ProgramLogger.Exception($"|An unexpected error occurred in the calling method LnkProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path); return(InvalidProgram); } }
private static Win32Program LnkProgram(string path) { var program = CreateWin32Program(path); try { const int MAX_PATH = 260; StringBuilder buffer = new StringBuilder(MAX_PATH); string target = Helper.RetrieveTargetPath(path); if (!string.IsNullOrEmpty(target)) { var extension = Extension(target); if (extension == ExeExtension && File.Exists(target)) { program.LnkResolvedPath = program.FullPath; program.FullPath = Path.GetFullPath(target).ToLower(CultureInfo.CurrentCulture); program.ExecutableName = Path.GetFileName(target); program.hasArguments = Helper.hasArguments; program.Arguments = Helper.Arguments; var description = Helper.description; if (!string.IsNullOrEmpty(description)) { program.Description = description; } else { var info = FileVersionInfoWrapper.GetVersionInfo(target); if (!string.IsNullOrEmpty(info?.FileDescription)) { program.Description = info.FileDescription; } } } } return(program); } // Only do a catch all in production. This is so make developer aware of any unhandled exception and add the exception handling in. // Error caused likely due to trying to get the description of the program catch (Exception e) { ProgramLogger.LogException( $"|Win32|LnkProgram|{path}" + "|An unexpected error occurred in the calling method LnkProgram", e); program.Valid = false; return(program); } }
private static Win32Program LnkProgram(string path) { try { var program = CreateWin32Program(path); const int MAX_PATH = 260; StringBuilder buffer = new StringBuilder(MAX_PATH); string target = Helper.RetrieveTargetPath(path); if (!string.IsNullOrEmpty(target)) { if (File.Exists(target) || Directory.Exists(target)) { program.LnkResolvedPath = program.FullPath; // Using CurrentCulture since this is user facing program.FullPath = Path.GetFullPath(target).ToLower(CultureInfo.CurrentCulture); program.AppType = GetAppTypeFromPath(target); var description = Helper.Description; if (!string.IsNullOrEmpty(description)) { program.Description = description; } else { var info = FileVersionInfoWrapper.GetVersionInfo(target); if (!string.IsNullOrEmpty(info?.FileDescription)) { program.Description = info.FileDescription; } } } } return(program); } // Only do a catch all in production. This is so make developer aware of any unhandled exception and add the exception handling in. // Error caused likely due to trying to get the description of the program catch (Exception e) { ProgramLogger.Exception($"|An unexpected error occurred in the calling method LnkProgram at {path}", e, MethodBase.GetCurrentMethod().DeclaringType, path); return(new Win32Program() { Valid = false, Enabled = false }); } }