some fixes

This commit is contained in:
2022-03-13 17:18:34 +03:00
parent c201f11ce1
commit 4ae26cab92
4 changed files with 356 additions and 356 deletions

View File

@@ -1,98 +1,98 @@
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;
using DTLib;
using DTLib.Filesystem;
using DTLib.Network;
using DTLib.Extensions;
namespace updater
{
class Updater
{
static readonly string logfile = $"logs\\updater-{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_');
static Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
static readonly string server_domain = "m1net.keenetic.pro";
static readonly int server_port = 25001;
static void Main(string[] args)
{
try
{
Console.Title = "dtlauncher updater";
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
PublicLog.LogEvent += Log;
PublicLog.LogNoTimeEvent += Log;
// подключение к центральному серверу
while (true)
{
try
{
Log("b", "server address: <", "c", server_domain, "b",
">\nserver port: <", "c", server_port.ToString(), "b", ">\n");
mainSocket.Connect(new IPEndPoint(Dns.GetHostAddresses(server_domain)[0], server_port));
Log("g", "connected to server\n");
break;
}
catch (SocketException ex)
{
Log("r", $"updater.Main() error:\n{ex.Message}\n{ex.StackTrace}\n");
}
}
var fsp = new FSP(mainSocket);
string recieved = mainSocket.GetPackage().BytesToString();
if (recieved != "requesting hash") throw new Exception("invalid server request");
mainSocket.SendPackage(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 });
recieved = mainSocket.GetPackage().BytesToString();
if (recieved != "updater") throw new Exception($"invalid central server answer <{recieved}>");
// обновление апдейтера
if (args.Length == 0 || args[0] != "updated")
{
fsp.DownloadFile("dtlauncher.exe", "TEMP\\dtlauncher.exe");
Log("g", "dtlauncher.exe downloaded\n");
fsp.DownloadFile("DTLib.dll", "TEMP\\DTLib.dll");
Log("g", "DTLib.dll downloaded\n");
Process.Start("cmd", "/c timeout 0 && copy TEMP\\dtlauncher.exe dtlauncher.exe && copy TEMP\\DTLib.dll DTLib.dll && start dtlauncher.exe updated");
}
else
{
// установка шрифтов
/*Log("installing fonts\n");
Process.Start("fonts\\fontinst.exe");
Directory.Delete("TEMP");*/
Log("deleted TEMP\n");
fsp.DownloadFile("dtlauncher-client-win.exe", "dtlauncher-client-win.exe");
Process.Start("dtlauncher-client-win.exe", "updated");
}
}
catch (Exception ex)
{
Log("r", $"updater.Main() error:\n{ex.Message}\n{ex.StackTrace}\n", "gray", "press any key to close...");
Console.ReadKey();
}
Log("gray", " \n");
}
// вывод лога в консоль и файл
public static void Log(params string[] msg)
{
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0];
else msg[1] = "[" + DateTime.Now.ToString() + "]: " + msg[1];
LogNoTime(msg);
}
public static void LogNoTime(params string[] msg)
{
lock (new object())
{
if (msg.Length == 1) File.AppendAllText(logfile, msg[0]);
else if (msg.Length % 2 != 0) throw new Exception("incorrect array to log\n");
else File.AppendAllText(logfile, msg.MergeToString());
ColoredConsole.Write(msg);
}
}
}
}
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Text;
using DTLib;
using DTLib.Filesystem;
using DTLib.Network;
using DTLib.Extensions;
namespace updater
{
class Updater
{
static readonly string logfile = $"logs\\updater-{DateTime.Now}.log".Replace(':', '-').Replace(' ', '_');
static Socket mainSocket = new(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
static readonly string server_domain = "m1net.keenetic.pro";
static readonly int server_port = 25001;
static void Main(string[] args)
{
try
{
Console.Title = "dtlauncher updater";
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
PublicLog.LogEvent += Log;
PublicLog.LogNoTimeEvent += Log;
// подключение к центральному серверу
while (true)
{
try
{
Log("b", "server address: <", "c", server_domain, "b",
">\nserver port: <", "c", server_port.ToString(), "b", ">\n");
mainSocket.Connect(new IPEndPoint(Dns.GetHostAddresses(server_domain)[0], server_port));
Log("g", "connected to server\n");
break;
}
catch (SocketException ex)
{
Log("r", $"updater.Main() error:\n{ex.Message}\n{ex.StackTrace}\n");
}
}
var fsp = new FSP(mainSocket);
string recieved = mainSocket.GetPackage().BytesToString();
if (recieved != "requesting hash") throw new Exception("invalid server request");
mainSocket.SendPackage(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 });
recieved = mainSocket.GetPackage().BytesToString();
if (recieved != "updater") throw new Exception($"invalid central server answer <{recieved}>");
// обновление апдейтера
if (args.Length == 0 || args[0] != "updated")
{
fsp.DownloadFile("updater.exe", "TEMP\\updater.exe");
Log("g", "updater.exe downloaded\n");
fsp.DownloadFile("DTLib.dll", "TEMP\\DTLib.dll");
Log("g", "DTLib.dll downloaded\n");
Process.Start("cmd", "/c timeout 0 && copy TEMP\\updater.exe updater.exe && copy TEMP\\DTLib.dll DTLib.dll && start updater.exe updated");
}
else
{
// установка шрифтов
/*Log("installing fonts\n");
Process.Start("fonts\\fontinst.exe");
Directory.Delete("TEMP");*/
Log("deleted TEMP\n");
fsp.DownloadFile("dtlauncher-client-win.exe", "dtlauncher-client-win.exe");
Process.Start("dtlauncher-client-win.exe", "updated");
}
}
catch (Exception ex)
{
Log("r", $"updater.Main() error:\n{ex.Message}\n{ex.StackTrace}\n", "gray", "press any key to close...");
Console.ReadKey();
}
Log("gray", " \n");
}
// вывод лога в консоль и файл
public static void Log(params string[] msg)
{
if (msg.Length == 1) msg[0] = "[" + DateTime.Now.ToString() + "]: " + msg[0];
else msg[1] = "[" + DateTime.Now.ToString() + "]: " + msg[1];
LogNoTime(msg);
}
public static void LogNoTime(params string[] msg)
{
lock (new object())
{
if (msg.Length == 1) File.AppendAllText(logfile, msg[0]);
else if (msg.Length % 2 != 0) throw new Exception("incorrect array to log\n");
else File.AppendAllText(logfile, msg.MergeToString());
ColoredConsole.Write(msg);
}
}
}
}

View File

@@ -1,94 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4784D974-A342-4202-9430-90FE5AC00FC7}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>updater</RootNamespace>
<AssemblyName>dtlauncher</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>9.0</LangVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Build|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>logo-D.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Updater.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 и x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="logo-D.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj">
<Project>{ce793497-2d5c-42d8-b311-e9b32af9cdfb}</Project>
<Name>DTLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>del /f /q dtlauncher.exe.config
copy dtlauncher.exe ..\..\dtlauncher-server-win\bin\share\client\dtlauncher.exe
copy DTLib.dll ..\..\dtlauncher-server-win\bin\share\client\DTLib.dll
copy dtlauncher.exe ..\..\release\dtlauncher.exe
copy DTLib.dll ..\..\release\DTLib.dll
</PostBuildEvent>
</PropertyGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4784D974-A342-4202-9430-90FE5AC00FC7}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>updater</RootNamespace>
<AssemblyName>updater</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>9.0</LangVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Build|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>logo-D.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Updater.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 и x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="logo-D.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\DTLib\DTLib\DTLib.csproj">
<Project>{ce793497-2d5c-42d8-b311-e9b32af9cdfb}</Project>
<Name>DTLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>del /f /q updater.exe.config
copy updater.exe ..\..\dtlauncher-server-win\bin\share\client\updater.exe
copy DTLib.dll ..\..\dtlauncher-server-win\bin\share\client\DTLib.dll
copy updater.exe ..\..\release\updater.exe
copy DTLib.dll ..\..\release\DTLib.dll
</PostBuildEvent>
</PropertyGroup>
</Project>