*.[修复]修复网页获取抓取工具Head设置不当会导致进度卡死的BUG。
This commit is contained in:
parent
d32f91ab95
commit
6dcf5500f2
Binary file not shown.
31
CHANGELOG.md
31
CHANGELOG.md
|
@ -1,24 +1,23 @@
|
|||
### 2020-11-28更新
|
||||
### 2020-12-07更新
|
||||
------
|
||||
#### SuperDesign V2.0.2011.2801
|
||||
*.[改进]更新日志和自述文件名更符合git备份规范。
|
||||
##### SuperDesign V2.0.2012.0701
|
||||
- *.[修复]修复网页获取抓取工具Head设置不当会导致进度卡死的BUG。
|
||||
|
||||
### 2020-11-28更新
|
||||
------
|
||||
##### SuperDesign V2.0.2011.2801
|
||||
- *.[改进]更新日志和自述文件名更符合git备份规范。
|
||||
|
||||
### 2019-12-13更新
|
||||
------
|
||||
#### SupperDesign V2.0.1911.2801
|
||||
暂无
|
||||
##### SupperDesign V2.0.1911.2801
|
||||
- 暂无
|
||||
|
||||
------
|
||||
### 2019-09-19更新
|
||||
------
|
||||
#### SupperDesign V2.0.1909.1901
|
||||
*.[新增]支持多项目。
|
||||
|
||||
*.[新增]支持文件关联。
|
||||
|
||||
*.[新增]新版一键打包功能,支持一键复制打包好的文件到历史版本区域。
|
||||
|
||||
*.[新增]支持快速创建毕方标准文件夹。
|
||||
|
||||
*.[改进]其它一些细节改进。
|
||||
##### SupperDesign V2.0.1909.1901
|
||||
- *.[新增]支持多项目。
|
||||
- *.[新增]支持文件关联。
|
||||
- *.[新增]新版一键打包功能,支持一键复制打包好的文件到历史版本区域。
|
||||
- *.[新增]支持快速创建毕方标准文件夹。
|
||||
- *.[改进]其它一些细节改进。
|
Binary file not shown.
|
@ -1,439 +1,439 @@
|
|||
using ryCommon;
|
||||
using ryCommonDb;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ryCommon;
|
||||
using ryCommonDb;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
|
||||
namespace 开发辅助工具.Manager
|
||||
{
|
||||
class RyProject
|
||||
{
|
||||
/// <summary>
|
||||
/// C#基准项目路径
|
||||
/// </summary>
|
||||
public string CshapeBasePath { get; private set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 引用dll文件夹列表
|
||||
/// </summary>
|
||||
public string ReferenceDllPath { get; private set; } = "";
|
||||
/// <summary>
|
||||
/// 是否将dll复制到Bin目录,并修改引用
|
||||
/// </summary>
|
||||
public bool CopyDllToBin { get; set; } = false;
|
||||
/// <summary>
|
||||
/// Bin目录相对于项目文件所在的位置,可使用相对路径或绝对路径
|
||||
/// </summary>
|
||||
public string BinFolder { get; set; } = "..\\..\\Bin";
|
||||
/// <summary>
|
||||
/// 是否修改输出路径
|
||||
/// </summary>
|
||||
using System.Xml;
|
||||
|
||||
namespace 开发辅助工具.Manager
|
||||
{
|
||||
class RyProject
|
||||
{
|
||||
/// <summary>
|
||||
/// C#基准项目路径
|
||||
/// </summary>
|
||||
public string CshapeBasePath { get; private set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 引用dll文件夹列表
|
||||
/// </summary>
|
||||
public string ReferenceDllPath { get; private set; } = "";
|
||||
/// <summary>
|
||||
/// 是否将dll复制到Bin目录,并修改引用
|
||||
/// </summary>
|
||||
public bool CopyDllToBin { get; set; } = false;
|
||||
/// <summary>
|
||||
/// Bin目录相对于项目文件所在的位置,可使用相对路径或绝对路径
|
||||
/// </summary>
|
||||
public string BinFolder { get; set; } = "..\\..\\Bin";
|
||||
/// <summary>
|
||||
/// 是否修改输出路径
|
||||
/// </summary>
|
||||
public bool ChangedOutputPath { get; set; } =true;
|
||||
public delegate void StringEventHandler(object sender, string e);
|
||||
/// <summary>
|
||||
/// 状态变化时激发
|
||||
/// </summary>
|
||||
[Description("状态变化时激发")]
|
||||
public event StringEventHandler OnStateChanged;
|
||||
public RyProject()
|
||||
{
|
||||
UpdateSetting();
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新设置
|
||||
/// </summary>
|
||||
public void UpdateSetting()
|
||||
{
|
||||
DataProvider mydb = new DataProvider();
|
||||
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
||||
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
||||
{
|
||||
var ds = db.ReadData("select * from Settings where name='Setting'");
|
||||
if (mydb.HaveData(ds))
|
||||
{
|
||||
var row = mydb.GetData(ds);
|
||||
ryCommon.Storage mStor = new ryCommon.Storage(row["value"].ToString());
|
||||
mStor.SelectNodeBySet();
|
||||
CshapeBasePath = mStor.GetAttrValue("CshapeBasePath");
|
||||
ReferenceDllPath = mStor.GetAttrValue("ReferenceDll");
|
||||
}
|
||||
}
|
||||
db.Free();
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过dll名称来寻找dll路径
|
||||
/// </summary>
|
||||
/// <param name="_ReferenceDllPath"></param>
|
||||
/// <param name="dll_name"></param>
|
||||
/// <returns></returns>
|
||||
public string GetDllPath(string dll_name)
|
||||
{
|
||||
var path_list = ReferenceDllPath.Replace("\r", "").Split('\n');
|
||||
var find = false;
|
||||
var result = "";
|
||||
#region 在引用文件夹查找是否有该dll,有则使用引用文件夹里的dll
|
||||
for (int m = 0; m < path_list.Length; m++)
|
||||
{
|
||||
if (path_list[m].Trim() == "") { continue; }
|
||||
if (!System.IO.Directory.Exists(path_list[m])) { continue; }
|
||||
var files = System.IO.Directory.GetFiles(path_list[m]);
|
||||
for (int z = 0; z < files.Length; z++)
|
||||
{
|
||||
if (System.IO.Path.GetFileName(files[z]).ToLower() == dll_name.ToLower())
|
||||
{
|
||||
result = files[z];
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find) { break; }
|
||||
}
|
||||
#endregion
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 相对路径转绝对路径,相对项目文件的路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string RelToAbsPath(string project_path,string rel_path)
|
||||
{
|
||||
string folder = System.IO.Path.GetDirectoryName(project_path);
|
||||
var _rel_path = rel_path;
|
||||
while (true)
|
||||
{
|
||||
if (_rel_path.IndexOf("..\\") == 0)
|
||||
{
|
||||
folder = System.IO.Path.GetDirectoryName(folder.TrimEnd('\\'));
|
||||
_rel_path = _rel_path.Substring(3);
|
||||
}
|
||||
else { break; }
|
||||
if (folder == "") { break; }
|
||||
}
|
||||
return folder+"\\"+ _rel_path;
|
||||
}
|
||||
/// <summary>
|
||||
/// 绝对路径转相对路径,相对项目文件的路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string AbsToRelPath(string project_path, string abs_path)
|
||||
{
|
||||
string folder = System.IO.Path.GetDirectoryName(project_path);
|
||||
var _rel_path = "";
|
||||
var _rel_path2 = "";
|
||||
while (true)
|
||||
{
|
||||
if (abs_path.IndexOfEx(folder) == 0)
|
||||
{
|
||||
if (_rel_path2 == "")
|
||||
{ _rel_path = abs_path.Substring(folder.Length); }
|
||||
else
|
||||
{
|
||||
_rel_path = _rel_path2.TrimEnd('\\') + abs_path.Substring(folder.Length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
folder = System.IO.Path.GetDirectoryName(folder.TrimEnd('\\'));
|
||||
_rel_path2 += "..\\";
|
||||
}
|
||||
if (folder == "") { break; }
|
||||
}
|
||||
return _rel_path;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新dll版本,如果全部复制成功,则返回0,否则返回错误个数
|
||||
/// </summary>
|
||||
public int UpdateDlls(string folder,out string error_str)
|
||||
{
|
||||
error_str = "";
|
||||
var _error_str = "";
|
||||
int error = 0;
|
||||
Updates(folder);
|
||||
void Updates(string _path)
|
||||
{
|
||||
var files = System.IO.Directory.GetFiles(_path, "*.dll");
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
string filename = System.IO.Path.GetFileName(files[i]);
|
||||
var dllpath = GetDllPath(filename);
|
||||
if (dllpath != "")
|
||||
{
|
||||
if (RyFiles.CopyFile(dllpath, files[i]) != 0)
|
||||
{ _error_str += files[i]+ "\r\n"; error++; }
|
||||
var dll_xml_path = System.IO.Path.GetDirectoryName(dllpath) +"\\"+ System.IO.Path.GetFileNameWithoutExtension(dllpath) + ".xml";
|
||||
if (System.IO.File.Exists(dll_xml_path))
|
||||
{
|
||||
if (RyFiles.CopyFile(dll_xml_path, System.IO.Path.GetDirectoryName(files[i]) + "\\" + System.IO.Path.GetFileNameWithoutExtension(files[i]) + ".xml") != 0)
|
||||
{ _error_str += files[i] + "\r\n"; error++; }
|
||||
}
|
||||
}
|
||||
}
|
||||
var dirs = System.IO.Directory.GetDirectories(_path);
|
||||
for (int i = 0; i < dirs.Length; i++)
|
||||
{
|
||||
Updates(dirs[i]);
|
||||
}
|
||||
}
|
||||
error_str = _error_str;
|
||||
return error;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新项目引用,定向为本地dll,如果全部复制成功,则返回0,否则返回错误个数
|
||||
/// </summary>
|
||||
public int UpdateCSproj(string folder)
|
||||
{
|
||||
int error = 0;
|
||||
Updates(folder);
|
||||
void Updates(string _path)
|
||||
{
|
||||
var files = System.IO.Directory.GetFiles(_path, "*.csproj");
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
SetCSproj(files[i], "");
|
||||
}
|
||||
var dirs = System.IO.Directory.GetDirectories(_path);
|
||||
for (int i = 0; i < dirs.Length; i++)
|
||||
{
|
||||
Updates(dirs[i]);
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
/// <summary>
|
||||
/// 自动设置csproj文件,将dll引用修改为指定区域的dll、修改命名空间
|
||||
/// </summary>
|
||||
/// <param name="path">项目文件(*.csproj)</param>
|
||||
/// <param name="_project_Eng_name">项目英文名</param>
|
||||
public void SetCSproj(string path, string _project_Eng_name)
|
||||
{
|
||||
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
|
||||
xml.Load(path);
|
||||
var xmlnsm = new XmlNamespaceManager(xml.NameTable);
|
||||
xmlnsm.AddNamespace("d", xml.DocumentElement.NamespaceURI);
|
||||
//var root = @"d:Project//d:ItemGroup//d:Reference";
|
||||
if (_project_Eng_name != "")
|
||||
{
|
||||
SetValue(@"d:Project//d:PropertyGroup//d:RootNamespace", _project_Eng_name.Replace(" ", ""));//命名空间名
|
||||
SetValue(@"d:Project//d:PropertyGroup//d:AssemblyName", _project_Eng_name.Replace(" ", ""));//程序集名称
|
||||
}
|
||||
var OutputPath = GetValue(@"d:Project//d:PropertyGroup[2]//d:OutputPath").TrimEnd('\\')+"\\";
|
||||
if (ChangedOutputPath)
|
||||
{
|
||||
SetValue(@"d:Project//d:PropertyGroup[2]//d:OutputPath", BinFolder.TrimEnd('\\') + "\\Debug\\"+ (_project_Eng_name==""?"": _project_Eng_name +"\\"));//Debug输出路径
|
||||
SetValue(@"d:Project//d:PropertyGroup[3]//d:OutputPath", BinFolder.TrimEnd('\\') + "\\Release\\" + (_project_Eng_name == "" ? "" : _project_Eng_name + "\\"));//Release输出路径
|
||||
}
|
||||
if (OutputPath == "") { OutputPath = BinFolder.TrimEnd('\\') + "\\Debug\\" + (_project_Eng_name == "" ? "" : _project_Eng_name + "\\"); }
|
||||
var list = xml.SelectNodes(@"d:Project//d:ItemGroup//d:Reference//d:HintPath", xmlnsm);
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var HintPath = list[i].InnerText;
|
||||
var iPos = HintPath.LastIndexOf("\\");
|
||||
if (iPos > 0)
|
||||
{
|
||||
var Reference_Name = HintPath.Substring(iPos + 1);//引用的dll名称
|
||||
var dll_path = GetDllPath(Reference_Name);
|
||||
if (dll_path != "")
|
||||
{
|
||||
if (CopyDllToBin)
|
||||
{
|
||||
list[i].InnerText = OutputPath + Reference_Name;
|
||||
RyFiles.CopyFile(dll_path,RelToAbsPath(path, OutputPath + Reference_Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
list[i].InnerText = dll_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var ProjectReference_list = xml.SelectNodes(@"d:Project//d:ItemGroup//d:ProjectReference", xmlnsm);//项目引用
|
||||
for (int i = 0; i < ProjectReference_list.Count; i++)
|
||||
{
|
||||
var element = (XmlElement)ProjectReference_list[i];
|
||||
var IncludePath = element.GetAttribute("Include");
|
||||
var iPos = IncludePath.LastIndexOf("\\");
|
||||
if (iPos > 0)
|
||||
{
|
||||
var Reference_FileName = IncludePath.Substring(iPos + 1).ToLower();//引用的项目文件名称
|
||||
string dll_name = "";
|
||||
if (Reference_FileName == "MyDbV4.csproj".ToLower())
|
||||
{ dll_name = "MyDb.dll"; }
|
||||
else if (Reference_FileName == "MyDb_SQLiteV4.csproj".ToLower())
|
||||
{ dll_name = "MyDb_SQLite.dll"; }
|
||||
else if (Reference_FileName == "ryControlsV4.csproj".ToLower())
|
||||
{ dll_name = "ryControls.dll"; }
|
||||
else if (Reference_FileName == "RyPrint.csproj".ToLower())
|
||||
{ dll_name = "RyPrint.dll"; }
|
||||
else if (Reference_FileName == "ryUpdateV4.csproj".ToLower())
|
||||
{ dll_name = "ryUpdate.dll"; }
|
||||
if (dll_name != "")
|
||||
{
|
||||
var dll_path = GetDllPath(dll_name);
|
||||
if (dll_path != "")
|
||||
{
|
||||
if (CopyDllToBin)
|
||||
{
|
||||
MoveReference(System.IO.Path.GetFileNameWithoutExtension(dll_name), OutputPath + dll_name);
|
||||
RyFiles.CopyFile(dll_path, RelToAbsPath(path, OutputPath + dll_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveReference(System.IO.Path.GetFileNameWithoutExtension(dll_name), dll_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
//将项目引用转换为dll引用
|
||||
void MoveReference(string reference_name, string dll_path)
|
||||
{
|
||||
ProjectReference_list[i].ParentNode.RemoveChild(ProjectReference_list[i]);
|
||||
var node = xml.SelectSingleNode(@"d:Project//d:ItemGroup", xmlnsm);
|
||||
XmlNode childXmlNode = xml.CreateElement("Reference");
|
||||
XmlNode childXmlNode2 = xml.CreateElement("HintPath");
|
||||
childXmlNode2.InnerText = dll_path;
|
||||
childXmlNode.AppendChild(childXmlNode2);
|
||||
node.AppendChild(childXmlNode);
|
||||
XmlElement element2 = (XmlElement)childXmlNode;
|
||||
element2.SetAttribute("Include", reference_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
xml.InnerXml = xml.InnerXml.Replace(" xmlns=\"\"", "");
|
||||
xml.Save(path);
|
||||
string GetValue(string xpath)
|
||||
{
|
||||
var node = xml.SelectSingleNode(xpath, xmlnsm);
|
||||
if (node != null)
|
||||
{
|
||||
return node.InnerText;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
bool SetValue(string xpath, string value)
|
||||
{
|
||||
var node = xml.SelectSingleNode(xpath, xmlnsm);
|
||||
if (node != null)
|
||||
{
|
||||
node.InnerText = value; return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取版本号
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public string GetAssemblyVersion(string path)
|
||||
{
|
||||
var AssemblyInfo_Path = System.IO.Path.GetDirectoryName(path) + "\\Properties\\AssemblyInfo.cs";
|
||||
if (System.IO.File.Exists(AssemblyInfo_Path))
|
||||
{
|
||||
var AssemblyInfo = ryCommon.RyFiles.ReadAllLines(AssemblyInfo_Path);
|
||||
for (int i = 0; i < AssemblyInfo.Length; i++)
|
||||
{
|
||||
if (AssemblyInfo[i].StartsWith("//")) { continue; }
|
||||
if (AssemblyInfo[i].StartsWith("[assembly: AssemblyVersion"))
|
||||
{
|
||||
return AssemblyInfo[i].GetStr("AssemblyVersion(\"", "\")");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新版本号
|
||||
/// </summary>
|
||||
/// <param name="AssemblyInfo_Path"></param>
|
||||
public static void UpdateVer(string AssemblyInfo_Path)
|
||||
{
|
||||
string AssemblyInfo_path = AssemblyInfo_Path;
|
||||
if (System.IO.File.Exists(AssemblyInfo_path))
|
||||
{
|
||||
string[] AssemblyInfo_list = ryCommon.RyFiles.ReadAllLines(AssemblyInfo_path);
|
||||
string text = "";
|
||||
string Revision_Ver = DateTime.Now.ToString("yyMM");
|
||||
string Build_Ver = DateTime.Now.ToString("dd00");
|
||||
for (int i = 0; i < AssemblyInfo_list.Length; i++)
|
||||
{
|
||||
string item = AssemblyInfo_list[i];
|
||||
if (item.IndexOf("[assembly: AssemblyVersion(\"") == 0)
|
||||
{
|
||||
|
||||
ChangeVer("[assembly: AssemblyVersion(\"");
|
||||
}
|
||||
else if (item.IndexOf("[assembly: AssemblyFileVersion(\"") == 0)
|
||||
{
|
||||
ChangeVer("[assembly: AssemblyFileVersion(\"");
|
||||
}
|
||||
if (text != "") { text += "\r\n"; }
|
||||
text += item;
|
||||
void ChangeVer(string id)
|
||||
{
|
||||
string ver = item.GetStr(id, "\")]", 0, out int pos, "");
|
||||
if (ver != "")
|
||||
{
|
||||
string[] ver_list = ver.Split('.');
|
||||
if (ver_list.Length == 4)
|
||||
{
|
||||
if (ver_list[2] != Revision_Ver)
|
||||
{
|
||||
ver = ver_list[0] + "." + ver_list[1] + "." + Revision_Ver + "." + (Build_Ver.ToInt() + 1).ToString("0000");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ver_list[3].IndexOf(DateTime.Now.ToString("dd")) == 0)
|
||||
{
|
||||
ver = ver_list[0] + "." + ver_list[1] + "." + Revision_Ver + "." + (ver_list[3].ToInt() + 1).ToString("0000");
|
||||
}
|
||||
else
|
||||
{
|
||||
ver = ver_list[0] + "." + ver_list[1] + "." + Revision_Ver + "." + (Build_Ver.ToInt() + 1).ToString("0000");
|
||||
}
|
||||
}
|
||||
item = id + ver + "\")]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ryCommon.RyFiles.WriteAllText(AssemblyInfo_path, text, Encoding.UTF8);
|
||||
}
|
||||
/// <summary>
|
||||
/// 状态变化时激发
|
||||
/// </summary>
|
||||
[Description("状态变化时激发")]
|
||||
public event StringEventHandler OnStateChanged;
|
||||
public RyProject()
|
||||
{
|
||||
UpdateSetting();
|
||||
}
|
||||
/// <summary>
|
||||
/// 等待进程执行完毕
|
||||
/// </summary>
|
||||
/// <param name="cmd_text"></param>
|
||||
/// <returns></returns>
|
||||
public string Read_Prog(string exe, string cmd_text)
|
||||
{
|
||||
String cmd = exe;
|
||||
Process p = new Process
|
||||
{
|
||||
StartInfo = new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = cmd,//设定程序名
|
||||
Arguments = cmd_text,
|
||||
UseShellExecute = false, //关闭shell的使用
|
||||
RedirectStandardInput = true, //重定向标准输入
|
||||
RedirectStandardOutput = true, //重定向标准输出
|
||||
RedirectStandardError = false, //重定向错误输出
|
||||
CreateNoWindow = true//设置不显示窗口
|
||||
}
|
||||
};
|
||||
p.Start();
|
||||
string result = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit(20000);
|
||||
p.Close();
|
||||
return result;
|
||||
/// <summary>
|
||||
/// 更新设置
|
||||
/// </summary>
|
||||
public void UpdateSetting()
|
||||
{
|
||||
DataProvider mydb = new DataProvider();
|
||||
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
||||
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
||||
{
|
||||
var ds = db.ReadData("select * from Settings where name='Setting'");
|
||||
if (mydb.HaveData(ds))
|
||||
{
|
||||
var row = mydb.GetData(ds);
|
||||
ryCommon.Storage mStor = new ryCommon.Storage(row["value"].ToString());
|
||||
mStor.SelectNodeBySet();
|
||||
CshapeBasePath = mStor.GetAttrValue("CshapeBasePath");
|
||||
ReferenceDllPath = mStor.GetAttrValue("ReferenceDll");
|
||||
}
|
||||
}
|
||||
db.Free();
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过dll名称来寻找dll路径
|
||||
/// </summary>
|
||||
/// <param name="_ReferenceDllPath"></param>
|
||||
/// <param name="dll_name"></param>
|
||||
/// <returns></returns>
|
||||
public string GetDllPath(string dll_name)
|
||||
{
|
||||
var path_list = ReferenceDllPath.Replace("\r", "").Split('\n');
|
||||
var find = false;
|
||||
var result = "";
|
||||
#region 在引用文件夹查找是否有该dll,有则使用引用文件夹里的dll
|
||||
for (int m = 0; m < path_list.Length; m++)
|
||||
{
|
||||
if (path_list[m].Trim() == "") { continue; }
|
||||
if (!System.IO.Directory.Exists(path_list[m])) { continue; }
|
||||
var files = System.IO.Directory.GetFiles(path_list[m]);
|
||||
for (int z = 0; z < files.Length; z++)
|
||||
{
|
||||
if (System.IO.Path.GetFileName(files[z]).ToLower() == dll_name.ToLower())
|
||||
{
|
||||
result = files[z];
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find) { break; }
|
||||
}
|
||||
#endregion
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 相对路径转绝对路径,相对项目文件的路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string RelToAbsPath(string project_path,string rel_path)
|
||||
{
|
||||
string folder = System.IO.Path.GetDirectoryName(project_path);
|
||||
var _rel_path = rel_path;
|
||||
while (true)
|
||||
{
|
||||
if (_rel_path.IndexOf("..\\") == 0)
|
||||
{
|
||||
folder = System.IO.Path.GetDirectoryName(folder.TrimEnd('\\'));
|
||||
_rel_path = _rel_path.Substring(3);
|
||||
}
|
||||
else { break; }
|
||||
if (folder == "") { break; }
|
||||
}
|
||||
return folder+"\\"+ _rel_path;
|
||||
}
|
||||
/// <summary>
|
||||
/// 绝对路径转相对路径,相对项目文件的路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string AbsToRelPath(string project_path, string abs_path)
|
||||
{
|
||||
string folder = System.IO.Path.GetDirectoryName(project_path);
|
||||
var _rel_path = "";
|
||||
var _rel_path2 = "";
|
||||
while (true)
|
||||
{
|
||||
if (abs_path.IndexOfEx(folder) == 0)
|
||||
{
|
||||
if (_rel_path2 == "")
|
||||
{ _rel_path = abs_path.Substring(folder.Length); }
|
||||
else
|
||||
{
|
||||
_rel_path = _rel_path2.TrimEnd('\\') + abs_path.Substring(folder.Length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
folder = System.IO.Path.GetDirectoryName(folder.TrimEnd('\\'));
|
||||
_rel_path2 += "..\\";
|
||||
}
|
||||
if (folder == "") { break; }
|
||||
}
|
||||
return _rel_path;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新dll版本,如果全部复制成功,则返回0,否则返回错误个数
|
||||
/// </summary>
|
||||
public int UpdateDlls(string folder,out string error_str)
|
||||
{
|
||||
error_str = "";
|
||||
var _error_str = "";
|
||||
int error = 0;
|
||||
Updates(folder);
|
||||
void Updates(string _path)
|
||||
{
|
||||
var files = System.IO.Directory.GetFiles(_path, "*.dll");
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
string filename = System.IO.Path.GetFileName(files[i]);
|
||||
var dllpath = GetDllPath(filename);
|
||||
if (dllpath != "")
|
||||
{
|
||||
if (RyFiles.CopyFile(dllpath, files[i]) != 0)
|
||||
{ _error_str += files[i]+ "\r\n"; error++; }
|
||||
var dll_xml_path = System.IO.Path.GetDirectoryName(dllpath) +"\\"+ System.IO.Path.GetFileNameWithoutExtension(dllpath) + ".xml";
|
||||
if (System.IO.File.Exists(dll_xml_path))
|
||||
{
|
||||
if (RyFiles.CopyFile(dll_xml_path, System.IO.Path.GetDirectoryName(files[i]) + "\\" + System.IO.Path.GetFileNameWithoutExtension(files[i]) + ".xml") != 0)
|
||||
{ _error_str += files[i] + "\r\n"; error++; }
|
||||
}
|
||||
}
|
||||
}
|
||||
var dirs = System.IO.Directory.GetDirectories(_path);
|
||||
for (int i = 0; i < dirs.Length; i++)
|
||||
{
|
||||
Updates(dirs[i]);
|
||||
}
|
||||
}
|
||||
error_str = _error_str;
|
||||
return error;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新项目引用,定向为本地dll,如果全部复制成功,则返回0,否则返回错误个数
|
||||
/// </summary>
|
||||
public int UpdateCSproj(string folder)
|
||||
{
|
||||
int error = 0;
|
||||
Updates(folder);
|
||||
void Updates(string _path)
|
||||
{
|
||||
var files = System.IO.Directory.GetFiles(_path, "*.csproj");
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
SetCSproj(files[i], "");
|
||||
}
|
||||
var dirs = System.IO.Directory.GetDirectories(_path);
|
||||
for (int i = 0; i < dirs.Length; i++)
|
||||
{
|
||||
Updates(dirs[i]);
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
/// <summary>
|
||||
/// 自动设置csproj文件,将dll引用修改为指定区域的dll、修改命名空间
|
||||
/// </summary>
|
||||
/// <param name="path">项目文件(*.csproj)</param>
|
||||
/// <param name="_project_Eng_name">项目英文名</param>
|
||||
public void SetCSproj(string path, string _project_Eng_name)
|
||||
{
|
||||
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
|
||||
xml.Load(path);
|
||||
var xmlnsm = new XmlNamespaceManager(xml.NameTable);
|
||||
xmlnsm.AddNamespace("d", xml.DocumentElement.NamespaceURI);
|
||||
//var root = @"d:Project//d:ItemGroup//d:Reference";
|
||||
if (_project_Eng_name != "")
|
||||
{
|
||||
SetValue(@"d:Project//d:PropertyGroup//d:RootNamespace", _project_Eng_name.Replace(" ", ""));//命名空间名
|
||||
SetValue(@"d:Project//d:PropertyGroup//d:AssemblyName", _project_Eng_name.Replace(" ", ""));//程序集名称
|
||||
}
|
||||
var OutputPath = GetValue(@"d:Project//d:PropertyGroup[2]//d:OutputPath").TrimEnd('\\')+"\\";
|
||||
if (ChangedOutputPath)
|
||||
{
|
||||
SetValue(@"d:Project//d:PropertyGroup[2]//d:OutputPath", BinFolder.TrimEnd('\\') + "\\Debug\\"+ (_project_Eng_name==""?"": _project_Eng_name +"\\"));//Debug输出路径
|
||||
SetValue(@"d:Project//d:PropertyGroup[3]//d:OutputPath", BinFolder.TrimEnd('\\') + "\\Release\\" + (_project_Eng_name == "" ? "" : _project_Eng_name + "\\"));//Release输出路径
|
||||
}
|
||||
if (OutputPath == "") { OutputPath = BinFolder.TrimEnd('\\') + "\\Debug\\" + (_project_Eng_name == "" ? "" : _project_Eng_name + "\\"); }
|
||||
var list = xml.SelectNodes(@"d:Project//d:ItemGroup//d:Reference//d:HintPath", xmlnsm);
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var HintPath = list[i].InnerText;
|
||||
var iPos = HintPath.LastIndexOf("\\");
|
||||
if (iPos > 0)
|
||||
{
|
||||
var Reference_Name = HintPath.Substring(iPos + 1);//引用的dll名称
|
||||
var dll_path = GetDllPath(Reference_Name);
|
||||
if (dll_path != "")
|
||||
{
|
||||
if (CopyDllToBin)
|
||||
{
|
||||
list[i].InnerText = OutputPath + Reference_Name;
|
||||
RyFiles.CopyFile(dll_path,RelToAbsPath(path, OutputPath + Reference_Name));
|
||||
}
|
||||
else
|
||||
{
|
||||
list[i].InnerText = dll_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var ProjectReference_list = xml.SelectNodes(@"d:Project//d:ItemGroup//d:ProjectReference", xmlnsm);//项目引用
|
||||
for (int i = 0; i < ProjectReference_list.Count; i++)
|
||||
{
|
||||
var element = (XmlElement)ProjectReference_list[i];
|
||||
var IncludePath = element.GetAttribute("Include");
|
||||
var iPos = IncludePath.LastIndexOf("\\");
|
||||
if (iPos > 0)
|
||||
{
|
||||
var Reference_FileName = IncludePath.Substring(iPos + 1).ToLower();//引用的项目文件名称
|
||||
string dll_name = "";
|
||||
if (Reference_FileName == "MyDbV4.csproj".ToLower())
|
||||
{ dll_name = "MyDb.dll"; }
|
||||
else if (Reference_FileName == "MyDb_SQLiteV4.csproj".ToLower())
|
||||
{ dll_name = "MyDb_SQLite.dll"; }
|
||||
else if (Reference_FileName == "ryControlsV4.csproj".ToLower())
|
||||
{ dll_name = "ryControls.dll"; }
|
||||
else if (Reference_FileName == "RyPrint.csproj".ToLower())
|
||||
{ dll_name = "RyPrint.dll"; }
|
||||
else if (Reference_FileName == "ryUpdateV4.csproj".ToLower())
|
||||
{ dll_name = "ryUpdate.dll"; }
|
||||
if (dll_name != "")
|
||||
{
|
||||
var dll_path = GetDllPath(dll_name);
|
||||
if (dll_path != "")
|
||||
{
|
||||
if (CopyDllToBin)
|
||||
{
|
||||
MoveReference(System.IO.Path.GetFileNameWithoutExtension(dll_name), OutputPath + dll_name);
|
||||
RyFiles.CopyFile(dll_path, RelToAbsPath(path, OutputPath + dll_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveReference(System.IO.Path.GetFileNameWithoutExtension(dll_name), dll_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
//将项目引用转换为dll引用
|
||||
void MoveReference(string reference_name, string dll_path)
|
||||
{
|
||||
ProjectReference_list[i].ParentNode.RemoveChild(ProjectReference_list[i]);
|
||||
var node = xml.SelectSingleNode(@"d:Project//d:ItemGroup", xmlnsm);
|
||||
XmlNode childXmlNode = xml.CreateElement("Reference");
|
||||
XmlNode childXmlNode2 = xml.CreateElement("HintPath");
|
||||
childXmlNode2.InnerText = dll_path;
|
||||
childXmlNode.AppendChild(childXmlNode2);
|
||||
node.AppendChild(childXmlNode);
|
||||
XmlElement element2 = (XmlElement)childXmlNode;
|
||||
element2.SetAttribute("Include", reference_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
xml.InnerXml = xml.InnerXml.Replace(" xmlns=\"\"", "");
|
||||
xml.Save(path);
|
||||
string GetValue(string xpath)
|
||||
{
|
||||
var node = xml.SelectSingleNode(xpath, xmlnsm);
|
||||
if (node != null)
|
||||
{
|
||||
return node.InnerText;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
bool SetValue(string xpath, string value)
|
||||
{
|
||||
var node = xml.SelectSingleNode(xpath, xmlnsm);
|
||||
if (node != null)
|
||||
{
|
||||
node.InnerText = value; return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取版本号
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public string GetAssemblyVersion(string path)
|
||||
{
|
||||
var AssemblyInfo_Path = System.IO.Path.GetDirectoryName(path) + "\\Properties\\AssemblyInfo.cs";
|
||||
if (System.IO.File.Exists(AssemblyInfo_Path))
|
||||
{
|
||||
var AssemblyInfo = ryCommon.RyFiles.ReadAllLines(AssemblyInfo_Path);
|
||||
for (int i = 0; i < AssemblyInfo.Length; i++)
|
||||
{
|
||||
if (AssemblyInfo[i].StartsWith("//")) { continue; }
|
||||
if (AssemblyInfo[i].StartsWith("[assembly: AssemblyVersion"))
|
||||
{
|
||||
return AssemblyInfo[i].GetStr("AssemblyVersion(\"", "\")");
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新版本号
|
||||
/// </summary>
|
||||
/// <param name="AssemblyInfo_Path"></param>
|
||||
public static void UpdateVer(string AssemblyInfo_Path)
|
||||
{
|
||||
string AssemblyInfo_path = AssemblyInfo_Path;
|
||||
if (System.IO.File.Exists(AssemblyInfo_path))
|
||||
{
|
||||
string[] AssemblyInfo_list = ryCommon.RyFiles.ReadAllLines(AssemblyInfo_path);
|
||||
string text = "";
|
||||
string Revision_Ver = DateTime.Now.ToString("yyMM");
|
||||
string Build_Ver = DateTime.Now.ToString("dd00");
|
||||
for (int i = 0; i < AssemblyInfo_list.Length; i++)
|
||||
{
|
||||
string item = AssemblyInfo_list[i];
|
||||
if (item.IndexOf("[assembly: AssemblyVersion(\"") == 0)
|
||||
{
|
||||
|
||||
ChangeVer("[assembly: AssemblyVersion(\"");
|
||||
}
|
||||
else if (item.IndexOf("[assembly: AssemblyFileVersion(\"") == 0)
|
||||
{
|
||||
ChangeVer("[assembly: AssemblyFileVersion(\"");
|
||||
}
|
||||
if (text != "") { text += "\r\n"; }
|
||||
text += item;
|
||||
void ChangeVer(string id)
|
||||
{
|
||||
string ver = item.GetStr(id, "\")]", 0, out int pos, "");
|
||||
if (ver != "")
|
||||
{
|
||||
string[] ver_list = ver.Split('.');
|
||||
if (ver_list.Length == 4)
|
||||
{
|
||||
if (ver_list[2] != Revision_Ver)
|
||||
{
|
||||
ver = ver_list[0] + "." + ver_list[1] + "." + Revision_Ver + "." + (Build_Ver.ToInt() + 1).ToString("0000");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ver_list[3].IndexOf(DateTime.Now.ToString("dd")) == 0)
|
||||
{
|
||||
ver = ver_list[0] + "." + ver_list[1] + "." + Revision_Ver + "." + (ver_list[3].ToInt() + 1).ToString("0000");
|
||||
}
|
||||
else
|
||||
{
|
||||
ver = ver_list[0] + "." + ver_list[1] + "." + Revision_Ver + "." + (Build_Ver.ToInt() + 1).ToString("0000");
|
||||
}
|
||||
}
|
||||
item = id + ver + "\")]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ryCommon.RyFiles.WriteAllText(AssemblyInfo_path, text, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 等待进程执行完毕
|
||||
/// </summary>
|
||||
/// <param name="cmd_text"></param>
|
||||
/// <returns></returns>
|
||||
public string Read_Prog(string exe, string cmd_text)
|
||||
{
|
||||
String cmd = exe;
|
||||
Process p = new Process
|
||||
{
|
||||
StartInfo = new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = cmd,//设定程序名
|
||||
Arguments = cmd_text,
|
||||
UseShellExecute = false, //关闭shell的使用
|
||||
RedirectStandardInput = true, //重定向标准输入
|
||||
RedirectStandardOutput = true, //重定向标准输出
|
||||
RedirectStandardError = false, //重定向错误输出
|
||||
CreateNoWindow = true//设置不显示窗口
|
||||
}
|
||||
};
|
||||
p.Start();
|
||||
string result = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit(20000);
|
||||
p.Close();
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 进行打包
|
||||
|
@ -522,6 +522,6 @@ namespace 开发辅助工具.Manager
|
|||
{
|
||||
OnStateChanged?.Invoke(this,text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("开发辅助工具")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("开发辅助工具")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("8177cfd1-097c-4d4e-919d-8b519289496e")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
// 方法是按如下所示使用“*”: :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.0.2011.2801")]
|
||||
[assembly: AssemblyFileVersion("2.0.2011.2801")]
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("开发辅助工具")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("开发辅助工具")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("8177cfd1-097c-4d4e-919d-8b519289496e")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
// 方法是按如下所示使用“*”: :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.0.2012.0701")]
|
||||
[assembly: AssemblyFileVersion("2.0.2012.0701")]
|
|
@ -178,6 +178,8 @@ namespace 开发辅助工具.Tools
|
|||
this.RichHtml.Text = exception.Message;
|
||||
Te_Format.Text = "";
|
||||
tabControl2.SelectedIndex = 0;
|
||||
BtnRunHtml.Text = "执行";
|
||||
IsRunning = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user