Add project files.
This commit is contained in:
27
Assets/Cryville/Common/IOExtensions.cs
Normal file
27
Assets/Cryville/Common/IOExtensions.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Common {
|
||||
public static class IOExtensions {
|
||||
public static DirectoryInfo GetSubdirectory(this DirectoryInfo dir, string name) {
|
||||
var l1 = dir.GetDirectories(name);
|
||||
if (l1.Length == 0) return dir.CreateSubdirectory(name);
|
||||
else return l1[0];
|
||||
}
|
||||
|
||||
public static string ReadUInt16String(this BinaryReader reader, Encoding encoding = null) {
|
||||
if (encoding == null) encoding = Encoding.UTF8;
|
||||
var len = reader.ReadUInt16();
|
||||
byte[] buffer = reader.ReadBytes(len);
|
||||
return encoding.GetString(buffer);
|
||||
}
|
||||
|
||||
public static void WriteUInt16String(this BinaryWriter writer, string value, Encoding encoding = null) {
|
||||
if (encoding == null) encoding = Encoding.UTF8;
|
||||
byte[] buffer = encoding.GetBytes(value);
|
||||
writer.Write((ushort)buffer.Length);
|
||||
writer.Write(buffer);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user