IPF Image-File Reader-Writer  1.0
IPF File information
MainWindow.xaml.cs
1 using Microsoft.Win32;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7 using System.Windows;
8 using System.Windows.Controls;
9 using System.Windows.Data;
10 using System.Windows.Documents;
11 using System.Windows.Input;
12 using System.Windows.Media;
13 using System.Windows.Media.Imaging;
14 using System.Windows.Navigation;
15 using System.Windows.Shapes;
16 
17 namespace ipf {
18  //http://www.thomaslevesque.com/2008/11/18/wpf-binding-to-application-settings-using-a-markup-extension/
19  public class SettingBindingExtension : Binding {
20  public SettingBindingExtension() {
21  Initialize();
22  }
23 
24  public SettingBindingExtension(string path)
25  : base(path) {
26  Initialize();
27  }
28 
29  private void Initialize() {
30  this.Source = ipf.Properties.Settings.Default;
31  this.Mode = BindingMode.TwoWay;
32  }
33  }
34 
38  public partial class MainWindow : Window {
39  Floppy _fd;
40  BufferWindow _trackWindow = null;
41  BufferWindow _sectorWindow = null;
42  bool _trackWindowOpen = false;
43  bool _sectorWindowOpen = false;
44 
45  public MainWindow() {
46  InitializeComponent();
47  string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
48  string progName = "IPF File Reader / Writer " + version;
49  Title = progName;
50  //tbVersion.Text = progName;
51  }
52 
53 
54 
55  private void btFileClick(object sender, RoutedEventArgs e) {
56  OpenFileDialog ofd = new OpenFileDialog();
57  ofd.Filter = "IPF/IPX file|*.ipf;*ipx|All Files|*.*";
58  bool? ok = ofd.ShowDialog();
59  if (ok == true) {
60  fileName.Text = ofd.FileName;
61  processFile(ofd.FileName);
62  }
63 
64  }
65 
66 
67  private void processFile(string file) {
68  IPFReader ipf = new IPFReader(infoBox, cbDataElem);
69  _fd = new Floppy();
70  ipf.readIPF(file, _fd);
71  }
72 
73  private void btWriteClick(object sender, RoutedEventArgs e) {
74  if (_fd == null) {
75  MessageBox.Show("Nothing to write", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
76  return;
77  }
78 
79  SaveFileDialog sfd = new SaveFileDialog();
80  sfd.Filter = "IPF file|*.ipf|All Files|*.*";
81 
82  bool? ok = sfd.ShowDialog();
83  if (ok == true) {
84  fileName.Text = sfd.FileName;
85  //if (File.Exists(sfd.FileName)) {
86  // MessageBoxResult result = MessageBox.Show("Do you want to overwrite?", "File already exist", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.No);
87  // if (result == MessageBoxResult.Cancel) return;
88  // if (result == MessageBoxResult.No) goto askOutput;
89  //}
90  IPFWriter ipf = new IPFWriter(infoBox);
91  ipf.writeIPF(sfd.FileName, _fd);
92  }
93 
94  }
95 
96 
97  private void btBlocksClick(object sender, RoutedEventArgs e) {
98  if (_fd == null) {
99  tbStatus.Text = "Nothing to display";
100  return;
101  }
102  int trackNumber;
103  int sideNumber;
104  tbStatus.Clear();
105  if (Int32.TryParse(tbTrack.Text, out trackNumber) == false) {
106  tbStatus.Text = "Invalid track number - please correct and try again";
107  return;
108  }
109  if (Int32.TryParse(tbSide.Text, out sideNumber) == false) {
110  tbStatus.Text = "Invalid side number - please correct and try again";
111  return;
112  }
113  if ((trackNumber < 0) || (trackNumber > 84) || (sideNumber < 0) || (sideNumber > 1)) {
114  tbStatus.Text = "Track or Side out of range - please correct and try again";
115  return;
116  }
117 
118  if (_sectorWindowOpen)
119  _sectorWindow.Close();
120 
121  _sectorWindow = new BufferWindow();
122  _sectorWindow.displayBlocksBuffer(_fd, trackNumber, sideNumber);
123  _sectorWindow.Closed += new EventHandler(sectorWindowClosed);
124  _sectorWindowOpen = true;
125  _sectorWindow.Show();
126 
127  }
128 
129 
130  void sectorWindowClosed(object sender, EventArgs e) {
131  _sectorWindowOpen = false;
132  }
133 
134 
135  private void mainWinClosing(object sender, System.ComponentModel.CancelEventArgs e) {
136  if (_sectorWindowOpen) _sectorWindow.Close();
137  if (_trackWindowOpen) _trackWindow.Close();
138  }
139 
140 
141  private void fileDropped(object sender, DragEventArgs e) {
142  string[] droppedFiles = null;
143  if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
144  droppedFiles = e.Data.GetData(DataFormats.FileDrop, true) as string[];
145  }
146 
147  if ((null == droppedFiles) || (!droppedFiles.Any())) { return; }
148  processFile(droppedFiles[0]);
149  }
150 
151  private void dragEnter(object sender, DragEventArgs e) {
152  e.Handled = true;
153  }
154 
155  }
156 }
Interaction logic for BufferWindow.xaml
bool writeIPF(string fileName, Floppy fd)
Write an IPF file from the Floppy structure
Definition: IPFWriter.cs:29
Store information about all tracks of a FD
Definition: Floppy.cs:56
Definition: App.xaml.cs:9
Interaction logic for MainWindow.xaml
void displayBlocksBuffer(Floppy floppy, int track, int side)
Draw the content of the buffer
The reader class
Definition: IPFReader.cs:42
bool readIPF(string fileName, Floppy fd)
Read an IPF file and fills the Floppy structure
Definition: IPFReader.cs:60