2021-05-07 17:06:56 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer
|
|
|
|
|
{
|
|
|
|
|
public static class IOUtility
|
|
|
|
|
{
|
2021-05-14 02:45:59 +10:00
|
|
|
|
private static readonly char[] invalidDirectoryCharacters = Path.GetInvalidPathChars();
|
|
|
|
|
private static readonly char[] invalidFilenameCharacters = Path.GetInvalidFileNameChars();
|
2021-05-07 17:06:56 +10:00
|
|
|
|
|
2021-10-16 18:10:23 +11:00
|
|
|
|
public static string EnsureValidFilePath(string fullPathWithFile)
|
2021-05-14 02:45:59 +10:00
|
|
|
|
{
|
2021-10-16 18:10:23 +11:00
|
|
|
|
// Remove invalid path characters
|
|
|
|
|
fullPathWithFile = string.Concat(fullPathWithFile.Split(invalidDirectoryCharacters));
|
2021-05-14 06:14:25 +10:00
|
|
|
|
|
2021-10-16 18:10:23 +11:00
|
|
|
|
// Create directory (does nothing if it exists)
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(fullPathWithFile));
|
2021-05-14 06:14:25 +10:00
|
|
|
|
|
2021-10-16 18:10:23 +11:00
|
|
|
|
return fullPathWithFile;
|
2021-05-07 17:06:56 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 02:45:59 +10:00
|
|
|
|
public static string EnsureValidFilename(string filename)
|
2021-05-07 17:06:56 +10:00
|
|
|
|
{
|
2021-05-14 02:45:59 +10:00
|
|
|
|
return string.Concat(filename.Split(invalidFilenameCharacters));
|
2021-05-07 17:06:56 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|