refactoring? why?
This commit is contained in:
parent
2ed8d5d9e8
commit
8e8c63e3f2
@ -16,8 +16,8 @@ namespace DTLib
|
||||
|
||||
public void CompressArray(T[] sourceArray)
|
||||
{
|
||||
List<T> listMem = new List<T>();
|
||||
List<byte> listDesc = new List<byte>();
|
||||
var listMem = new List<T>();
|
||||
var listDesc = new List<byte>();
|
||||
T prevElement = sourceArray[0];
|
||||
listMem.Add(sourceArray[0]);
|
||||
listDesc.Add(1);
|
||||
|
||||
@ -10,7 +10,7 @@ namespace DTLib
|
||||
public static void SetLogfile(string dir, string programName)
|
||||
=> Logfile = $"{dir}\\{programName}_{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_');
|
||||
|
||||
static public string Logfile { get; set; }
|
||||
public static string Logfile { get; set; }
|
||||
public static void Log(params string[] msg)
|
||||
{
|
||||
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0];
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
|
||||
namespace DTLib
|
||||
{
|
||||
public delegate Task EventHandlerAsync<TEventArgs>(object sender, TEventArgs e);
|
||||
public delegate Task EventHandlerAsync<TEventArgs>(TEventArgs e);
|
||||
public delegate Task EventHandlerAsync();
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ namespace DTLib.Filesystem
|
||||
public static void Copy(string source_dir, string new_dir, bool owerwrite = false)
|
||||
{
|
||||
Create(new_dir);
|
||||
List<string> subdirs = new List<string>();
|
||||
var subdirs = new List<string>();
|
||||
List<string> files = GetAllFiles(source_dir, ref subdirs);
|
||||
for (int i = 0; i < subdirs.Count; i++)
|
||||
{
|
||||
@ -40,7 +40,7 @@ namespace DTLib.Filesystem
|
||||
public static void Copy(string source_dir, string new_dir, out List<string> conflicts, bool owerwrite = false)
|
||||
{
|
||||
conflicts = new List<string>();
|
||||
List<string> subdirs = new List<string>();
|
||||
var subdirs = new List<string>();
|
||||
List<string> files = GetAllFiles(source_dir, ref subdirs);
|
||||
Create(new_dir);
|
||||
for (int i = 0; i < subdirs.Count; i++)
|
||||
@ -60,7 +60,7 @@ namespace DTLib.Filesystem
|
||||
// удаляет папку со всеми подпапками и файлами
|
||||
public static void Delete(string dir)
|
||||
{
|
||||
List<string> subdirs = new List<string>();
|
||||
var subdirs = new List<string>();
|
||||
List<string> files = GetAllFiles(dir, ref subdirs);
|
||||
for (int i = 0; i < files.Count; i++)
|
||||
File.Delete(files[i]);
|
||||
@ -82,7 +82,7 @@ namespace DTLib.Filesystem
|
||||
// выдает список всех файлов
|
||||
public static List<string> GetAllFiles(string dir)
|
||||
{
|
||||
List<string> all_files = new List<string>();
|
||||
var all_files = new List<string>();
|
||||
string[] cur_files = Directory.GetFiles(dir);
|
||||
for (int i = 0; i < cur_files.Length; i++)
|
||||
{
|
||||
@ -101,7 +101,7 @@ namespace DTLib.Filesystem
|
||||
// выдает список всех файлов и подпапок в папке
|
||||
public static List<string> GetAllFiles(string dir, ref List<string> all_subdirs)
|
||||
{
|
||||
List<string> all_files = new List<string>();
|
||||
var all_files = new List<string>();
|
||||
string[] cur_files = Directory.GetFiles(dir);
|
||||
for (int i = 0; i < cur_files.Length; i++)
|
||||
{
|
||||
@ -122,7 +122,7 @@ namespace DTLib.Filesystem
|
||||
|
||||
public static void GrantAccess(string fullPath)
|
||||
{
|
||||
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(fullPath);
|
||||
var dirInfo = new System.IO.DirectoryInfo(fullPath);
|
||||
System.Security.AccessControl.DirectorySecurity dirSecurity = dirInfo.GetAccessControl();
|
||||
dirSecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(
|
||||
new System.Security.Principal.SecurityIdentifier(
|
||||
|
||||
@ -22,7 +22,7 @@ namespace DTLib.Filesystem
|
||||
lock (new object())
|
||||
{
|
||||
key += ": ";
|
||||
using System.IO.StreamReader reader = new System.IO.StreamReader(configfile);
|
||||
using var reader = new System.IO.StreamReader(configfile);
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
string st = reader.ReadLine();
|
||||
@ -64,8 +64,5 @@ namespace DTLib.Filesystem
|
||||
throw new Exception($"ReadFromConfig({configfile}, {key}) error: key not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace DTLib
|
||||
// массив в лист
|
||||
public static List<T> ToList<T>(this T[] input)
|
||||
{
|
||||
List<T> list = new List<T>();
|
||||
var list = new List<T>();
|
||||
list.AddRange(input);
|
||||
return list;
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace DTLib
|
||||
// удаление нескольких элементов массива
|
||||
public static T[] RemoveRange<T>(this T[] input, int startIndex, int count)
|
||||
{
|
||||
List<T> list = input.ToList();
|
||||
var list = input.ToList();
|
||||
list.RemoveRange(startIndex, count);
|
||||
return list.ToArray();
|
||||
}
|
||||
@ -109,7 +109,7 @@ namespace DTLib
|
||||
// хеш в виде массива байт в строку (хеш изначально не в кодировке UTF8, так что метод выше не работает с ним)
|
||||
public static string HashToString(this byte[] hash)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
var builder = new StringBuilder();
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
{
|
||||
builder.Append(hash[i].ToString("x2"));
|
||||
@ -217,7 +217,7 @@ namespace DTLib
|
||||
}
|
||||
public static T IfNull<T>(this T input, Func<T> if_true) =>
|
||||
input is null ? if_true() : input;
|
||||
public static void IfIsNull<T>(this T input, Action if_true)
|
||||
public static void IfIsNull<T>(this T input, Action if_true)
|
||||
{
|
||||
if (input is null) if_true();
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ namespace DTLib
|
||||
// хеш из двух массивов
|
||||
public byte[] Hash(byte[] input, byte[] salt)
|
||||
{
|
||||
List<byte> rez = new List<byte>();
|
||||
var rez = new List<byte>();
|
||||
rez.AddRange(input);
|
||||
rez.AddRange(salt);
|
||||
return sha256.ComputeHash(rez.ToArray());
|
||||
|
||||
@ -52,7 +52,7 @@ namespace DTLib.Network
|
||||
|
||||
public byte[] DownloadFileToMemory()
|
||||
{
|
||||
using System.IO.MemoryStream fileStream = new System.IO.MemoryStream();
|
||||
using var fileStream = new System.IO.MemoryStream();
|
||||
Download_SharedCode(fileStream, false);
|
||||
byte[] output = fileStream.GetBuffer();
|
||||
fileStream.Close();
|
||||
@ -142,9 +142,9 @@ namespace DTLib.Network
|
||||
if (!dirOnServer.EndsWith("\\"))
|
||||
dirOnServer += "\\";
|
||||
Debug("b", "downloading manifest <", "c", dirOnServer + "manifest.dtsod", "b", ">\n");
|
||||
DtsodV22 manifest = new DtsodV22(DownloadFileToMemory(dirOnServer + "manifest.dtsod").BytesToString());
|
||||
var manifest = new DtsodV22(DownloadFileToMemory(dirOnServer + "manifest.dtsod").BytesToString());
|
||||
Debug("g", $"found {manifest.Values.Count} files in manifest\n");
|
||||
Hasher hasher = new Hasher();
|
||||
var hasher = new Hasher();
|
||||
foreach (string fileOnServer in manifest.Keys)
|
||||
{
|
||||
string fileOnClient = dirOnClient + fileOnServer;
|
||||
|
||||
@ -16,7 +16,7 @@ namespace DTLib.Network
|
||||
// пингует айпи с помощью встроенной в винду проги, возвращает задержку
|
||||
public static string PingIP(string address)
|
||||
{
|
||||
Process proc = new Process();
|
||||
var proc = new Process();
|
||||
proc.StartInfo.FileName = "cmd.exe";
|
||||
proc.StartInfo.Arguments = "/c @echo off & chcp 65001 >nul & ping -n 5 " + address;
|
||||
proc.StartInfo.CreateNoWindow = true;
|
||||
|
||||
@ -42,7 +42,7 @@ namespace DTLib.Network
|
||||
throw new Exception($"SendPackage() error: package is too big ({data.Length} bytes)");
|
||||
if (data.Length == 0)
|
||||
throw new Exception($"SendPackage() error: package has zero size");
|
||||
List<byte> list = new List<byte>();
|
||||
var list = new List<byte>();
|
||||
byte[] packageSize = data.Length.ToBytes();
|
||||
if (packageSize.Length == 1)
|
||||
list.Add(0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user