上传文件至 TslTools
This commit is contained in:
parent
eb994a812f
commit
a5c3a264f8
5 changed files with 244 additions and 0 deletions
14
TslTools/App.xaml.cs
Normal file
14
TslTools/App.xaml.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace TslTools
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
|
||||
}
|
37
TslTools/MainWindow.xaml
Normal file
37
TslTools/MainWindow.xaml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<Window x:Class="TslTools.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="TslTools"
|
||||
Height="450"
|
||||
Width="800"
|
||||
Icon="pack://application:,,,/Resource/Icon/MWIcon.ico"
|
||||
ResizeMode="NoResize">
|
||||
<Grid>
|
||||
<TextBox x:Name="LogTextBox"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Auto"
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
Margin="40,42,488,206"/>
|
||||
<TextBlock
|
||||
Foreground="Black"
|
||||
HorizontalAlignment="Left"
|
||||
FontSize="20"
|
||||
FontFamily="Alimama FangYuanTi VF SemiBold"
|
||||
Margin="132,10,0,-14" Width="58"><Run Text="Log"/><Run Language="zh-cn" Text="s"/></TextBlock>
|
||||
<TextBox x:Name="TrashLogTextBox"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HorizontalScrollBarVisibility="Auto"
|
||||
IsReadOnly="True"
|
||||
TextWrapping="Wrap"
|
||||
Margin="468,42,60,206"/>
|
||||
<TextBlock
|
||||
Foreground="Black"
|
||||
HorizontalAlignment="Left"
|
||||
FontSize="20"
|
||||
FontFamily="Alimama FangYuanTi VF SemiBold"
|
||||
Margin="552,10,0,-14" Width="110" Text="Clear Logs"/>
|
||||
<Button x:Name="btnCleanDmp" Content="Clean DMP Files" Margin="312,159,332,206" Click="btnCleanDmp_Click"/>
|
||||
<Button x:Name="btnCleanLogs" Content="Clean Logs Folder" Margin="312,42,332,323" Click="btnCleanLogs_Click"/>
|
||||
</Grid>
|
||||
</Window>
|
167
TslTools/MainWindow.xaml.cs
Normal file
167
TslTools/MainWindow.xaml.cs
Normal file
|
@ -0,0 +1,167 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace TslTools
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly string processName = "TslGame";
|
||||
private readonly string batFilePath = @"D:\TslGameServer\TslGame\Binaries\Win64\LocalServer.bat";
|
||||
private Timer processCheckTimer;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Log("Monitoring process initiated...");
|
||||
StartProcessCheck();
|
||||
}
|
||||
|
||||
private void StartProcessCheck()
|
||||
{
|
||||
processCheckTimer = new Timer(CheckProcess, null, 0, 3000);
|
||||
}
|
||||
|
||||
private void CheckProcess(object state)
|
||||
{
|
||||
bool processExists = Process.GetProcessesByName(processName).Length > 0;
|
||||
|
||||
if (!processExists)
|
||||
{
|
||||
Log("TslGame not found! Attempting to restart...");
|
||||
StartLocalServer();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartLocalServer()
|
||||
{
|
||||
if (File.Exists(batFilePath))
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = batFilePath,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using (Process process = Process.Start(startInfo))
|
||||
{
|
||||
process.WaitForExit();
|
||||
string output = process.StandardOutput.ReadToEnd();
|
||||
string error = process.StandardError.ReadToEnd();
|
||||
|
||||
if (!string.IsNullOrEmpty(output))
|
||||
{
|
||||
Log(output);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
Log($"启动失败,错误信息:{error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("An error occurred during the attempt to start!");
|
||||
}
|
||||
}
|
||||
|
||||
private void Log(string message)
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
LogTextBox.AppendText(message + Environment.NewLine);
|
||||
LogTextBox.ScrollToEnd();
|
||||
});
|
||||
}
|
||||
|
||||
// 清理.dmp文件按钮点击事件
|
||||
private void btnCleanDmp_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string currentDirectory = Environment.CurrentDirectory;
|
||||
string[] dmpFiles = Directory.GetFiles(currentDirectory, "*.dmp");
|
||||
int deletedCount = 0;
|
||||
|
||||
foreach (string file in dmpFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
deletedCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"删除文件 {file} 时发生错误:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
if (deletedCount > 0)
|
||||
{
|
||||
TrashLog($"{deletedCount} DMP file has been deleted");
|
||||
}
|
||||
else
|
||||
{
|
||||
TrashLog("No .dmp files detected, no need to clean.");
|
||||
}
|
||||
}
|
||||
|
||||
// 清理Logs文件夹按钮点击事件
|
||||
private void btnCleanLogs_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string logsDirectory = @"C:\Users\Administrator\AppData\Local\TslGame\Saved\Logs";
|
||||
string[] files = Directory.GetFiles(logsDirectory);
|
||||
int deletedCount = 0;
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
deletedCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"删除文件 {file} 时发生错误:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
string[] directories = Directory.GetDirectories(logsDirectory);
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(directory, true);
|
||||
deletedCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"删除文件夹 {directory} 时发生错误:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
if (deletedCount > 0)
|
||||
{
|
||||
TrashLog($"{deletedCount} file and folder have been deleted.");
|
||||
}
|
||||
else
|
||||
{
|
||||
TrashLog("No files or folders found, no need to clean.");
|
||||
}
|
||||
}
|
||||
|
||||
private void TrashLog(string message)
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
TrashLogTextBox.AppendText(message + Environment.NewLine);
|
||||
TrashLogTextBox.ScrollToEnd();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
20
TslTools/TslTools.csproj
Normal file
20
TslTools/TslTools.csproj
Normal file
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Resource\Icon\MWIcon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="Resource\Icon\MWIcon.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
6
TslTools/TslTools.csproj.user
Normal file
6
TslTools/TslTools.csproj.user
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<_LastSelectedProfileId>C:\Users\WMR-821\source\repos\TslTools\TslTools\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue