|
|
|
@ -311,7 +311,7 @@ namespace Apewer |
|
|
|
|
|
|
|
#region file
|
|
|
|
|
|
|
|
/// <summary>打开文件,并获取文件流。若文件不存在,则先创建文件;若获取失败,则返回 NULL 值。可选文件的锁定状态。</summary>
|
|
|
|
/// <summary>打开文件,并获取文件流。若文件不存在,则先创建文件。</summary>
|
|
|
|
public static FileStream OpenFile(string path, bool share = true) |
|
|
|
{ |
|
|
|
try |
|
|
|
@ -450,27 +450,19 @@ namespace Apewer |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var file = OpenFile(path, true); |
|
|
|
var success = false; |
|
|
|
try |
|
|
|
{ |
|
|
|
var dir = Path.GetDirectoryName(path); |
|
|
|
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); |
|
|
|
|
|
|
|
var write1 = BytesUtility.Write(file, TextUtility.Bom); |
|
|
|
if (write1 == TextUtility.Bom.Length) |
|
|
|
using (var file = OpenFile(path, true)) |
|
|
|
{ |
|
|
|
var write2 = BytesUtility.Write(file, bytes); |
|
|
|
if (bytes != null && bytes.LongLength > 0L) |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
file.SetLength(0); |
|
|
|
BytesUtility.Write(file, TextUtility.Bom); |
|
|
|
BytesUtility.Write(file, bytes); |
|
|
|
return true; |
|
|
|
} |
|
|
|
success = true; |
|
|
|
catch { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
catch { } |
|
|
|
RuntimeUtility.Dispose(file); |
|
|
|
return success; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|