private async void SavePositionButton_Click(object sender, RoutedEventArgs e) { if (await Picker.PickSaveFileAsync() is StorageFile SaveFile) { TargetFile = new FileSystemStorageFile(SaveFile, await SaveFile.GetThumbnailBitmapAsync(), await SaveFile.GetSizeRawDataAsync(), await SaveFile.GetModifiedTimeAsync()); } }
private async Task InitializeAsync(FileSystemStorageFile PdfFile) { LoadingControl.IsLoading = true; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } NumIndicator.Text = Convert.ToString(Pdf.PageCount); TextBoxControl.Text = "1"; for (uint i = 0; i < Pdf.PageCount; i++) { PdfCollection.Add(new BitmapImage()); LoadTable.Add(i); } Flip.ItemsSource = PdfCollection; await JumpToPageIndexAsync(0); } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync(); Frame.GoBack(); } finally { await Task.Delay(500); LoadingControl.IsLoading = false; } }
private bool TryOpenInternally(FileSystemStorageFile File) { Type InternalType = File.Type.ToLower() switch { ".jpg" or ".png" or ".bmp" => typeof(PhotoViewer), ".mkv" or ".mp4" or ".mp3" or ".flac" or ".wma" or ".wmv" or ".m4a" or ".mov" or ".alac" => typeof(MediaPlayer), ".txt" => typeof(TextViewer), ".pdf" => typeof(PdfReader), _ => null }; if (InternalType != null) { NavigationTransitionInfo NavigationTransition = AnimationController.Current.IsEnableAnimation ? new DrillInNavigationTransitionInfo() : new SuppressNavigationTransitionInfo(); Frame.Navigate(InternalType, File, NavigationTransition); return(true); } else { return(false); } }
private async void SavePositionButton_Click(object sender, RoutedEventArgs e) { if (await Picker.PickSaveFileAsync() is StorageFile SaveFile) { TargetFile = await FileSystemStorageFile.CreateFromExistingStorageItem(SaveFile); } }
private async Task LoadTextFromFileWithEncoding(FileSystemStorageFile File, Encoding Enco) { LoadingControl.IsLoading = true; await Task.Delay(500); try { using (FileStream Stream = await File.GetFileStreamFromFileAsync(AccessMode.Read)) using (StreamReader Reader = new StreamReader(Stream, Enco, false)) { EditText.Text = await Reader.ReadToEndAsync(); } } catch (Exception ex) { LogTracer.Log(ex, "Could not load the content in file"); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_CouldReadWriteFile_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } await Task.Delay(500); LoadingControl.IsLoading = false; }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (e?.Parameter is FileSystemStorageFile Parameters) { TextFile = Parameters; Title.Text = TextFile.Name; } }
public ProgramPickerDialog(FileSystemStorageFile OpenFile) { InitializeComponent(); this.OpenFile = OpenFile ?? throw new ArgumentNullException(nameof(OpenFile), "Parameter could not be null"); Loading += ProgramPickerDialog_Loading; }
public SecureFilePropertyDialog(FileSystemStorageFile File) { InitializeComponent(); StorageItem = File ?? throw new ArgumentNullException(nameof(File), "Parameter could not be null"); Loading += SecureFilePropertyDialog_Loading; }
protected override async void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.New && e.Parameter is FileSystemStorageFile File) { SelectedPhotoFile = File; await Initialize().ConfigureAwait(false); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter is FileSystemStorageFile File) { MediaFile = File; CoreWindow.GetForCurrentThread().KeyDown += MediaPlayer_KeyDown; await InitializeAsync().ConfigureAwait(false); } }
public TextEncodingDialog(FileSystemStorageFile TextFile, IEnumerable <Encoding> Encodings) { InitializeComponent(); this.TextFile = TextFile; this.Encodings = new ObservableCollection <Encoding>(Encodings); Loading += TextEncodingDialog_Loading; }
protected async override void OnNavigatedTo(NavigationEventArgs e) { if (e?.Parameter is FileSystemStorageFile TextFile) { Title.Text = TextFile.Name; this.TextFile = TextFile; await Initialize(); } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { CoreWindow.GetForCurrentThread().KeyDown -= MediaPlayer_KeyDown; MVControl.MediaPlayer.Pause(); MediaFile = null; MVControl.Source = null; Cover.Source = null; Source?.Dispose(); Source = null; }
public ProgramPickerDialog(FileSystemStorageFile OpenFile, bool OpenFromPropertiesWindow = false) { InitializeComponent(); this.OpenFile = OpenFile ?? throw new ArgumentNullException(nameof(OpenFile), "Parameter could not be null"); this.OpenFromPropertiesWindow = OpenFromPropertiesWindow; if (OpenFromPropertiesWindow) { UseAsAdmin.Visibility = Visibility.Collapsed; } Loading += ProgramPickerDialog_Loading; }
protected override void OnNavigatedFrom(NavigationEventArgs e) { Cropper.Source = null; AspList.SelectedIndex = 0; FilterImage?.Dispose(); OriginBackupImage?.Dispose(); OriginImage?.Dispose(); FilterBackupImage?.Dispose(); FilterBackupImage = null; FilterImage = null; OriginBackupImage = null; OriginImage = null; OriginFile = null; HistogramImage.Source = null; FilterGrid.SelectionChanged -= FilterGrid_SelectionChanged; foreach (FilterItem Item in FilterCollection) { Item.Dispose(); } FilterCollection.Clear(); }
private async void TranscodeImage_Click(object sender, RoutedEventArgs e) { FileSystemStorageFile Item = PhotoCollection[Flip.SelectedIndex].PhotoFile; TranscodeImageDialog Dialog = null; using (IRandomAccessStream OriginStream = await Item.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read)) { BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(OriginStream); Dialog = new TranscodeImageDialog(Decoder.PixelWidth, Decoder.PixelHeight); } if (await Dialog.ShowAsync() == ContentDialogResult.Primary) { TranscodeLoadingControl.IsLoading = true; await GeneralTransformer.TranscodeFromImageAsync(Item, Dialog.TargetFile, Dialog.IsEnableScale, Dialog.ScaleWidth, Dialog.ScaleHeight, Dialog.InterpolationMode); await Task.Delay(500); TranscodeLoadingControl.IsLoading = false; } }
protected async override void OnNavigatedFrom(NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.Back) { Cancellation?.Cancel(); await Task.Run(() => { ExitLocker.WaitOne(); }); ExitLocker.Dispose(); ExitLocker = null; Cancellation.Dispose(); Cancellation = null; Behavior.Detach(); PhotoCollection?.Clear(); PhotoCollection = null; SelectedPhotoFile = null; Flip.SelectionChanged -= Flip_SelectionChanged; Flip.SelectionChanged -= Flip_SelectionChanged1; Flip.Opacity = 0; } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { try { if (e?.Parameter is PhotoDisplaySupport Item) { OriginFile = Item.PhotoFile; OriginImage = await Item.GenerateImageWithRotation().ConfigureAwait(true); OriginBackupImage = SoftwareBitmap.Copy(OriginImage); WriteableBitmap WBitmap = new WriteableBitmap(OriginImage.PixelWidth, OriginImage.PixelHeight); OriginImage.CopyToBuffer(WBitmap.PixelBuffer); Cropper.Source = WBitmap; UnchangeRegion = Cropper.CroppedRegion; await AddEffectsToPane().ConfigureAwait(false); } } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when initializing CropperPage"); } }
private async Task Initialize(FileSystemStorageFile PdfFile) { LoadingControl.IsLoading = true; PdfCollection = new ObservableCollection <BitmapImage>(); LoadQueue = new Queue <int>(); ExitLocker = new ManualResetEvent(false); Cancellation = new CancellationTokenSource(); Flip.ItemsSource = PdfCollection; MaxLoad = 0; LastPageIndex = 0; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read).ConfigureAwait(true)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } for (uint i = 0; i < 10 && i < Pdf.PageCount && !Cancellation.IsCancellationRequested; i++) { using (PdfPage Page = Pdf.GetPage(i)) using (InMemoryRandomAccessStream PageStream = new InMemoryRandomAccessStream()) { await Page.RenderToStreamAsync(PageStream); BitmapImage DisplayImage = new BitmapImage(); PdfCollection.Add(DisplayImage); await DisplayImage.SetSourceAsync(PageStream); } } } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); Frame.GoBack(); } finally { ExitLocker.Set(); if (!Cancellation.IsCancellationRequested) { Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; } await Task.Delay(1000).ConfigureAwait(true); LoadingControl.IsLoading = false; } }
private async Task ImportFilesAsync(IEnumerable <StorageFile> FileList) { if (FileList.Any()) { await ActivateLoading(true, DisplayString : Globalization.GetString("Progress_Tip_Importing")); Cancellation = new CancellationTokenSource(); try { ulong TotalSize = 0; ulong CurrentPosition = 0; List <FileSystemStorageFile> NewFileList = new List <FileSystemStorageFile>(); foreach (StorageFile ImportFile in FileList) { FileSystemStorageFile File = await FileSystemStorageItemBase.CreatedByStorageItemAsync(ImportFile); if (File != null) { NewFileList.Add(File); TotalSize += File.SizeRaw; } } foreach (FileSystemStorageFile OriginFile in NewFileList) { string EncryptedFilePath = Path.Combine(SecureFolder.Path, $"{Path.GetFileNameWithoutExtension(OriginFile.Name)}.sle"); if (await FileSystemStorageItemBase.CreateAsync(EncryptedFilePath, StorageItemTypes.File, CreateOption.GenerateUniqueName) is FileSystemStorageFile EncryptedFile) { using (FileStream OriginFStream = await OriginFile.GetFileStreamFromFileAsync(AccessMode.Read)) using (FileStream EncryptFStream = await EncryptedFile.GetFileStreamFromFileAsync(AccessMode.Write)) using (SLEOutputStream SLEStream = new SLEOutputStream(EncryptFStream, OriginFile.Name, AESKey, AESKeySize)) { await OriginFStream.CopyToAsync(SLEStream, OriginFStream.Length, async (s, e) => { await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { ProBar.IsIndeterminate = false; ProBar.Value = Convert.ToInt32((CurrentPosition + Convert.ToUInt64(e.ProgressPercentage / 100d * OriginFile.SizeRaw)) * 100d / TotalSize); }); }, Cancellation.Token); CurrentPosition += OriginFile.SizeRaw; await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { ProBar.Value = Convert.ToInt32(CurrentPosition * 100d / TotalSize); }); } await EncryptedFile.RefreshAsync(); SecureCollection.Add(EncryptedFile); await OriginFile.DeleteAsync(false); } } } catch (OperationCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex, "An exception was threw when importing file"); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } finally { Cancellation.Dispose(); Cancellation = null; await ActivateLoading(false); } } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { TextFile = null; Text.Text = string.Empty; EncodingProfile.SelectedIndex = -1; }
private async Task Initialize(FileSystemStorageFile PdfFile) { LoadingControl.IsLoading = true; PdfCollection.Clear(); LoadQueue.Clear(); Cancellation = new CancellationTokenSource(); MaxLoad = 0; LastPageIndex = 0; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } for (uint i = 0; i < 10 && i < Pdf.PageCount && !Cancellation.IsCancellationRequested; i++) { using (PdfPage Page = Pdf.GetPage(i)) using (InMemoryRandomAccessStream PageStream = new InMemoryRandomAccessStream()) { await Page.RenderToStreamAsync(PageStream, new PdfPageRenderOptions { DestinationHeight = Convert.ToUInt32(Page.Size.Height * 1.5), DestinationWidth = Convert.ToUInt32(Page.Size.Width * 1.5) }); BitmapImage DisplayImage = new BitmapImage(); PdfCollection.Add(DisplayImage); await DisplayImage.SetSourceAsync(PageStream); } } } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync(); Frame.GoBack(); } finally { if (!Cancellation.IsCancellationRequested) { Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; } await Task.Delay(1000); LoadingControl.IsLoading = false; } }
protected override void OnNavigatedFrom(NavigationEventArgs e) { TextFile = null; EditText.Text = string.Empty; }
public void ProcessRequest(HttpContext context) { FileSystemStorageFile file = FileStorageProvider.GetStorageFileByUrl(context.Request.Path) as FileSystemStorageFile; if (file == null) { //文件未找到 context.Response.StatusCode = 404; return; } DateTime lastModified = (new FileInfo(file.FullLocalPath)).LastWriteTime; DateTime currentLastModifiedDate = DateTime.MinValue; //文件未被修改过 DateTime.TryParse(context.Request.Headers["If-Modified-Since"] ?? "", out currentLastModifiedDate); if (Math.Abs(((TimeSpan)lastModified.ToUniversalTime().Subtract(currentLastModifiedDate.ToUniversalTime())).TotalSeconds) <= 1) { context.Response.StatusCode = 304; context.Response.Status = "304 Not Modified"; return; } long eTag = 0; if (long.TryParse(context.Request.Headers["If-None-Match"] ?? "", out eTag)) { currentLastModifiedDate = new DateTime(eTag); if (lastModified == currentLastModifiedDate) { context.Response.StatusCode = 304; context.Response.Status = "304 Not Modified"; return; } } //设置客户端设置 context.Response.ContentType = MimeTypeManager.GetMimeType(file.FileName); context.Response.Cache.SetAllowResponseInBrowserHistory(true); context.Response.Cache.SetLastModified(lastModified.ToUniversalTime()); context.Response.Cache.SetETag(lastModified.Ticks.ToString()); string disposition; if (context.Response.ContentType == "application/pdf" || context.Response.ContentType == "application/octet-stream") { disposition = "attachment"; } else { disposition = "inline"; } //设置文件名称 if (context.Request.Browser.Browser.IndexOf("Netscape") != -1) { context.Response.AddHeader("Content-disposition", disposition + "; filename*0*=" + context.Server.UrlEncode(GlobalSettings.UrlDecodeFileComponent(file.FileName)).Replace("+", "%20") + ""); } else { context.Response.AddHeader("Content-disposition", disposition + "; filename=" + context.Server.UrlEncode(GlobalSettings.UrlDecodeFileComponent(file.FileName)).Replace("+", "%20") + ""); } if (!file.FullLocalPath.StartsWith(@"\")) { context.Response.TransmitFile(file.FullLocalPath); } else { context.Response.AddHeader("Content-Length", file.ContentLength.ToString("0")); context.Response.Buffer = false; context.Response.BufferOutput = false; using (Stream s = new FileStream(file.FullLocalPath, FileMode.Open, FileAccess.Read)) { byte[] buffer = new byte[64 * 1024]; int read; while ((read = s.Read(buffer, 0, buffer.Length)) > 0) { if (!context.Response.IsClientConnected) { break; } context.Response.OutputStream.Write(buffer, 0, read); context.Response.OutputStream.Flush(); } context.Response.OutputStream.Flush(); context.Response.Flush(); context.Response.Close(); s.Close(); } } }