2025-08-29 14:57:55 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
2025-09-03 16:16:00 +08:00
|
|
|
|
using System.IO;
|
2025-08-29 14:57:55 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ramitta.lib
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class Basic
|
|
|
|
|
|
{
|
|
|
|
|
|
#region ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
public static SolidColorBrush <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ = new SolidColorBrush(Color.FromRgb(92, 40, 147));
|
|
|
|
|
|
public static SolidColorBrush <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ = new SolidColorBrush(Color.FromRgb(134, 27, 45));
|
|
|
|
|
|
public static SolidColorBrush <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ = new SolidColorBrush(Color.FromRgb(202, 81, 0));
|
|
|
|
|
|
public static SolidColorBrush <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ = new SolidColorBrush(Color.FromRgb(66, 164, 60));
|
|
|
|
|
|
public static SolidColorBrush ֪ͨ<EFBFBD><EFBFBD>ɫ = new SolidColorBrush(Color.FromRgb(0, 122, 204));
|
|
|
|
|
|
public static SolidColorBrush <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ = new SolidColorBrush(Color.FromRgb(30, 30, 30));
|
|
|
|
|
|
public static SolidColorBrush Ĭ<EFBFBD>ϻ<EFBFBD>ɫ = new SolidColorBrush(Color.FromRgb(66, 66, 66));
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region <EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
public static void DebugBar(Label obj, String text, SolidColorBrush? color=null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (obj == null) return;
|
|
|
|
|
|
// ͨ<><CDA8>Dispatcherȷ<72><C8B7><EFBFBD><EFBFBD>UI<55>߳<EFBFBD>ִ<EFBFBD><D6B4>
|
|
|
|
|
|
obj.Dispatcher.Invoke(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
obj.Content = text;
|
|
|
|
|
|
if(color!=null)obj.Background = color;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3>
|
|
|
|
|
|
public class DebugbarException : Exception
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Message { get; }
|
|
|
|
|
|
public SolidColorBrush Brush { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public DebugbarException(string message, SolidColorBrush brush)
|
|
|
|
|
|
: base(message)
|
|
|
|
|
|
{
|
|
|
|
|
|
Message = message;
|
|
|
|
|
|
Brush = brush;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
public static Dictionary<string, string>? Startupe;
|
|
|
|
|
|
public static Dictionary<string, string> ParseCommandLineArgs(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
var arguments = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < args.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string arg = args[i];
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><>/<2F><>ͷ<EFBFBD><CDB7>
|
|
|
|
|
|
if (arg.StartsWith("-") || arg.StartsWith("/"))
|
|
|
|
|
|
{
|
|
|
|
|
|
string key = arg.TrimStart('-', '/');
|
|
|
|
|
|
string value = "true"; // Ĭ<><C4AC>ֵΪtrue<75><65><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><>/<2F><>ͷ<EFBFBD><CDB7>
|
|
|
|
|
|
if (i + 1 < args.Length && !args[i + 1].StartsWith("-") && !args[i + 1].StartsWith("/"))
|
|
|
|
|
|
{
|
|
|
|
|
|
value = args[i + 1];
|
|
|
|
|
|
i++; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
arguments[key] = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-09-03 16:16:00 +08:00
|
|
|
|
public static void FileWrite(string outputPath, string outputText)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (StreamWriter writer = new StreamWriter(outputPath, false))
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.WriteLine(outputText);
|
|
|
|
|
|
|
|
|
|
|
|
writer.WriteLine(outputText);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string FileRead(string outputPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
return File.ReadAllText(outputPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-02 18:41:07 +08:00
|
|
|
|
public static async Task<int> RunExternalCommand(string? applicationPath = "explorer.exe", string arguments="", bool UseShellExecute = false, bool CreateNoWindow = false)
|
2025-08-29 14:57:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
FileName = applicationPath,
|
|
|
|
|
|
Arguments = arguments,
|
|
|
|
|
|
UseShellExecute = UseShellExecute,
|
|
|
|
|
|
CreateNoWindow = CreateNoWindow
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Process process = Process.Start(startInfo) ??
|
|
|
|
|
|
throw new InvalidOperationException("Failed to start process.");
|
|
|
|
|
|
|
|
|
|
|
|
if (UseShellExecute != true)
|
|
|
|
|
|
{
|
|
|
|
|
|
await Task.Run(() => process.WaitForExit());
|
|
|
|
|
|
return process.ExitCode; // <20><><EFBFBD>ؽ<EFBFBD><D8BD>̵<EFBFBD><CCB5>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task<string> RunExternalCommandResult(string applicationPath, string arguments, bool CreateNoWindow = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>µĽ<C2B5><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
FileName = applicationPath,
|
|
|
|
|
|
Arguments = arguments,
|
|
|
|
|
|
UseShellExecute = false, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ false <20>Ա<EFBFBD><D4B1>ܹ<EFBFBD><DCB9>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
RedirectStandardOutput = true, // <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD>
|
|
|
|
|
|
RedirectStandardError = true, // <20><>ѡ<EFBFBD><D1A1>Ҳ<EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
CreateNoWindow = CreateNoWindow // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
using (Process process = new Process())
|
|
|
|
|
|
{
|
|
|
|
|
|
process.StartInfo = startInfo;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
string output = await process.StandardOutput.ReadToEndAsync();
|
|
|
|
|
|
string error = await process.StandardError.ReadToEndAsync(); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>̽<EFBFBD><CCBD><EFBFBD>
|
|
|
|
|
|
await process.WaitForExitAsync();
|
|
|
|
|
|
/*
|
|
|
|
|
|
if (process.ExitCode != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
throw new Exception($"Process exited with code {process.ExitCode}: {error}");
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
return output; // <20><><EFBFBD>ر<EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>Լ<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣
|
|
|
|
|
|
throw; // <20><><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><D7B3>쳣<EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|