diff --git a/Apewer/BytesUtility.cs b/Apewer/BytesUtility.cs
index 20b682c..68371d0 100644
--- a/Apewer/BytesUtility.cs
+++ b/Apewer/BytesUtility.cs
@@ -271,7 +271,7 @@ namespace Apewer
/// 转换字节数组为文本,默认使用 UTF-8 代码页。
public static string ToText(byte[] bytes, Encoding encoding = null)
{
- if (bytes.Length < 1) return Constant.EmptyString;
+ if (bytes == null || bytes.Length < 1) return Constant.EmptyString;
try { return (encoding ?? Encoding.UTF8).GetString(bytes); }
catch { return Constant.EmptyString; }
}
@@ -464,26 +464,23 @@ namespace Apewer
{
if (files == null) return null;
- var output = new MemoryStream();
-
- var input = null as Stream;
- var ex = ToZip(files.Keys, output, (name) =>
+ using (var output = new MemoryStream())
{
- RuntimeUtility.Dispose(input);
- if (name.IsEmpty()) return null;
+ var ex = ToZip(files.Keys, output, (name) =>
+ {
+ if (name.IsEmpty()) return null;
- var bytes = files[name];
- if (bytes == null || bytes.LongLength < 1L) return null;
+ var bytes = files[name];
+ if (bytes == null || bytes.LongLength < 1L) return null;
- input = new MemoryStream();
- Write(input, bytes);
- return input;
- }, null, true);
- RuntimeUtility.Dispose(input);
+ var input = new MemoryStream();
+ Write(input, bytes);
+ input.Position = 0;
+ return input;
+ }, null, true);
- var result = output.ToArray();
- RuntimeUtility.Dispose(result);
- return result;
+ return output.ToArray();
+ }
}
/// 解压 ZIP 文件。
@@ -997,7 +994,7 @@ namespace Apewer
///
public static byte[] AesDecrypt(byte[] cipher, byte[] key, CipherMode cipherMode = CipherMode.ECB, PaddingMode paddingMode = PaddingMode.PKCS7)
{
- return UseAes(cipher, key, null, cipherMode, paddingMode, (rijndael) => rijndael.CreateEncryptor(rijndael.Key, rijndael.IV));
+ return UseAes(cipher, key, null, cipherMode, paddingMode, (rijndael) => rijndael.CreateDecryptor(rijndael.Key, rijndael.IV));
}
/// 执行 AES 128/192/256 解密。
@@ -1012,7 +1009,7 @@ namespace Apewer
///
public static byte[] AesDecrypt(byte[] cipher, byte[] key, byte[] iv, CipherMode cipherMode = CipherMode.ECB, PaddingMode paddingMode = PaddingMode.PKCS7)
{
- return UseAes(cipher, key, iv, cipherMode, paddingMode, (rijndael) => rijndael.CreateEncryptor(rijndael.Key, rijndael.IV));
+ return UseAes(cipher, key, iv, cipherMode, paddingMode, (rijndael) => rijndael.CreateDecryptor(rijndael.Key, rijndael.IV));
}
#endregion
diff --git a/Apewer/CollectionUtility.cs b/Apewer/CollectionUtility.cs
index 51997a9..16ee9b4 100644
--- a/Apewer/CollectionUtility.cs
+++ b/Apewer/CollectionUtility.cs
@@ -655,7 +655,7 @@ namespace Apewer
/// 根据条件筛选,将符合条件的元素组成新数组。
public static T[] FindAll(this IEnumerable collection, Predicate match)
{
- if (collection == null) new ArgumentNullException(nameof(collection));
+ if (collection == null) throw new ArgumentNullException(nameof(collection));
if (match == null) throw new ArgumentNullException(nameof(match));
if (collection is T[] array)
@@ -765,7 +765,7 @@ namespace Apewer
if (capacity == count)
{
capacity += 1024;
- list.Capacity += capacity;
+ list.Capacity = capacity;
}
list.Add(selector.Invoke(item, count));
count += 1;
@@ -999,7 +999,7 @@ namespace Apewer
// 生成新数组
var result = new T[array.Length];
for (var i = 0; i < result.Length; i++) result[i] = array[i];
- result[index] = value;
+ result[offset] = value;
return result;
}
diff --git a/Apewer/Logger.cs b/Apewer/Logger.cs
index 6ab5467..4964265 100644
--- a/Apewer/Logger.cs
+++ b/Apewer/Logger.cs
@@ -365,7 +365,7 @@ namespace Apewer
if (bytes.Length > 0)
{
var gzipData = BytesUtility.ToGzip(bytes);
- if (gzipData != null || gzipData.Length > 0)
+ if (gzipData != null && gzipData.Length > 0)
{
var gzipPath = path + ".gzip";
StorageUtility.WriteFile(gzipPath, gzipData);
diff --git a/Apewer/NumberUtility.cs b/Apewer/NumberUtility.cs
index 52b6fa2..d6706a9 100644
--- a/Apewer/NumberUtility.cs
+++ b/Apewer/NumberUtility.cs
@@ -428,7 +428,6 @@ namespace Apewer
foreach (var value in values)
{
up += (value - avg) * (value - avg);
- count++;
}
}
diff --git a/Apewer/Source/Execute.cs b/Apewer/Source/Execute.cs
index 80df06a..c5cfa78 100644
--- a/Apewer/Source/Execute.cs
+++ b/Apewer/Source/Execute.cs
@@ -24,7 +24,7 @@ namespace Apewer.Source
/// 创建实例。
public Execute(bool success, string message)
{
- _success = false;
+ _success = success;
_message = message;
}
diff --git a/Apewer/Source/Query.cs b/Apewer/Source/Query.cs
index d1fc953..44e1d7e 100644
--- a/Apewer/Source/Query.cs
+++ b/Apewer/Source/Query.cs
@@ -22,7 +22,7 @@ namespace Apewer.Source
/// 创建实例,默认状态为失败。
public Query(bool success = false, string message = null)
{
- _success = false;
+ _success = success;
_message = message;
}
diff --git a/Apewer/StorageUtility.cs b/Apewer/StorageUtility.cs
index 49f5510..e4eb4b6 100644
--- a/Apewer/StorageUtility.cs
+++ b/Apewer/StorageUtility.cs
@@ -82,7 +82,7 @@ namespace Apewer
if (!Directory.Exists(path)) return new DirectoryNotFoundException();
var temp = Environment.GetEnvironmentVariable("TEMP");
- var name = Path.GetDirectoryName(path);
+ var name = Path.GetFileName(path);
var dest = null as string;
while (dest == null || Directory.Exists(dest))
diff --git a/Apewer/TextUtility.cs b/Apewer/TextUtility.cs
index 4c7b208..33e6cab 100644
--- a/Apewer/TextUtility.cs
+++ b/Apewer/TextUtility.cs
@@ -137,7 +137,7 @@ namespace Apewer
if (cell is string) text = cell as string;
else if (cell is Type type) text = type.Name;
- else cell.ToString();
+ else text = cell.ToString();
if (string.IsNullOrEmpty(text)) continue;
if (!first && hasSeparator) sb.Append(separator);
@@ -610,7 +610,8 @@ namespace Apewer
// foot
length = text.IndexOf(foot);
- if (length < 1) return text;
+ if (length == 0) return Empty;
+ if (length < 0) return text;
return text.Substring(0, length);
}
else