Skip to content

Commit

Permalink
添加赞助页面
Browse files Browse the repository at this point in the history
添加一些动图
添加Q&A页面
添加展开侧边栏小标题
添加缺失字体图标安装
添加某些元素中的图标
添加获取抽卡缓存链接功能
添加自动生成错误日志功能
添加几近完整的生成错误报告功能
添加了一些计划中的功能(功能选项不可用)
添加启动程序同时按下Shift强制启动控制台
修改代理按钮提示位置
修复抽卡分析代理与缓存链接冲突问题
修复关于页面版本号与更新界面冲突的问题
修复进入抽卡分析界面时会加载两次的问题
修复导入SRGF后需要重新切换界面才能显示的问题
  • Loading branch information
JamXi233 committed Aug 4, 2023
1 parent bae39a2 commit 4578949
Show file tree
Hide file tree
Showing 27 changed files with 668 additions and 115 deletions.
36 changes: 19 additions & 17 deletions SRTools/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,11 @@

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Shapes;
using SRTools.Depend;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Popups;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -33,12 +16,16 @@ namespace SRTools
{
public partial class App : Application
{
public static bool SDebugMode { get; set; }
// 导入 AllocConsole 和 FreeConsole 函数
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AllocConsole();
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeConsole();
// 导入 GetAsyncKeyState 函数
[DllImport("User32.dll")]
public static extern short GetAsyncKeyState(int vKey);
GetNotify getNotify = new GetNotify();
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
Expand All @@ -55,7 +42,22 @@ public App()
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
// 获取根Frame并导航到初始页面
Init();

bool isShiftPressed = (GetAsyncKeyState(0x10) & 0x8000) != 0;

if (isShiftPressed)
{
Logging.Write("Pressed", 1);
Console.Title = "🆂𝐃𝐞𝐛𝐮𝐠𝐌𝐨𝐝𝐞:SRTools";
TerminalMode.ShowConsole();
SDebugMode = true;
}
else
{
Logging.Write("NoPressed", 1);
}
}

public async void Init()
Expand Down
Binary file added SRTools/Assets/Don_Alipay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SRTools/Assets/Don_Hand.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SRTools/Assets/Don_Hand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SRTools/Assets/Don_Icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SRTools/Assets/Don_Wechat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed SRTools/Assets/StoreLogo.backup(1).png
Binary file not shown.
Binary file removed SRTools/Assets/StoreLogo.backup.png
Binary file not shown.
28 changes: 28 additions & 0 deletions SRTools/Depend/ExceptionSave.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace SRTools.Depend
{
public class ExceptionSave
{
public static async Task Write(string message, int severity, string fileName)
{
// 获取用户文档目录下的JSG-LLC\Panic目录
StorageFolder folder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("JSG-LLC\\Panic", CreationCollisionOption.OpenIfExists);

// 创建或覆盖log.txt文件
StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

// 将ex变量内容写入文件
using (StreamWriter writer = new StreamWriter(await file.OpenStreamForWriteAsync()))
{
await writer.WriteLineAsync(DateTime.Now.ToString() + " [" + severity.ToString() + "] \n" + message);
}
}
}
}
3 changes: 3 additions & 0 deletions SRTools/Depend/GachaRecords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using Newtonsoft.Json.Linq;
using static Vanara.PInvoke.User32.RAWINPUT;
using Newtonsoft.Json;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml;
using SRTools.Views;

namespace SRTools.Depend
{
Expand Down
2 changes: 1 addition & 1 deletion SRTools/Depend/GetNetData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<bool> DownloadFileWithProgressAsync(string fileUrl, string loc

bytesDownloaded += bytesRead;
double progressPercentage = (double)bytesDownloaded / totalBytes * 100;
progress.Report(progressPercentage);
progress.Report(progressPercentage);

}
}
Expand Down
72 changes: 72 additions & 0 deletions SRTools/Depend/InstallFont.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.System;

namespace SRTools.Depend
{
class InstallFont
{

// Import the AddFontResource function from gdi32.dll
[DllImport("gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)]
public static extern int AddFontResource([In] [MarshalAs(UnmanagedType.LPWStr)]
string lpFileName);

// Import the SendMessage function from user32.dll
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam,
IntPtr lParam, uint fuFlags, uint uTimeout, out IntPtr lpdwResult);

public static async Task<int> SegoeFluentFontAsync()
{
GetNetData getNetData;
string UpdateFileFolder = "\\JSG-LLC\\Fonts\\";
string UpdateFileName = "SegoeFluentIcons.zip";
string userDocumentsFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string localFilePath = Path.Combine(userDocumentsFolderPath + UpdateFileFolder, UpdateFileName);
var progress = new Progress<double>();
getNetData = new GetNetData();
try
{
await getNetData.DownloadFileWithProgressAsync("https://aka.ms/SegoeFluentIcons", localFilePath, progress);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

string fontZipFile = Path.Combine(userDocumentsFolderPath + UpdateFileFolder, UpdateFileName);
string tempFolder = Path.Combine(userDocumentsFolderPath + UpdateFileFolder, "temp");
// 创建临时文件夹
if (!Directory.Exists(tempFolder))
{
Directory.CreateDirectory(tempFolder);
}
Directory.Delete(tempFolder, true);
// 解压 zip 文件到临时文件夹中
ZipFile.ExtractToDirectory(fontZipFile, tempFolder);

// 获取字体文件路径
StorageFile fontFile = await StorageFile.GetFileFromPathAsync(tempFolder + "\\Segoe Fluent Icons.ttf");

if (fontFile != null)
{
// 启动 Windows 默认的字体查看器
Process.Start("fontview", fontFile.Path);

// 字体已成功安装
return 0;
}
else { return 1; }
}
}
}
2 changes: 1 addition & 1 deletion SRTools/Depend/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace SRTools.Depend
{
internal class Logging
{
public static void Write(string Info, int Mode, string ProgramName = null)
public static void Write(string Info, int Mode = 0, string ProgramName = null)
{
if (Mode == 0) { AnsiConsole.Write(new Markup("[bold White][[INFO]][/]"));Console.WriteLine(Info); }
else if (Mode == 1) { AnsiConsole.Write(new Markup("[bold Yellow][[WARN]][/]")); Console.WriteLine(Info); }
Expand Down
62 changes: 58 additions & 4 deletions SRTools/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,61 @@
</NavigationView.Resources>

<NavigationView.MenuItems>
<NavigationViewItem Content="首页" Icon="Home" Tag="home" IsSelected="True" />
<NavigationViewItem Content="开始游戏" Icon="Play" Tag="startgame"/>
<NavigationViewItem Content="抽卡记录" Icon="SolidStar" Tag="gacha"/>
<NavigationViewItemHeader Content="启动器"/>
<NavigationViewItem Content="首页" Tag="home" IsSelected="True">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xE80F;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="开始游戏" Tag="startgame">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xE768;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItemHeader Content="工具箱"/>
<NavigationViewItem Content="抽卡记录" Tag="gacha">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xe734;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="状态信息(计划中)" Tag="info" SelectsOnInvoked="False" IsEnabled="False">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xf180;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="活动时间表(计划中)" Tag="event" SelectsOnInvoked="False" IsEnabled="False">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xE787;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="伤害计算器(待定)" Tag="calc" SelectsOnInvoked="False" IsEnabled="False">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xe8ef;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>

</NavigationView.MenuItems>

<NavigationView.FooterMenuItems>

<NavigationViewItem Content="账号管理(计划中)" Tag="account" SelectsOnInvoked="False" IsEnabled="False">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xe77b;"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="帮助文档" Tag="question">
<NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe Fluent Icons" Glyph="&#xe897;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="赞助" Tag="donation">
<NavigationViewItem.Icon>
<ImageIcon Source="ms-appx:///Assets/Don_Icon.gif"/>
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationView.FooterMenuItems>


<Frame x:Name="MainFrame"/>

</NavigationView>
Expand Down Expand Up @@ -108,7 +158,11 @@
</StackPanel>

</Grid>
<InfoBar x:Name="infoBar" IsOpen="False" Severity="Error" Title="" Message="" VerticalAlignment="Top" HorizontalAlignment="Right" Width="400" Height="auto" Margin="0 64 12 0"/>
<InfoBar x:Name="infoBar" IsOpen="False" Severity="Error" Title="" Message="" VerticalAlignment="Top" HorizontalAlignment="Right" Width="400" Height="auto" Margin="0 64 12 0">
<InfoBar.ActionButton>
<Button Content="打开文件夹" Click="ExpectionFolderOpen_Click"/>
</InfoBar.ActionButton>
</InfoBar>
</Grid>

</Window>
53 changes: 35 additions & 18 deletions SRTools/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
using System.Threading;
using System.Security.AccessControl;
using Spectre.Console;
using Windows.System;
using Windows.UI.Core;
using Org.BouncyCastle.Asn1.X509;
using Windows.Storage.AccessCache;

namespace SRTools
{
Expand All @@ -36,7 +40,7 @@ public partial class MainWindow : Window
private AppWindow appWindow;
private AppWindowTitleBar titleBar;
private SystemBackdrop backdrop;

string ExpectionFileName;
string backgroundUrl = "";

private const string KeyPath = "SRTools";
Expand Down Expand Up @@ -66,6 +70,7 @@ public MainWindow()
InitializeMicaBackground();
InitializeWindowProperties();
BackgroundImage();
CleanUpdate();

_getNetData = new GetNetData();
}
Expand Down Expand Up @@ -253,7 +258,7 @@ private async void DependDownload_Click(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{
depend_Info.Text = ex.Message;
throw new Exception(ex.Message);
}

if (downloadResult)
Expand Down Expand Up @@ -352,7 +357,6 @@ private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelec
{
NavigationViewItem item = args.SelectedItem as NavigationViewItem;
string tag = item.Tag.ToString();
Type pageType = null;
if (args.IsSettingsSelected)
{
MainFrame.Navigate(typeof(AboutView));
Expand All @@ -362,22 +366,19 @@ private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelec
switch (args.SelectedItemContainer.Tag.ToString())
{
case "home":
// 导航到主页
MainFrame.Navigate(typeof(MainView));
break;
case "startgame":
// 导航到启动游戏页
MainFrame.Navigate(typeof(StartGameView));
break;
case "gacha":
// 导航到启动游戏页
pageType = typeof(GachaView);
GachaView gachaViewInstance = MainFrame.Content as GachaView;
if (gachaViewInstance == null)
{
gachaViewInstance = new GachaView();
}
MainFrame.Navigate(pageType);
MainFrame.Navigate(typeof(GachaView));
break;
case "question":
MainFrame.Navigate(typeof(QuestionView));
break;
case "donation":
MainFrame.Navigate(typeof(DonationView));
break;
}
}
Expand All @@ -396,21 +397,37 @@ public class ApiResponse
public Data data { get; set; }
}

private void OnUnhandledErrorDetected(object sender, Windows.ApplicationModel.Core.UnhandledErrorDetectedEventArgs e)
private void CleanUpdate()
{
string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "JSG-LLC", "Updates");
if (Directory.Exists(folderPath)) Directory.Delete(folderPath, true);
}

private async void OnUnhandledErrorDetected(object sender, Windows.ApplicationModel.Core.UnhandledErrorDetectedEventArgs e)
{
try
{
e.UnhandledError.Propagate();
}
catch (Exception ex)
{
ExpectionFileName = string.Format("SRTools_Panic_{0:yyyyMMdd_HHmmss}.SRToolsPanic", DateTime.Now);
infoBar.IsOpen = true;
infoBar.Title = "严重错误";
infoBar.Message = ex.Message;
AnsiConsole.WriteException(ex,
ExceptionFormats.ShortenPaths | ExceptionFormats.ShortenTypes |
ExceptionFormats.ShortenMethods | ExceptionFormats.ShowLinks);
infoBar.Message = ex.Message.Trim()+"\n\n已生成错误报告\n如再次尝试仍会重现错误\n您可以到Github提交Issue";
AnsiConsole.WriteException(ex,ExceptionFormats.ShortenPaths | ExceptionFormats.ShortenTypes | ExceptionFormats.ShortenMethods | ExceptionFormats.ShowLinks);
await ExceptionSave.Write("应用程序:" + ex.Source+"\n错误标题:"+ex.Message + "\n堆栈跟踪:\n" + ex.StackTrace + "\n结束代码:" + ex.HResult, 1,ExpectionFileName);
}
}

private async void ExpectionFolderOpen_Click(object sender, RoutedEventArgs e)
{
StorageFolder folder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("JSG-LLC\\Panic", CreationCollisionOption.OpenIfExists);
// 获取指定文件
StorageFile file = await folder.GetFileAsync(ExpectionFileName);
// 将文件添加到最近使用列表中
StorageApplicationPermissions.MostRecentlyUsedList.Add(file);
await Launcher.LaunchFolderAsync(folder, new FolderLauncherOptions { ItemsToSelect = { file } });
}
}
}
Loading

0 comments on commit 4578949

Please sign in to comment.