Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Unowhy Tools WPF/Services/ApplicationHostService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;
using System.IO.Pipes;
Expand Down Expand Up @@ -72,7 +72,7 @@ private async Task HandleActivationAsync()
{
if (!await UT.CheckTray())
{
Task.Run(() => UTTwait());
_ = Task.Run(UTTwait);
_testWindowService.Show<Views.TrayWindow>();
}
else
Expand Down
55 changes: 38 additions & 17 deletions Unowhy Tools WPF/UT.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*


."I!ii>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>ii!I".
Expand Down Expand Up @@ -120,6 +120,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
Expand Down Expand Up @@ -152,6 +153,10 @@ namespace Unowhy_Tools
{
public partial class UT
{
private static readonly HttpClient _httpClient = new HttpClient();
private static readonly ConcurrentDictionary<string, string> _wmiCache = new ConcurrentDictionary<string, string>(StringComparer.Ordinal);
private static readonly ConcurrentDictionary<string, BitmapImage> _resourceImageCache = new ConcurrentDictionary<string, BitmapImage>(StringComparer.OrdinalIgnoreCase);

#region DLL
[DllImport("DwmApi")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
Expand Down Expand Up @@ -229,7 +234,6 @@ public static string getverbuild()

public static async Task<bool> newver()
{
var web = new HttpClient();
string newver = await UT.OnlineDatas.GetUpdates("utnewver");
int newverint = Convert.ToInt32(newver);
if (verfull < newverint)
Expand Down Expand Up @@ -982,25 +986,25 @@ public static async Task Set(string name, string value)
}
}

public static async Task DeployDABack()
public static Task DeployDABack()
{
var mainWindow = System.Windows.Application.Current.MainWindow as Unowhy_Tools_WPF.Views.MainWindow;
mainWindow.DeployDABack();
return mainWindow.DeployDABack();
}

public static async Task DeployBack(Type type, Grid grid, Border border)
public static Task DeployBack(Type type, Grid grid, Border border)
{
var mainWindow = System.Windows.Application.Current.MainWindow as Unowhy_Tools_WPF.Views.MainWindow;
mainWindow.DeployBack(type, grid, border);
return mainWindow.DeployBack(type, grid, border);
}

public static async Task UnDeployBack()
public static Task UnDeployBack()
{
var mainWindow = System.Windows.Application.Current.MainWindow as Unowhy_Tools_WPF.Views.MainWindow;
mainWindow.UnDeployBack();
return mainWindow.UnDeployBack();
}

public static async void NavigateTo(Type page)
public static void NavigateTo(Type page)
{
var mainWindow = System.Windows.Application.Current.MainWindow as Unowhy_Tools_WPF.Views.MainWindow;
mainWindow.Navigate(page);
Expand Down Expand Up @@ -4106,6 +4110,12 @@ public static async Task Check(string step)

public static string GetWMI(string classname, string propertyname)
{
string cacheKey = classname + "|" + propertyname;
if (_wmiCache.TryGetValue(cacheKey, out var cached))
{
return cached;
}

Write2Log("Get WMI: " + classname + " | " + propertyname);

try
Expand All @@ -4114,24 +4124,27 @@ public static string GetWMI(string classname, string propertyname)
ManagementObjectCollection result = searcher.Get();
foreach (ManagementObject obj in result)
{
Write2Log("Get WMI done: " + obj[propertyname]?.ToString());
return obj[propertyname]?.ToString();
string value = obj[propertyname]?.ToString() ?? "null";
Write2Log("Get WMI done: " + value);
_wmiCache.TryAdd(cacheKey, value);
return value;
}
Write2Log("Get WMI fail");
_wmiCache.TryAdd(cacheKey, "null");
return "null";
}
catch
{
Write2Log("Get WMI fail");
_wmiCache.TryAdd(cacheKey, "null");
return "null";
}
}

public static async Task DlFilewithProgress(string url, string path, IProgress<double> progress, CancellationToken token)
{
Write2Log("Downloading file: From \"" + url + "\" to \"" + path + "\"");
HttpClient client = new HttpClient();
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
using var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);

if (!response.IsSuccessStatusCode)
{
Expand All @@ -4144,8 +4157,8 @@ public static async Task DlFilewithProgress(string url, string path, IProgress<d
int updateInterval = 100;
DateTime lastUpdate = DateTime.Now;

using (Stream stream = await response.Content.ReadAsStreamAsync())
using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
await using (Stream stream = await response.Content.ReadAsStreamAsync(token))
await using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
{
byte[] buffer = new byte[1024*1024];
int bytesRead;
Expand Down Expand Up @@ -4186,8 +4199,16 @@ public static async Task Extract(string file, string outPath)

public static BitmapImage GetImgSource(string resname)
{
BitmapImage bmp = new BitmapImage(new System.Uri("pack://application:,,,/Resources/" + resname));
return bmp;
return _resourceImageCache.GetOrAdd(resname, static key =>
{
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.UriSource = new Uri("pack://application:,,,/Resources/" + key);
bmp.EndInit();
bmp.Freeze();
return bmp;
});
}

public static ImageSource GetImageSourceFromExe(string path)
Expand Down
4 changes: 2 additions & 2 deletions Unowhy Tools WPF/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Win32;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -70,7 +70,7 @@ public MainWindow(INavigationService navigationService, IPageService pageService

SnackBarService = _snackbarService;

applylang();
Loaded += async (_, __) => await applylang();
this.KeyDown += MainWindow_KonamiKeyDown;
this.KeyUp += MainWindow_KonamiKeyUp;
}
Expand Down
6 changes: 3 additions & 3 deletions Unowhy Tools WPF/Views/Pages/About.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.Diagnostics;
Expand Down Expand Up @@ -33,8 +33,8 @@ public DashboardViewModel ViewModel

public async void GoUpdater(object sender, RoutedEventArgs e)
{
UT.anim.RegisterParent(RootGrid, RootBorder);
UT.anim.AnimParent("zoomout2");
await UT.anim.RegisterParent(RootGrid, RootBorder);
await UT.anim.AnimParent("zoomout2");
await Task.Delay(500);
UT.NavigateTo(typeof(Updater));
}
Expand Down
4 changes: 2 additions & 2 deletions Unowhy Tools WPF/Views/Pages/AddUser.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -39,7 +39,7 @@ public async void InitAnim(object sender, RoutedEventArgs e)
}

await UT.DeployBack(typeof(Customize), RootGrid, RootBorder);
UT.anim.BorderZoomOut(RootBorder);
await UT.anim.BorderZoomOut(RootBorder);

foreach (UIElement element in RootStack.Children)
{
Expand Down
5 changes: 2 additions & 3 deletions Unowhy Tools WPF/Views/Pages/Dashboard.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -50,7 +50,7 @@ public async void Init(object sender, EventArgs e)

lababout2.Text = ver;

applylang();
await applylang();
pcname.Text = UT.GetLine(UTdata.HostName, 1);

if (await UT.CheckInternet())
Expand All @@ -62,7 +62,6 @@ public async void Init(object sender, EventArgs e)
{
Color white = (Color)ColorConverter.ConvertFromString("#FFFFFF");
Color gray = (Color)ColorConverter.ConvertFromString("#bebebe");
var web = new HttpClient();
string newver = await UT.OnlineDatas.GetUpdates("utnewver");
newver = newver.Insert(2, ".");
newver = newver.Replace("\n", "");
Expand Down
9 changes: 5 additions & 4 deletions Unowhy Tools WPF/Views/Pages/DrvCloud.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -32,6 +32,8 @@ public DashboardViewModel ViewModel
get;
}

private static readonly HttpClient _http = new HttpClient();

public void GoForw(object sender, RoutedEventArgs e)
{
//UT.anim.TransitionForw(RootGrid);
Expand Down Expand Up @@ -314,11 +316,10 @@ public async Task SyncWithCloud()
SkeletonStack.Visibility = Visibility.Collapsed;

string datasurl = UT.online_datas;
HttpClient web = new HttpClient();
HttpResponseMessage rep = await web.GetAsync(datasurl);
HttpResponseMessage rep = await _http.GetAsync(datasurl);
if (rep.StatusCode == HttpStatusCode.OK)
{
string jsonContent = await web.GetStringAsync(datasurl);
string jsonContent = await _http.GetStringAsync(datasurl);
dynamic jsonObject = JsonConvert.DeserializeObject(jsonContent);
if (jsonObject.drivers != null && jsonObject.drivers.Count > 0)
{
Expand Down
28 changes: 21 additions & 7 deletions Unowhy Tools WPF/Views/Pages/PCinfo.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -18,6 +18,7 @@ namespace Unowhy_Tools_WPF.Views.Pages;
public partial class PCinfo : INavigableView<DashboardViewModel>
{
UT.Data UTdata = new UT.Data();
private string _tempWallpaperPath;

public DashboardViewModel ViewModel
{
Expand Down Expand Up @@ -91,11 +92,24 @@ public async Task infoapply()
{
imgwv.Source = new BitmapImage(new System.Uri("pack://application:,,,/Resources/win10.png"));
}
Random rand = new Random();
int random = rand.Next(0, 1000000);
File.Copy(Environment.GetEnvironmentVariable("USERPROFILE") + "\\AppData\\Roaming\\Microsoft\\Windows\\Themes\\TranscodedWallpaper", Environment.GetEnvironmentVariable("TEMP") + $"\\TranscodedWallpaper_{random}.jpg");
string curentbgpath = Environment.GetEnvironmentVariable("TEMP") + $"\\TranscodedWallpaper_{random}.jpg";
bgimg.Source = new BitmapImage(new System.Uri(curentbgpath));
try
{
if (!string.IsNullOrWhiteSpace(_tempWallpaperPath) && File.Exists(_tempWallpaperPath))
{
File.Delete(_tempWallpaperPath);
}

string source = Environment.GetEnvironmentVariable("USERPROFILE") + "\\AppData\\Roaming\\Microsoft\\Windows\\Themes\\TranscodedWallpaper";
string dest = Path.Combine(Environment.GetEnvironmentVariable("TEMP") ?? Path.GetTempPath(), $"TranscodedWallpaper_{Guid.NewGuid():N}.jpg");
File.Copy(source, dest, true);
_tempWallpaperPath = dest;

bgimg.Source = new BitmapImage(new System.Uri(dest));
}
catch
{
// best-effort wallpaper; ignore failures
}
}

public async void InitAnim(object sender, RoutedEventArgs e)
Expand All @@ -112,7 +126,7 @@ public async void InitAnim(object sender, RoutedEventArgs e)
bgimg.Visibility = Visibility.Hidden;

await UT.DeployBack(typeof(Dashboard), RootGrid, RootBorder);
UT.anim.BorderZoomOut(RootBorder);
await UT.anim.BorderZoomOut(RootBorder);

await infoapply();

Expand Down
4 changes: 1 addition & 3 deletions Unowhy Tools WPF/Views/Pages/Updater.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Web.WebView2.Wpf;
using Microsoft.Web.WebView2.Wpf;
using Microsoft.Win32.TaskScheduler;
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -169,7 +169,6 @@ public async void CheckButton_Click(object sender, RoutedEventArgs e)
if (await UT.version.newver())
{
labimg.Source = UT.GetImgSource("yes.png");
var web = new HttpClient();
string newver = await UT.OnlineDatas.GetUpdates("utnewver");
newver = newver.Insert(2, ".");
newver = newver.Replace("\n", "");
Expand All @@ -183,7 +182,6 @@ public async void CheckButton_Click(object sender, RoutedEventArgs e)
else if (UT.version.isdeb())
{
labimg.Source = UT.GetImgSource("yes.png");
var web = new HttpClient();
string newver = await UT.OnlineDatas.GetUpdates("utnewver");
newver = newver.Insert(2, ".");
newver = newver.Replace("\n", "");
Expand Down
14 changes: 7 additions & 7 deletions Unowhy Tools WPF/Views/Pages/Wifi.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand All @@ -23,6 +23,7 @@ namespace Unowhy_Tools_WPF.Views.Pages;
public partial class Wifi : INavigableView<DashboardViewModel>
{
UT.Data UTdata = new UT.Data();
private static readonly HttpClient _http = new HttpClient();

public DashboardViewModel ViewModel
{
Expand All @@ -40,7 +41,7 @@ public async void GoForw(object sender, RoutedEventArgs e)

public async void Init(object sender, EventArgs e)
{
applylang();
await applylang();
string confserv = await UT.Config.Get("ConfServer");
if (confserv == "idf")
{
Expand Down Expand Up @@ -78,7 +79,7 @@ public async void InitAnim(object sender, RoutedEventArgs e)
}

await UT.DeployBack(typeof(Dashboard), RootGrid, RootBorder);
UT.anim.BorderZoomOut(RootBorder);
await UT.anim.BorderZoomOut(RootBorder);

foreach (UIElement element in RootGrid2.Children)
{
Expand Down Expand Up @@ -219,7 +220,6 @@ public async Task Get()
await UT.waitstatus.open(await UT.GetLang("wait.get"), "clouddl.png");
await Task.Delay(1000);

var web = new HttpClient();
string sn = serial.Text;
string preurl = "null";
if (confserv_idf.IsSelected == true)
Expand All @@ -232,7 +232,7 @@ public async Task Get()
}
string configurl = $"{preurl}/devices/{sn}/configuration";

HttpResponseMessage response = await web.GetAsync(configurl);
HttpResponseMessage response = await _http.GetAsync(configurl);
if (response.StatusCode == HttpStatusCode.OK)
{
DoubleAnimation translateAnimation = new DoubleAnimation
Expand All @@ -248,7 +248,7 @@ public async Task Get()
transform.BeginAnimation(TranslateTransform.XProperty, translateAnimation);
await Task.Delay(500);

string g = await web.GetStringAsync(configurl);
string g = await _http.GetStringAsync(configurl);
string jsonString = g;
List<dynamic> dataList = JsonConvert.DeserializeObject<List<dynamic>>(jsonString);

Expand All @@ -266,7 +266,7 @@ public async Task Get()

foreach (var url in urlList)
{
JObject json = JObject.Parse(await web.GetStringAsync(url));
JObject json = JObject.Parse(await _http.GetStringAsync(url));
mergedJson.Merge(json);
}

Expand Down
Loading