FileWork update
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace DTLib
|
||||
{
|
||||
@@ -14,12 +13,7 @@ namespace DTLib
|
||||
{
|
||||
lock (new object())
|
||||
{
|
||||
File.Create(logfile);
|
||||
var st = File.OpenAppend(logfile);
|
||||
var writer = new StreamWriter(st, SimpleConverter.UTF8);
|
||||
writer.Write(msg);
|
||||
writer.Close();
|
||||
st.Close();
|
||||
File.WriteAllText(logfile, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +23,7 @@ namespace DTLib
|
||||
lock (new object())
|
||||
{
|
||||
key += ": ";
|
||||
using var reader = new StreamReader(configfile);
|
||||
using var reader = new System.IO.StreamReader(configfile);
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
string st = reader.ReadLine();
|
||||
@@ -66,7 +60,7 @@ namespace DTLib
|
||||
}
|
||||
}
|
||||
reader.Close();
|
||||
throw new System.Exception($"ReadFromConfig({configfile}, {key}) error: key not found");
|
||||
throw new Exception($"ReadFromConfig({configfile}, {key}) error: key not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +131,7 @@ namespace DTLib
|
||||
}
|
||||
|
||||
public static string[] GetFiles(string dir) => System.IO.Directory.GetFiles(dir);
|
||||
public static string[] GetFiles(string dir, string searchPattern) => System.IO.Directory.GetFiles(dir, searchPattern);
|
||||
public static string[] GetDirectories(string dir) => System.IO.Directory.GetDirectories(dir);
|
||||
|
||||
// выдает список всех файлов
|
||||
@@ -208,7 +203,7 @@ namespace DTLib
|
||||
|
||||
public static byte[] ReadAllBytes(string file)
|
||||
{
|
||||
using FileStream stream = System.IO.File.OpenRead(file);
|
||||
using var stream = File.OpenRead(file);
|
||||
int size = GetSize(file);
|
||||
byte[] output = new byte[size];
|
||||
stream.Read(output, 0, size);
|
||||
@@ -220,8 +215,7 @@ namespace DTLib
|
||||
|
||||
public static void WriteAllBytes(string file, byte[] content)
|
||||
{
|
||||
File.Create(file);
|
||||
using FileStream stream = System.IO.File.OpenWrite(file);
|
||||
using var stream = File.OpenWrite(file);
|
||||
stream.Write(content, 0, content.Length);
|
||||
stream.Close();
|
||||
}
|
||||
@@ -231,27 +225,27 @@ namespace DTLib
|
||||
public static void AppendAllBytes(string file, byte[] content)
|
||||
{
|
||||
File.Create(file);
|
||||
using FileStream stream = System.IO.File.OpenWrite(file);
|
||||
stream.Write(content, GetSize(file), content.Length);
|
||||
using var stream = File.OpenAppend(file);
|
||||
stream.Write(content, 0, content.Length);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
public static void AppendAllText(string file, string content) => AppendAllBytes(file, content.ToBytes());
|
||||
|
||||
public static FileStream OpenRead(string file)
|
||||
public static System.IO.FileStream OpenRead(string file)
|
||||
{
|
||||
if (!Exists(file)) throw new Exception($"file not found: <{file}>");
|
||||
return System.IO.File.OpenRead(file);
|
||||
}
|
||||
public static FileStream OpenWrite(string file)
|
||||
public static System.IO.FileStream OpenWrite(string file)
|
||||
{
|
||||
File.Create(file);
|
||||
return System.IO.File.OpenWrite(file);
|
||||
}
|
||||
public static FileStream OpenAppend(string file)
|
||||
public static System.IO.FileStream OpenAppend(string file)
|
||||
{
|
||||
File.Create(file);
|
||||
return System.IO.File.Open(file, FileMode.Append);
|
||||
return System.IO.File.Open(file, System.IO.FileMode.Append);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using static DTLib.Filework;
|
||||
|
||||
namespace DTLib
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
//using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
@@ -141,7 +140,6 @@ namespace DTLib
|
||||
}
|
||||
fileStream.Close();
|
||||
Log(new string[] { "g", $" uploaded {packagesCount * 5120 + buffer.Length} of {fileSize} bytes\n" });
|
||||
|
||||
}
|
||||
|
||||
// получает с сайта публичный ip
|
||||
@@ -163,33 +161,6 @@ namespace DTLib
|
||||
return rezult.Remove(rezult.Length - 4);
|
||||
}
|
||||
|
||||
// скачивание файла с фтп сервера
|
||||
/*public static void FtpDownload(string address, string login, string password, string outfile)
|
||||
{
|
||||
try
|
||||
{
|
||||
// debug
|
||||
Log(new string[] { "y", "file on server: <", "c", address, "y", ">\nfile on client: <", "c", outfile, "y", ">\n" });
|
||||
// создание запроса
|
||||
// "ftp://m1net.keenetic.pro:20000/" + @infile
|
||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(address);
|
||||
request.Credentials = new NetworkCredential(login, password);
|
||||
request.Method = WebRequestMethods.Ftp.DownloadFile;
|
||||
// получение ответа на запрос
|
||||
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
|
||||
Stream responseStream = response.GetResponseStream();
|
||||
FileStream fs = new FileStream(@Directory.GetCurrentDirectory() + '\\' + @outfile, FileMode.Create);
|
||||
byte[] buffer = new byte[64];
|
||||
int size = 0;
|
||||
|
||||
while ((size = responseStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
fs.Write(buffer, 0, size);
|
||||
fs.Close();
|
||||
response.Close();
|
||||
}
|
||||
catch (WebException e) { throw new Exception("ftp error:\n" + ((FtpWebResponse)e.Response).StatusDescription + '\n'); }
|
||||
}*/
|
||||
|
||||
public class FSP
|
||||
{
|
||||
Socket mainSocket;
|
||||
|
||||
Reference in New Issue
Block a user