Skip to content

Commit 0128e53

Browse files
committed
Implement update.
1 parent 56d4aed commit 0128e53

17 files changed

+627
-127
lines changed

App.config

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
55
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
614
</configuration>

App.xaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@
5353

5454
<Setter Property="Background" Value="{DynamicResource SecondaryBackgroundColor}"/>
5555
</Style>
56+
57+
<Style TargetType="local:ExtendedButton">
58+
<Setter Property="Background" Value="{DynamicResource BackgroundColor2}"/>
59+
60+
<Setter Property="Foreground" Value="{DynamicResource ForegroundColor1}"/>
61+
62+
<Setter Property="CornerRadius" Value="6"/>
63+
64+
<Setter Property="BorderBrush" Value="LightGray"/>
65+
66+
<Setter Property="BorderThickness" Value="2"/>
67+
68+
<Setter Property="Padding" Value="14 6 14 6"/>
69+
70+
<Style.Triggers>
71+
<Trigger Property="IsMouseOver" Value="True">
72+
<Setter Property="BorderBrush" Value="Gray"/>
73+
</Trigger>
74+
75+
<Trigger Property="IsPressed" Value="True">
76+
<Setter Property="Background" Value="DarkGray"/>
77+
</Trigger>
78+
</Style.Triggers>
79+
</Style>
5680
</ResourceDictionary>
5781
</Application.Resources>
5882
</Application>

App.xaml.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ public partial class App : Application
1919

2020
public readonly ResourceDictionary DARK_THEME = null;
2121

22-
public readonly string tempDirFilePath = "";
22+
public readonly string TEMP_DIR_FILE_PATH = "";
23+
24+
public readonly string LOGS_DIR_FILE_PATH = "";
25+
26+
public readonly string LOG_FILE_PATH = "";
27+
28+
public readonly string CONFIG_DIR_FILE_PATH = "";
29+
30+
public readonly string CONFIG_FILE_PATH = "";
31+
32+
public readonly Logger logger = null;
33+
34+
public readonly Configuration configuration = null;
2335

2436
public static new App Current
2537
{
@@ -65,15 +77,23 @@ public string BaseDirectory
6577

6678
private void CreateTempDirIfDoesNotExist()
6779
{
68-
if (Directory.Exists(this.tempDirFilePath) == false)
80+
if (Directory.Exists(this.TEMP_DIR_FILE_PATH) == false)
6981
{
70-
Directory.CreateDirectory(this.tempDirFilePath);
82+
Directory.CreateDirectory(this.TEMP_DIR_FILE_PATH);
7183
}
7284
}
7385

7486
public App()
7587
{
76-
this.tempDirFilePath = this.BaseDirectory + "/Temp";
88+
this.TEMP_DIR_FILE_PATH = this.BaseDirectory + "/Temp";
89+
90+
this.LOGS_DIR_FILE_PATH = this.BaseDirectory + "/Logs";
91+
92+
this.LOG_FILE_PATH = this.LOGS_DIR_FILE_PATH + "/log.txt";
93+
94+
this.CONFIG_DIR_FILE_PATH = this.BaseDirectory + "/Config";
95+
96+
this.CONFIG_FILE_PATH = this.CONFIG_DIR_FILE_PATH + "/config.json";
7797

7898
this.CreateTempDirIfDoesNotExist();
7999

@@ -86,6 +106,10 @@ public App()
86106
{
87107
Source = new Uri("/Themes/DarkTheme.xaml", UriKind.Relative)
88108
};
109+
110+
this.configuration = Configuration.Open();
111+
112+
this.logger = new Logger();
89113
}
90114
}
91115
}

Configuration.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Text.Json;
7+
using System.Text.Json.Serialization;
8+
using System.Threading.Tasks;
9+
10+
namespace Java_Bytecode_Toolkit
11+
{
12+
public class Configuration
13+
{
14+
[JsonInclude]
15+
public bool EnableLogging { get; set; } = false;
16+
17+
public static Configuration Open()
18+
{
19+
if (Directory.Exists(App.Current.CONFIG_DIR_FILE_PATH) == false)
20+
{
21+
Directory.CreateDirectory(App.Current.CONFIG_DIR_FILE_PATH);
22+
}
23+
24+
if (File.Exists(App.Current.CONFIG_FILE_PATH) == false)
25+
{
26+
File.Create(App.Current.CONFIG_FILE_PATH).Close();
27+
}
28+
29+
string configFileContents = File.ReadAllText(
30+
App.Current.CONFIG_FILE_PATH
31+
);
32+
33+
if (configFileContents == "")
34+
{
35+
return new Configuration();
36+
}
37+
38+
return JsonSerializer.Deserialize<Configuration>(configFileContents);
39+
}
40+
41+
public Configuration()
42+
{
43+
44+
}
45+
46+
public void Save()
47+
{
48+
File.WriteAllText(
49+
App.Current.CONFIG_FILE_PATH,
50+
JsonSerializer.Serialize(this)
51+
);
52+
}
53+
}
54+
}

ExtendedButton.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Animation;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Shapes;
16+
17+
namespace Java_Bytecode_Toolkit
18+
{
19+
public class ExtendedButton : Button
20+
{
21+
private Border border = null;
22+
23+
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(
24+
nameof(CornerRadius),
25+
typeof(CornerRadius),
26+
typeof(ExtendedButton)
27+
);
28+
29+
public CornerRadius CornerRadius
30+
{
31+
get
32+
{
33+
if (this.border == null)
34+
{
35+
return new CornerRadius();
36+
}
37+
38+
return this.border.CornerRadius;
39+
}
40+
set
41+
{
42+
if (this.border == null)
43+
{
44+
return;
45+
}
46+
47+
this.border.CornerRadius = value;
48+
}
49+
}
50+
51+
static ExtendedButton()
52+
{
53+
DefaultStyleKeyProperty.OverrideMetadata(typeof(ExtendedButton), new FrameworkPropertyMetadata(typeof(ExtendedButton)));
54+
}
55+
56+
public ExtendedButton()
57+
{
58+
59+
}
60+
61+
public override void OnApplyTemplate()
62+
{
63+
this.border = this.Template.FindName(
64+
"Border",
65+
this
66+
) as Border;
67+
}
68+
}
69+
}

ExtensionsNS/Extensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,15 @@ public static void WriteToXMLWriter(this object obj, XmlWriter xmlWriter, JavaCl
142142
capitalizedFieldName
143143
);
144144

145-
Array fieldValueAsObjectArray = fieldInfo.GetValue(obj) as Array;
145+
Array fieldValueAsArray = fieldInfo.GetValue(obj) as Array;
146146

147-
foreach (object element in fieldValueAsObjectArray)
147+
foreach (object element in fieldValueAsArray)
148148
{
149+
if (element == null)
150+
{
151+
continue;
152+
}
153+
149154
Type elementType = element.GetType();
150155

151156
if (elementType.IsPrimitive == true)

HomeScreen.xaml

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,14 @@
1010
FontWeight="SemiBold" FontSize="12">
1111
<Grid>
1212
<Grid.RowDefinitions>
13-
<RowDefinition Height="auto"/>
14-
1513
<RowDefinition Height="*"/>
1614
</Grid.RowDefinitions>
1715

1816
<Grid.ColumnDefinitions>
1917
<ColumnDefinition Width="*"/>
2018
</Grid.ColumnDefinitions>
2119

22-
<ScrollViewer Grid.Row="0" Grid.Column="0" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">
23-
<Menu Name="ToolbarMenu" FontWeight="SemiBold" Foreground="{DynamicResource ForegroundColor1}" Background="{DynamicResource BackgroundColor2}">
24-
<MenuItem Padding="10 6" Header="File">
25-
<MenuItem Name="OpenFileMenuItem" Header="Open a File...">
26-
<MenuItem.Icon>
27-
<Image Source="/Assets/file-icon.svg"/>
28-
</MenuItem.Icon>
29-
</MenuItem>
30-
</MenuItem>
31-
32-
<MenuItem Header="Help"/>
33-
34-
<MenuItem Header="About"/>
35-
36-
<MenuItem Header="Report a Bug"/>
37-
38-
<MenuItem Header="Request a Feature"/>
39-
40-
<MenuItem Header="Change Theme">
41-
<MenuItem Name="LightThemeMenuItem" Header="Light Theme" Icon="{DynamicResource LightThemeIcon}"/>
42-
43-
<MenuItem Name="DarkThemeMenuItem" Header="Dark Theme" Icon="{DynamicResource DarkThemeIcon}"/>
44-
</MenuItem>
45-
</Menu>
46-
</ScrollViewer>
47-
48-
<Grid Grid.Row="1" Grid.Column="0">
20+
<Grid Grid.Row="0" Grid.Column="0">
4921
<Grid.RowDefinitions>
5022
<RowDefinition Height="*"/>
5123
</Grid.RowDefinitions>

HomeScreen.xaml.cs

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,8 @@ namespace Java_Bytecode_Toolkit
2424
/// </summary>
2525
public partial class HomeScreen : UserControl
2626
{
27-
private OpenFileDialog openFileDialog = new OpenFileDialog();
28-
2927
public Dictionary<JavaClassFileTreeViewItem, JavaClassFile> javaClassFileTreeViewItemToJavaClassFileMap = new Dictionary<JavaClassFileTreeViewItem, JavaClassFile>();
3028

31-
private void OnLightThemeMenuItemClick(object sender, RoutedEventArgs e)
32-
{
33-
App.Current.Theme = App.Current.LIGHT_THEME;
34-
}
35-
36-
private void OnDarkThemeMenuItemClick(object sender, RoutedEventArgs e)
37-
{
38-
App.Current.Theme = App.Current.DARK_THEME;
39-
}
40-
41-
private void OnOpenFileMenuItemClick(object sender, RoutedEventArgs e)
42-
{
43-
this.openFileDialog.ShowDialog();
44-
}
45-
46-
private void OnOpenFileDialogFileOk(object sender, CancelEventArgs e)
47-
{
48-
this.OpenFile(this.openFileDialog.FileNames);
49-
}
50-
5129
private void OpenJavaClassFile(string javaClassFilePath)
5230
{
5331
JavaClassFile javaClassFile = new JavaClassFile(javaClassFilePath);
@@ -71,23 +49,6 @@ private void OpenJarFile(string jarFilePath)
7149

7250
}
7351

74-
private void OpenFile(params string[] filePaths)
75-
{
76-
foreach (string currentFilePath in filePaths)
77-
{
78-
string currentFileName = System.IO.Path.GetFileName(currentFilePath);
79-
80-
if (currentFileName.Contains(".class") == true)
81-
{
82-
this.OpenJavaClassFile(currentFilePath);
83-
}
84-
else if (currentFileName.Contains(".jar") == true)
85-
{
86-
this.OpenJarFile(currentFilePath);
87-
}
88-
}
89-
}
90-
9152
private void OnMainTreeViewSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
9253
{
9354
if (this.MainTreeView.SelectedItem == null)
@@ -128,22 +89,26 @@ public HomeScreen()
12889
{
12990
InitializeComponent();
13091

131-
this.openFileDialog.SetFilter(
132-
FileDialogFilter.JAVA_CLASS_FILE_FILTER,
133-
FileDialogFilter.JAR_FILE_FILTER
134-
);
135-
13692
this.OnMainTreeViewSelectedItemChanged(null, null);
13793

138-
this.OpenFileMenuItem.Click += this.OnOpenFileMenuItemClick;
139-
140-
this.openFileDialog.FileOk += this.OnOpenFileDialogFileOk;
141-
142-
this.LightThemeMenuItem.Click += this.OnLightThemeMenuItemClick;
94+
this.MainTreeView.SelectedItemChanged += this.OnMainTreeViewSelectedItemChanged;
95+
}
14396

144-
this.DarkThemeMenuItem.Click += this.OnDarkThemeMenuItemClick;
97+
public void OpenFile(params string[] filePaths)
98+
{
99+
foreach (string currentFilePath in filePaths)
100+
{
101+
string currentFileName = System.IO.Path.GetFileName(currentFilePath);
145102

146-
this.MainTreeView.SelectedItemChanged += this.OnMainTreeViewSelectedItemChanged;
103+
if (currentFileName.Contains(".class") == true)
104+
{
105+
this.OpenJavaClassFile(currentFilePath);
106+
}
107+
else if (currentFileName.Contains(".jar") == true)
108+
{
109+
this.OpenJarFile(currentFilePath);
110+
}
111+
}
147112
}
148113
}
149114
}

0 commit comments

Comments
 (0)