Browse Source

修正代码错误。

master
Elivo 1 month ago
parent
commit
ec0791835b
  1. 21
      Apewer/BytesUtility.cs
  2. 6
      Apewer/CollectionUtility.cs
  3. 2
      Apewer/Logger.cs
  4. 1
      Apewer/NumberUtility.cs
  5. 2
      Apewer/Source/Execute.cs
  6. 2
      Apewer/Source/Query.cs
  7. 2
      Apewer/StorageUtility.cs
  8. 5
      Apewer/TextUtility.cs

21
Apewer/BytesUtility.cs

@ -271,7 +271,7 @@ namespace Apewer
/// <summary>转换字节数组为文本,默认使用 UTF-8 代码页。</summary>
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;
using (var output = new MemoryStream())
{
var ex = ToZip(files.Keys, output, (name) =>
{
RuntimeUtility.Dispose(input);
if (name.IsEmpty()) return null;
var bytes = files[name];
if (bytes == null || bytes.LongLength < 1L) return null;
input = new MemoryStream();
var input = new MemoryStream();
Write(input, bytes);
input.Position = 0;
return input;
}, null, true);
RuntimeUtility.Dispose(input);
var result = output.ToArray();
RuntimeUtility.Dispose(result);
return result;
return output.ToArray();
}
}
/// <summary>解压 ZIP 文件。</summary>
@ -997,7 +994,7 @@ namespace Apewer
/// <exception cref="CryptographicException" />
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));
}
/// <summary>执行 AES 128/192/256 解密。</summary>
@ -1012,7 +1009,7 @@ namespace Apewer
/// <exception cref="CryptographicException" />
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

6
Apewer/CollectionUtility.cs

@ -655,7 +655,7 @@ namespace Apewer
/// <summary>根据条件筛选,将符合条件的元素组成新数组。</summary>
public static T[] FindAll<T>(this IEnumerable<T> collection, Predicate<T> 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;
}

2
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);

1
Apewer/NumberUtility.cs

@ -428,7 +428,6 @@ namespace Apewer
foreach (var value in values)
{
up += (value - avg) * (value - avg);
count++;
}
}

2
Apewer/Source/Execute.cs

@ -24,7 +24,7 @@ namespace Apewer.Source
/// <summary>创建实例。</summary>
public Execute(bool success, string message)
{
_success = false;
_success = success;
_message = message;
}

2
Apewer/Source/Query.cs

@ -22,7 +22,7 @@ namespace Apewer.Source
/// <summary>创建实例,默认状态为失败。</summary>
public Query(bool success = false, string message = null)
{
_success = false;
_success = success;
_message = message;
}

2
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))

5
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

Loading…
Cancel
Save