ParadoxSaveParser/ParadoxSaveParser.WebAPI/PathHelper.cs

36 lines
1.1 KiB
C#

using System.IO;
namespace ParadoxSaveParser.WebAPI;
public static class PathHelper
{
public static readonly IOPath DATA_DIR = "data";
public static readonly IOPath SAVES_DIR = Path.Concat(DATA_DIR, "saves");
public static readonly IOPath PARSED_DIR = Path.Concat(DATA_DIR, "parsed");
public static readonly IOPath TEMP_DIR = "temp";
public static void CreateProgramDirectories()
{
Directory.Create(DATA_DIR);
Directory.Create(SAVES_DIR);
Directory.Create(PARSED_DIR);
Directory.Create(TEMP_DIR);
}
public static void CleanTempDirectory()
{
Directory.Delete(TEMP_DIR);
Directory.Create(TEMP_DIR);
}
public static Stream CreateTempFile()
{
string fileName = Guid.NewGuid().ToString();
IOPath filePath = Path.Concat(TEMP_DIR, fileName);
var stream = System.IO.File.Open(filePath.Str, FileMode.CreateNew, FileAccess.ReadWrite,
FileShare.Read | FileShare.Delete);
// file stays as a ghost until it is closed
File.Delete(filePath);
return stream;
}
}