Skip to content

Commit e0b7600

Browse files
committed
Add project files.
1 parent 5c8c0e4 commit e0b7600

15 files changed

+1922
-0
lines changed

AboutDialog.xaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Window x:Class="QDTool.AboutDialog"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:QDTool"
7+
mc:Ignorable="d"
8+
Title="About" Height="175" Width="300">
9+
<StackPanel Margin="10">
10+
<TextBlock FontWeight="Bold" FontSize="14"><Run Language="cs-cz" Text="QDTool"/></TextBlock>
11+
<TextBlock><Run Text="V"/><Run Text="ersion"/><Run Text=" "/><Run Text="0"/><Run Text=".1"/><Run Text=".0"/><Run Text=" alpha (25 Feb 2024)"/></TextBlock>
12+
<TextBlock><Run Text="© 2024 "/><Run Text="Martin Lukasek"/></TextBlock>
13+
<TextBlock><Run Language="cs-cz" Text="Simple app to convert SHARP MZ files."/></TextBlock>
14+
<TextBlock>
15+
<Hyperlink NavigateUri="https://www.8bity.cz" RequestNavigate="Hyperlink_RequestNavigate">
16+
www.8bity.cz
17+
</Hyperlink>
18+
</TextBlock>
19+
<Button Content="OK" HorizontalAlignment="Right" Margin="0,10,0,0" Click="OkButton_Click" RenderTransformOrigin="-3.09,-1.299"/>
20+
</StackPanel>
21+
</Window>

AboutDialog.xaml.cs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
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 QDTool
18+
{
19+
/// <summary>
20+
/// Interaction logic for AboutDialog.xaml
21+
/// </summary>
22+
public partial class AboutDialog : Window
23+
{
24+
public AboutDialog()
25+
{
26+
InitializeComponent();
27+
}
28+
29+
private void OkButton_Click(object sender, RoutedEventArgs e)
30+
{
31+
this.Close();
32+
}
33+
34+
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
35+
{
36+
// Otevření URL v externím prohlížeči
37+
Process.Start(new ProcessStartInfo
38+
{
39+
FileName = e.Uri.AbsoluteUri,
40+
UseShellExecute = true
41+
});
42+
e.Handled = true;
43+
}
44+
}
45+
}

App.xaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="QDTool.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:QDTool"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

App.xaml.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace QDTool
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}

AssemblyInfo.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

HexBrowser.xaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Window x:Class="QDTool.HexBrowser"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:QDTool"
7+
mc:Ignorable="d"
8+
Title="HexBrowser" Height="450" Width="800">
9+
<ScrollViewer>
10+
<Canvas Name="canvas">
11+
<!-- Dynamicky přidané prvky, jako jsou TextBlocks nebo Shapes -->
12+
</Canvas>
13+
</ScrollViewer>
14+
</Window>

HexBrowser.xaml.cs

+248
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.IO.Pipes;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Shapes;
16+
using static QDTool.Utility;
17+
18+
namespace QDTool
19+
{
20+
/// <summary>
21+
/// Interaction logic for HexBrowser.xaml
22+
/// </summary>
23+
public partial class HexBrowser : Window
24+
{
25+
public HexBrowser()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
public void AddTextToCanvas(string text)
31+
{
32+
var textBlock = new TextBlock
33+
{
34+
Text = text,
35+
Foreground = Brushes.Black,
36+
Background = Brushes.White
37+
// Další nastavení vzhledu, pokud je potřeba
38+
};
39+
40+
Canvas.SetLeft(textBlock, 50); // Nastavte X pozici
41+
Canvas.SetTop(textBlock, 50); // Nastavte Y pozici
42+
canvas.Children.Add(textBlock);
43+
}
44+
45+
private readonly byte[] SharpASCII = {
46+
(byte)'_', (byte)' ', (byte)'e', (byte)' ', (byte)'~', (byte)' ', (byte)'t', (byte)'g',
47+
(byte)'h', (byte)' ', (byte)'b', (byte)'x', (byte)'d', (byte)'r', (byte)'p', (byte)'c',
48+
(byte)'q', (byte)'a', (byte)'z', (byte)'w', (byte)'s', (byte)'u', (byte)'i', (byte)' ',
49+
(byte)' ', (byte)'k', (byte)'f', (byte)'v', (byte)' ', (byte)' ', (byte)' ', (byte)'j',
50+
(byte)'n', (byte)' ', (byte)' ', (byte)'m', (byte)' ', (byte)' ', (byte)' ', (byte)'o',
51+
(byte)'l', (byte)' ', (byte)' ', (byte)' ', (byte)' ', (byte)'y', (byte)'{', (byte)' ',
52+
(byte)'|' };
53+
54+
private byte FromSHASCII(byte c)
55+
{
56+
if (c <= 0x5d) return c;
57+
if (c == 0x80) return (byte)'}';
58+
if (c < 0x90 || c > 0xc0) return (byte)' '; // z neznámých znaků uděláme ' '
59+
return SharpASCII[c - 0x90];
60+
}
61+
62+
private string ConvertToHexDump(byte[] data, int bytesPerLine = 16)
63+
{
64+
StringBuilder hexDump = new StringBuilder();
65+
66+
for (int i = 0; i < data.Length; i += bytesPerLine)
67+
{
68+
hexDump.AppendFormat("{0:X8}: ", i); // Hexadecimální adresa
69+
70+
// Hexadecimální hodnoty bajtů
71+
for (int j = 0; j < bytesPerLine; j++)
72+
{
73+
if (i + j < data.Length)
74+
hexDump.AppendFormat("{0:X2} ", data[i + j]);
75+
else
76+
hexDump.Append(" "); // Pro poslední řádek s méně než 16 bajty
77+
if ((i + j) % 4 == 3)
78+
hexDump.Append(' ');
79+
}
80+
81+
//hexDump.Append(" ");
82+
83+
// ASCII reprezentace bajtů
84+
//int cnt = 0;
85+
for (int j = 0; j < bytesPerLine; j++)
86+
{
87+
if (i + j < data.Length)
88+
{
89+
hexDump.Append(char.IsControl((char)data[i + j]) ? '.' : (char)data[i + j]);
90+
//cnt++;
91+
}
92+
else
93+
hexDump.Append(' '); // Pro poslední řádek s méně než 16 bajty
94+
}
95+
//for (int j = 0; j < bytesPerLine - cnt; j++)
96+
//{
97+
// hexDump.Append(' ');
98+
//}
99+
100+
hexDump.Append(" ");
101+
102+
// ASCII reprezentace bajtů
103+
for (int j = 0; j < bytesPerLine; j++)
104+
{
105+
if (i + j < data.Length)
106+
hexDump.Append(char.IsControl((char)data[i + j]) ? '.' : (char)FromSHASCII(data[i + j]));
107+
}
108+
109+
hexDump.AppendLine();
110+
}
111+
return hexDump.ToString();
112+
}
113+
114+
public void ShowHexDump((MZQFileHeader , MZQFileBody) MzfBlock)
115+
{
116+
MZQFileHeader header = MzfBlock.Item1;
117+
MZQFileBody body = MzfBlock.Item2;
118+
119+
StringBuilder hexDump = new StringBuilder();
120+
121+
byte[] mzfHeaderData = new byte[128];
122+
mzfHeaderData[0] = header.MzfFtype;
123+
Array.Copy(header.MzfFname, 0, mzfHeaderData, 1, header.MzfFname.Length);
124+
mzfHeaderData[17] = header.MzfFnameEnd;
125+
var mzfSizeBytes = BitConverter.GetBytes(header.MzfSize);
126+
Array.Copy(mzfSizeBytes, 0, mzfHeaderData, 18, mzfSizeBytes.Length);
127+
var mzfStartBytes = BitConverter.GetBytes(header.MzfStart);
128+
Array.Copy(mzfStartBytes, 0, mzfHeaderData, 20, mzfStartBytes.Length);
129+
var mzfExecBytes = BitConverter.GetBytes(header.MzfExec);
130+
Array.Copy(mzfExecBytes, 0, mzfHeaderData, 22, mzfExecBytes.Length);
131+
Array.Copy(header.MzfHeaderDescription, 0, mzfHeaderData, 24, 38+2+64);
132+
133+
byte[] qdfHeaderData = new byte[70];
134+
qdfHeaderData[0] = 0xA5;
135+
CRC_check(0xA5, true);
136+
qdfHeaderData[1] = header.MzfHeaderSign;
137+
CRC_check(header.MzfHeaderSign);
138+
var dataSizeBytes = BitConverter.GetBytes(header.DataSize);
139+
Array.Copy(dataSizeBytes, 0, qdfHeaderData, 2, dataSizeBytes.Length);
140+
CRC_check(dataSizeBytes, 0, dataSizeBytes.Length);
141+
qdfHeaderData[4] = header.MzfFtype;
142+
CRC_check(header.MzfFtype);
143+
Array.Copy(header.MzfFname, 0, qdfHeaderData, 5, header.MzfFname.Length);
144+
CRC_check(header.MzfFname, 0, header.MzfFname.Length);
145+
qdfHeaderData[21] = header.MzfFnameEnd;
146+
CRC_check(header.MzfFnameEnd);
147+
Array.Copy(header.Unused1, 0, qdfHeaderData, 22, header.Unused1.Length);
148+
CRC_check(header.Unused1, 0, header.Unused1.Length);
149+
Array.Copy(mzfSizeBytes, 0, qdfHeaderData, 24, mzfSizeBytes.Length);
150+
CRC_check(mzfSizeBytes, 0, mzfSizeBytes.Length);
151+
Array.Copy(mzfStartBytes, 0, qdfHeaderData, 26, mzfStartBytes.Length);
152+
CRC_check(mzfStartBytes, 0, mzfStartBytes.Length);
153+
Array.Copy(mzfExecBytes, 0, qdfHeaderData, 28, mzfExecBytes.Length);
154+
CRC_check(mzfExecBytes, 0, mzfExecBytes.Length);
155+
Array.Copy(header.MzfHeaderDescription, 0, qdfHeaderData, 30, 38);
156+
ushort crc = CRC_check(header.MzfHeaderDescription, 0, 38);
157+
qdfHeaderData[68] = ReverseBits((byte)(crc >> 8));
158+
qdfHeaderData[69] = ReverseBits((byte)(crc & 0xFF));
159+
160+
hexDump.Append("ADDRESS MZF HEADER DATA ASCII SHASCII (EU)");
161+
hexDump.AppendLine();
162+
hexDump.Append(ConvertToHexDump(mzfHeaderData));
163+
hexDump.AppendLine();
164+
165+
hexDump.Append("ADDRESS QDF HEADER DATA ASCII SHASCII (EU)");
166+
hexDump.AppendLine();
167+
hexDump.Append(ConvertToHexDump(qdfHeaderData));
168+
hexDump.AppendLine();
169+
170+
hexDump.Append("ADDRESS FILE DATA ASCII SHASCII (EU)");
171+
hexDump.AppendLine();
172+
hexDump.Append(ConvertToHexDump(body.MzfBody));
173+
174+
TextBlock textBlock = new TextBlock
175+
{
176+
Text = hexDump.ToString(),
177+
FontFamily = new FontFamily("Consolas"), // Monospace font pro lepší čitelnost
178+
TextWrapping = TextWrapping.NoWrap,
179+
Margin = new Thickness(10)
180+
};
181+
182+
double letterWidth = 0;
183+
double lineHeight = 0;
184+
185+
textBlock.Loaded += (sender, e) =>
186+
{
187+
canvas.MinHeight = textBlock.ActualHeight;
188+
189+
Typeface typeface = new Typeface(textBlock.FontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch);
190+
double fontSize = textBlock.FontSize;
191+
double pixelsPerDip = VisualTreeHelper.GetDpi(textBlock).PixelsPerDip;
192+
193+
// Předpokládáme, že používáte monospace font
194+
string sampleText = "M"; // Máme zvolené "M", protože je to často jeden z nejširších znaků v monospace fontech
195+
196+
FormattedText formattedText = new FormattedText(
197+
sampleText,
198+
System.Globalization.CultureInfo.CurrentCulture,
199+
FlowDirection.LeftToRight,
200+
typeface,
201+
fontSize,
202+
Brushes.Black,
203+
new NumberSubstitution(),
204+
TextFormattingMode.Display,
205+
pixelsPerDip);
206+
207+
letterWidth = formattedText.Width; // WidthIncludingTrailingWhitespace;
208+
lineHeight = formattedText.Height;
209+
210+
Rectangle rect1 = new Rectangle
211+
{
212+
Width = letterWidth * 11 + 1,
213+
Height = lineHeight,
214+
Stroke = Brushes.Red,
215+
StrokeThickness = 1,
216+
Fill = null
217+
};
218+
219+
Rectangle rect2 = new Rectangle
220+
{
221+
Width = letterWidth * 5 + 2,
222+
Height = lineHeight,
223+
Stroke = Brushes.Blue,
224+
StrokeThickness = 1,
225+
Fill = null
226+
};
227+
228+
var transform = textBlock.TransformToAncestor(canvas);
229+
var position = transform.Transform(new Point(0, 0));
230+
231+
Canvas.SetLeft(rect1, position.X + letterWidth * 10 - 7);
232+
Canvas.SetTop(rect1, position.Y + lineHeight * 11 + 1);
233+
234+
Canvas.SetLeft(rect2, position.X + letterWidth * 22 - 4);
235+
Canvas.SetTop(rect2, position.Y + lineHeight * 15 + 1);
236+
237+
canvas.Children.Add(rect1);
238+
canvas.Children.Add(rect2);
239+
240+
};
241+
242+
canvas.Children.Clear();
243+
canvas.Children.Add(textBlock);
244+
245+
}
246+
247+
}
248+
}

0 commit comments

Comments
 (0)