* 重构文件扩展类
This commit is contained in:
parent
5715d13fac
commit
e33f97b192
@ -71,8 +71,8 @@ namespace Sunny.UI
|
||||
/// <returns>打开是否成功</returns>
|
||||
public static bool OpenDialog(ref string filename, string filter = "", string defaultExt = "")
|
||||
{
|
||||
using (OpenFileDialog od = new OpenFileDialog { Title = "打开" })
|
||||
{
|
||||
using OpenFileDialog od = new OpenFileDialog { Title = UILocalize.Open };
|
||||
|
||||
try
|
||||
{
|
||||
od.FileName = filename;
|
||||
@ -84,14 +84,9 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
od.DefaultExt = defaultExt;
|
||||
if (od.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
filename = od.FileName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
bool isOk = od.ShowDialog() == DialogResult.OK;
|
||||
if (isOk) filename = od.FileName;
|
||||
return isOk;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,8 +98,7 @@ namespace Sunny.UI
|
||||
/// <returns>保存是否成功</returns>
|
||||
public static bool SaveDialog(ref string filename, string filter = "", string defaultExt = "")
|
||||
{
|
||||
using (SaveFileDialog od = new SaveFileDialog { Title = "保存" })
|
||||
{
|
||||
using SaveFileDialog od = new SaveFileDialog { Title = UILocalize.Save };
|
||||
try
|
||||
{
|
||||
od.FileName = filename;
|
||||
@ -116,14 +110,9 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
od.DefaultExt = defaultExt;
|
||||
if (od.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
filename = od.FileName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
bool isOk = od.ShowDialog() == DialogResult.OK;
|
||||
if (isOk) filename = od.FileName;
|
||||
return isOk;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -542,52 +531,6 @@ namespace Sunny.UI
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 复制
|
||||
/// </summary>
|
||||
/// <param name="source">源目录</param>
|
||||
/// <param name="dest">目标目录</param>
|
||||
public static void Copy(string source, string dest)
|
||||
{
|
||||
Copy(new DirectoryInfo(source), new DirectoryInfo(dest));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 复制
|
||||
/// </summary>
|
||||
/// <param name="source">源目录</param>
|
||||
/// <param name="dest">目标目录</param>
|
||||
public static void Copy(DirectoryInfo source, DirectoryInfo dest)
|
||||
{
|
||||
if (dest.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
throw new Exception("父目录不能拷贝到子目录!");
|
||||
}
|
||||
|
||||
if (!source.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dest.Exists)
|
||||
{
|
||||
dest.Create();
|
||||
}
|
||||
|
||||
FileInfo[] files = source.GetFiles();
|
||||
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
File.Copy(file.FullName, Path.Combine(dest.FullName, file.Name), true);
|
||||
}
|
||||
|
||||
DirectoryInfo[] dirs = source.GetDirectories();
|
||||
foreach (DirectoryInfo dir in dirs)
|
||||
{
|
||||
Copy(dir.FullName, Path.Combine(dest.FullName, dir.Name));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据完整文件路径获取FileStream
|
||||
/// </summary>
|
||||
@ -605,16 +548,6 @@ namespace Sunny.UI
|
||||
return fileStream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测指定文件是否存在,如果存在则返回true。
|
||||
/// </summary>
|
||||
/// <param name="filePath">文件的绝对路径</param>
|
||||
/// <returns>结果</returns>
|
||||
public static bool Exists(string filePath)
|
||||
{
|
||||
return File.Exists(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个文件。
|
||||
/// </summary>
|
||||
@ -625,7 +558,7 @@ namespace Sunny.UI
|
||||
try
|
||||
{
|
||||
//如果文件不存在则创建该文件
|
||||
if (!Exists(filePath))
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
//创建一个FileInfo对象
|
||||
FileInfo file = new FileInfo(filePath);
|
||||
@ -654,7 +587,7 @@ namespace Sunny.UI
|
||||
try
|
||||
{
|
||||
//如果文件不存在则创建该文件
|
||||
if (!Exists(filePath))
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
//创建一个FileInfo对象
|
||||
FileInfo file = new FileInfo(filePath);
|
||||
|
@ -226,6 +226,9 @@ namespace Sunny.UI
|
||||
/// 清除
|
||||
/// </summary>
|
||||
public static string Clear = "清除";
|
||||
|
||||
public static string Open = "打开";
|
||||
public static string Save = "保存";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -253,13 +256,13 @@ namespace Sunny.UI
|
||||
UILocalize.GridDataSourceException = "The data source must be DataTable or List";
|
||||
UILocalize.SystemProcessing = "The system is processing, please wait...";
|
||||
|
||||
UILocalize.Monday = "Mon.";
|
||||
UILocalize.Tuesday = "Tue.";
|
||||
UILocalize.Wednesday = "Wed.";
|
||||
UILocalize.Thursday = "Thur.";
|
||||
UILocalize.Friday = "Fri.";
|
||||
UILocalize.Saturday = "Sat.";
|
||||
UILocalize.Sunday = "Sun.";
|
||||
UILocalize.Monday = "MON";
|
||||
UILocalize.Tuesday = "TUE";
|
||||
UILocalize.Wednesday = "WED";
|
||||
UILocalize.Thursday = "THU";
|
||||
UILocalize.Friday = "FRI";
|
||||
UILocalize.Saturday = "SAT";
|
||||
UILocalize.Sunday = "SUN";
|
||||
|
||||
UILocalize.Prev = "Previous";
|
||||
UILocalize.Next = "Next";
|
||||
@ -284,6 +287,9 @@ namespace Sunny.UI
|
||||
UILocalize.Search = "Search";
|
||||
UILocalize.Clear = "Clear";
|
||||
|
||||
UILocalize.Open = "Open";
|
||||
UILocalize.Save = "Save";
|
||||
|
||||
UIStyles.Translate();
|
||||
}
|
||||
|
||||
@ -339,6 +345,9 @@ namespace Sunny.UI
|
||||
UILocalize.Search = "搜索";
|
||||
UILocalize.Clear = "清除";
|
||||
|
||||
UILocalize.Open = "打开";
|
||||
UILocalize.Save = "保存";
|
||||
|
||||
UIStyles.Translate();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user