Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit f0a5bb5

Browse files
szagidullinamadetara
authored andcommitted
изменения для первого тестового самообновления
1 parent cee066a commit f0a5bb5

File tree

2 files changed

+85
-18
lines changed

2 files changed

+85
-18
lines changed

Commands/SelfUpdate.cs

+39-18
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void UpdateIfOld()
4545
}
4646
catch (Exception exception)
4747
{
48-
Log.LogError("Auto update failed, error: '{Exception}'", exception);
48+
Log.LogError(exception, "Auto update failed, error: '{ErrorMessage}'", exception.Message);
4949
ConsoleWriter.WriteWarning("Auto update failed. Check logs for details");
5050
}
5151
}
@@ -81,13 +81,14 @@ protected override int Execute()
8181
}
8282
catch (Exception exception)
8383
{
84-
Log.LogError("Fail to install cement", exception);
84+
Log.LogError(exception, "Fail to install cement: '{ErrorMessage}'", exception.Message);
8585
ConsoleWriter.WriteError("Fail to install cement: " + exception);
8686
}
8787

8888
var server = CementSettings.Get().CementServer;
8989
Log.LogInformation($"Cement server: {server}");
90-
var updater = server == null
90+
91+
var updater = server == null
9192
? (ICementUpdater) new CementFromGitHubUpdater(Log)
9293
: (ICementUpdater) new CementFromServerUpdater(server, branch, Log);
9394

@@ -99,23 +100,39 @@ private static void CreateRunners()
99100
const string cmdText = @"@echo off
100101
""%~dp0\dotnet\cm.exe"" %*
101102
SET exit_code=%errorlevel%
102-
if exist %~dp0\dotnet\cm_new.exe (
103-
copy %~dp0\dotnet\cm_new.exe %~dp0\dotnet\cm.exe /Y > nul
104-
del %~dp0\dotnet\cm_new.exe > nul
105-
)
103+
if exist %~dp0\dotnet\win10-x64\cm.exe (
104+
copy %~dp0\dotnet\win10-x64\cm.exe %~dp0\dotnet\cm.exe /Y > nul
105+
del %~dp0\dotnet\win10-x64\cm.exe > nul
106+
) else (
107+
if exist %~dp0\dotnet\cm_new.exe (
108+
copy %~dp0\dotnet\cm_new.exe %~dp0\dotnet\cm.exe /Y > nul
109+
del %~dp0\dotnet\cm_new.exe > nul
110+
)
111+
)
106112
cmd /C exit %exit_code% > nul";
107113

108114
var bashTextUnix = @"#!/bin/bash
109115
path=""`dirname \""$0\""`/dotnet/cm.exe""
110-
cmd=""mono $path""
116+
usingMono=""mono ""
117+
if [ -f ~/bin/dotnet/linux-x64/cm ]
118+
then
119+
usingMono=""""
120+
fi
121+
cmd=""$usingMono$path""
111122
for word in ""$@""; do cmd=""$cmd \""$word\""""; done
112123
eval $cmd
113124
exit_code=$?
114-
if [ -f ~/bin/dotnet/cm_new.exe ];
125+
if [ -f ~/bin/dotnet/linux-x64/cm ];
115126
then
116-
cp ~/bin/dotnet/cm_new.exe ~/bin/dotnet/cm.exe
117-
rm ~/bin/dotnet/cm_new.exe
127+
cp ~/bin/dotnet/linux-x64/cm ~/bin/dotnet/cm.exe
128+
rm ~/bin/dotnet/linux-x64/cm
118129
chmod u+x ~/bin/dotnet/cm.exe
130+
else
131+
if [ -f ~/bin/dotnet/cm_new.exe ]
132+
then
133+
cp ~/bin/dotnet/cm_new.exe ~/bin/dotnet/cm.exe
134+
rm ~/bin/dotnet/cm_new.exe
135+
fi
119136
fi
120137
exit $exit_code";
121138
bashTextUnix = bashTextUnix.Replace("\r\n", "\n");
@@ -125,11 +142,17 @@ chmod u+x ~/bin/dotnet/cm.exe
125142
args=$@
126143
$path ""$@""
127144
exit_code=$?
128-
if [ -f ~/bin/dotnet/cm_new.exe ];
145+
if [ -f ~/bin/dotnet/os-x64/cm ];
129146
then
130-
cp ~/bin/dotnet/cm_new.exe ~/bin/dotnet/cm.exe
131-
rm ~/bin/dotnet/cm_new.exe
147+
cp ~/bin/dotnet/os-x64/cm ~/bin/dotnet/cm.exe
148+
rm ~/bin/dotnet/os-x64/cm
132149
chmod u+x ~/bin/dotnet/cm.exe
150+
else
151+
if [ -f ~/bin/dotnet/cm_new.exe ]
152+
then
153+
cp ~/bin/dotnet/cm_new.exe ~/bin/dotnet/cm.exe
154+
rm ~/bin/dotnet/cm_new.exe
155+
fi
133156
fi
134157
exit $exit_code";
135158

@@ -196,7 +219,7 @@ private bool UpdateBinaries(ICementUpdater updater, string oldHash, string newHa
196219
}
197220
catch (WebException webException)
198221
{
199-
Log.LogError("Fail self-update, exception: '{Exception}'", webException);
222+
Log.LogError(webException, "Fail self-update, exception: '{ErrorMessage}'", webException.Message);
200223

201224
if (webException.Status == WebExceptionStatus.ProtocolError && webException.Response != null)
202225
{
@@ -239,9 +262,7 @@ private void CopyNewCmExe(string from)
239262
Log.LogDebug("dotnet install folder: " + dotnetInstallFolder);
240263

241264
var cm = Path.Combine(from, "cm.exe");
242-
var cmNew = Path.Combine(from, "cm_new.exe");
243-
File.Copy(cm, cmNew, true);
244-
if (!IsInstallingCement && File.Exists(Path.Combine(dotnetInstallFolder, "cm.exe")))
265+
if (!IsInstallingCement && File.Exists(Path.Combine(dotnetInstallFolder, "cm.exe")))
245266
File.Delete(cm);
246267

247268
var files = Directory.GetFiles(from, "*", SearchOption.AllDirectories);

Common/CementFromLocalPathUpdater.cs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.IO;
3+
using Microsoft.Extensions.Logging;
4+
5+
namespace Common
6+
{
7+
public sealed class CementFromLocalPathUpdater : ICementUpdater
8+
{
9+
private readonly ILogger log;
10+
11+
public CementFromLocalPathUpdater(ILogger log)
12+
{
13+
this.log = log;
14+
}
15+
16+
public string GetNewCommitHash()
17+
{
18+
return DateTime.Now.Ticks.ToString();
19+
}
20+
21+
public byte[] GetNewCementZip()
22+
{
23+
try
24+
{
25+
return File.ReadAllBytes(Path.Combine(GetZipCementDirectory(), "cement.zip"));
26+
}
27+
catch (Exception ex)
28+
{
29+
log.LogError(ex,"Fail self-update, exception: '{ErrorMessage}' ", ex.Message);
30+
}
31+
32+
return null;
33+
}
34+
35+
private string GetZipCementDirectory()
36+
{
37+
var zipDir = Path.Combine(Helper.HomeDirectory(), "work");
38+
if (!Directory.Exists(zipDir))
39+
Directory.CreateDirectory(zipDir);
40+
return zipDir;
41+
}
42+
43+
public string GetName() =>
44+
"fileSystemLocalPath";
45+
}
46+
}

0 commit comments

Comments
 (0)