/// <summary> /// Copy this registry's to another registry (contents, flags and constraints). /// </summary> /// <param name="other">The other registry to copy to.</param> public void CopyTo(IRegistry other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } other.Tags.Clear(); other.Tags.AddRange(Tags); other.Clear(); other.AddAll(this); }
public static void LoadModule(string modulePath, IRegistry registry) { registry.Clear(); LoadAllModules(registry); var guid = AssetDatabase.AssetPathToGUID(modulePath); registry.UnregisterAllBySource(guid); LoadJson(modulePath, registry, UTinyRegistry.DefaultSourceIdentifier); foreach (var module in registry.FindAllBySource(UTinyRegistry.DefaultSourceIdentifier).OfType <UTinyModule>()) { module.PersistenceId = AssetDatabase.AssetPathToGUID(modulePath); } }
public static void LoadProject(string projectPath, IRegistry registry) { registry.Clear(); LoadAllModules(registry); // the project itself has no identifier registry.UnregisterAllBySource(UTinyRegistry.DefaultSourceIdentifier); LoadJson(projectPath, registry, UTinyRegistry.DefaultSourceIdentifier); foreach (var project in registry.FindAllBySource(UTinyRegistry.DefaultSourceIdentifier).OfType <UTinyProject>()) { project.PersistenceId = AssetDatabase.AssetPathToGUID(projectPath); UTinyUpdater.UpdateProject(project); } }
/// <summary> /// Removes all active environments. /// </summary> public static void Clear() { ActiveSigmaEnvironments.Clear(); }
//public public static void ClearAddressCache() { addressCache.Clear(); }
/// <summary> /// @TODO This method has too many conditionals and checks... it should be managed at a higher level /// </summary> /// <param name="registry"></param> /// <param name="persistenceId"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static bool Accept(IRegistry registry, out string persistenceId) { Assert.IsTrue(Exists()); registry.Clear(); UTinyPersistence.LoadAllModules(registry); registry.UnregisterAllBySource(UTinyRegistry.DefaultSourceIdentifier); persistenceId = null; using (var command = new MemoryStream()) using (var stream = File.OpenRead(GetTempLocation().FullName)) using (var reader = new BinaryReader(stream)) using (registry.SourceIdentifierScope(UTinyRegistry.DefaultSourceIdentifier)) { var version = reader.ReadInt32(); Assert.IsTrue(version > 0); var type = (SaveType)reader.ReadByte(); switch (type) { case SaveType.PersistentUnchanged: persistenceId = reader.ReadString(); return(false); case SaveType.PersistentChanged: persistenceId = reader.ReadString(); var hash = reader.ReadString(); if (!string.IsNullOrEmpty(hash) && !string.Equals(hash, ComputeHash(persistenceId))) { // Ask the user if they want to keep their changes or reload from disc if (EditorUtility.DisplayDialog($"{UTinyConstants.ApplicationName} assets changed", $"{UTinyConstants.ApplicationName} assets have changed on disk, would you like to reload the current project?", "Yes", "No")) { return(false); } } break; case SaveType.Temporary: break; default: throw new ArgumentOutOfRangeException(); } // This is to handle module editing. // We want to unregister it from its current source and re-register it with the persistenceId as the scope if (!string.IsNullOrEmpty(persistenceId)) { registry.UnregisterAllBySource(persistenceId); } FrontEnd.Accept(stream, command); command.Position = 0; Serialization.CommandStream.FrontEnd.Accept(command, registry); } foreach (var project in registry.FindAllBySource(UTinyRegistry.DefaultSourceIdentifier).OfType <UTinyProject>()) { project.PersistenceId = persistenceId; } return(true); }