Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用C#重写总调用(ffdev) #11

Closed
wants to merge 4 commits into from
Closed
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
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,35 @@ cython_debug/

# winget version
pack.iss

# Csharp
# .NET Core and Visual Studio Code specific
.vscode/
bin/
obj/

# Rider specific
.idea/

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2019 directories which contain build results, logs, or module files
.vs/
Binary file modified 开发工具-打包-done/Script/ffdev.exe
Binary file not shown.
50 changes: 0 additions & 50 deletions 开发工具-打包/Script/ffdev.py

This file was deleted.

114 changes: 114 additions & 0 deletions 开发工具-打包/Script/ffdev/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace FFDev
{
class Program
{
static readonly string version = "2024.08.05.0100";

static readonly Dictionary<string, string> scripts = new()
{
{ "总调用", "代码校对/参数查重.exe" },
{ "目录复制", "目录复制.exe" },
{ "参数查重", "代码校对/参数查重.exe" },
{ "非UTF-8编码", "代码校对/非UTF-8编码.exe" },
{ "尾随空格", "代码校对/尾随空格.exe" },
{ "需求生成", "生成工具/需求生成.exe" },
{ "代码行数", "统计/代码总行数.exe" },
{ "账号切换", "git/账号切换.exe" },
{ "连续push", "git/连续push尝试.exe" },
{ "连续pull", "git/连续pull尝试.exe" },
{ "git连续尝试", "git/git连续尝试.exe" }
};

static void Main(string[] args)
{
if (args.Length < 2)
{
Environment.ExitCode = 2;
Console.WriteLine("Usage: ffdev <工具> <命令> [<参数>...]");
return;
}

string program = args[0];
string command = args.Length > 1 ? args[1] : "";
string[] inputArgs = new string[args.Length - 2];
Array.Copy(args, 2, inputArgs, 0, inputArgs.Length);

string parentDir = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetFullPath(Environment.GetCommandLineArgs()[0])));

if (IsVersionCommand(program))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"✓ Version {version}");
Console.ResetColor();
return;
}

if (!scripts.TryGetValue(program, out string? value))
{
Environment.ExitCode = 1;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("✕ 无效的程序调用");
Console.ResetColor();
Console.WriteLine("[!] 可用程序: [总调用] [目录复制] [参数查重] [非UTF-8编码] [尾随空格] [需求生成] [代码行数] [账号切换] [连续push] [连续pull] [git连续尝试]");
return;
}

string programPath = Path.Combine(parentDir, value);

if (!File.Exists(programPath))
{
Environment.ExitCode = 1;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"✕ 缺少工具 {programPath} !");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("⚠ 尝试重新安装程序以解决该问题");
Console.ResetColor();
return;
}

string commandArgs = $"{command} {string.Join(" ", inputArgs)}";
ExecuteCommand(programPath, commandArgs);
}

static bool IsVersionCommand(string program)
{
return program.Equals("ver", StringComparison.OrdinalIgnoreCase) ||
program.Equals("版本", StringComparison.OrdinalIgnoreCase) ||
program.Equals("version", StringComparison.OrdinalIgnoreCase) ||
program.Equals("--version", StringComparison.OrdinalIgnoreCase) ||
program.Equals("--ver", StringComparison.OrdinalIgnoreCase) ||
program.Equals("-v", StringComparison.OrdinalIgnoreCase);
}

static void ExecuteCommand(string programPath, string arguments)
{
try
{
var process = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = programPath,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = false,
CreateNoWindow = true
}
};
process.Start();
process.WaitForExit();
}
catch (Exception ex)
{
Environment.ExitCode = 1;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"执行命令时出错: {ex.Message}");
Console.ResetColor();
}
}
}
}
10 changes: 10 additions & 0 deletions 开发工具-打包/Script/ffdev/ffdev.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions 开发工具-打包/Script/ffdev/ffdev.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35122.118
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ffdev", "ffdev.csproj", "{C1A19354-FF74-46A1-89D4-80AFB57D8444}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C1A19354-FF74-46A1-89D4-80AFB57D8444}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1A19354-FF74-46A1-89D4-80AFB57D8444}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1A19354-FF74-46A1-89D4-80AFB57D8444}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1A19354-FF74-46A1-89D4-80AFB57D8444}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AB6F343-EFBD-40A5-8D8A-FE92C16716DF}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion 开发工具-源码/Script/ffdev.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ param(
)

$parentDir = Split-Path -Path $PSScriptRoot -Parent
$version = "2024.08.04.2345"
$version = "2024.08.05.0100"
$flag = 0

if ($program -eq "总调用") {
Expand Down
2 changes: 0 additions & 2 deletions 开发工具-源码/Script/提示.txt

This file was deleted.