mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-18 00:21:33 -07:00
* add custom bootstrappers * add avalonedit to licenses page * add gif support * add stretch & stretchdirection to images * dont create a bitmapimage for gifs * remove maxheight and maxwidth sets * remove comment * add isenabled * add more textblock properties * add markdowntextblocks * update how transform elements are stored * overhaul textbox content * dont set fontsize if not set * fix warnings * add foreground property to control * add background property to textblock * count descendants and increase element cap * add auto complete * dont display completion window if there is no data * sort schema elements and types * make ! close the completion window * add end tag auto complete * fix pos being wrong * dont treat comments as elements * add imagebrushes * follow same conventions as brushes * fix exception messages * fix them again * update schema * fix crash * now it works * wrong attribute name * add solidcolorbrush * move converters into a separate file * add lineargradientbrushes * unify handlers * update schema * add fake BloxstrapCustomBootstrapper * stop adding an extra end character * add property element auto-complete * add title attribute to custombloxstrapbootstrapper * add shapes * add string translation support * use default wpf size instead of 100x100 * update min height of window * fix verticalalignment not working * uncap height and width * add effects * move transformation handler inside frameworkelement * fix title bar effect & transformation removal * add more frameworkelement properties * add layout transform * add font properties to control * improve window border stuff * make sure file contents are in CRLF * add cornerradius to progress bar * add progressring * Update wpfui * update schema * update function names * add children check to content * make sure only one content is defined * add fontfamily * update schema * only allow file uris for images * disable backdrop * move text setter to textblock handler from base * split up creator into multiple files * turn version into a constant * add grids * cleanup converters * add IgnoreTitleBarInset * add Version to schema * reveal custom bootstrapper stuff on selection * increase listbox height * only set statustext binding in textblock * update ui * rename ZIndex to Panel.ZIndex * add stackpanel * add border * fix being unable to apply transforms on grids * rearrange and add new editor button * use snackbars for saving * add close confirmation message * use viewmodel variable * remove pointless onpropertychanged call * add version string format * start editor window in the centre * update licenses page also resized the about window so everything could fit nicely * fix border not inheriting frameworkelement * add WindowCornerPreference * add the import dialog * add an export theme button * update version number * localise CustomDialog exceptions * localise custom theme editor * localise custom theme add dialog * localise frontend * localise appearance menu page * change customtheme error strings namespace * change icons on appearance page * update button margin on appearance page
105 lines
3.0 KiB
C#
105 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Bloxstrap.Utility
|
|
{
|
|
internal static class PathValidator
|
|
{
|
|
public enum ValidationResult
|
|
{
|
|
Ok,
|
|
IllegalCharacter,
|
|
ReservedFileName,
|
|
ReservedDirectoryName
|
|
}
|
|
|
|
private static readonly string[] _reservedNames = new string[]
|
|
{
|
|
"CON",
|
|
"PRN",
|
|
"AUX",
|
|
"NUL",
|
|
"COM1",
|
|
"COM2",
|
|
"COM3",
|
|
"COM4",
|
|
"COM5",
|
|
"COM6",
|
|
"COM7",
|
|
"COM8",
|
|
"COM9",
|
|
"LPT1",
|
|
"LPT2",
|
|
"LPT3",
|
|
"LPT4",
|
|
"LPT5",
|
|
"LPT6",
|
|
"LPT7",
|
|
"LPT8",
|
|
"LPT9"
|
|
};
|
|
|
|
private static readonly char[] _directorySeperatorDelimiters = new char[]
|
|
{
|
|
Path.DirectorySeparatorChar,
|
|
Path.AltDirectorySeparatorChar
|
|
};
|
|
|
|
private static readonly char[] _invalidPathChars = GetInvalidPathChars();
|
|
|
|
public static char[] GetInvalidPathChars()
|
|
{
|
|
char[] invalids = new char[] { '/', '\\', ':', '*', '?', '"', '<', '>', '|' };
|
|
char[] otherInvalids = Path.GetInvalidPathChars();
|
|
|
|
char[] result = new char[invalids.Length + otherInvalids.Length];
|
|
invalids.CopyTo(result, 0);
|
|
otherInvalids.CopyTo(result, invalids.Length);
|
|
|
|
return result;
|
|
}
|
|
|
|
public static ValidationResult IsFileNameValid(string fileName)
|
|
{
|
|
if (fileName.IndexOfAny(_invalidPathChars) != -1)
|
|
return ValidationResult.IllegalCharacter;
|
|
|
|
string fileNameNoExt = Path.GetFileNameWithoutExtension(fileName).ToUpperInvariant();
|
|
if (_reservedNames.Contains(fileNameNoExt))
|
|
return ValidationResult.ReservedFileName;
|
|
|
|
return ValidationResult.Ok;
|
|
}
|
|
|
|
public static ValidationResult IsPathValid(string path)
|
|
{
|
|
string? pathRoot = Path.GetPathRoot(path);
|
|
string pathNoRoot = pathRoot != null ? path[pathRoot.Length..] : path;
|
|
|
|
string[] pathParts = pathNoRoot.Split(_directorySeperatorDelimiters);
|
|
|
|
foreach (var part in pathParts)
|
|
{
|
|
if (part.IndexOfAny(_invalidPathChars) != -1)
|
|
return ValidationResult.IllegalCharacter;
|
|
|
|
if (_reservedNames.Contains(part))
|
|
return ValidationResult.ReservedDirectoryName;
|
|
}
|
|
|
|
string fileName = Path.GetFileName(path);
|
|
if (fileName.IndexOfAny(_invalidPathChars) != -1)
|
|
return ValidationResult.IllegalCharacter;
|
|
|
|
string fileNameNoExt = Path.GetFileNameWithoutExtension(path).ToUpperInvariant();
|
|
if (_reservedNames.Contains(fileNameNoExt))
|
|
return ValidationResult.ReservedFileName;
|
|
|
|
return ValidationResult.Ok;
|
|
}
|
|
}
|
|
}
|