public static string ExtractPath(string uri, params string[] additional) { var index = uri.IndexOf(MakeFileUri.Scheme); if (-1 == index) { return(MakeFileUri.Combine(uri, additional)); } int skipLength = MakeFileUri.Scheme.Length; int addedLength = MakeFileUri.GetLength(additional); var sb = new StringBuilder(uri.Length + addedLength - skipLength); if (skipLength < uri.Length && '/' == uri[skipLength]) { int winIndex = uri.IndexOf(MakeFileUri.WindowsScheme, skipLength + 1); if (-1 != winIndex && winIndex < 10) { skipLength += 1; } } sb.Append(uri, skipLength, uri.Length - skipLength); return(MakeFileUri.Combine(sb, additional)); }
public static bool IsExistScheme(string text, out int next) { if (MakeFileUri.IsFileUri(text)) { next = MakeFileUri.FILE_URI_START; return(true); } else if (MakeFileUri.IsApkUri(text)) { next = MakeFileUri.APK_URI_START; return(true); } int idx = text.IndexOf(MakeFileUri.Scheme); if (-1 != idx && idx < 10) { next = idx + MakeFileUri.Scheme.Length; return(true); } else { next = 0; return(false); } }
public static string RebuildWithoutRootSlash(string text) { #if !UNITY_EDITOR && UNITY_WEBGL return(text); #else// !UNITY_EDITOR && UNITY_WEBGL return(MakeFileUri.OnRebuild(text, false)); #endif// !UNITY_EDITOR && UNITY_WEBGL }
public static string Rebuild(string text) { #if !UNITY_EDITOR && UNITY_WEBGL return(text); #else// !UNITY_EDITOR && UNITY_WEBGL return(MakeFileUri.OnRebuild(text, true)); #endif// !UNITY_EDITOR && UNITY_WEBGL }
static string Combine(string origin, string[] additional) { if (string.IsNullOrEmpty(origin)) { return(origin); } if (null == additional) { return(origin); } return(MakeFileUri.Combine(new StringBuilder(origin, origin.Length + MakeFileUri.GetLength(additional)), additional)); }
public static bool IsUrl(string text) { int _; return(MakeFileUri.IsExistScheme(text, out _)); }
private static string OnRebuild(string text, bool isRootSlash) { #if !UNITY_EDITOR && UNITY_WEBGL return(text); #else// !UNITY_EDITOR && UNITY_WEBGL if (string.IsNullOrEmpty(text)) { return(isRootSlash ? "file:///" : "file://"); } #if LOG_FILE_URI UnityEngine.Debug.Log("MAKE_FILE_URI_FROM:" + text + ", ROOTSLASH:" + isRootSlash); #endif// LOG_FILE_URI if (MakeFileUri.IsUrl(text)) { #if LOG_IO UnityEngine.Debug.Log("MakeFileUri (isUri) : text = " + text + ", url = " + text); #endif// LOG_IO #if LOG_FILE_URI UnityEngine.Debug.Log("MAKE_FILE_URI_TO#1:" + text); #endif// LOG_FILE_URI return(text); } if (!MakeFileUri.IsFileUri(text)) { MakeFileUri.sbToUri.Length = FILE_URI_START; int start; int next; if (isRootSlash && MakeFileUri.IsExistWindowsDriver(text, out start, out next)) { MakeFileUri.sbToUri.Append('/').Append(text.Substring(start)); #if LOG_FILE_URI UnityEngine.Debug.Log("MAKE_FILE_URI_WINDOWS_DRIVER"); #endif// LOG_FILE_URI } else { MakeFileUri.sbToUri.Append(text); #if LOG_FILE_URI UnityEngine.Debug.Log("MAKE_FILE_URI_UNIX"); #endif// LOG_FILE_URI } } if (isRootSlash) { if ('/' != MakeFileUri.sbToUri[FILE_URI_START]) { MakeFileUri.sbToUri.Insert(FILE_URI_START, '/'); } } string url = MakeFileUri.sbToUri.ToString(); #if LOG_FILE_URI UnityEngine.Debug.Log("MAKE_FILE_URI_TO#2:" + url); #endif// LOG_FILE_URI #if LOG_IO UnityEngine.Debug.Log("MakeFileUri : text = " + text + ", url = " + url); #endif // LOG_IO return(url); #endif // !UNITY_EDITOR && UNITY_WEBGL }