static void WriteLocalizedValue(string valueName, StreamWriter stream, Locale locale, LocalizedString localizedString, PlistDocument plistDocument) { if (localizedString.IsEmpty) { return; } var tableCollection = LocalizationEditorSettings.GetStringTableCollection(localizedString.TableReference); var table = tableCollection?.GetTable(locale.Identifier) as StringTable; var entry = table?.GetEntryFromReference(localizedString.TableEntryReference); if (entry == null || string.IsNullOrWhiteSpace(entry.LocalizedValue)) { // Use fallback? var fallBack = FallbackLocaleHelper.GetLocaleFallback(locale); if (fallBack != null) { WriteLocalizedValue(valueName, stream, fallBack, localizedString, plistDocument); return; } Debug.LogWarning($"{valueName}: Could not find a localized value for {locale} from {localizedString}"); return; } Debug.Assert(!entry.IsSmart, $"Localized App Values ({valueName}) do not support Smart Strings - {localizedString}"); stream.WriteLine($"\"{valueName}\" = \"{entry.LocalizedValue}\";"); plistDocument.root.SetString(valueName, string.Empty); }
// --- CONVERSION --- public static int FromLocalDateTime(DateTime localDateTime) { Debug.Assert(localDateTime.Kind == DateTimeKind.Utc, "Provided DateTime is not Local. Please use ServerTimeStamp.FromUTCDateTime() instead"); return(FromUTCDateTime(localDateTime.ToUniversalTime())); }
public static unsafe void ReadProfilerTrace(ref ProfilerTrace trace, Stream stream, Allocator allocator) { var basePos = stream.Position; var reader = new RawReader(stream); ProfilerDataSerializationHeader serializationHeader = default; reader.Read(&serializationHeader); Debug.Assert(basePos + serializationHeader.TotalLength <= stream.Length); ProfilerTraceHeader traceHeader = default; reader.Read(&traceHeader); trace.Header = traceHeader; Read(out trace.Samples, serializationHeader.NumSamples, basePos + serializationHeader.SamplesOffset); Read(out trace.StackFrames, serializationHeader.NumStackFrames, basePos + serializationHeader.StackFramesOffset); Read(out trace.Functions, serializationHeader.NumFunctions, basePos + serializationHeader.FunctionsOffset); Read(out trace.Modules, serializationHeader.NumModules, basePos + serializationHeader.ModulesOffset); Read(out trace.Threads, serializationHeader.NumThreads, basePos + serializationHeader.ThreadsOffset); void Read <T>(out NativeArray <T> arr, int num, long offset) where T : unmanaged { stream.Position = basePos + offset; arr = new NativeArray <T>(num, allocator, NativeArrayOptions.UninitializedMemory); reader.ReadBytes(arr.GetUnsafePtr(), sizeof(T) * num); } }
public string GenerateFilterString(string fieldName) { Debug.Assert(!string.IsNullOrEmpty(fieldName)); Debug.Assert(!string.IsNullOrEmpty(this.notLikeValue)); return(fieldName + "-not-lk=" + notLikeValue); }
/// <summary> /// Some NuGet feeds such as Visual Studio Team Services do not implement the GetUpdates function. /// In that case this fallback function can be used to retrieve updates by using the FindPackagesById function. /// </summary> /// <param name="installedPackages">The list of currently installed packages.</param> /// <param name="includePrerelease">True to include prerelease packages (alpha, beta, etc).</param> /// <param name="includeAllVersions">True to include older versions that are not the latest version.</param> /// <param name="targetFrameworks">The specific frameworks to target?</param> /// <param name="versionContraints">The version constraints?</param> /// <returns>A list of all updates available.</returns> private List <NugetPackage> GetUpdatesFallback(IEnumerable <NugetPackage> installedPackages, bool includePrerelease = false, bool includeAllVersions = false, string targetFrameworks = "", string versionContraints = "") { Debug.Assert(string.IsNullOrEmpty(targetFrameworks) && string.IsNullOrEmpty(versionContraints)); // These features are not supported by this version of GetUpdates. List <NugetPackage> updates = new List <NugetPackage>(); foreach (NugetPackage installedPackage in installedPackages) { List <NugetPackage> packageUpdates = new List <NugetPackage>(); string versionRange = string.Format("({0},)", installedPackage.Version); // Minimum of Current ID (exclusive) with no maximum (exclusive). NugetPackageIdentifier id = new NugetPackageIdentifier(installedPackage.Id, versionRange); packageUpdates = FindPackagesById(id); NugetPackage mostRecentPrerelease = includePrerelease ? packageUpdates.FindLast(p => p.IsPrerelease) : default(NugetPackage); packageUpdates.RemoveAll(p => p.IsPrerelease && p != mostRecentPrerelease); if (!includeAllVersions && packageUpdates.Count > 0) { packageUpdates.RemoveRange(0, packageUpdates.Count - 1); } updates.AddRange(packageUpdates); } return(updates); }
/// <summary> /// Some NuGet feeds such as Visual Studio Team Services do not implement the GetUpdates function. /// In that case this fallback function can be used to retrieve updates by using the FindPackagesById function. /// </summary> /// <param name="installedPackages">The list of currently installed packages.</param> /// <param name="includePrerelease">True to include prerelease packages (alpha, beta, etc).</param> /// <param name="includeAllVersions">True to include older versions that are not the latest version.</param> /// <param name="targetFrameworks">The specific frameworks to target?</param> /// <param name="versionContraints">The version constraints?</param> /// <returns>A list of all updates available.</returns> private List <NugetPackage> GetUpdatesFallback(IEnumerable <NugetPackage> installedPackages, bool includePrerelease = false, bool includeAllVersions = false, string targetFrameworks = "", string versionContraints = "") { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Debug.Assert(string.IsNullOrEmpty(targetFrameworks) && string.IsNullOrEmpty(versionContraints)); // These features are not supported by this version of GetUpdates. List <NugetPackage> updates = new List <NugetPackage>(); foreach (NugetPackage installedPackage in installedPackages) { string versionRange = string.Format("({0},)", installedPackage.Version); // Minimum of Current ID (exclusive) with no maximum (exclusive). NugetPackageIdentifier id = new NugetPackageIdentifier(installedPackage.Id, versionRange); List <NugetPackage> packageUpdates = FindPackagesById(id); if (!includePrerelease) { packageUpdates.RemoveAll(p => p.IsPrerelease); } if (packageUpdates.Count == 0) { continue; } int skip = includeAllVersions ? 0 : packageUpdates.Count - 1; updates.AddRange(packageUpdates.Skip(skip)); } NugetHelper.LogVerbose("NugetPackageSource.GetUpdatesFallback took {0} ms", stopwatch.ElapsedMilliseconds); return(updates); }
public void FreeIndexRange(int startIndex, int range) { var lastIndex = startIndex + range; if (startIndex < 0 || lastIndex > indexToID.Length) { throw new ArgumentOutOfRangeException($"StartIndex {startIndex} with range {range}, must be between 0 and {indexToID.Length}"); } if (range == 0) { return; // nothing to do } for (int index = startIndex; index < lastIndex; index++) { var idInternal = indexToID[index] - 1; indexToID[index] = 0; Debug.Assert(!freeIDs.Contains(idInternal)); freeIDs.Add(idInternal); var idLookup = idToIndex[idInternal]; idLookup.index = -1; idToIndex[idInternal] = idLookup; } sectionManager.FreeRange(startIndex, range); }
public string GenerateFilterString(string fieldName) { Debug.Assert(!string.IsNullOrEmpty(fieldName)); Debug.Assert(this.maximum != null); return(fieldName + (isInclusive ? "-max=" : "-st=") + maximum); }
/// <summary>Converts an array of MetadataKVP to a Dictionary.</summary> public static Dictionary <string, List <string> > ArrayToDictionary_DuplicateKeys(MetadataKVP[] kvpArray) { Debug.Assert(kvpArray != null); List <string> stringList = null; var dictionary = new Dictionary <string, List <string> >(kvpArray.Length); foreach (MetadataKVP kvp in kvpArray) { if (string.IsNullOrEmpty(kvp.key)) { continue; } if (!dictionary.TryGetValue(kvp.key, out stringList)) { stringList = new List <string>(); dictionary[kvp.key] = stringList; } stringList.Add(kvp.value); } return(dictionary); }
/// <summary>Converts a dictionary to a MetadataKVP array.</summary> public static IList <MetadataKVP> DictionaryToArray(Dictionary <string, List <string> > dictionary) { Debug.Assert(dictionary != null); var list = new List <MetadataKVP>(); foreach (var kvp in dictionary) { if (kvp.Value == null) { MetadataKVP newKVP = new MetadataKVP() { key = kvp.Key, value = null, }; list.Add(newKVP); } else { foreach (var stringValue in kvp.Value) { MetadataKVP newKVP = new MetadataKVP() { key = kvp.Key, value = stringValue, }; list.Add(newKVP); } } } return(list); }
// ---------[ IPlatformIO Interface ]--------- // --- File I/O --- /// <summary>Reads a file.</summary> public virtual bool ReadFile(string path, out byte[] data) { Debug.Assert(!string.IsNullOrEmpty(path)); if (!File.Exists(path)) { data = null; return(false); } try { data = File.ReadAllBytes(path); return(true); } catch (Exception e) { string warningInfo = ("[mod.io] Failed to read file.\nFile: " + path + "\n\n"); Debug.LogWarning(warningInfo + Utility.GenerateExceptionDebugString(e)); data = null; return(false); } }
public unsafe int GetIndex(int id, int generation) { Debug.Assert(IsCreated); var idInternal = id - 1; // We don't want 0 to be a valid id var maxID = idToIndex.Length; if (idInternal < 0 || idInternal >= maxID) { CheckID(id, maxID); return(-1); } var idLookup = idToIndex.Ptr[idInternal]; if (idLookup.generation != generation) { CheckGeneration(generation, idLookup.generation); return(-1); } var maxIndex = indexToID.Length; var index = idLookup.index; if (index < 0 || index >= maxIndex) { CheckIndexInRange(id, index, maxIndex); return(-1); } return(idLookup.index); }
public unsafe int GetIndexNoErrors(int id, int generation) { Debug.Assert(IsCreated); var idInternal = id - 1; // We don't want 0 to be a valid id if (idInternal < 0 || idInternal >= idToIndex.Length) { return(-1); } var idLookup = idToIndex.Ptr[idInternal]; if (idLookup.generation != generation) { return(-1); } var index = idLookup.index; if (index < 0 || index >= indexToID.Length) { return(-1); } return(idLookup.index); }
public string GenerateFilterString(string fieldName) { Debug.Assert(!string.IsNullOrEmpty(fieldName)); Debug.Assert(this.filterValue != null); return(fieldName + "-not=" + filterValue.ToString()); }
/// <summary>Gets the size and md5 hash of a file.</summary> public void GetFileSizeAndHash(string relativePath, GetFileSizeAndHashCallback callback) { Debug.Assert(!string.IsNullOrEmpty(relativePath)); Debug.Assert(callback != null); string path = IOUtilities.CombinePath(this.userDir, relativePath); byte[] data = null; Int64 byteCount = -1; string md5Hash = null; if (Steamworks.SteamRemoteStorage.FileExists(path)) { data = Steamworks.SteamRemoteStorage.FileRead(path); if (data != null) { byteCount = data.Length; using (var md5 = System.Security.Cryptography.MD5.Create()) { var hash = md5.ComputeHash(data); md5Hash = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } } } callback.Invoke(relativePath, (data != null), byteCount, md5Hash); }
public override string GenerateFilterString(string fieldName) { Debug.Assert(!string.IsNullOrEmpty(fieldName)); Debug.Assert(this.filterArray != null); StringBuilder valueList = new StringBuilder(); if (this.filterArray.Length > 0) { foreach (T arrayItem in this.filterArray) { if (arrayItem != null) { valueList.Append(arrayItem.ToString() + ","); } } if (valueList.Length > 0) { // Remove trailing comma valueList.Length -= 1; } } return(fieldName + this.apiStringOperator + valueList.ToString()); }
public static void Dispose(ref T[] disposing) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(!typeof(IDrawer).IsAssignableFrom(typeof(T)), "Use DrawerArrayPool instead"); Debug.Assert(typeof(T) != Types.UnityObject || !LinkedMemberHierarchy.AnyHierarchyTargetsArrayEquals(disposing as UnityEngine.Object[])); #endif int length = disposing.Length; //don't pool zero-length arrays since we'll be using ZeroSizeArray field for those purposes if (length > 0) { PolymorphicPool <T[]> pool; #if DEV_MODE && WARN_IF_POOLING_EXTERNALLY_CREATED_ITEMS if (!created.TryGetValue(length, out pool) || !pool.Contains(disposing)) { Debug.LogWarning("ArrayPool<" + StringUtils.ToString(typeof(T)) + ">.Dispose was called for array that was not created by ArrayPool. This could lead to bugs:\ndisposing: " + StringUtils.ToString(disposing)); } else { pool.Remove(disposing); } #endif if (!pools.TryGetValue(length, out pool)) { pool = new PolymorphicPool <T[]>(1, 25); pools[length] = pool; } pool.Pool(ref disposing); } disposing = null; }
public static bool IsStatic(this MemberInfo member) { var field = member as FieldInfo; if (field != null) { return(field.IsStatic); } var property = member as PropertyInfo; if (property != null) { return(property.CanRead ? property.GetGetMethod(true).IsStatic : property.GetSetMethod(true).IsStatic); } var method = member as MethodInfo; if (method != null) { return(method.IsStatic); } #if NETFX_CORE Debug.Assert(false, "not implemented"); throw new NotSupportedException("not implemented"); #else string message = string.Format("Unable to determine IsStatic for member {0}.{1}" + "MemberType was {2} but only fields, properties and methods are supported.", member.Name, member.MemberType, Environment.NewLine); throw new NotSupportedException(message); #endif }
private void LoadNext() { Debug.Log("Load tile " + m_nextX + ", " + m_nextY); RenderMode mode = (Math.Abs(m_nextX) < (((int)m_manager.DetailedWorldSize.x + 1) / 2) && Math.Abs(m_nextY) < (((int)m_manager.DetailedWorldSize.y + 1) / 2)) ? RenderMode.Scene : RenderMode.Overview; var tileCenter = new Vector2d( m_nextX * m_manager.TileSize, m_nextY * m_manager.TileSize); var tile = new Tile( m_manager.Centre, tileCenter, mode, new Canvas(m_objectPool), m_manager.TileSize, m_manager.TileSize); m_messageBus.Send(new TileLoadStartMessage(tileCenter)); m_tileLoader.Load(tile) .Subscribe(_ => { }, () => { m_messageBus.Send(new TileLoadFinishMessage(tile)); /* * Dodgy as hell hack to work around a bug without me having * to install VS to recompile ASM. Basically there's some * problem caching data which means if you load a tile then * all adjacent tiles will fail to load properly because it * will think the data is cached when it actually isn't. * The Configure method on ElementSourceProvider will clear * out its cache, however that class is internal to the * assembly, so use reflection to get at it and call it. */ Type type = m_elementSourceProvider.GetType(); MethodInfo methodInfo = type.GetMethod("Configure"); Debug.Assert(methodInfo != null); IConfigSection config = m_manager.Config.GetSection(@"data/map"); methodInfo.Invoke(m_elementSourceProvider, new object[] { config }); if (++m_nextX > m_endX) { m_nextX = m_startX; m_nextY++; } if (m_nextY <= m_endY) { LoadNext(); } else { /* Notify the exporter that we have finished. */ m_messageBus.Send(new WorldLoadFinishMessage()); } }); }
public string GenerateFilterString(string fieldName) { Debug.Assert(!string.IsNullOrEmpty(fieldName)); Debug.Assert(this.min != null); Debug.Assert(this.max != null); return(fieldName + (isMinInclusive ? "-min=" : "-gt=") + min + "&" + fieldName + (isMaxInclusive ? "-max=" : "-st=") + max); }
/// <summary>Reads a user data file. (Standalone Application)</summary> public static void ReadFile_Standalone(string filePath, ReadFileCallback callback) { Debug.Assert(!string.IsNullOrEmpty(filePath)); Debug.Assert(callback != null); byte[] data = null; data = IOUtilities.LoadBinaryFile(filePath); callback.Invoke(true, data); }
/// <summary>Function for deleting a user-specific file.</summary> public static void DeleteFile(string filePathRelative, WriteFileCallback callback) { Debug.Assert(UserDataStorage.isInitialized); Debug.Assert(!string.IsNullOrEmpty(filePathRelative)); string filePath = IOUtilities.CombinePath(UserDataStorage.activeUserDirectory, filePathRelative); UserDataStorage.PLATFORM.DeleteFile(filePath, callback); }
public virtual string GenerateFilterString(string fieldName) { Debug.Assert(!string.IsNullOrEmpty(fieldName)); Debug.Assert(this.filterValue != null); return(fieldName + this.apiStringOperator + this.filterValue.ToString()); }
public static int FromUTCDateTime(DateTime utcDateTime) { Debug.Assert(utcDateTime.Kind == DateTimeKind.Utc, "Provided DateTime is not UTC. Consider using ServerTimeStamp.Now() instead of DateTime.Now() or by converting a local time to UTC using the DateTime.ToUniversalTime() method"); int serverTimeStamp = (int)utcDateTime.Subtract(UNIX_EPOCH).TotalSeconds; return(serverTimeStamp); }
public static StringValueParameter Create(string k, object v) { Debug.Assert(!String.IsNullOrEmpty(k) && v != null); StringValueParameter retVal = new StringValueParameter(); retVal.key = k; retVal.value = v.ToString(); return(retVal); }
/// <summary>Checks for the existence of a file.</summary> public void GetFileExists(string relativePath, GetFileExistsCallback callback) { Debug.Assert(!string.IsNullOrEmpty(relativePath)); Debug.Assert(callback != null); string path = IOUtilities.CombinePath(this.userDir, relativePath); bool doesExist = this.GetFileExists(path); callback.Invoke(relativePath, doesExist); }
/// <summary>Gets the size of a file.</summary> public void GetFileSize(string relativePath, GetFileSizeCallback callback) { Debug.Assert(!string.IsNullOrEmpty(relativePath)); Debug.Assert(callback != null); string path = IOUtilities.CombinePath(this.userDir, relativePath); Int64 byteCount = this.GetFileSize(path); callback.Invoke(relativePath, byteCount); }
/// Creates a widget that parses and displays Markdown. /// /// The [data] argument must not be null. protected MarkdownWidget(Key key, string data, MarkdownStyleSheet markdownStyleSheet, SyntaxHighlighter syntaxHighlighter1, MarkdownTapLinkCallback onTapLink, string imageDirectory) : base(key) { Debug.Assert(data != null, "data != null"); this.data = data; this.styleSheet = markdownStyleSheet; this.syntaxHighlighter = syntaxHighlighter1; this.onTapLink = onTapLink; this.imageDirectory = imageDirectory; }
/// <summary>Checks for the existence of a file.</summary> public void GetFileExists(string relativePath, GetFileExistsCallback callback) { Debug.Assert(!string.IsNullOrEmpty(relativePath)); Debug.Assert(callback != null); string path = IOUtilities.CombinePath(this.userDir, relativePath); bool fileExists = Steamworks.SteamRemoteStorage.FileExists(path); callback.Invoke(relativePath, fileExists); }
/// <summary>Gets the size of a file.</summary> public void GetFileSize(string relativePath, GetFileSizeCallback callback) { Debug.Assert(!string.IsNullOrEmpty(relativePath)); Debug.Assert(callback != null); string path = IOUtilities.CombinePath(this.userDir, relativePath); int fileSize = Steamworks.SteamRemoteStorage.FileSize(path); callback.Invoke(relativePath, (Int64)fileSize); }