2019-05-28 16:11:40 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-05-28 16:53:02 -04:00
|
|
|
|
using System.IO;
|
2019-05-28 16:11:40 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2019-05-28 16:53:02 -04:00
|
|
|
|
using System.Text.RegularExpressions;
|
2019-05-28 16:11:40 -04:00
|
|
|
|
|
|
|
|
|
namespace Switch_Toolbox.Library.IO
|
|
|
|
|
{
|
|
|
|
|
public static class IOExtensions
|
|
|
|
|
{
|
|
|
|
|
public static uint Reverse(this uint x)
|
|
|
|
|
{
|
|
|
|
|
// swap adjacent 16-bit blocks
|
|
|
|
|
x = (x >> 16) | (x << 16);
|
|
|
|
|
// swap adjacent 8-bit blocks
|
|
|
|
|
return ((x & 0xFF00FF00) >> 8) | ((x & 0x00FF00FF) << 8);
|
|
|
|
|
}
|
2019-05-28 16:53:02 -04:00
|
|
|
|
|
2019-05-28 16:55:17 -04:00
|
|
|
|
//https://stackoverflow.com/questions/2230826/remove-invalid-disallowed-bad-characters-from-filename-or-directory-folder/12800424#12800424
|
2019-05-28 17:13:01 -04:00
|
|
|
|
public static string RemoveIllegaleFileNameCharacters(this string str)
|
2019-05-28 16:53:02 -04:00
|
|
|
|
{
|
2019-05-28 16:55:17 -04:00
|
|
|
|
return string.Join("_", str.Split(Path.GetInvalidFileNameChars()));
|
2019-05-28 16:53:02 -04:00
|
|
|
|
}
|
2019-05-28 16:55:17 -04:00
|
|
|
|
|
2019-05-28 17:13:01 -04:00
|
|
|
|
public static string RemoveIllegaleFolderNameCharacters(this string str)
|
|
|
|
|
{
|
|
|
|
|
return string.Join("_", str.Split(Path.GetInvalidPathChars()));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 16:11:40 -04:00
|
|
|
|
}
|
|
|
|
|
}
|