Example #1
0
        /// <summary>
        /// Converts a list of workshop ids into a list of ModItemInfo objects
        /// </summary>
        /// <param name="value">A string containing workshop ids separated by new lines</param>
        /// <param name="targetType">This parameter will be ignored</param>
        /// <param name="parameter">
        /// A list of ModItemInfos which should
        /// contain the requestted mods
        /// (or they will be dropped)
        /// </param>
        /// <param name="culture">This parameter will be ignored</param>
        /// <returns>A list of ModItemInfo objects</returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var list = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(Type));
            var mods = parameter as ICollection <ModItemInfo>;

            if (mods == null)
            {
                throw new ArgumentException("parameter needs to be of type ICollection<ModItemInfo>!");
            }
            var input = ((string)value).Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in input)
            {
                if (ulong.TryParse(item, out ulong id))
                {
                    var mod = mods.FirstOrDefault((m) => m.PublishedFileId == id);
                    if (mod != null)
                    {
                        list.Add(mod);
                    }
                    else
                    {
                        list.Add(ModItemUtils.Create(id));
                    }
                }
            }

            return(list);
        }
Example #2
0
 public TorchSessionManager(ITorchBase torchInstance) : base(torchInstance)
 {
     _overrideMods = new Dictionary <ulong, MyObjectBuilder_Checkpoint.ModItem>();
     if (Torch.Config.UgcServiceType == UGCServiceType.Steam)
     {
         _overrideMods.Add(TorchModCore.MOD_ID, ModItemUtils.Create(TorchModCore.MOD_ID));
     }
 }
Example #3
0
        /// <inheritdoc/>
        public bool AddOverrideMod(ulong modId)
        {
            if (_overrideMods.ContainsKey(modId))
            {
                return(false);
            }
            var item = ModItemUtils.Create(modId);

            _overrideMods.Add(modId, item);

            OverrideModsChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Add, item));
            return(true);
        }
Example #4
0
        public void SaveConfig()
        {
            if (((TorchServer)Torch).HasRun)
            {
                Log.Warn("Checkpoint cache is stale, not saving dedicated config.");
                return;
            }

            DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME));
            Log.Info("Saved dedicated config.");

            try
            {
                var world = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == DedicatedConfig.LoadWorld) ?? new WorldViewModel(DedicatedConfig.LoadWorld);

                world.Checkpoint.SessionName      = DedicatedConfig.WorldName;
                world.WorldConfiguration.Settings = DedicatedConfig.SessionSettings;
                world.WorldConfiguration.Mods.Clear();

                foreach (var mod in DedicatedConfig.Mods)
                {
                    var savedMod = ModItemUtils.Create(mod.PublishedFileId);
                    savedMod.IsDependency = mod.IsDependency;
                    savedMod.Name         = mod.Name;
                    savedMod.FriendlyName = mod.FriendlyName;

                    world.WorldConfiguration.Mods.Add(savedMod);
                }
                Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());

                world.SaveSandbox();

                Log.Info("Saved world config.");
            }
            catch (Exception e)
            {
                Log.Error("Failed to write sandbox config, changes will not appear on server");
                Log.Error(e);
            }
        }
Example #5
0
        private void BulkButton_OnClick(object sender, RoutedEventArgs e)
        {
            var editor = new CollectionEditor();

            //let's see just how poorly we can do this
            var modList = ((MtObservableList <ModItemInfo>)DataContext).ToList();
            var idList  = modList.Select(m => m.ToString()).ToList();
            var tasks   = new List <Task>();

            //blocking
            editor.Edit <string>(idList, "Mods");

            modList.RemoveAll(m =>
            {
                var mod = m.ToString();
                return(idList.Any(mod.Equals));
            });
            modList.AddRange(idList.Select(id =>
            {
                var info = new ModItemInfo(ModItemUtils.Create(id));
                tasks.Add(Task.Run(info.UpdateModInfoAsync));
                return(info);
            }));
            _instanceManager.DedicatedConfig.Mods.Clear();
            foreach (var mod in modList)
            {
                _instanceManager.DedicatedConfig.Mods.Add(mod);
            }

            if (tasks.Any())
            {
                Task.WaitAll(tasks.ToArray());
            }

            Dispatcher.Invoke(() =>
            {
                _instanceManager.DedicatedConfig.Save();
            });
        }
Example #6
0
 private void AddBtn_OnClick(object sender, RoutedEventArgs e)
 {
     if (TryExtractId(AddModIDTextBox.Text, out ulong id))
     {
         var mod = new ModItemInfo(ModItemUtils.Create(id));
         //mod.PublishedFileId = id;
         _instanceManager.DedicatedConfig.Mods.Add(mod);
         Task.Run(mod.UpdateModInfoAsync)
         .ContinueWith((t) =>
         {
             Dispatcher.Invoke(() =>
             {
                 _instanceManager.DedicatedConfig.Save();
             });
         });
         AddModIDTextBox.Text = "";
     }
     else
     {
         AddModIDTextBox.BorderBrush = Brushes.Red;
         Log.Warn("Invalid mod id!");
         MessageBox.Show("Invalid mod id!");
     }
 }
Example #7
0
 public TorchSessionManager(ITorchBase torchInstance) : base(torchInstance)
 {
     _overrideMods = new Dictionary <ulong, MyObjectBuilder_Checkpoint.ModItem>();
     _overrideMods.Add(TorchModCore.MOD_ID, ModItemUtils.Create(TorchModCore.MOD_ID));
 }