private void ButtonLoadClick(object sender, RoutedEventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog { InitialDirectory = Mainframe.IsDirectoryPathValid(this.openFileFolder.Value) ? this.openFileFolder.Value : Mainframe.DefaultProjectFolder() }; bool?result = dialog.ShowDialog(this); if (result.HasValue && result.Value) { this.openFileFolder.Value = Path.GetDirectoryName(dialog.FileName); int addressBitWidth = this.AddressBitWidth; int dataBitWidth = this.DataBitWidth; byte[] buffer = new byte[Memory.BytesPerCellFor(dataBitWidth)]; int cellCount = Memory.NumberCellsFor(addressBitWidth); Tracer.Assert(cellCount * buffer.Length == this.data.Length); using (FileStream stream = File.Open(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { for (int i = 0; i < cellCount; i++) { int readed = stream.Read(buffer, 0, buffer.Length); if (readed <= 0) { Array.Clear(this.data, i * buffer.Length, this.data.Length - i * buffer.Length); break; } int value = Memory.CellValue(buffer, Math.Min(8 * readed, dataBitWidth), 0); Memory.SetCellValue(this.data, dataBitWidth, i, value); } } this.FunctionMemory = new MemoryEditor(this.data, addressBitWidth, dataBitWidth); } } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
private void InsertImage() { try { OpenFileDialog dialog = new OpenFileDialog { InitialDirectory = Mainframe.IsDirectoryPathValid(this.openImageFolder.Value) ? this.openImageFolder.Value : Mainframe.DefaultPictureFolder(), Filter = Properties.Resources.ImageFileFilter, FilterIndex = 0 }; bool?result = dialog.ShowDialog(this); if (result.HasValue && result.Value) { string path = dialog.FileName; this.openImageFolder.Value = Path.GetDirectoryName(path); if (Uri.TryCreate(path, UriKind.Absolute, out Uri uri)) { Image image = new Image(); image.BeginInit(); image.Source = new BitmapImage(uri); image.MaxWidth = image.Source.Width; image.EndInit(); Span span = new Span(this.editor.Selection.End, this.editor.Selection.End); span.Inlines.Add(image); } } } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
private void Import() { if (this.Editor != null && this.Editor.InEditMode) { string dir = Mainframe.DefaultProjectFolder(); string recent = Settings.User.RecentFile(); if (Mainframe.IsFilePathValid(recent)) { dir = Path.GetDirectoryName(recent); } SettingsStringCache location = new SettingsStringCache(Settings.User, "ImportFile.Folder", dir); OpenFileDialog dialog = new OpenFileDialog { Filter = Mainframe.FileFilter, DefaultExt = Mainframe.FileExtention, InitialDirectory = Mainframe.IsDirectoryPathValid(location.Value) ? location.Value : Mainframe.DefaultProjectFolder() }; bool?result = dialog.ShowDialog(this); if (result.HasValue && result.Value) { string file = dialog.FileName; location.Value = Path.GetDirectoryName(file); this.Editor.Import(file); } } }
private string DefaultFileName() { string imagePath = this.imageExportFolder.Value; if (!Mainframe.IsDirectoryPathValid(imagePath)) { imagePath = Mainframe.DefaultPictureFolder(); } string name = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}", this.editor.Project.Name, this.editor.Project.LogicalCircuit.Name, this.Encoder.Name ); return(Path.Combine(imagePath, name)); }
private void ButtonSaveClick(object sender, RoutedEventArgs e) { try { SaveFileDialog dialog = new SaveFileDialog(); dialog.InitialDirectory = Mainframe.IsDirectoryPathValid(this.openFileFolder.Value) ? this.openFileFolder.Value : Mainframe.DefaultProjectFolder(); bool? result = dialog.ShowDialog(this); if(result.HasValue && result.Value) { string file = dialog.FileName; this.openFileFolder.Value = Path.GetDirectoryName(file); using(FileStream stream = File.Open(file, FileMode.Create, FileAccess.Write, FileShare.Write)) { stream.Write(this.data, 0, this.data.Length); stream.Flush(); } } } catch(Exception exception) { App.Mainframe.ReportException(exception); } }