You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.2 KiB

using connor_zwcadm.util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZWCAD;
using ZwmToolKitLib;
using ZwSoft.ZwCAD.ApplicationServices;
namespace connor_zwcadm.commands {
public class ReadInfoCommand : AbstractCADCommand {
public const string FILE_NAME = "info.txt";
public ReadInfoCommand(string file_path) : base(file_path, false) { }
protected override void InitCommand() { }
protected override void ExecuteCommand() {
if (string.IsNullOrWhiteSpace(File_Path)) {
throw new Exception("文件路径不能为空");
}
if (!File_Path.Contains(":")) {
KUtil.Log("非本地文件:"+File_Path);
//return;
}
if (!File.Exists(File_Path)) {
throw new Exception("文件不存在:" + File_Path);
}
InitCommand();
string infoPath = Path.Combine(Path.GetDirectoryName(File_Path), FILE_NAME);
KUtil.Log("读取本地同步信息:" + File_Path);
if (!File.Exists(infoPath)) {
KUtil.Log("没有数据文件");
return;
}
string[] info = File.ReadAllLines(infoPath, Encoding.UTF8);
KUtil.Log("文件信息");
KUtil.Log("------------------------------------------------------");
int lineCnt = KUtil.GetLen(info);
Dictionary<string, string> titleProps = new Dictionary<string, string>();
for (int i = 0; i < lineCnt; i++) {
string text = info[i];
KUtil.Log(text);
if (string.IsNullOrWhiteSpace(text)) {
continue;
}
int ind = text.IndexOf('=');
if (ind < 0) {
continue;
}
string name = text.Substring(0, ind);
string value = text.Substring(ind + 1);
KUtil.Put(titleProps, name, value);
}
KUtil.Log("------------------------------------------------------");
if (titleProps.Count == 0) {
KUtil.Log("无有效数据");
return;
}
KCADUtil.WriteTitle(titleProps);
KUtil.Log("更新标题栏完成");
}
}
}