Change most things to new byte strings, introduce new ResourceLoader and Logger fully.

This commit is contained in:
Ottermandias 2022-03-06 16:45:16 +01:00
parent 5d77cd5514
commit f5fccb0235
55 changed files with 2681 additions and 2730 deletions

View file

@ -1,34 +1,33 @@
using System.IO;
using System.Linq;
namespace Penumbra.Util
namespace Penumbra.Util;
public static class TempFile
{
public static class TempFile
public static FileInfo TempFileName( DirectoryInfo baseDir, string suffix = "" )
{
public static FileInfo TempFileName( DirectoryInfo baseDir, string suffix = "" )
const uint maxTries = 15;
for( var i = 0; i < maxTries; ++i )
{
const uint maxTries = 15;
for( var i = 0; i < maxTries; ++i )
var name = Path.GetRandomFileName();
var path = new FileInfo( Path.Combine( baseDir.FullName,
suffix.Any() ? name.Substring( 0, name.LastIndexOf( '.' ) ) + suffix : name ) );
if( !path.Exists )
{
var name = Path.GetRandomFileName();
var path = new FileInfo( Path.Combine( baseDir.FullName,
suffix.Any() ? name.Substring( 0, name.LastIndexOf( '.' ) ) + suffix : name ) );
if( !path.Exists )
{
return path;
}
return path;
}
throw new IOException();
}
public static FileInfo WriteNew( DirectoryInfo baseDir, byte[] data, string suffix = "" )
{
var fileName = TempFileName( baseDir, suffix );
using var stream = fileName.OpenWrite();
stream.Write( data, 0, data.Length );
fileName.Refresh();
return fileName;
}
throw new IOException();
}
public static FileInfo WriteNew( DirectoryInfo baseDir, byte[] data, string suffix = "" )
{
var fileName = TempFileName( baseDir, suffix );
using var stream = fileName.OpenWrite();
stream.Write( data, 0, data.Length );
fileName.Refresh();
return fileName;
}
}