public ArchiveFileEntry(FileBase aFileBase, string aArchiveFileAndPath, bool aDataLoaded) : base(aFileBase.Name, aFileBase.GetFileType()) { this.archivedFile = aFileBase; this.dataLoaded = aDataLoaded; this.archiveFileAndPath = aArchiveFileAndPath; }
public async Task Save(FileBase file) { try { FileType type = file.GetFileType(); string path = file.Path; if (path == null) { path = await App.Current.Dispatcher.InvokeAsync <string>(() => { CommonSaveFileDialog dlg = new CommonSaveFileDialog(); dlg.Filters.Add(ToFilter(type)); CommonFileDialogResult selected = dlg.ShowDialog(); if (selected != CommonFileDialogResult.Ok) { return(null); } return(Path.Combine(Path.GetDirectoryName(dlg.FileName), Path.GetFileNameWithoutExtension(dlg.FileName))); }); if (path == null) { return; } } path += "." + type.Extension; using (FileStream stream = new FileStream(path, FileMode.Create)) { if (type.Serialize != null) { type.Serialize.Invoke(stream, file); } else { using (TextWriter writer = new StreamWriter(stream)) { string json = Serializer.Serialize(file); writer.Write(json); } } } } catch (Exception ex) { Log.Write(new Exception("Failed to save file", ex)); } }
public async Task Save(FileBase file, string path = null) { try { FileType type = file.GetFileType(); if (path == null) { path = file.Path; } if (path == null) { path = await App.Current.Dispatcher.InvokeAsync <string>(() => { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = ToFilter(type); bool?result = dlg.ShowDialog(); if (result != true) { return(null); } return(Path.Combine(Path.GetDirectoryName(dlg.FileName), Path.GetFileNameWithoutExtension(dlg.FileName))); }); if (path == null) { return; } } path += "." + type.Extension; using FileStream stream = new FileStream(path, FileMode.Create); if (type.Serialize != null) { type.Serialize.Invoke(stream, file); } else { using TextWriter writer = new StreamWriter(stream); string json = Serializer.Serialize(file); writer.Write(json); } } catch (Exception ex) { Log.Write(new Exception("Failed to save file", ex), "Files", Log.Severity.Error); } }