/// <summary> /// Ensure that the current skin is in a state it can accept user modifications. /// This will create a copy of any internal skin and being tracking in the database if not already. /// </summary> public void EnsureMutableSkin() { CurrentSkinInfo.Value.PerformRead(s => { if (!s.Protected) { return; } // if the user is attempting to save one of the default skin implementations, create a copy first. var result = skinModelManager.Import(new SkinInfo { Name = s.Name + @" (modified)", Creator = s.Creator, InstantiationInfo = s.InstantiationInfo, }).Result; if (result != null) { // save once to ensure the required json content is populated. // currently this only happens on save. result.PerformRead(skin => Save(skin.CreateInstance(this))); CurrentSkinInfo.Value = result; } }); }
/// <summary> /// Ensure that the current skin is in a state it can accept user modifications. /// This will create a copy of any internal skin and being tracking in the database if not already. /// </summary> public void EnsureMutableSkin() { CurrentSkinInfo.Value.PerformRead(s => { if (!s.Protected) { return; } string[] existingSkinNames = realm.Run(r => r.All <SkinInfo>() .Where(skin => !skin.DeletePending) .AsEnumerable() .Select(skin => skin.Name).ToArray()); // if the user is attempting to save one of the default skin implementations, create a copy first. var skinInfo = new SkinInfo { Creator = s.Creator, InstantiationInfo = s.InstantiationInfo, Name = NamingUtils.GetNextBestName(existingSkinNames, $"{s.Name} (modified)") }; var result = skinModelManager.Import(skinInfo); if (result != null) { // save once to ensure the required json content is populated. // currently this only happens on save. result.PerformRead(skin => Save(skin.CreateInstance(this))); CurrentSkinInfo.Value = result; } }); }
/// <summary> /// Ensure that the current skin is in a state it can accept user modifications. /// This will create a copy of any internal skin and being tracking in the database if not already. /// </summary> public void EnsureMutableSkin() { if (CurrentSkinInfo.Value.ID >= 1) { return; } var skin = CurrentSkin.Value; // if the user is attempting to save one of the default skin implementations, create a copy first. CurrentSkinInfo.Value = skinModelManager.Import(new SkinInfo { Name = skin.SkinInfo.Name + @" (modified)", Creator = skin.SkinInfo.Creator, InstantiationInfo = skin.SkinInfo.InstantiationInfo, }).Result.Value; }