From 08d175ae36441fdae6fad92ddfe050823a404add Mon Sep 17 00:00:00 2001
From: muqing <1966944300@qq.com>
Date: Mon, 16 Sep 2024 11:06:23 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=90=9C=E7=B4=A2=E5=BC=95?=
=?UTF-8?q?=E6=93=8E=E7=B3=BB=E7=BB=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Mod.cs | 209 --------------------------------------------------
Program.cs | 2 +-
SearchFile.cs | 160 ++++++++++++++++++++++++++++++++++++++
3 files changed, 161 insertions(+), 210 deletions(-)
delete mode 100644 Mod.cs
create mode 100644 SearchFile.cs
diff --git a/Mod.cs b/Mod.cs
deleted file mode 100644
index 451c484..0000000
--- a/Mod.cs
+++ /dev/null
@@ -1,209 +0,0 @@
-
-using Debug;
-using Microsoft.VisualBasic;
-using Microsoft.Win32;
-using System.Runtime.InteropServices;
-///
-/// 模组搜索引擎操作
-///
-public class Mod
-{
- private static DateTime StartTime;
- ///
- /// 结束时间
- ///
- private static void EndTime()
- {
- Console.WriteLine("结束" + (DateTime.Now - StartTime).TotalMilliseconds + "ms");
- }
-
- private readonly bool Isdot = true;
- private readonly List ExcludeFile = [
- "Android", "androidword", "Java",
- "Linux", "linuxword", "Mac",
- "Windows", "Windows 10", "Steam",
- "Genshin Impact Game", "Godot", "Gradle",
- "WeGame", "Mental Omega", "WeGameApps",
- "ramboplayGame", "QQ", "QQWORD","Microsoft SDKs","Creator","editors","AndroidSDK","SDK","Pr","PR","PS","Ps","WE",
- "androidstudioword","xshell7"
- ];
- public string FileDir = string.Empty;
-
- public Mod()
- {
- Console.Clear();
- ModeSwitch.New("搜索模式", ["返回主页", "默认", "steam", "全盘"], MODE);
-
- //Action action = MODE;
- }
- public void MODE(int a)
- {
- Console.Clear();
- if (a == 0)
- {
- _ = new Program();
- return;
- }
- // StartTime = DateTime.Now;
- if (a == 1 || a == 2)
- {
- steam();//先看看steam中有没有安装铁锈战争
- //steam中没有安装铁锈战争扫全盘
- }
- if ((a == 1 || a == 3) && FileDir == string.Empty)
- {
- init();
- }
- Console.Clear();
- if (!string.IsNullOrEmpty(FileDir))
- {
- ModeSwitch.New("找到了:" + FileDir, ["返回主页", "默认", "steam", "全盘"], MODE);
- }
- else
- {
- ModeSwitch.New("未找到", ["返回主页", "默认", "steam", "全盘"], MODE);
- }
- //FileDir=string.Empty;
- }
- private void steam()
- {
- var steamPath = GetSteamInstallPath();
- if (!string.IsNullOrEmpty(steamPath))
- {
- string v = Path.Combine(steamPath, "steamapps\\common\\Rusted Warfare");
- // Program.printfLine("找到了:" + v);
- if (Directory.Exists(v))
- {
- FileDir = v;
- // EndTime();
- }
- }
-
- }
-
- private void init()
- {
- var allDrives = DriveInfo.GetDrives();
- foreach (var d in allDrives)
- {
- Console.WriteLine();
- if (d.IsReady == true)
- {
- var name = d.Name;
- if (ExcludeFile.Contains(name))
- {
- continue;
- }
-
- if (name.Equals("C:\\"))
- {
- FileSearch(name);
- }
- else
- {
- if (Directory.Exists(name + "/Rusted Warfare"))
- {
- EndTime();
- break;
- }
- else
- {
- FileSearch(name);
- }
- }
-
- }
- }
- }
-
- public bool IsSearch = true;
- private void FileSearch(string path)
- {
- try
- {
- foreach (var file in Directory.EnumerateDirectories(path))
- {
- if (!IsSearch)
- {
- return;
- }
- var name = Path.GetFileName(file);
- if (Isdot && name.StartsWith("."))
- {
- continue;
- }
- if (ExcludeFile.Contains(name))
- {
- continue;
- }
- if (name.Equals("Rusted Warfare"))
- {
- FileDir = file;
- EndTime();
- break;
- }
- else
- {
- FileSearch(file);
- }
-
- }
- }
- catch (UnauthorizedAccessException)
- {
- Console.WriteLine($"Access denied for: {path}");
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Error accessing directory '{path}': {ex.Message}");
- }
- }
-
-
- private static string GetSteamInstallPath()
- {
- if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- return string.Empty;
- // Windows 相关逻辑
- }
-
- var installPath = GetInstallPathFromKey(@"Software\Valve\Steam");
-
- if (string.IsNullOrEmpty(installPath))
- {
- installPath = GetInstallPathFromKey(@"SOFTWARE\Wow6432Node\Valve\Steam");
- }
-
- return installPath;
-
- string GetInstallPathFromKey(string subKey)
- {
- using (var key = Registry.CurrentUser.OpenSubKey(subKey))
- {
- if (key != null)
- {
- var path = key.GetValue("InstallPath");
- if (path != null)
- {
- return (string)path;
- }
- }
- }
-
- using (var key = Registry.LocalMachine.OpenSubKey(subKey))
- {
- if (key != null)
- {
- var path = key.GetValue("InstallPath");
- if (path != null)
- {
- return (string)path;
- }
- }
- }
-
- return string.Empty;
- }
- }
-}
\ No newline at end of file
diff --git a/Program.cs b/Program.cs
index 07a2d52..d482fc8 100644
--- a/Program.cs
+++ b/Program.cs
@@ -57,7 +57,7 @@ public class Program
// MinLong.Main.ResetChars();
// _ = new MinLong.Main();
// return;
- string[] str = ["退出", "抽卡", "铁锈位置搜索引擎", "音乐调试", "小龙快跑"];
+ string[] str = ["退出", "抽卡", "搜索引擎", "音乐调试", "小龙快跑"];
var modeSwitch = new ModeSwitch("请选择你要执行的操作:", str, (a) =>
{
switch (a)
diff --git a/SearchFile.cs b/SearchFile.cs
new file mode 100644
index 0000000..b6ea546
--- /dev/null
+++ b/SearchFile.cs
@@ -0,0 +1,160 @@
+
+using Debug;
+///
+/// 文件夹文件搜索引擎操作
+///
+public class Mod
+{
+ private static DateTime time;
+ ///
+ /// 结束时间
+ ///
+ private static void EndTime()
+ {
+ Console.WriteLine("结束" + (DateTime.Now - time).TotalMilliseconds + "ms");
+ }
+ private static void StartTime()
+ {
+ time = DateTime.Now;
+ }
+
+ private readonly bool Isdot = true;
+ //过滤系统
+ private readonly List ExcludeFile = [
+ "Android", "androidword", "Java",
+ "Linux", "linuxword", "Mac",
+ "Windows", "Windows 10", "Steam",
+ "Genshin Impact Game", "Godot", "Gradle",
+ "WeGame", "Mental Omega", "WeGameApps",
+ "ramboplayGame", "QQ", "QQWORD","Microsoft SDKs","Creator","editors","AndroidSDK","SDK","Pr","PR","PS","Ps","WE",
+ "androidstudioword","xshell7"
+ ];
+ private readonly bool isExcludeFile = false;
+ public string FileDir = string.Empty;
+ public Mod()
+ {
+ Console.Clear();
+ ModeSwitch.New("搜索模式", ["返回主页", "文件", "文件夹"], MODE);
+ }
+ public void MODE(int a)
+ {
+ Console.Clear();
+ if (a == 0)
+ {
+ _ = new Program();
+ return;
+ }
+ if (a == 1)
+ {
+ isFile = true;
+ }
+ else if (a == 2)
+ {
+ isFile = false;
+ }
+ Console.Write($"请输入{(isFile ? "文件" : "文件夹")}:");
+ var v = Console.ReadLine();
+ if (v == null || string.IsNullOrEmpty(v))
+ {
+ Console.Write("输入错误");
+ _ = new Program();
+ return;
+ }
+ fileName = v;
+ Console.Clear();
+
+ Init();
+ }
+ private bool isFile = true;//是否搜索的是文件
+ private string fileName = string.Empty;
+
+
+ private void Init()
+ {
+ StartTime();
+ var allDrives = DriveInfo.GetDrives();
+ foreach (var d in allDrives)
+ {
+ Console.WriteLine();
+ if (d.IsReady == true)
+ {
+ var name = d.Name;
+
+ // if (name.Contains("C:\\"))//排除系统盘
+ // {
+ // continue;
+ // }
+ // Console.WriteLine(name);
+ FileSearch(name);
+
+ }
+ EndTime();
+ Yes();
+ }
+ }
+ private void FileSearch(string path)
+ {
+ try
+ {
+ // Console.WriteLine("正在搜索:" + path);
+
+ DirectoryInfo dirInfo = new(path);
+ foreach (var directory in dirInfo.EnumerateDirectories())
+ {
+ Console.WriteLine("正在搜索:" + directory);
+ //判断是否有访问权限
+ if (!directory.Exists)
+ {
+ Console.WriteLine("没有访问的权限 " + directory);
+ continue;
+ }
+ //获取名称
+ var name = directory.Name;
+ // 是否过滤掉隐藏文件夹
+ if (Isdot && name.StartsWith('.'))
+ {
+ continue;
+ }
+ if (isExcludeFile && ExcludeFile.Contains(name))
+ {
+ continue;
+ }
+ if (name.Equals(fileName) && directory.Exists)
+ {
+ FileDir = directory.FullName;
+ return;
+ }
+ FileSearch(directory.FullName);
+ }
+ if (isFile)
+ {
+ foreach (var file in dirInfo.EnumerateFiles())
+ {
+ Console.WriteLine("正在搜索:" + file.FullName);
+ // 处理文件
+ if (file.Name.Equals(fileName) && file.Exists)
+ {
+ FileDir = file.FullName;
+ return;
+ }
+ }
+ }
+ return;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error accessing directory '{path}': {ex.Message}");
+ }
+ }
+ private void Yes()
+ {
+ if (!string.IsNullOrEmpty(FileDir))
+ {
+ Console.Write($"已经找到{(isFile ? "文件" : "文件夹")} {FileDir}");
+ }
+ else
+ {
+ Console.Write($"未找到 {(isFile ? "文件" : "文件夹")}");
+ }
+ }
+}
\ No newline at end of file