com.wallstop-studios.unity-helpers 2.0.0-rc74.3 → 2.0.0-rc74.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.pre-commit-config.yaml
CHANGED
|
@@ -15,7 +15,7 @@ repos:
|
|
|
15
15
|
description: Install the .NET tools listed at .config/dotnet-tools.json.
|
|
16
16
|
- id: csharpier
|
|
17
17
|
name: Run CSharpier on C# files
|
|
18
|
-
entry: dotnet tool run
|
|
18
|
+
entry: dotnet tool run Csharpier format
|
|
19
19
|
language: system
|
|
20
20
|
types:
|
|
21
21
|
- c#
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.IO;
|
|
5
|
+
using System.Threading;
|
|
6
|
+
using System.Threading.Tasks;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
|
|
9
|
+
public static class FileHelper
|
|
10
|
+
{
|
|
11
|
+
public static bool InitializePath(string path, byte[] contents = null)
|
|
12
|
+
{
|
|
13
|
+
if (File.Exists(path))
|
|
14
|
+
{
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
string directory = Path.GetDirectoryName(path);
|
|
19
|
+
if (!string.IsNullOrWhiteSpace(directory))
|
|
20
|
+
{
|
|
21
|
+
Directory.CreateDirectory(directory);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try
|
|
25
|
+
{
|
|
26
|
+
using FileStream fileStream = new(
|
|
27
|
+
path,
|
|
28
|
+
FileMode.CreateNew,
|
|
29
|
+
FileAccess.Write,
|
|
30
|
+
FileShare.None
|
|
31
|
+
);
|
|
32
|
+
contents ??= Array.Empty<byte>();
|
|
33
|
+
fileStream.Write(contents, 0, contents.Length);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch (IOException e)
|
|
37
|
+
{
|
|
38
|
+
Debug.LogError($"File {path} already exists, not creating.\n{e}");
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public static async ValueTask<bool> CopyFileAsync(
|
|
44
|
+
string sourcePath,
|
|
45
|
+
string destinationPath,
|
|
46
|
+
int bufferSize = 81920,
|
|
47
|
+
CancellationToken cancellationToken = default
|
|
48
|
+
)
|
|
49
|
+
{
|
|
50
|
+
try
|
|
51
|
+
{
|
|
52
|
+
await using FileStream sourceStream = new(
|
|
53
|
+
sourcePath,
|
|
54
|
+
FileMode.Open,
|
|
55
|
+
FileAccess.Read,
|
|
56
|
+
FileShare.Read,
|
|
57
|
+
bufferSize,
|
|
58
|
+
useAsync: true
|
|
59
|
+
);
|
|
60
|
+
await using FileStream destinationStream = new(
|
|
61
|
+
destinationPath,
|
|
62
|
+
FileMode.Create,
|
|
63
|
+
FileAccess.Write,
|
|
64
|
+
FileShare.None,
|
|
65
|
+
bufferSize,
|
|
66
|
+
useAsync: true
|
|
67
|
+
);
|
|
68
|
+
await sourceStream.CopyToAsync(destinationStream, bufferSize, cancellationToken);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch
|
|
72
|
+
{
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
package/package.json
CHANGED