Skip to content

Commit 14ce877

Browse files
committed
fixed demos upload fix #3002
1 parent 504ebc4 commit 14ce877

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

.idea/.idea.Zero-K/.idea/projectSettingsUpdater.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Zero-K.info/Controllers/ReplaysController.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
56
using System.Net;
@@ -18,7 +19,17 @@ public ActionResult Index() {
1819

1920
public ActionResult Download(string name)
2021
{
21-
return Redirect(ReplayStorage.Instance.GetFileUrl(name));
22+
try
23+
{
24+
var url = ReplayStorage.Instance.GetFileUrl(name);
25+
if (url != null) return Redirect(url);
26+
}
27+
catch (Exception ex)
28+
{
29+
Trace.TraceWarning("Error downloading replay {0}, attempting local copy: {1}", name, ex.Message);
30+
}
31+
32+
return File(ReplayStorage.Instance.GetLocalFileContent(name), "application/octet-stream", name);
2233
}
2334

2435
}

Zero-K.info/Web.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
</dependentAssembly>
148148
<dependentAssembly>
149149
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
150-
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
150+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
151151
</dependentAssembly>
152152
<dependentAssembly>
153153
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />

ZkLobbyServer/ReplayStorage.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,26 @@ namespace ZkLobbyServer
1414
public class ReplayStorage
1515
{
1616
public static ReplayStorage Instance { get; } = new ReplayStorage();
17-
17+
1818
BlobContainerClient azureContainer;
1919

20+
string basePath = GlobalConst.SpringieDataDir;
21+
2022
internal ReplayStorage()
2123
{
22-
azureContainer = new BlobContainerClient(MiscVar.ReplaysConnectionString, MiscVar.ReplaysContainerName);
24+
try
25+
{
26+
if (string.IsNullOrEmpty(MiscVar.ReplaysConnectionString) || string.IsNullOrEmpty(MiscVar.ReplaysContainerName))
27+
{
28+
Trace.TraceWarning("Replay storage not configured, replays won't be stored in blobs");
29+
return;
30+
}
31+
32+
azureContainer = new BlobContainerClient(MiscVar.ReplaysConnectionString, MiscVar.ReplaysContainerName);
33+
} catch (Exception ex)
34+
{
35+
Trace.TraceError("Error initializing replay storage: {0}", ex.Message);
36+
}
2337
}
2438

2539
public async Task<bool> UploadAndDeleteFileAsync(string path)
@@ -65,17 +79,25 @@ public async Task<byte[]> GetFileContent(string replayName)
6579
return stream.ToArray();
6680
}
6781

82+
83+
public byte[] GetLocalFileContent(string replayName)
84+
{
85+
var path = Path.Combine(basePath, "demos-server", replayName);
86+
if (!File.Exists(path)) return null;
87+
return File.ReadAllBytes(path);
88+
}
89+
6890
public async Task MigrateReplays()
6991
{
7092
// replays themselves
71-
var files = Directory.GetFiles(@"c:\Projekty\springie_spring\demos-server");
93+
var files = Directory.GetFiles(Path.Combine(basePath,"demos-server"));
7294
foreach (var fi in files)
7395
{
7496
await UploadAndDeleteFileAsync(fi);
7597
}
7698

7799
// infologs
78-
files = Directory.GetFiles(@"c:\Projekty\springie_spring","infolog_*.txt");
100+
files = Directory.GetFiles(basePath,"infolog_*.txt");
79101
foreach (var fi in files)
80102
{
81103
await UploadAndDeleteFileAsync(fi);

0 commit comments

Comments
 (0)