public async Task OpenFile() { if (ReferenceFile.IsReferenceFile(File)) { ReferenceFile referenceFile = await ReferenceFile.GetFile(File); if (referenceFile.ReferencedFile == null) { return; } await Launcher.LaunchFileAsync(referenceFile.ReferencedFile); } else { await Launcher.LaunchFileAsync(File); } }
public async Task OpenContainingFolder(bool checkForReference) { IStorageFolder folder; IStorageFile fileToSelect; if (checkForReference && ReferenceFile.IsReferenceFile(File)) { ReferenceFile referenceFile = await ReferenceFile.GetFile(File); if (referenceFile.ReferencedFile == null) { folder = await StorageHelpers.ToStorageItem <StorageFolder>(Path.GetDirectoryName(File.Path)); fileToSelect = File; } else { folder = await StorageHelpers.ToStorageItem <StorageFolder>(Path.GetDirectoryName(referenceFile.ReferencedFile.Path)); fileToSelect = referenceFile.ReferencedFile; } } else { folder = await StorageHelpers.ToStorageItem <StorageFolder>(Path.GetDirectoryName(File.Path)); fileToSelect = File; } if (folder != null) { FolderLauncherOptions launcherOptions = new FolderLauncherOptions(); if (File != null) { launcherOptions.ItemsToSelect.Add(fileToSelect); } await Launcher.LaunchFolderAsync(folder, launcherOptions); } }
public static async Task <BasePastedContentTypeDataModel> GetContentType(IStorageItem item, BasePastedContentTypeDataModel contentType) { if (contentType is InvalidContentTypeDataModel invalidContentType) { if (!invalidContentType.needsReinitialization) { return(invalidContentType); } } if (contentType != null) { return(contentType); } if (item is StorageFile file) { string ext = Path.GetExtension(file.Path); if (ReferenceFile.IsReferenceFile(file)) { // Reference File, get the destination file extension ReferenceFile referenceFile = await ReferenceFile.GetFile(file); if (referenceFile.ReferencedFile == null) { return(new InvalidContentTypeDataModel(referenceFile.LastError, false)); } file = referenceFile.ReferencedFile; ext = Path.GetExtension(file.Path); } // Image if (ImageCanvasViewModel.Extensions.Contains(ext)) { return(new ImageContentType()); } // Text if (TextCanvasViewModel.Extensions.Contains(ext)) { return(new TextContentType()); } // Media if (MediaCanvasViewModel.Extensions.Contains(ext)) { return(new MediaContentType()); } // WebView if (WebViewCanvasViewModel.Extensions.Contains(ext)) { if (ext == Constants.FileSystem.WEBSITE_LINK_FILE_EXTENSION) { return(new WebViewContentType(WebViewCanvasMode.ReadWebsite)); } return(new WebViewContentType(WebViewCanvasMode.ReadHtml)); } // Markdown if (MarkdownCanvasViewModel.Extensions.Contains(ext)) { return(new MarkdownContentType()); } // Default, try as text if (await TextCanvasViewModel.CanLoadAsText(file)) { // Text return(new TextContentType()); } // Use fallback return(new FallbackContentType()); } else if (item is StorageFolder folder) { // TODO: Handle also folders return(new InvalidContentTypeDataModel(new SafeWrapperResult(OperationErrorCode.InvalidOperation, new InvalidOperationException(), "Displaying content for folders is not yet supported."), false)); } return(new InvalidContentTypeDataModel(new SafeWrapperResult(OperationErrorCode.InvalidOperation, new InvalidOperationException(), "Couldn't display content for this file"), false)); }