Skip to content

Commit

Permalink
Idk
Browse files Browse the repository at this point in the history
  • Loading branch information
ADeltaX committed Jan 18, 2020
1 parent 87a28a7 commit 46b6023
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 39 deletions.
46 changes: 25 additions & 21 deletions src/UWPSettingsEditor/Classes/Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,6 @@ public static Dictionary<string, object> GetCompositeValue(byte[] data)
return dict;
}

public static string PrettyPrintArray(Array array)
{
StringBuilder stringBuilder = new StringBuilder();

for (int i = 0; i < array.Length; i++)
{
stringBuilder.Append("[" + array.GetValue(i).ToString() + "]");
if (i < array.Length - 1)
stringBuilder.Append(", ");
}

return stringBuilder.ToString();
}

public static string PrettyPrintDictionary(Dictionary<string, object> dict)
{
StringBuilder stringBuilder = new StringBuilder();
Expand All @@ -288,10 +274,14 @@ public static string PrettyPrintDictionary(Dictionary<string, object> dict)
formatted = "\"" + item.Value + "\"";
else if (item.Value is char)
formatted = "'" + item.Value + "'";
else if (item.Value is char[])
formatted = "[ " + PrettyPrintArray(item.Value as Array, "'") + " ]";
else if (item.Value is string[])
formatted = "[ " + PrettyPrintArray(item.Value as Array, "\"") + " ]";
else if (item.Value is Array)
formatted = "[" + PrettyPrintArray(item.Value as Array) + "]";
formatted = "[ " + PrettyPrintArray(item.Value as Array) + " ]";

stringBuilder.Append("{\"" + item.Key + "\":" + formatted + "}");
stringBuilder.Append("{ \"" + item.Key + "\" : " + formatted + " }");

if (++i < dict.Count)
stringBuilder.Append(", ");
Expand All @@ -300,19 +290,33 @@ public static string PrettyPrintDictionary(Dictionary<string, object> dict)
return stringBuilder.ToString();
}

public static string PrettyPrintStringArray(byte[] data)
public static string PrettyPrintArray(Array array, string quotes = "")
{
StringBuilder stringBuilder = new StringBuilder();

for (int position = 0; position < data.Length;)
for (int i = 0; i < array.Length; i++)
{
var stringLength = BitConverter.ToInt32(data, position);
stringBuilder.Append("[ " + quotes + array.GetValue(i).ToString() + quotes + " ]");
if (i < array.Length - 1)
stringBuilder.Append(", ");
}

return stringBuilder.ToString();
}

public static string PrettyPrintStringArrayFromRaw(byte[] dataRaw)
{
StringBuilder stringBuilder = new StringBuilder();

for (int position = 0; position < dataRaw.Length;)
{
var stringLength = BitConverter.ToInt32(dataRaw, position);
var index = position + 4;
position = position + 4 + stringLength;


stringBuilder.Append("[\"" + GetString(data, index, stringLength) + "\"]");
if (position != data.Length)
stringBuilder.Append("[ \"" + MethodHelpers.ReplaceMultilineWithSymbols(GetString(dataRaw, index, stringLength)) + "\" ]");
if (position != dataRaw.Length)
stringBuilder.Append(", ");
}

Expand Down
25 changes: 25 additions & 0 deletions src/UWPSettingsEditor/Classes/MethodHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;

Expand Down Expand Up @@ -33,5 +34,29 @@ public static T VisualUpwardSearch<T>(this DependencyObject source) where T : cl

return source as T;
}

//ToDo: find a better name for this pls
/// <summary>
/// Method for splitting the data into the actual data + timestamp
/// </summary>
/// <param name="data">Complete data raw</param>
/// <returns>KeyValuePair of data and timestamp</returns>
public static KeyValuePair<byte[], byte[]> SplitDataRaw(byte[] dataRaw)
{
byte[] data = dataRaw.SkipLast(8).ToArray();
byte[] timestamp = dataRaw.Skip(data.Length).ToArray();

return new KeyValuePair<byte[], byte[]>(data, timestamp);
}

public static string ReplaceMultilineWithSymbols(string str)
{
var repStr = str.Replace("\r\n", "\\r\\n").Replace("\r", "\\r").Replace("\n", "\\n");

if (repStr.Length > 256)
repStr = repStr.Substring(0, 256) + "...";

return repStr;
}
}
}
2 changes: 1 addition & 1 deletion src/UWPSettingsEditor/Controls/StringComponent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:UWPSettingsEditor.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TextBox AcceptsReturn="True">
<TextBox x:Name="TextBox" AcceptsReturn="True">

</TextBox>
</UserControl>
3 changes: 2 additions & 1 deletion src/UWPSettingsEditor/Controls/StringComponent.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows.Controls;
using UWPSettingsEditor.Interfaces;
using static UWPSettingsEditor.UWPDeserializer;

namespace UWPSettingsEditor.Controls
{
Expand All @@ -20,7 +21,7 @@ public byte GetValueData()

public void SetValueData(byte[] data)
{
throw new System.NotImplementedException();
TextBox.Text = GetString(data);
}
}
}
15 changes: 8 additions & 7 deletions src/UWPSettingsEditor/Converters/ByteArrayToStringConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ private string DisplayData(byte[] dataRaw, DataTypeEnum dataType)
{
if ((int)dataType > 256 && (int)dataType < 294)
{
byte[] data = dataRaw.SkipLast(8).ToArray();
byte[] timestamp = dataRaw.Skip(data.Length).ToArray();
var timeStampOffsetless = DateTimeOffset.FromFileTime(BitConverter.ToInt64(timestamp, 0));
var splittedDataRaw = MethodHelpers.SplitDataRaw(dataRaw);
var data = splittedDataRaw.Key;
//var timestamp = DateTimeOffset.FromFileTime(BitConverter.ToInt64(timestamp, 0));
//var timeStamp = ;

switch (dataType)
{
case DataTypeEnum.RegUwpByte:
return GetByte(data).ToString("X2");
return GetByte(data).ToString();
case DataTypeEnum.RegUwpInt16:
return GetInt16(data).ToString();
case DataTypeEnum.RegUwpUint16:
Expand All @@ -54,7 +55,7 @@ private string DisplayData(byte[] dataRaw, DataTypeEnum dataType)
case DataTypeEnum.RegUwpBoolean:
return GetBoolean(data).ToString();
case DataTypeEnum.RegUwpString:
return "\"" + GetString(data) + "\"";
return "\"" + MethodHelpers.ReplaceMultilineWithSymbols(GetString(data)) + "\"";
case DataTypeEnum.RegUwpCompositeValue:
return PrettyPrintDictionary(GetCompositeValue(data));
case DataTypeEnum.RegUwpDateTimeOffset:
Expand Down Expand Up @@ -89,11 +90,11 @@ private string DisplayData(byte[] dataRaw, DataTypeEnum dataType)
case DataTypeEnum.RegUwpArrayDouble:
return PrettyPrintArray(GetArray(data.Length, 8, i => GetDouble(data, i)));
case DataTypeEnum.RegUwpArrayChar16:
return PrettyPrintArray(GetArray(data.Length, 2, i => GetChar(data, i)));
return PrettyPrintArray(GetArray(data.Length, 2, i => GetChar(data, i)), "'");
case DataTypeEnum.RegUwpArrayBoolean:
return PrettyPrintArray(GetArray(data.Length, 1, i => GetBoolean(data, i)));
case DataTypeEnum.RegUwpArrayString:
return PrettyPrintStringArray(data);
return PrettyPrintStringArrayFromRaw(data);
case DataTypeEnum.RegUwpArrayDateTimeOffset:
return PrettyPrintArray(GetArray(data.Length, 8, i => GetDateTimeOffset(data, i)));
case DataTypeEnum.RegUwpArrayTimeSpan:
Expand Down
3 changes: 2 additions & 1 deletion src/UWPSettingsEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void PopulateListView(Registry.Abstractions.RegistryKey registryKey)

private void MenuItem_Click(object sender, RoutedEventArgs e)
{
About about = new About();
AboutWindow about = new AboutWindow();
about.ShowDialog();
}

Expand Down Expand Up @@ -247,6 +247,7 @@ private void listView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
if (listViewItem != null)
{
EditValueWindow window = new EditValueWindow((KeyVal)listViewItem.DataContext);
window.Owner = this;
window.ShowDialog();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/UWPSettingsEditor/UWPSettingsEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\About.xaml">
<Page Include="Windows\AboutWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand All @@ -104,8 +104,8 @@
<Compile Include="Windows\EditValueWindow.xaml.cs">
<DependentUpon>EditValueWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\About.xaml.cs">
<DependentUpon>About.xaml</DependentUpon>
<Compile Include="Windows\AboutWindow.xaml.cs">
<DependentUpon>AboutWindow.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="UWPSettingsEditor.About"
<Window x:Class="UWPSettingsEditor.AboutWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace UWPSettingsEditor
/// <summary>
/// Interaction logic for About.xaml
/// </summary>
public partial class About : Window
public partial class AboutWindow : Window
{
public About()
public AboutWindow()
{
InitializeComponent();
}
Expand Down
3 changes: 2 additions & 1 deletion src/UWPSettingsEditor/Windows/EditValueWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ResizeMode="CanResizeWithGrip"
Title="Edit Value"
Height="300" Width="400"
WindowStartupLocation="CenterOwner"
MinHeight="250" MinWidth="400" WindowStyle="ToolWindow">
<Grid>
<Grid HorizontalAlignment="Stretch" Margin="12,12,12,48">
Expand All @@ -23,7 +24,7 @@
</Grid.RowDefinitions>

<TextBlock Grid.Column="0" Height="20" HorizontalAlignment="Center" Text="Value name:" />
<TextBox Grid.Column="2" Height="20" />
<TextBox x:Name="ValueNameTextBox" Grid.Column="2" Height="20" />

<Grid x:Name="ContainerGrid" Grid.Row="2" Grid.ColumnSpan="3" Background="AliceBlue" />
</Grid>
Expand Down
9 changes: 8 additions & 1 deletion src/UWPSettingsEditor/Windows/EditValueWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UWPSettingsEditor.Interfaces;
using UWPSettingsEditor.Controls;
using static UWPSettingsEditor.UWPDeserializer;

namespace UWPSettingsEditor
{
Expand All @@ -9,17 +10,23 @@ namespace UWPSettingsEditor
public partial class EditValueWindow
{
readonly IValueDataSet valueDataSet;
KeyVal currentKeyVal;

public EditValueWindow(KeyVal val)
{
currentKeyVal = val;
var splitted = MethodHelpers.SplitDataRaw(val.Data);

InitializeComponent();
ValueNameTextBox.Text = val.Name;

if (val.DataTypeEnum == DataTypeEnum.RegUwpString)
{
var componentControl = new StringComponent();
ContainerGrid.Children.Add(componentControl);
valueDataSet = componentControl as IValueDataSet;

valueDataSet.SetValueData(val.Data);
valueDataSet.SetValueData(splitted.Key);
}
}

Expand Down

0 comments on commit 46b6023

Please sign in to comment.