8ca6e89d
Tuo Wenbo
20211021
|
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
namespace OS.Spin.Common
{
/// <summary>
/// 文件 操作
/// </summary>
public static class FilesOperate
{
/// <summary>
/// 获取App的当前路径 \\结束
/// </summary>
/// <returns></returns>
public static string getAppPath()
{
return GetAssemblyPath();
}
/// <summary>
/// 获取Assembly的运行路径 \\结束
/// </summary>
/// <returns></returns>
public static string GetAssemblyPath()
{
try
{
string sCodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
sCodeBase = sCodeBase.Substring(8, sCodeBase.Length - 8); // 8是 file:// 的长度
string[] arrSection = sCodeBase.Split(new char[] { '/' });
string sDirPath = "";
for (int i = 0; i < arrSection.Length - 1; i++)
{
sDirPath += arrSection[i] + Path.DirectorySeparatorChar;
}
return sDirPath;
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("GetAssemblyPath:{0}", ex.Message));
return "";
}
}
/// <summary>
/// 文件夹复制
/// </summary>
/// <param name="sSourceDirName">原始路径</param>
/// <param name="sDestDirName">目标路径</param>
/// <returns></returns>
public static bool CopyDirectory(string sSourceDirName, string sDestDirName)
{
try
{
if (string.IsNullOrEmpty(sSourceDirName) || string.IsNullOrEmpty(sDestDirName))
{
return false;
}
//不复制.svn文件夹
if (sSourceDirName.EndsWith("svn"))
{
return true;
}
if (sSourceDirName.Substring(sSourceDirName.Length - 1) != Path.DirectorySeparatorChar.ToString())
{
sSourceDirName = sSourceDirName + Path.DirectorySeparatorChar;
}
if (sDestDirName.Substring(sDestDirName.Length - 1) != Path.DirectorySeparatorChar.ToString())
{
sDestDirName = sDestDirName + Path.DirectorySeparatorChar;
}
#region 复制函数
if (Directory.Exists(sSourceDirName))
{
if (!Directory.Exists(sDestDirName))
{
Directory.CreateDirectory(sDestDirName);
}
foreach (string item in Directory.GetFiles(sSourceDirName))
{
File.Copy(item, sDestDirName + System.IO.Path.GetFileName(item), true);
}
foreach (string item in Directory.GetDirectories(sSourceDirName))
{
CopyDirectory(item, sDestDirName + item.Substring(item.LastIndexOf(Path.DirectorySeparatorChar) + 1));
}
}
return true;
#endregion
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("CopyDirectory:{0}", ex.Message));
return false;
}
}
/// <summary>
/// 启动其他的应用程序
/// </summary>
/// <param name="file">应用程序名称</param>
/// <param name="workdirectory">应用程序工作目录</param>
/// <param name="args">命令行参数</param>
/// <param name="style">窗口风格</param>
public static bool StartProcess(string file, string workdirectory, string args, ProcessWindowStyle style)
{
try
{
Process pMyProcess = new Process();
ProcessStartInfo pStartInfo = new ProcessStartInfo(file, args);
pStartInfo.WindowStyle = style;
pStartInfo.WorkingDirectory = workdirectory;
pMyProcess.StartInfo = pStartInfo;
pMyProcess.StartInfo.UseShellExecute = false;
pMyProcess.Start();
return true;
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("StartProcess:{0}", ex.Message));
//LogAPI.debug(ex);
return false;
}
}
/// <summary>
/// 获得本地计算机名
/// </summary>
/// <returns></returns>
public static string GetComputerName()
{
return Dns.GetHostName();
}
/// <summary>
/// 获得计算机IP地址
/// </summary>
/// <returns></returns>
public static string GetIPAddress()
{
try
{
string sComputerName;
sComputerName = GetComputerName();
string sIpAddress = "";
IPAddress[] addr = Dns.GetHostAddresses(sComputerName);
//for (int i = 0; i < addr.Length; i++)
//{
// sIpAddress += addr[i].ToString() + " ";
//}
sIpAddress = addr[0].ToString();
return sIpAddress;
}
catch (Exception ep)
{
//LogAPI.debug(ep);
return "127.0.0.1";
}
}
/// <summary>
/// 描述:创建目录
/// </summary>
/// <returns></returns>
public static bool CreateFolder(string sFolder)
{
//如果临时文件夹不存在,则创建该文件夹
if (!Directory.Exists(sFolder))
{
Directory.CreateDirectory(sFolder);
}
return true;
}
}
}
|