|
@@ -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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|