-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileStructAnalyzer.cs
More file actions
60 lines (53 loc) · 1.99 KB
/
Copy pathFileStructAnalyzer.cs
File metadata and controls
60 lines (53 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Diagnostics;
using System.IO;
namespace RYCBEditorX.Utils;
public class FileStructAnalyzer
{
private string JSONPath, JSONContent;
public string FilePath
{
get; set;
}
public FileStructAnalyzer(string filePath)
{
FilePath = filePath;
var ext = Path.GetExtension(FilePath);
if (!ext.Contains(".py") & !ext.Contains(".pyw") & !ext.Contains(".pyx"))
{
GlobalConfig.CurrentLogger.Log("传入参数不正确。应为.py|.pyw|.pyx结尾,实际结尾: " +
ext,
EnumLogType.ERROR,
module: EnumLogModule.CUSTOM, customModuleName: "文件结构分析模块");
}
}
public string Analyze()
{
var pythonScript = GlobalConfig.StartupPath.Replace("\\", "/") + "Tools/st_getter.py";
var startInfo = new ProcessStartInfo
{
FileName = "python", // Ensure python is in PATH
Arguments = $"{pythonScript} \"{FilePath.Replace("\\", "/")}\" \"{GlobalConfig.StartupPath.Replace("\\", "/") + "/Cache"}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (var process = Process.Start(startInfo))
{
if (process == null)
{
GlobalConfig.CurrentLogger.Error(new InvalidOperationException("无法启动Python进程"),
type: EnumLogType.ERROR,
module: EnumLogModule.CUSTOM,
customModuleName: "文件结构分析模块");
}
var _ = process.StandardOutput.ReadToEnd();
var _1 = process.StandardError.ReadToEnd();
JSONContent = process.StandardOutput.ReadToEnd();
}
JSONPath = GlobalConfig.StartupPath + "\\Cache\\" + Path.GetFileName(FilePath) + ".json";
//File.WriteAllText(JSONPath, JSONContent);
return JSONPath;
}
}