mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-16 21:54:19 +01:00
Apply meta manipulation and load the corresponding files when encountering meta files.
This commit is contained in:
parent
739627b7c2
commit
db5ce7a2e4
5 changed files with 234 additions and 3 deletions
31
Penumbra/Util/TempFile.cs
Normal file
31
Penumbra/Util/TempFile.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System.IO;
|
||||
|
||||
namespace Penumbra.Util
|
||||
{
|
||||
public static class TempFile
|
||||
{
|
||||
public static FileInfo TempFileName( DirectoryInfo baseDir )
|
||||
{
|
||||
const uint maxTries = 15;
|
||||
for( var i = 0; i < maxTries; ++i )
|
||||
{
|
||||
var name = Path.GetRandomFileName();
|
||||
var path = new FileInfo( Path.Combine( baseDir.FullName, name ) );
|
||||
if( !path.Exists )
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
public static FileInfo WriteNew( DirectoryInfo baseDir, byte[] data )
|
||||
{
|
||||
var fileName = TempFileName( baseDir );
|
||||
File.WriteAllBytes( fileName.FullName, data );
|
||||
fileName.Refresh();
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue