mirror of
https://github.com/BrianLima/UWPHook.git
synced 2024-11-12 01:10:26 +00:00
Trying to serialize and deserialize Json
This commit is contained in:
parent
18d659a6b9
commit
03b7fff6ce
1030
.vs/config/applicationhost.config
Normal file
1030
.vs/config/applicationhost.config
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using UWPHook.Properties;
|
||||
|
||||
namespace UWPHook
|
||||
{
|
||||
@ -15,6 +18,7 @@ public class GameModel
|
||||
public GameModel()
|
||||
{
|
||||
games = new ObservableCollection<Game>();
|
||||
var y = JsonConvert.DeserializeObject<GameModel>("games.json");
|
||||
}
|
||||
|
||||
private ObservableCollection<Game> _games;
|
||||
@ -25,19 +29,23 @@ public ObservableCollection<Game> games
|
||||
set { _games = value; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Add(Game game)
|
||||
{
|
||||
this.games.Add(game);
|
||||
}
|
||||
|
||||
public string game_alias { get; set; }
|
||||
public string game_path { get; set; }
|
||||
|
||||
public void Store()
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
using (StreamWriter sw = new StreamWriter(@"games.json")) {
|
||||
using (JsonWriter writer = new JsonTextWriter(sw)){
|
||||
serializer.Serialize(writer, _games);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Game:INotifyPropertyChanged
|
||||
public class Game : INotifyPropertyChanged
|
||||
{
|
||||
private string _game_alias;
|
||||
|
||||
@ -55,7 +63,6 @@ public string game_path
|
||||
set { _game_path = value; }
|
||||
}
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged(string Obj)
|
||||
@ -65,6 +72,5 @@ private void NotifyPropertyChanged(string Obj)
|
||||
this.PropertyChanged(this, new PropertyChangedEventArgs(Obj));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
|
||||
private void addButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
games.Store();
|
||||
games.Add(new Game{ game_alias = alias_textBox.Text, game_path = path_textBox.Text });
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,10 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
@ -87,6 +91,10 @@
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="games.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
|
BIN
UWPHook/bin/Debug/Newtonsoft.Json.dll
Normal file
BIN
UWPHook/bin/Debug/Newtonsoft.Json.dll
Normal file
Binary file not shown.
9229
UWPHook/bin/Debug/Newtonsoft.Json.xml
Normal file
9229
UWPHook/bin/Debug/Newtonsoft.Json.xml
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
15
UWPHook/bin/Debug/games.json
Normal file
15
UWPHook/bin/Debug/games.json
Normal file
@ -0,0 +1,15 @@
|
||||
[
|
||||
|
||||
{
|
||||
"game_alias": "teste",
|
||||
"game_path": "teste"
|
||||
},
|
||||
{
|
||||
"game_alias": "teste",
|
||||
"game_path": "teste"
|
||||
},
|
||||
{
|
||||
"game_alias": "teste",
|
||||
"game_path": "teste"
|
||||
}
|
||||
]
|
3
UWPHook/games.json
Normal file
3
UWPHook/games.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -12,3 +12,6 @@ c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\U
|
||||
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\UWPHook.csproj.GenerateResource.Cache
|
||||
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\UWPHook.exe
|
||||
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\obj\Debug\UWPHook.pdb
|
||||
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\bin\Debug\games.json
|
||||
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\bin\Debug\Newtonsoft.Json.dll
|
||||
c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\bin\Debug\Newtonsoft.Json.xml
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\App.xaml
|
||||
11151548125
|
||||
|
||||
6-470569544
|
||||
131569487696
|
||||
14-1541981460
|
||||
MainWindow.xaml;
|
||||
|
||||
False
|
||||
|
@ -13,7 +13,7 @@ c:\users\brian\documents\visual studio 2015\Projects\UWPHook\UWPHook\App.xaml
|
||||
11151548125
|
||||
|
||||
10-1855892474
|
||||
131569487696
|
||||
14-1541981460
|
||||
MainWindow.xaml;
|
||||
|
||||
False
|
||||
|
4
UWPHook/packages.config
Normal file
4
UWPHook/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
|
||||
</packages>
|
BIN
packages/Newtonsoft.Json.9.0.1/Newtonsoft.Json.9.0.1.nupkg
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/Newtonsoft.Json.9.0.1.nupkg
vendored
Normal file
Binary file not shown.
BIN
packages/Newtonsoft.Json.9.0.1/lib/net20/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/lib/net20/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
9793
packages/Newtonsoft.Json.9.0.1/lib/net20/Newtonsoft.Json.xml
vendored
Normal file
9793
packages/Newtonsoft.Json.9.0.1/lib/net20/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.9.0.1/lib/net35/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/lib/net35/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
8922
packages/Newtonsoft.Json.9.0.1/lib/net35/Newtonsoft.Json.xml
vendored
Normal file
8922
packages/Newtonsoft.Json.9.0.1/lib/net35/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.9.0.1/lib/net40/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/lib/net40/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
9229
packages/Newtonsoft.Json.9.0.1/lib/net40/Newtonsoft.Json.xml
vendored
Normal file
9229
packages/Newtonsoft.Json.9.0.1/lib/net40/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
9229
packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.xml
vendored
Normal file
9229
packages/Newtonsoft.Json.9.0.1/lib/net45/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/lib/netstandard1.0/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
8756
packages/Newtonsoft.Json.9.0.1/lib/netstandard1.0/Newtonsoft.Json.xml
vendored
Normal file
8756
packages/Newtonsoft.Json.9.0.1/lib/netstandard1.0/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.9.0.1/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
8409
packages/Newtonsoft.Json.9.0.1/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
8409
packages/Newtonsoft.Json.9.0.1/lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/Newtonsoft.Json.9.0.1/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
BIN
packages/Newtonsoft.Json.9.0.1/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll
vendored
Normal file
Binary file not shown.
8756
packages/Newtonsoft.Json.9.0.1/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
8756
packages/Newtonsoft.Json.9.0.1/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.xml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
116
packages/Newtonsoft.Json.9.0.1/tools/install.ps1
vendored
Normal file
116
packages/Newtonsoft.Json.9.0.1/tools/install.ps1
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
param($installPath, $toolsPath, $package, $project)
|
||||
|
||||
# open json.net splash page on package install
|
||||
# don't open if json.net is installed as a dependency
|
||||
|
||||
try
|
||||
{
|
||||
$url = "http://www.newtonsoft.com/json/install?version=" + $package.Version
|
||||
$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
|
||||
|
||||
if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
|
||||
{
|
||||
# user is installing from VS NuGet console
|
||||
# get reference to the window, the console host and the input history
|
||||
# show webpage if "install-package newtonsoft.json" was last input
|
||||
|
||||
$consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
|
||||
|
||||
$props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
|
||||
$prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
|
||||
if ($prop -eq $null) { return }
|
||||
|
||||
$hostInfo = $prop.GetValue($consoleWindow)
|
||||
if ($hostInfo -eq $null) { return }
|
||||
|
||||
$history = $hostInfo.WpfConsole.InputHistory.History
|
||||
|
||||
$lastCommand = $history | select -last 1
|
||||
|
||||
if ($lastCommand)
|
||||
{
|
||||
$lastCommand = $lastCommand.Trim().ToLower()
|
||||
if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
|
||||
{
|
||||
$dte2.ItemOperations.Navigate($url) | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# user is installing from VS NuGet dialog
|
||||
# get reference to the window, then smart output console provider
|
||||
# show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation
|
||||
|
||||
$instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
|
||||
$consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
|
||||
if ($instanceField -eq $null -or $consoleField -eq $null) { return }
|
||||
|
||||
$instance = $instanceField.GetValue($null)
|
||||
|
||||
if ($instance -eq $null) { return }
|
||||
|
||||
$consoleProvider = $consoleField.GetValue($instance)
|
||||
if ($consoleProvider -eq $null) { return }
|
||||
|
||||
$console = $consoleProvider.CreateOutputConsole($false)
|
||||
|
||||
$messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
|
||||
[System.Reflection.BindingFlags]::NonPublic)
|
||||
if ($messagesField -eq $null) { return }
|
||||
|
||||
$messages = $messagesField.GetValue($console)
|
||||
if ($messages -eq $null) { return }
|
||||
|
||||
$operations = $messages -split "=============================="
|
||||
|
||||
$lastOperation = $operations | select -last 1
|
||||
|
||||
if ($lastOperation)
|
||||
{
|
||||
$lastOperation = $lastOperation.ToLower()
|
||||
|
||||
$lines = $lastOperation -split "`r`n"
|
||||
|
||||
$installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
|
||||
|
||||
if ($installMatch)
|
||||
{
|
||||
$dte2.ItemOperations.Navigate($url) | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
$pmPane = $dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item("Package Manager")
|
||||
|
||||
$selection = $pmPane.TextDocument.Selection
|
||||
$selection.StartOfDocument($false)
|
||||
$selection.EndOfDocument($true)
|
||||
|
||||
if ($selection.Text.StartsWith("Attempting to gather dependencies information for package 'Newtonsoft.Json." + $package.Version + "'"))
|
||||
{
|
||||
# don't show on upgrade
|
||||
if (!$selection.Text.Contains("Removed package"))
|
||||
{
|
||||
$dte2.ItemOperations.Navigate($url) | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
# stop potential errors from bubbling up
|
||||
# worst case the splash page won't open
|
||||
}
|
||||
}
|
||||
|
||||
# still yolo
|
Loading…
Reference in New Issue
Block a user