Exemple #1
0
 static DisplayableFile FromFullPath(string path)
 {
     var instance = new DisplayableFile
     {
         FullPath = path,
         DisplayName = Path.GetFileName(path),
         Icon = GetImage(path),
     };
     
     return instance;
 }
        public FileToShortCutModel(string tentativeFilePath)
        {
            var fileInfo = new FileInfo(tentativeFilePath);
            
            this.ShortcutName = fileInfo.Name.Replace(fileInfo.Extension, string.Empty);

            if (this.IsLink(fileInfo.Extension))
            {
                fileInfo = this.ResolveLink(fileInfo);
            }

            this.FilePath = fileInfo.FullName;
            this.Extension = fileInfo.Extension;
            this.IsExecutable = CheckIfIsExecutable(fileInfo.Extension);

            this.ExecutableFiles = this.BuildExecutableFilesList();
            this.SelectedExecutableFile = this.SelectExecutableFile();
        }
        private static DisplayableFile FindByProgramName(string program)
        {
            DisplayableFile displayableFile = new DisplayableFile();

            displayableFile.Command = Win32Api.AssocQueryString(Win32Api.AssocF.Open_ByExeName, Win32Api.AssocStr.Command,program);
            displayableFile.DisplayName = Win32Api.AssocQueryString(Win32Api.AssocF.Open_ByExeName,Win32Api.AssocStr.FriendlyAppName, program);
            displayableFile.IconPath = Win32Api.AssocQueryString(Win32Api.AssocF.Open_ByExeName,Win32Api.AssocStr.DefaultIcon, program);

            if (string.IsNullOrEmpty(displayableFile.Command))
            {
                var path = RegHelper.GetPathForAppName(program);
                if (path != null)
                {
                    displayableFile.Command = path.EndsWith(".exe") ? path : Path.Combine(path, program);
                }
            }

            if (string.IsNullOrEmpty(displayableFile.Command))
                return null;

            displayableFile.Command = FormatAsCommand(displayableFile.Command);

            return displayableFile;
        }
        private static DisplayableFile FindByProgramId(string program)
        {
            // Look assuming program is a programID or CLSID. More at https://msdn.microsoft.com/en-us/library/windows/desktop/bb773471%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
            var displayableFile = new DisplayableFile();
            displayableFile.Command = Win32Api.AssocQueryString(Win32Api.AssocStr.Command, program);
            if (string.IsNullOrEmpty(displayableFile.Command))
                return null;

            displayableFile.DisplayName = Win32Api.AssocQueryString(Win32Api.AssocStr.FriendlyAppName, program);
            displayableFile.IconPath = Win32Api.AssocQueryString(Win32Api.AssocStr.DefaultIcon, program);

            displayableFile.Command = FormatAsCommand(displayableFile.Command);

            return displayableFile;
        }