- tweak: error cleanup
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Threading;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
@@ -9,11 +7,17 @@ namespace Nebula.Launcher.Views;
|
||||
|
||||
public partial class ServerEntryView : UserControl
|
||||
{
|
||||
private DispatcherTimer _scrollTimer;
|
||||
private bool _scrollingDown = true;
|
||||
private readonly TimeSpan _interval = TimeSpan.FromMilliseconds(25);
|
||||
private readonly DispatcherTimer _scrollTimer;
|
||||
private TimeSpan _currTime = TimeSpan.Zero;
|
||||
|
||||
public ServerEntryView()
|
||||
{
|
||||
_scrollTimer = new DispatcherTimer
|
||||
{
|
||||
Interval = _interval
|
||||
};
|
||||
|
||||
InitializeComponent();
|
||||
StartAutoScrolling();
|
||||
}
|
||||
@@ -25,45 +29,17 @@ public partial class ServerEntryView : UserControl
|
||||
|
||||
private void StartAutoScrolling()
|
||||
{
|
||||
_scrollTimer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(50) // Adjust the interval for scroll speed
|
||||
};
|
||||
_scrollTimer.Tick += AutoScroll;
|
||||
_scrollTimer.Start();
|
||||
}
|
||||
|
||||
private void AutoScroll(object? sender, EventArgs e)
|
||||
{
|
||||
// Get the current offset and extent
|
||||
var currentOffset = AutoScrollViewer.Offset.X;
|
||||
var maxOffset = AutoScrollViewer.Extent.Width - AutoScrollViewer.Viewport.Width;
|
||||
|
||||
if (_scrollingDown)
|
||||
{
|
||||
// Scroll down
|
||||
if (currentOffset < maxOffset)
|
||||
{
|
||||
AutoScrollViewer.Offset = new Avalonia.Vector(currentOffset + 2, AutoScrollViewer.Offset.Y); // Adjust speed
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reverse direction when reaching the bottom
|
||||
_scrollingDown = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scroll up
|
||||
if (currentOffset > 0)
|
||||
{
|
||||
AutoScrollViewer.Offset = new Avalonia.Vector(currentOffset - 2, AutoScrollViewer.Offset.Y); // Adjust speed
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reverse direction when reaching the top
|
||||
_scrollingDown = true;
|
||||
}
|
||||
}
|
||||
var value = (Math.Sin(_currTime.TotalSeconds / 2) + 1) * (maxOffset / 2) ;
|
||||
|
||||
AutoScrollViewer.Offset = new Avalonia.Vector(value, AutoScrollViewer.Offset.Y);
|
||||
_currTime += _interval;
|
||||
if (_currTime > TimeSpan.FromSeconds(10000)) _currTime = TimeSpan.Zero;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Robust.LoaderApi;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.LoaderApi;
|
||||
|
||||
namespace Nebula.Shared.FileApis;
|
||||
|
||||
@@ -11,7 +12,7 @@ public class AssemblyApi : IFileApi
|
||||
_root = root;
|
||||
}
|
||||
|
||||
public bool TryOpen(string path, out Stream? stream)
|
||||
public bool TryOpen(string path,[NotNullWhen(true)] out Stream? stream)
|
||||
{
|
||||
return _root.TryOpen(path, out stream);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
|
||||
namespace Nebula.Shared.FileApis;
|
||||
|
||||
@@ -11,7 +12,7 @@ public sealed class FileApi : IReadWriteFileApi
|
||||
RootPath = rootPath;
|
||||
}
|
||||
|
||||
public bool TryOpen(string path, out Stream? stream)
|
||||
public bool TryOpen(string path,[NotNullWhen(true)] out Stream? stream)
|
||||
{
|
||||
var fullPath = Path.Join(RootPath, path);
|
||||
if (File.Exists(fullPath))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Nebula.Shared.Models;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Nebula.Shared.Models;
|
||||
using Robust.LoaderApi;
|
||||
|
||||
namespace Nebula.Shared.FileApis;
|
||||
@@ -15,7 +16,7 @@ public class HashApi : IFileApi
|
||||
foreach (var item in manifest) Manifest.TryAdd(item.Path, item);
|
||||
}
|
||||
|
||||
public bool TryOpen(string path, out Stream? stream)
|
||||
public bool TryOpen(string path,[NotNullWhen(true)] out Stream? stream)
|
||||
{
|
||||
if (path[0] == '/') path = path.Substring(1);
|
||||
|
||||
|
||||
@@ -5,30 +5,16 @@ namespace Nebula.Shared.Services;
|
||||
[ServiceRegister]
|
||||
public class DebugService : IDisposable
|
||||
{
|
||||
private static string LogPath = Path.Combine(FileService.RootPath, "log");
|
||||
public DateTime LogDate = DateTime.Now;
|
||||
public ILogger Logger;
|
||||
private FileStream LogStream;
|
||||
private StreamWriter LogWriter;
|
||||
|
||||
public DebugService(ILogger logger)
|
||||
{
|
||||
Logger = logger;
|
||||
|
||||
//if (!Directory.Exists(LogPath))
|
||||
// Directory.CreateDirectory(LogPath);
|
||||
|
||||
//var filename = String.Format("{0:yyyy-MM-dd}.txt", DateTime.Now);
|
||||
|
||||
//LogStream = File.Open(Path.Combine(LogPath, filename),
|
||||
// FileMode.Append, FileAccess.Write);
|
||||
//LogWriter = new StreamWriter(LogStream);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
LogWriter.Dispose();
|
||||
LogStream.Dispose();
|
||||
|
||||
}
|
||||
|
||||
public void Debug(string message)
|
||||
@@ -56,13 +42,6 @@ public class DebugService : IDisposable
|
||||
private void Log(LoggerCategory category, string message)
|
||||
{
|
||||
Logger.Log(category, message);
|
||||
//SaveToLog(category, message);
|
||||
}
|
||||
|
||||
private void SaveToLog(LoggerCategory category, string message)
|
||||
{
|
||||
LogWriter.WriteLine($"[{category}] {message}");
|
||||
LogWriter.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public sealed class EngineService
|
||||
var api = _fileService.OpenZip(version, _fileService.EngineFileApi);
|
||||
if (api != null) return _assemblyService.Mount(api);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
_fileService.EngineFileApi.Remove(version);
|
||||
throw;
|
||||
@@ -164,9 +164,9 @@ public sealed class EngineService
|
||||
|
||||
try
|
||||
{
|
||||
return _assemblyService.Mount(_fileService.OpenZip(fileName, _fileService.EngineFileApi));
|
||||
return _assemblyService.Mount(_fileService.OpenZip(fileName, _fileService.EngineFileApi) ?? throw new InvalidOperationException($"{fileName} is not exist!"));
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
_fileService.EngineFileApi.Remove(fileName);
|
||||
throw;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class FileService
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) prefix = "Space Station 14.app/Contents/Resources/";
|
||||
return new ZipFileApi(zipArchive, prefix);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
zipStream?.Dispose();
|
||||
throw;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class RestService
|
||||
return await ReadResult<T>(response, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<RestResult<T>> ReadResult<T>(HttpResponseMessage response, CancellationToken cancellationToken)
|
||||
private async Task<RestResult<T>> ReadResult<T>(HttpResponseMessage response, CancellationToken cancellationToken) where T : notnull
|
||||
{
|
||||
var content = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public class ManifestReader : StreamReader
|
||||
|
||||
private void ReadManifestVersion()
|
||||
{
|
||||
ManifestVersion = ReadLine();
|
||||
ManifestVersion = ReadLine() ?? throw new InvalidOperationException("File is empty!");
|
||||
}
|
||||
|
||||
public RobustManifestItem? ReadItem()
|
||||
|
||||
Reference in New Issue
Block a user