Skip to content

Commit

Permalink
destination directory will be created if doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cathei committed Aug 13, 2022
1 parent ae8d0c6 commit b098cab
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions BakingSheet.Converters.Csv/CsvSheetConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ protected override Task<bool> LoadData()

protected override Task<bool> SaveData()
{
_fileSystem.CreateDirectory(_loadPath);

foreach (var tableItem in _dataTables)
{
var file = Path.Combine(_loadPath, $"{tableItem.Key}.{_extension}");
Expand Down
2 changes: 2 additions & 0 deletions BakingSheet.Converters.Json/JsonSheetConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public async Task<bool> Export(SheetConvertingContext context)
{
var sheetProps = context.Container.GetSheetProperties();

_fileSystem.CreateDirectory(_loadPath);

foreach (var prop in sheetProps)
{
using (context.Logger.BeginScope(prop.Name))
Expand Down
5 changes: 5 additions & 0 deletions BakingSheet.Tests/Utils/TestFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public Stream OpenRead(string path)
return files[path];
}

public void CreateDirectory(string path)
{
// do nothing
}

public Stream OpenWrite(string path)
{
files[path] = new MemoryStream();
Expand Down
7 changes: 7 additions & 0 deletions BakingSheet/Src/Internal/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface IFileSystem

bool Exists(string path);
Stream OpenRead(string path);

void CreateDirectory(string path);
Stream OpenWrite(string path);
}

Expand All @@ -31,6 +33,11 @@ public Stream OpenRead(string path)
return File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}

public void CreateDirectory(string path)
{
Directory.CreateDirectory(path);
}

public Stream OpenWrite(string path)
{
return File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read);
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ public class StreamingAssetFileSystem : IFileSystem
public Stream OpenRead(string path)
=> BetterStreamingAssets.OpenRead(path);

// write access to streaming assets is not allowed
public void CreateDirectory(string path)
=> throw new System.NotImplementedException();

// write access to streaming assets is not allowed
public Stream OpenWrite(string path)
=> throw new System.NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ static async void OnPostprocessAllAssets(string[] importedAssets, string[] delet
var excelPath = Path.GetDirectoryName(excelAsset);
var jsonPath = Path.Combine(Application.streamingAssetsPath, "Excel");

Directory.CreateDirectory(jsonPath);

var logger = new UnityLogger();
var sheetContainer = new SheetContainer(logger);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public static async void ConvertFromGoogle()
{
var jsonPath = Path.Combine(Application.streamingAssetsPath, "Google");

Directory.CreateDirectory(jsonPath);

var googleConverter = new GoogleSheetConverter("1iWMZVI4FgtGbig4EgPIun_BRbzp4ulqRIzINZQl-AFI", GoogleCredential, TimeZoneInfo.Utc);

var sheetContainer = new Google.SheetContainer(new UnityLogger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ static async void OnPostprocessAllAssets(string[] importedAssets, string[] delet
var csvPath = Path.GetDirectoryName(csvAsset);
var resultPath = Path.Combine(Application.streamingAssetsPath, "CSV");

Directory.CreateDirectory(resultPath);

var logger = new UnityLogger();
var sheetContainer = new SheetContainer(logger);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ protected override Task<bool> LoadData()

protected override Task<bool> SaveData()
{
_fileSystem.CreateDirectory(_loadPath);

foreach (var tableItem in _dataTables)
{
var file = Path.Combine(_loadPath, $"{tableItem.Key}.{_extension}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public async Task<bool> Export(SheetConvertingContext context)
{
var sheetProps = context.Container.GetSheetProperties();

_fileSystem.CreateDirectory(_loadPath);

foreach (var prop in sheetProps)
{
using (context.Logger.BeginScope(prop.Name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface IFileSystem

bool Exists(string path);
Stream OpenRead(string path);

void CreateDirectory(string path);
Stream OpenWrite(string path);
}

Expand All @@ -31,6 +33,11 @@ public Stream OpenRead(string path)
return File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}

public void CreateDirectory(string path)
{
Directory.CreateDirectory(path);
}

public Stream OpenWrite(string path)
{
return File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read);
Expand Down

0 comments on commit b098cab

Please sign in to comment.