Skip to content

Commit 7643a7b

Browse files
committed
feat(URL encoding/decoding): Added URL encoding and decoding functionality to the page
- Added URL encoding/decoding function page and navigation buttons - Implement the core functions of URL encoding and decoding - Add page state management functionality to save user input - Update multilingual resource files - Optimize the existing page text display controls to be copyable TextBoxes - Added PageStateManager for managing page states
1 parent 9819466 commit 7643a7b

17 files changed

Lines changed: 451 additions & 5 deletions

Helpers/PageStateManager.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text.Json;
5+
using System.Windows.Controls;
6+
7+
namespace DevTools.Helpers
8+
{
9+
public class PageStateManager
10+
{
11+
private static readonly string StateFilePath = Path.Combine(
12+
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
13+
"DevTools",
14+
"page_states.json");
15+
16+
private static Dictionary<string, Dictionary<string, string>> _pageStates = new();
17+
18+
static PageStateManager()
19+
{
20+
LoadStates();
21+
}
22+
23+
private static void LoadStates()
24+
{
25+
try
26+
{
27+
if (File.Exists(StateFilePath))
28+
{
29+
var json = File.ReadAllText(StateFilePath);
30+
_pageStates = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(json) ?? new Dictionary<string, Dictionary<string, string>>();
31+
}
32+
}
33+
catch
34+
{
35+
_pageStates = new Dictionary<string, Dictionary<string, string>>();
36+
}
37+
}
38+
39+
private static void SaveStates()
40+
{
41+
try
42+
{
43+
var directory = Path.GetDirectoryName(StateFilePath);
44+
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
45+
{
46+
Directory.CreateDirectory(directory);
47+
}
48+
49+
var json = JsonSerializer.Serialize(_pageStates, new JsonSerializerOptions { WriteIndented = true });
50+
File.WriteAllText(StateFilePath, json);
51+
}
52+
catch
53+
{
54+
}
55+
}
56+
57+
public static void SavePageState(Page page, Dictionary<string, string> state)
58+
{
59+
var pageName = page.GetType().Name;
60+
_pageStates[pageName] = state;
61+
SaveStates();
62+
}
63+
64+
public static Dictionary<string, string>? GetPageState(Page page)
65+
{
66+
var pageName = page.GetType().Name;
67+
return _pageStates.TryGetValue(pageName, out var state) ? state : null;
68+
}
69+
70+
public static void ClearPageState(Page page)
71+
{
72+
var pageName = page.GetType().Name;
73+
_pageStates.Remove(pageName);
74+
SaveStates();
75+
}
76+
77+
public static void ClearAllStates()
78+
{
79+
_pageStates.Clear();
80+
SaveStates();
81+
}
82+
}
83+
}

Pages/BarcodePage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf070;" FontSize="32" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />
6060
</Grid>
6161
</Grid>
62-
<TextBlock Text="{Binding Text}" Margin="0,8,0,0" TextWrapping="Wrap" TextAlignment="Center" Width="400" />
62+
<TextBox Text="{Binding Text}" Margin="0,8,0,0" TextWrapping="Wrap" TextAlignment="Center" Width="400" IsReadOnly="True" BorderThickness="0" Background="Transparent" VerticalContentAlignment="Center" />
6363
</StackPanel>
6464

6565
<!-- Right column: controls -->

Pages/BarcodePage.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Collections.ObjectModel;
34
using System.ComponentModel;
45
using System.Drawing;
@@ -8,6 +9,7 @@
89
using System.Windows.Controls;
910
using System.Windows.Data;
1011
using System.Windows.Media.Imaging;
12+
using DevTools.Helpers;
1113
using DevTools.Resources;
1214
using ZXing;
1315
using ZXing.Common;
@@ -26,13 +28,33 @@ public BarcodePage()
2628
InitializeComponent();
2729
LogsList.ItemsSource = _logs;
2830
Unloaded += BarcodePage_Unloaded;
31+
LoadState();
2932
}
3033

3134
private void Back_Click(object sender, RoutedEventArgs e)
3235
{
36+
SaveState();
3337
NavigationService?.Navigate(new HomePage());
3438
}
3539

40+
private void SaveState()
41+
{
42+
var state = new Dictionary<string, string>
43+
{
44+
{ "InputText", InputText.Text ?? string.Empty }
45+
};
46+
PageStateManager.SavePageState(this, state);
47+
}
48+
49+
private void LoadState()
50+
{
51+
var state = PageStateManager.GetPageState(this);
52+
if (state != null)
53+
{
54+
InputText.Text = state.GetValueOrDefault("InputText", string.Empty);
55+
}
56+
}
57+
3658
private void Generate_Click(object sender, RoutedEventArgs e)
3759
{
3860
var text = InputText.Text ?? string.Empty;

Pages/Base64ImagePage.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Windows;
45
using System.Windows.Controls;
@@ -7,6 +8,7 @@
78
using System.Windows.Media.Effects;
89
using System.Windows.Media.Imaging;
910
using Microsoft.Win32;
11+
using DevTools.Helpers;
1012
using DevTools.Resources;
1113
using MessageBox = System.Windows.MessageBox;
1214
using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
@@ -30,13 +32,33 @@ public partial class Base64ImagePage : Page
3032
public Base64ImagePage()
3133
{
3234
InitializeComponent();
35+
LoadState();
3336
}
3437

3538
private void Back_Click(object sender, RoutedEventArgs e)
3639
{
40+
SaveState();
3741
NavigationService?.Navigate(new HomePage());
3842
}
3943

44+
private void SaveState()
45+
{
46+
var state = new Dictionary<string, string>
47+
{
48+
{ "InputText", InputText.Text ?? string.Empty }
49+
};
50+
PageStateManager.SavePageState(this, state);
51+
}
52+
53+
private void LoadState()
54+
{
55+
var state = PageStateManager.GetPageState(this);
56+
if (state != null)
57+
{
58+
InputText.Text = state.GetValueOrDefault("InputText", string.Empty);
59+
}
60+
}
61+
4062
private void Decode_Click(object sender, RoutedEventArgs e)
4163
{
4264
var base64 = (InputText.Text ?? string.Empty).Trim();

Pages/HomePage.xaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</Button.Template>
2323
</Button>
2424

25-
<UniformGrid Rows="2" Columns="3" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,150">
25+
<UniformGrid Rows="3" Columns="3" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0">
2626
<Button x:Name="BtnMd5" Click="BtnMd5_Click" Style="{StaticResource CardButtonStyle}" Margin="8">
2727
<StackPanel Width="140" HorizontalAlignment="Center" VerticalAlignment="Center">
2828
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf023;" FontSize="32" FontWeight="Bold" HorizontalAlignment="Center" TextAlignment="Center" Foreground="#FFFFFF" />
@@ -65,6 +65,12 @@
6565
<TextBlock Text="{x:Static resources:Strings.PageSignature}" FontSize="14" HorizontalAlignment="Center" TextAlignment="Center" Margin="0,8,0,0" TextWrapping="Wrap" Foreground="#FFFFFF" />
6666
</StackPanel>
6767
</Button>
68+
<Button x:Name="BtnUrlEncode" Click="BtnUrlEncode_Click" Style="{StaticResource CardButtonStyle}" Margin="8">
69+
<StackPanel Width="140" HorizontalAlignment="Center" VerticalAlignment="Center">
70+
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf0c1;" FontSize="32" FontWeight="Bold" HorizontalAlignment="Center" TextAlignment="Center" Foreground="#FFFFFF" />
71+
<TextBlock Text="{x:Static resources:Strings.PageUrlEncode}" FontSize="14" HorizontalAlignment="Center" TextAlignment="Center" Margin="0,8,0,0" TextWrapping="Wrap" Foreground="#FFFFFF" />
72+
</StackPanel>
73+
</Button>
6874
</UniformGrid>
6975
</Grid>
7076
</Page>

Pages/HomePage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ private void BtnSignature_Click(object sender, RoutedEventArgs e)
4545
NavigationService?.Navigate(new SignaturePage());
4646
}
4747

48+
private void BtnUrlEncode_Click(object sender, RoutedEventArgs e)
49+
{
50+
NavigationService?.Navigate(new UrlEncodePage());
51+
}
52+
4853
private void BtnSettings_Click(object sender, RoutedEventArgs e)
4954
{
5055
NavigationService?.Navigate(new SettingsPage());

Pages/ImageToBase64Page.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Windows;
45
using System.Windows.Controls;
@@ -17,13 +18,38 @@ public partial class ImageToBase64Page : Page
1718
public ImageToBase64Page()
1819
{
1920
InitializeComponent();
21+
LoadState();
2022
}
2123

2224
private void Back_Click(object sender, RoutedEventArgs e)
2325
{
26+
SaveState();
2427
NavigationService?.Navigate(new HomePage());
2528
}
2629

30+
private void SaveState()
31+
{
32+
var state = new Dictionary<string, string>
33+
{
34+
{ "Base64Text", Base64Text.Text ?? string.Empty },
35+
{ "IncludeDataUri", IncludeDataUriCheck.IsChecked?.ToString() ?? "false" }
36+
};
37+
PageStateManager.SavePageState(this, state);
38+
}
39+
40+
private void LoadState()
41+
{
42+
var state = PageStateManager.GetPageState(this);
43+
if (state != null)
44+
{
45+
Base64Text.Text = state.GetValueOrDefault("Base64Text", string.Empty);
46+
if (state.TryGetValue("IncludeDataUri", out var includeDataUriStr) && bool.TryParse(includeDataUriStr, out var includeDataUri))
47+
{
48+
IncludeDataUriCheck.IsChecked = includeDataUri;
49+
}
50+
}
51+
}
52+
2753
private void SelectImage_Click(object sender, RoutedEventArgs e)
2854
{
2955
var dlg = new OpenFileDialog();

Pages/JsonFormatPage.xaml.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
using System.Collections.Generic;
12
using System.Windows;
23
using System.Windows.Controls;
34
using System.Windows.Controls.Primitives;
45
using System.Windows.Input;
56
using System.Text.Json;
67
using DevTools.Helpers;
78
using DevTools.Resources;
8-
using System.Collections.Generic;
99
using Button = System.Windows.Controls.Button;
1010
using TextBox = System.Windows.Controls.TextBox;
1111
using Panel = System.Windows.Controls.Panel;
@@ -22,13 +22,35 @@ public partial class JsonFormatPage : Page
2222
public JsonFormatPage()
2323
{
2424
InitializeComponent();
25+
LoadState();
2526
}
2627

2728
private void Back_Click(object sender, RoutedEventArgs e)
2829
{
30+
SaveState();
2931
NavigationService?.Navigate(new HomePage());
3032
}
3133

34+
private void SaveState()
35+
{
36+
var state = new Dictionary<string, string>
37+
{
38+
{ "InputText", InputText.Text ?? string.Empty },
39+
{ "LastFormattedJson", _lastFormattedJson }
40+
};
41+
PageStateManager.SavePageState(this, state);
42+
}
43+
44+
private void LoadState()
45+
{
46+
var state = PageStateManager.GetPageState(this);
47+
if (state != null)
48+
{
49+
InputText.Text = state.GetValueOrDefault("InputText", string.Empty);
50+
_lastFormattedJson = state.GetValueOrDefault("LastFormattedJson", string.Empty);
51+
}
52+
}
53+
3254
private void Format_Click(object sender, RoutedEventArgs e)
3355
{
3456
var json = InputText.Text ?? string.Empty;

Pages/Md5Page.xaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Security.Cryptography;
23
using System.Text;
34
using System.Windows;
@@ -14,13 +15,41 @@ public partial class Md5Page : Page
1415
public Md5Page()
1516
{
1617
InitializeComponent();
18+
LoadState();
1719
}
1820

1921
private void Back_Click(object sender, RoutedEventArgs e)
2022
{
23+
SaveState();
2124
NavigationService?.Navigate(new HomePage());
2225
}
2326

27+
private void SaveState()
28+
{
29+
var state = new Dictionary<string, string>
30+
{
31+
{ "InputText", InputText.Text ?? string.Empty },
32+
{ "Out32Lower", Out32Lower.Text ?? string.Empty },
33+
{ "Out32Upper", Out32Upper.Text ?? string.Empty },
34+
{ "Out16Lower", Out16Lower.Text ?? string.Empty },
35+
{ "Out16Upper", Out16Upper.Text ?? string.Empty }
36+
};
37+
PageStateManager.SavePageState(this, state);
38+
}
39+
40+
private void LoadState()
41+
{
42+
var state = PageStateManager.GetPageState(this);
43+
if (state != null)
44+
{
45+
InputText.Text = state.GetValueOrDefault("InputText", string.Empty);
46+
Out32Lower.Text = state.GetValueOrDefault("Out32Lower", string.Empty);
47+
Out32Upper.Text = state.GetValueOrDefault("Out32Upper", string.Empty);
48+
Out16Lower.Text = state.GetValueOrDefault("Out16Lower", string.Empty);
49+
Out16Upper.Text = state.GetValueOrDefault("Out16Upper", string.Empty);
50+
}
51+
}
52+
2453
private void Compute_Click(object sender, RoutedEventArgs e)
2554
{
2655
var input = InputText.Text ?? string.Empty;

Pages/QrPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="&#xf070;" FontSize="32" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />
5858
</Grid>
5959
</Grid>
60-
<TextBlock Text="{Binding Text}" Margin="0,8,0,0" TextWrapping="Wrap" TextAlignment="Center" Width="200" />
60+
<TextBox Text="{Binding Text}" Margin="0,8,0,0" TextWrapping="Wrap" TextAlignment="Center" Width="200" IsReadOnly="True" BorderThickness="0" Background="Transparent" VerticalContentAlignment="Center" />
6161
</StackPanel>
6262

6363
<!-- Right column: controls -->

0 commit comments

Comments
 (0)