private static async Task SaveTextFile(List <string> subtitleLines, string fileName) { FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.Desktop; savePicker.SuggestedFileName = fileName + " retimed"; savePicker.FileTypeChoices.Add("SRT file", new List <string>() { ".srt" }); savePicker.FileTypeChoices.Add("Text file", new List <string>() { ".txt" }); StorageFile savefile = await savePicker.PickSaveFileAsync(); if (savefile != null) { await FileIO.WriteLinesAsync(savefile, subtitleLines); Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(savefile); if (status != Windows.Storage.Provider.FileUpdateStatus.Complete) { await Dialogs.ErrorDialog($"File {savefile.Name} couldn't be saved."); } Parameters.ViewModel.Status.StatusMessage = $"{fileName} was exported successfully"; } }
private async void _Drop(object sender, DragEventArgs e) { try { if (e.DataView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems)) { var droppedItems = await e.DataView.GetStorageItemsAsync(); if (droppedItems.Count == 1) { var storageFile = droppedItems[0] as StorageFile; if (storageFile.FileType == ".srt") { await Importer.LoadTextFile(storageFile); } else { throw new Exception(); } } else { await Dialogs.ErrorDialog("Hold on!", "Only one file at a time, please."); } } } catch { await Dialogs.ErrorDialog("This file is not supported"); } }
public static async Task LoadTextFile(StorageFile storageFile) { if (storageFile != null) { if (storageFile.FileType != ".srt" && storageFile.FileType != ".txt") { await Dialogs.ErrorDialog("Unable to open: The file wasn't a .srt or .txt file."); } else { try { await SubtitleParser(storageFile); Parameters.FileName = Path.GetFileNameWithoutExtension(storageFile.Name); Parameters.ViewModel.Status.StatusMessage = $"{storageFile.Name} is loaded"; } catch (Exception) { await Dialogs.ErrorDialog("The file you selected isn't in the right format. Please check if the file is UTF-8."); } } } }
private async void ButtonExport_Click(object sender, RoutedEventArgs e) { if (Parameters.SubtitleList.Count != 0) { try { List <SubtitleItem> subtitleListChanged = CopyList(Parameters.SubtitleList); if (ComboBoxMath.SelectedIndex == 0) //add { if (ComboBoxTime.SelectedIndex == 0) { Exporter.Add(subtitleListChanged, int.Parse(TextBoxInput.Text)); } //add milliseconds if (ComboBoxTime.SelectedIndex == 1) { Exporter.Add(subtitleListChanged, int.Parse(TextBoxInput.Text) * 1000); } //add seconds if (ComboBoxTime.SelectedIndex == 2) { Exporter.Add(subtitleListChanged, int.Parse(TextBoxInput.Text) * 60000); } //add minutes if (ComboBoxTime.SelectedIndex == 3) { Exporter.Add(subtitleListChanged, int.Parse(TextBoxInput.Text) * 3600000); } //add hours } if (ComboBoxMath.SelectedIndex == 1) //subtract { if (ComboBoxTime.SelectedIndex == 0) { Exporter.Subtract(subtitleListChanged, int.Parse(TextBoxInput.Text)); } //subtract milliseconds if (ComboBoxTime.SelectedIndex == 1) { Exporter.Subtract(subtitleListChanged, int.Parse(TextBoxInput.Text) * 1000); } //subtract seconds if (ComboBoxTime.SelectedIndex == 2) { Exporter.Subtract(subtitleListChanged, int.Parse(TextBoxInput.Text) * 60000); } //subtract minutes if (ComboBoxTime.SelectedIndex == 3) { Exporter.Subtract(subtitleListChanged, int.Parse(TextBoxInput.Text) * 3600000); } //subtract hours } await Exporter.Export(Parameters.FileName, subtitleListChanged); } catch (Exception) { await Dialogs.ErrorDialog("Exporing aborted", "The value you entered isn't a numeric value or a whole number. Please try again."); } } else { await Dialogs.ErrorDialog("Exporting aborted", "Please load a subtitle file first."); } }