Переглянути джерело

20241220001 列表查询功能

向羽 孟 8 місяців тому
батько
коміт
6c40fe24e0

+ 109 - 0
BaiduYunBeiFen/Controller/PybyClass.cs

@@ -0,0 +1,109 @@
+using BaiduYunBeiFen.ResultModel;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BaiduYunBeiFen.Controller
+{
+    public class PybyClass
+    {
+        public List<FileMessageModelClass> CheckPathFile(string YunPath)
+        {
+            //存储解析后的全部信息
+            List<FileMessageModelClass> Result = new List<FileMessageModelClass>();
+            string OutYunPath;
+            //新建CMD程序
+            ProcessStartInfo processStartInfo = new ProcessStartInfo();
+            processStartInfo.FileName = "cmd.exe";
+            processStartInfo.Arguments = YunPath;
+            processStartInfo.RedirectStandardOutput = true;
+            processStartInfo.UseShellExecute = false;
+            processStartInfo.CreateNoWindow = true;
+            // 创建并启动Process对象
+            Process process = new Process();
+            process.StartInfo = processStartInfo;
+            process.Start();
+            // 读取CMD输出
+            string output = process.StandardOutput.ReadToEnd();
+            //退出ProCess
+            process.WaitForExit();
+            process.Dispose();
+            //把读取到的输出数据按行划分
+            string[] Message = output.Split(Environment.NewLine);
+            //去除警告信息
+            Result = ReMoveWarnMessage(Message.ToList(), out OutYunPath);
+            return Result;
+        }
+        /// <summary>
+        /// 去除队列中的警告信息及已知的提示信息
+        /// </summary>
+        /// <param name="FileList">需要删选的队列</param>
+        /// <param name="YunPath">返回被检查的云端文件地址</param>
+        /// <returns></returns>
+        private List<FileMessageModelClass> ReMoveWarnMessage(List<string> MessageList, out string YunPath)
+        {
+            List<FileMessageModelClass> Result = new();
+            List<string> MessageCopy = new List<string>(MessageList);
+            List<string> WarnList = new List<string>()
+            {
+                "<W>",
+                "Files with non-ASCII names may not be handled correctly.",
+                "You should set your System Locale to 'UTF-8'.",
+                "Current locale is 'cp65001'"
+            };
+            foreach (string Message in MessageList)
+            {
+                if (WarnList.Exists(t => Message.Contains(t)))
+                {
+                    MessageCopy.Remove(Message);
+                }
+            }
+            YunPath = MessageCopy[0].Split(' ')[0];
+            MessageCopy.Remove(MessageCopy[0]);
+            Result = PareseMessage(MessageCopy);
+            return Result;
+        }
+
+        /// <summary>
+        /// 将文件列表数据由字符串转成类
+        /// </summary>
+        /// <param name="FileList"></param>
+        /// <returns></returns>
+        private List<FileMessageModelClass> PareseMessage(List<string> FileList)
+        {
+            List<FileMessageModelClass> Result = new();
+            FileList.ForEach(File => {
+                string[] strGetAllMessage = File.Split(' ');
+                if(strGetAllMessage.Count() == 6)
+                {
+                    try
+                    {
+                        string[] FileNameSplit = strGetAllMessage[1].Split(".");
+                        string GetFileType = strGetAllMessage[0] == "D" ? "Folder" : FileNameSplit[FileNameSplit.Count() - 1];
+                        int GetOtherNum = Convert.ToInt32(strGetAllMessage[2]);
+                        DateTime GetFileTime = Convert.ToDateTime(strGetAllMessage[3] + strGetAllMessage[4]);
+                        Result.Add(new FileMessageModelClass()
+                        {
+                            MessageType = strGetAllMessage[0],
+                            FileName = strGetAllMessage[1],
+                            FileType = GetFileType,
+                            OtherNumber = GetOtherNum,
+                            FileYunChangeTime = GetFileTime,
+                            OtherCode = strGetAllMessage[5]
+                        });
+                    }
+                    catch
+                    {
+                        Console.WriteLine("数据队列转换异常");
+                        FileList.ForEach(File => { Console.WriteLine(File); });
+                    }
+                }
+            });
+            return Result;
+        }
+    }
+}

+ 4 - 2
BaiduYunBeiFen/Program.cs

@@ -1,6 +1,8 @@
 // See https://aka.ms/new-console-template for more information
-using BaiduYunBeiFen;
+using BaiduYunBeiFen.Controller;
+using BaiduYunBeiFen.ResultModel;
 using System.Diagnostics;
 
 PybyClass pybyClass = new PybyClass();
-pybyClass.CheckPathFile("/c bypy ls LuBo/377943_栗枯Likuu/23_11_07");
+List<FileMessageModelClass> fileMessages = pybyClass.CheckPathFile("/c bypy ls LuBo/377943_栗枯Likuu/23_11_07");
+Console.ReadKey();

+ 0 - 57
BaiduYunBeiFen/PybyClass.cs

@@ -1,57 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BaiduYunBeiFen
-{
-    public class PybyClass
-    {
-        public List<string> CheckPathFile(string YunPath)
-        {
-            List<string> Result = new List<string>();
-            string OutYunPath;
-            ProcessStartInfo processStartInfo = new ProcessStartInfo();
-            processStartInfo.FileName = "cmd.exe";
-            processStartInfo.Arguments = YunPath;
-            processStartInfo.RedirectStandardOutput = true;
-            processStartInfo.UseShellExecute = false;
-            processStartInfo.CreateNoWindow = true;
-            // 创建并启动Process对象
-            Process process = new Process();
-            process.StartInfo = processStartInfo;
-            process.Start();
-            // 读取CMD输出
-            string output = process.StandardOutput.ReadToEnd();
-            process.WaitForExit();
-            process.Dispose();
-            string[] Message = output.Split(Environment.NewLine);
-            Result = ReMoveWarnMessage(Message.ToList(),out OutYunPath);
-            return Result;
-        }
-        public List<string> ReMoveWarnMessage(List<string> FileList,out string YunPath)
-        {
-            List<string> Result = new List<string>(FileList);
-            List<string> WarnList = new List<string>()
-            {
-                "<W>",
-                "Files with non-ASCII names may not be handled correctly.",
-                "You should set your System Locale to 'UTF-8'.",
-                "Current locale is 'cp65001'"
-            };
-            foreach (string File in FileList)
-            {
-                if (WarnList.Exists(t => File.Contains(t)))
-                {
-                    Result.Remove(File);
-                }
-            }
-            YunPath = Result[0];
-            Result.Remove(Result[0]);
-            return Result;
-        }
-    }
-}

+ 43 - 0
BaiduYunBeiFen/ResultModel/FileMessgeModelClass.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BaiduYunBeiFen.ResultModel
+{
+    public class FileMessageModelClass
+    {
+        //"F 录制-377943-20231107-190101-319-黑猫探头.cover.jpg 86006 2024-12-19, 10:56:21 a0b4c263eidd172aaa48ffebcf61f7cb"
+
+        /// <summary>
+        /// 此段返回数据类型
+        /// </summary>
+        public string? MessageType{ get; set; }
+
+        /// <summary>
+        /// 文件名称
+        /// </summary>
+        public string? FileName { get; set; }
+
+        /// <summary>
+        /// 文件类型
+        /// </summary>
+        public string? FileType { get; set; }
+
+        /// <summary>
+        /// 中间一段意义不明的数字
+        /// </summary>
+        public int OtherNumber { get; set; }
+
+        /// <summary>
+        /// 云端文件最后修改时间
+        /// </summary>
+        public DateTime FileYunChangeTime { get; set; }
+
+        /// <summary>
+        /// 最后一段不明意义code
+        /// </summary>
+        public string? OtherCode { get; set; }
+    }
+}