- tweak: error cleanup
This commit is contained in:
@@ -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