Example #1
0
            private void OnTextBoxLostFocus(object sender, RoutedEventArgs e)
            {
                string text  = TextBox.Text;
                object color = null;

                try
                {
                    color = Newtonsoft.Json.JsonConvert.DeserializeObject <Color>('"' + text + '"');
                }
                catch
                {
                    color = null;
                }
                if (color == null)
                {
                    MessageBox.Show(StringAdapter.GetResource("Invalid_Value") + "\r\n" + text);
                }
                else
                {
                    if (!Color.Equals((Color)color))
                    {
                        SetColor((Color)color);
                        Callback((Color)color);
                    }
                }
            }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var           item = value as L4D2MM.ModInfo;
            StringBuilder sb   = new StringBuilder();

            if (item.IsHaveCollision)
            {
                sb.Append(StringAdapter.GetInfo("HaveCollision") + " : ");
                foreach (var v in item.Resources)
                {
                    if (v.Value)
                    {
                        sb.Append("\r\n-" + v.Key.Display);
                    }
                }
            }
            else
            {
                if (item.IsIgnoreCollision)
                {
                    sb.Append(StringAdapter.GetInfo("IgnoredCollision"));
                }
                else
                {
                    sb.Append(StringAdapter.GetInfo("NoCollision"));
                }
            }
            return(sb.ToString());
        }
        private void ButtonOkClick(object sender, RoutedEventArgs e)
        {
            bool   valid   = false;
            bool   convert = true;
            object o       = null;

            try
            {
                o = Newtonsoft.Json.JsonConvert.DeserializeObject(ctlTextBox.Text, InitializeValue.GetType());
            }
            catch
            {
                convert = false;
            }
            if (convert && Verify(o))
            {
                InputValue = o;
                valid      = true;
                this.Close();
            }
            if (!valid)
            {
                var msg = StringAdapter.GetResource("Invalid_Value");
                if (VerifyErrorMsg != null)
                {
                    msg += "\r\n" + VerifyErrorMsg;
                }
                MessageBox.Show(msg);
            }
        }
Example #4
0
        private void MenuItemLanguageClick(object sender, RoutedEventArgs e)
        {
            var newlanguage = (sender as MenuItem).DataContext as string;

            if (Configure.Language != newlanguage)
            {
                LanguageHelper.LoadLanguageFile(newlanguage);
                Configure.Language = newlanguage;
                WindowCallbacks.Print(StringAdapter.GetInfo("ChangeLanguage"));
                m_categorySelected.RefreshLanguage();
                InitializeListViewMenu();
                Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(newlanguage);
                Thread.CurrentThread.CurrentCulture   = new System.Globalization.CultureInfo(newlanguage);
                Logging.Log("change language to " + newlanguage);

                //refresh check box
                int count = 0;
                foreach (var v in ctlMenuLanguage.Items)
                {
                    var  language = (v as MenuItem).DataContext as string;
                    bool match    = language.Equals(Configure.Language);
                    (v as MenuItem).IsChecked = match;
                    count += match ? 1 : 0;
                }
                Logging.Assert(count == 1);
            }
        }
Example #5
0
        public WindowColors()
        {
            InitializeComponent();
            FontSize = 14;

            colors = new List <ColorRow>();
            var AddColor = new Action <string, object, Color, Action <Color> >((key, o, color, action) =>
            {
                string content;
                if (o is L4D2MM.ModState)
                {
                    content = o.GetString();
                }
                else
                {
                    content = StringAdapter.GetResource(o.ToString());
                }
                colors.Add(new ColorRow(StringAdapter.GetResource(key) + '.' + content, color, action));
            });

            AddColor("Indicator", "Normal", Configure.View.IndicatorNormal, c => Configure.View.IndicatorNormal                     = c);
            AddColor("Indicator", "Ignored", Configure.View.IndicatorIgnore, c => Configure.View.IndicatorIgnore                    = c);
            AddColor("Indicator", "Conflicted", Configure.View.IndicatorCollision, c => Configure.View.IndicatorCollision           = c);
            AddColor("State", L4D2MM.ModState.Unregisted, Configure.View.StateUnregisted, c => Configure.View.StateUnregisted       = c);
            AddColor("State", L4D2MM.ModState.Unsubscribed, Configure.View.StateUnsubscribed, c => Configure.View.StateUnsubscribed = c);
            AddColor("State", L4D2MM.ModState.Miss, Configure.View.StateMiss, c => Configure.View.StateMiss = c);
            AddColor("State", L4D2MM.ModState.Off, Configure.View.StateOff, c => Configure.View.StateOff    = c);
            AddColor("State", L4D2MM.ModState.On, Configure.View.StateOn, c => Configure.View.StateOn       = c);

            int Col = 3;
            int Row = colors.Count;

            while (Col-- > 0)
            {
                ColumnDefinition cd = new ColumnDefinition();
                cd.Width = new GridLength();
                ctlGrid.ColumnDefinitions.Add(cd);
            }
            while (Row-- > 0)
            {
                RowDefinition rd = new RowDefinition();
                rd.Height = new GridLength();
                ctlGrid.RowDefinitions.Add(rd);
            }

            var GirdAction = new Action <UIElement, int, int>((ctl, col, row) =>
            {
                ctlGrid.Children.Add(ctl);
                Grid.SetColumn(ctl, col);
                Grid.SetRow(ctl, row);
            });

            foreach (var c in colors)
            {
                var row = colors.IndexOf(c);
                GirdAction(c.Label, 0, row);
                GirdAction(c.Border, 1, row);
                GirdAction(c.TextBox, 2, row);
            }
        }
Example #6
0
 public bool SetEnableSteam(bool enable)
 {
     Logging.Log("enable Steam " + enable.ToString());
     if (m_steam != null && !enable)
     {
         m_steam.Dispose();
         m_steam = null;
     }
     else if (m_steam == null && enable)
     {
         WindowCallbacks.Print(StringAdapter.GetInfo("LinkToSteam"));
         m_steam = new Facepunch.Steamworks.Client(m_appid);
         if (m_steam != null && m_steam.SteamId <= 0)
         {
             m_steam.Dispose();
             m_steam = null;
         }
         if (m_steam != null)
         {
             WindowCallbacks.Print(StringAdapter.GetInfo("LinkToSteamUser") + " : " + m_steam.Username);
         }
         else
         {
             WindowCallbacks.Print(StringAdapter.GetInfo("LinkToSteamFailed"));
         }
     }
     return(m_steam != null || !enable);
 }
Example #7
0
 private void MenuItemAboutClick(object sender, RoutedEventArgs e)
 {
     MessageBox.Show(
         StringAdapter.GetInfo("About") + '.'
         + "\r\n" + StringAdapter.GetResource("License") + " : MIT"
         + "\r\n" + StringAdapter.GetResource("Project") + " : https://github.com/XavierCai1996/L4D2ModManager"
         + "\r\n" + StringAdapter.GetResource("Contact") + " : [email protected]"
         , StringAdapter.GetResource("About"));
 }
Example #8
0
        private void MenuItemLocalModClassificationRuleClick(object sender, RoutedEventArgs e)
        {
            var window = new WindowClassify();

            window.Title    = StringAdapter.GetResource("Menu_LocalModClassificationRule");
            window.FontSize = FontSize;
            window.Owner    = this;
            window.ShowDialog();
        }
Example #9
0
        private void LoadSteamWorkshop()
        {
            if (m_steam != null)
            {
                WindowCallbacks.OperationEnable(this.GetType().ToString(), false);
                WindowCallbacks.Print(StringAdapter.GetInfo("LoadSteamWorkshop"));
                WindowCallbacks.Process(0, 1, StringAdapter.GetInfo("LoadSteamWorkshop"));

                var list = m_steam.Workshop.GetSubscribedItemIds();
                if (list.Length > 0)
                {
                    if (Configure.DelegateSteam)
                    {
                        GetDelegateSteamResult(list.ToList(), ModSource.Workshop, true);
                    }
                    else
                    {
                        var query = m_steam.Workshop.CreateQuery();
                        query.FileId = list.ToList();
                        query.Run();
                        query.Block();
                        Logging.Assert(!query.IsRunning);
                        //Logging.Assert(query.TotalResults > 0);
                        //Logging.Assert(query.Items.Length > 0);
                        int total = query.Items.Length;
                        int count = 0;
                        foreach (var item in query.Items)
                        {
                            ulong id = item.Id;
                            //Facepunch.Steamworks.Workshop.Item item = m_steam.Workshop.GetItem(v);
                            if (id > 0)
                            {
                                WindowCallbacks.Process(count++, total, StringAdapter.GetInfo("LoadSteamWorkshop") + " : " + id.ToString());
                                string key = @"workshop\" + id.ToString() + ".vpk";
                                if (!m_modStates.ContainsKey(key))
                                {
                                    L4D2Mod mod = new L4D2Mod(item);
                                    if (mod.Title != null && mod.Title.Length > 0)
                                    {
                                        m_modStates.Add(key, new ModInfo(this, key, ModState.On, ModSource.Workshop, mod));
                                    }
                                }
                                else
                                {
                                    m_modStates[key].Mod.LoadItem(item);
                                }
                                Logging.Log("load from Steam workshop " + id.ToString());
                            }
                        }
                    }
                }
                WindowCallbacks.Process(1, 1, "");
                WindowCallbacks.Print(StringAdapter.GetInfo("LoadComplete"));
                WindowCallbacks.OperationEnable(this.GetType().ToString(), true);
            }
        }
 public ComboItem(object value, object category, bool special = false)
 {
     Value    = value;
     Category = category;
     if (!special)
     {
         Converter = o => (o as L4D2Type.Category)?.Name;
     }
     else
     {
         Converter = o => "---" + StringAdapter.GetResource(Value as string) + "---";
     }
 }
Example #11
0
        private void GetDelegateSteamResult(List <ulong> ids, ModSource source, bool create, int start = 0)
        {
            bool delegateSuccess = false;
            int  delegateCount   = 5;

            while (!delegateSuccess && delegateCount-- > 0)
            {
                using (var steamDelegate = new SteamDelegate(ids))
                {
                    steamDelegate.RunDelegate();
                    if (!steamDelegate.Timeout)
                    {
                        delegateSuccess = true;
                        if (!steamDelegate.Result)
                        {
                            WindowCallbacks.Print(StringAdapter.GetInfo("LinkToSteamFailed"));
                        }
                        else
                        {
                            int count = 0;
                            while (true)
                            {
                                count++;
                                var delegateResult = steamDelegate.Read();
                                if (delegateResult == null)
                                {
                                    break;
                                }
                                if (delegateResult.FileId > 0)
                                {
                                    //if(source == ModSource.Workshop)
                                    WindowCallbacks.Process(start + count, start + ids.Count, StringAdapter.GetInfo("LoadSteamWorkshop") + " : " + delegateResult.FileId.ToString());
                                    string key = (source == ModSource.Workshop ? @"workshop\" : "") + delegateResult.FileId.ToString() + ".vpk";
                                    if (!m_modStates.ContainsKey(key))
                                    {
                                        if (create)
                                        {
                                            m_modStates.Add(key, new ModInfo(this, key, ModState.On, source, new L4D2Mod(delegateResult.Json, delegateResult.Description)));
                                        }
                                    }
                                    else
                                    {
                                        m_modStates[key].Mod.LoadJson(delegateResult.Json, delegateResult.Description);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        private void MenuItemCustomCategoryClick(object sender, RoutedEventArgs e)
        {
            var window = new WindowCategory();

            window.Title    = StringAdapter.GetResource("Menu_CustomCategory");
            window.FontSize = FontSize;
            window.Owner    = this;
            window.ShowDialog();
            m_categorySelected.Refresh();
            LoadModInfo(LoadedModInfo);
            foreach (var mod in m_manager.Mods.Values)
            {
                mod.RefreshResources();
            }
        }
Example #13
0
        private bool SetGamePath()
        {
            //require [Windows API Code Pack]
            //in Visual Studio, open [Tool->Package Manager Consol]
            //input the command [Install-Package WindowsAPICodePack-Shell]
            var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();

            dialog.IsFolderPicker = true;
            Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult result = dialog.ShowDialog();
            if (result != Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok)
            {
                return(false);
            }
            Configure.InstallPath = dialog.FileName;
            WindowCallbacks.Print(StringAdapter.GetResource("Menu_SetPath") + " : " + dialog.FileName);
            return(true);
        }
Example #14
0
        private void MenuItemFontSizeClick(object sender, RoutedEventArgs e)
        {
            double oldFontSize = FontSize;
            var    window      = new WindowSetValue();

            window.Owner = this;
            window.Initialize(FontSize, StringAdapter.GetResource("Menu_FontSize"), StringAdapter.GetResource("Font_Size"));
            window.Verify         = o => (double)o >= 6 && (double)o <= 30;
            window.VerifyErrorMsg = "-> [6.0, 30.0]";
            window.FontSize       = FontSize;
            window.ShowDialog();
            if (window.InputValue != null)
            {
                this.FontSize           = (double)window.InputValue;
                ctlMenu.FontSize        = this.FontSize;
                Configure.View.FontSize = this.FontSize;
            }
        }
Example #15
0
        public MainWindow()
        {
            InitializeComponent();

            //UI
            this.FontSize    = Configure.View.FontSize;
            ctlMenu.FontSize = Configure.View.FontSize;
            this.SetSize(Configure.View.WindowSize);

            foreach (var col in CustomInformation.Instance.ViewLists)
            {
                if (CheckModInfoReflection(col.Reflection))
                {
                    var textBlockFactory = new FrameworkElementFactory(typeof(TextBlock));
                    textBlockFactory.SetValue(TextElement.ForegroundProperty, Brushes.Black);
                    textBlockFactory.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding("Mod")
                    {
                        Converter = new StringDisplayConverter(), ConverterParameter = "Mod." + col.Reflection
                    });
                    textBlockFactory.SetValue(TextBlock.TextAlignmentProperty, col.TextAlignment);

                    GridViewColumn column = new GridViewColumn();
                    column.Header       = col.TryTranslate ? StringAdapter.GetResource(col.Header) : col.Header;
                    column.Width        = col.Width;
                    column.CellTemplate = new DataTemplate {
                        VisualTree = textBlockFactory
                    };
                    ctlGridView.Columns.Add(column);

                    SortReflectionMap.Add(column, col.Reflection);
                }
            }

            //new
            m_manager          = new L4D2MM();
            m_categorySelected = new CategorySelecter(ctlCategoryList, ctlSubcategoryList, ctlTextSearch, ctlListView);

            //initialize property
            ctlPrintText.AppendText(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " [version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + ']');
            ctlProgressBar.SetValue(ProgressBar.ValueProperty, 100.0);
            InitializeListViewMenu();
            InitializeWindowMenu();
        }
Example #16
0
        private void DoInitialize(string path)
        {
            if (Configure.EnableSteam && m_steam != null)
            {
                LoadSteamWorkshop();
            }
            LoadLocalFiles(path);
            foreach (var mod in m_modStates.Values)
            {
                mod.RefreshResources();
            }

            //read the addons list file
            WindowCallbacks.OperationEnable(this.GetType().ToString(), false);
            WindowCallbacks.Print(StringAdapter.GetInfo("UpdateModState"));
            WindowCallbacks.Process(1, 1, StringAdapter.GetInfo("UpdateModState"));
            ReadAddonList(path);
            WindowCallbacks.Process(1, 1, StringAdapter.GetInfo("LoadComplete"));
            WindowCallbacks.OperationEnable(this.GetType().ToString(), true);

            //foreach (var v in m_modStates)
            //Logging.Log(v.Key + " : \t" + v.Value.ModState.GetString());

            //download preview files
            new System.Threading.Thread(new System.Threading.ThreadStart(() => {
                foreach (var v in m_modStates)
                {
                    var mod = v.Value.Mod;
                    if (mod.Image == null && mod.ImageURL != "")
                    {
                        try
                        {
                            mod.LoadPreviewImageFromURL(m_path + (v.Value.Source == ModSource.Workshop ? m_dirWorkshop : m_dirAddons));
                            WindowCallbacks.NotifyRefresh(v.Key, v.Value);
                        }
                        catch { }
                    }
                }
            })).Start();

            Logging.Log("initialize success : " + path);
        }
Example #17
0
 private void LoadModManager()
 {
     new Thread(new ThreadStart(() =>
     {
         WindowCallbacks.OperationEnable(this.GetType().ToString(), false);
         if (!m_manager.LoadConfig())
         {
             WindowCallbacks.Print(StringAdapter.GetInfo("CheckPath"));
             WindowCallbacks.OperationEnable(this.GetType().ToString(), true);
             return;
         }
         if (!m_manager.SetEnableSteam(Configure.EnableSteam))
         {
             WindowCallbacks.Print(StringAdapter.GetInfo("NeedSteam"));
             WindowCallbacks.OperationEnable(this.GetType().ToString(), true);
             return;
         }
         m_manager.Initialize();
         Logging.Log("mod manager initialize success");
         m_categorySelected.Update(m_manager);
         WindowCallbacks.OperationEnable(this.GetType().ToString(), true);
     })).Start();
 }
Example #18
0
 private string DetectConfig()
 {
     try //from registry
     {
         RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(m_registryPath);
         string      path        = new FileInfo(registryKey.GetValue(m_registryKey).ToString().Split('\"')[1]).DirectoryName;
         Logging.Log("find path from registry : " + path);
         WindowCallbacks.Print(StringAdapter.GetInfo("FindPath") + " : " + path);
         return(path);
     }
     catch
     {
         //can not get path from registry
         //try get it from cache
         if (Configure.InstallPath != "")
         {
             Logging.Log("find path from cache file : " + Configure.InstallPath);
             WindowCallbacks.Print(StringAdapter.GetInfo("FindPath") + " : " + Configure.InstallPath);
             return(Configure.InstallPath);
         }
     }
     return(null);
 }
Example #19
0
 private bool CheckConfig(string path)
 {
     //check path valid
     if (path == null)
     {
         Logging.Log("invalid path");
         return(false);
     }
     WindowCallbacks.Print(StringAdapter.GetResource("Path") + " : " + path);
     if (!Directory.Exists(path + m_dirCore))
     {
         Logging.Log("can not find main directory");
         return(false);
     }
     if (!File.Exists(path + m_fileList))
     {
         Logging.Log("can not find addons list file");
         WindowCallbacks.Print(StringAdapter.GetResource("Create") + " : " + path + m_fileList);
         File.WriteAllText(path + m_fileList, "\"AddonList\"\n{\n}\n"); //create it
         //return false;
     }
     if (!Directory.Exists(path + m_dirAddons))
     {
         Logging.Log("can not find addons directory");
         Directory.CreateDirectory(path + m_dirAddons);
         WindowCallbacks.Print(StringAdapter.GetResource("Create") + " : " + path + m_dirAddons);
         //return false;
     }
     if (!Directory.Exists(path + m_dirWorkshop))
     {
         Logging.Log("can not find addons directory");
         Directory.CreateDirectory(path + m_dirWorkshop);
         WindowCallbacks.Print(StringAdapter.GetResource("Create") + " : " + path + m_dirWorkshop);
         //return false;
     }
     return(true);
 }
Example #20
0
        void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
        {
            var headerClicked = e.OriginalSource as GridViewColumnHeader;

            if (headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding)
            {
                Comparison <ViewItem> method = null;
                if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModId")))
                {
                    method = (a, b) => a.ID.CompareTo(b.ID);
                }
                else if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModSource")))
                {
                    method = (a, b) => a.Source.CompareTo(b.Source);
                }
                else if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModState")))
                {
                    method = (a, b) => a.State.CompareTo(b.State);
                }
                else if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModSize")))
                {
                    method = (a, b) => a.Mod.Mod.FileSize.CompareTo(b.Mod.Mod.FileSize);
                }
                else if (SortReflectionMap.ContainsKey(headerClicked.Column))
                {
                    method = (a, b) =>
                    {
                        var reflection = SortReflectionMap[headerClicked.Column];
                        var oa         = typeof(L4D2Mod).InvokeMember(reflection, System.Reflection.BindingFlags.GetProperty, null, a.Mod.Mod, null);
                        var ob         = typeof(L4D2Mod).InvokeMember(reflection, System.Reflection.BindingFlags.GetProperty, null, b.Mod.Mod, null);
                        if (oa is IComparable && ob is IComparable)
                        {
                            return((oa as IComparable).CompareTo(ob));
                        }
                        return(oa.Display().CompareTo(ob.Display()));
                    }
                }
                ;
                else
                {
                    return;
                }

                if (method == null)
                {
                    return;
                }
                else
                {
                    if (SortMethodId.Equals(0))
                    {
                        m_categorySelected.Sort(null);
                    }
                    else
                    {
                        m_categorySelected.Sort((a, b) => SortMethodId * method(a, b));
                    }
                }
                SortMethodId += 1;
                if (SortMethodId > 1)
                {
                    SortMethodId = -1;
                }
            }
        }
Example #21
0
        private void InitializeListViewMenu()
        {
            ContextMenu menu = new ContextMenu();

            var menuItemConfirm = new Dictionary <string, Func <bool> >();
            var menuItemClick   = new Dictionary <string, Func <L4D2MM.ModInfo, bool> >();
            RoutedEventHandler OnMenuItemClick = (o, e) =>
            {
                var name = (o as MenuItem).Name;
                if (!menuItemClick.ContainsKey(name))
                {
                    return;
                }
                if (menuItemConfirm.ContainsKey(name))
                {
                    if (!menuItemConfirm[name]())
                    {
                        return;
                    }
                }
                var items = ctlListView.SelectedItems;
                if (items == null || items.Count <= 0)
                {
                    return;
                }
                var      func  = menuItemClick[name];
                int      count = 0;
                object[] copy  = new object[items.Count];
                items.CopyTo(copy, 0);
                string firstName = (items[0] as ViewItem).Key;
                foreach (var item in copy)
                {
                    if (func((item as ViewItem).Mod))
                    {
                        count++;
                    }
                }
                StringBuilder sb = new StringBuilder();
                sb.Append(StringAdapter.GetResource("Operation") + " : " + (o as MenuItem).Header as string + " : ");
                if (copy.Length > 1)
                {
                    sb.Append(StringAdapter.GetResource("Success") + ' ' + count.ToString() + " / " + StringAdapter.GetResource("Selected") + ' ' + copy.Length.ToString());
                }
                else
                {
                    sb.Append(firstName);
                }
                WindowCallbacks.Print(sb.ToString());
                ctlListView.Items.Refresh();
                m_manager.SaveModState();
            };

            var menuItemMap = new Dictionary <string, MenuItem>();
            Func <string, Func <bool>, Func <L4D2MM.ModInfo, bool>, MenuItem> GenerateMenuItem = (name, confirm, func) =>
            {
                MenuItem btn = new MenuItem();
                btn.Name   = name;
                btn.Click += OnMenuItemClick;
                btn.Header = StringAdapter.GetResource(name);
                menuItemConfirm.Add(name, confirm);
                menuItemClick.Add(name, func);
                menuItemMap.Add(name, btn);
                return(btn);
            };

            Func <string, Func <L4D2MM.ModInfo, bool>, MenuItem> GenerateMenuItemWithoutConfirm = (name, func) =>
            {
                return(GenerateMenuItem(name, () => { return true; }, func));
            };

            menu.Items.Add(GenerateMenuItemWithoutConfirm("On", o => { return(o.SetOn()); }));
            menu.Items.Add(GenerateMenuItemWithoutConfirm("Off", o => { return(o.SetOff()); }));
            menu.Items.Add(new Separator());
            menu.Items.Add(GenerateMenuItemWithoutConfirm("Subscribe", o => { return(o.Subscribe()); }));
            menu.Items.Add(GenerateMenuItemWithoutConfirm("Unsubscribe", o => { return(o.Unsubscribe()); }));
            menu.Items.Add(new Separator());
            menu.Items.Add(GenerateMenuItemWithoutConfirm("Ignore_Collision", o => { return(o.IgnoreCollision()); }));
            menu.Items.Add(GenerateMenuItemWithoutConfirm("Detect_Collision", o => { return(o.DetectCollision()); }));
            menu.Items.Add(new Separator());
            menu.Items.Add(GenerateMenuItem("Delete", () => { return(CtlExtension.ConfirmBox(StringAdapter.GetInfo("ConfirmDeleteFile"))); }, o => { bool ret = o.Delete(); m_categorySelected.Update(m_manager); return(ret); }));

            ctlListView.ContextMenu = menu;

            FindListViewMenuItem = name => menuItemMap[name];
        }
 public void Initialize <T>(T value)
 {
     Initialize(value, "", StringAdapter.GetResource("Value"));
 }
Example #23
0
        private void LoadLocalFiles(string path)
        {
            WindowCallbacks.OperationEnable(this.GetType().ToString(), false);
            WindowCallbacks.Print(StringAdapter.GetInfo("LoadLocalFile"));
            int total = new DirectoryInfo(path + m_dirWorkshop).GetFiles("*.vpk").Length;

            if (Configure.EnableAddons)
            {
                total += new DirectoryInfo(path + m_dirAddons).GetFiles("*.vpk").Length;
            }
            int current = 0;

            foreach (FileInfo vpkFile in new DirectoryInfo(path + m_dirWorkshop).GetFiles("*.vpk")) //from workshop
            {
                //update process bar
                WindowCallbacks.Process(current, total, StringAdapter.GetInfo("LoadLocalFile") + " : workshop/" + vpkFile.Name);
                string key = @"workshop\" + vpkFile.Name;
                if (!m_modStates.ContainsKey(key))
                {
                    //continue; //local file not valid in this path
                    L4D2Mod mod  = new L4D2Mod(vpkFile, true);
                    ModInfo info = new ModInfo(this, key, SteamEnabled ? ModState.Unsubscribed : ModState.On, ModSource.Workshop, mod);
                    m_modStates.Add(key, info);
                }
                else
                {
                    m_modStates[key].Mod.LoadLocalFile(vpkFile, Configure.EnableReadVpk);
                }
                current++;
                Logging.Log("load from workshop : " + vpkFile.Name);
            }
            //for addons
            if (Configure.EnableAddons)
            {
                List <ulong> fileIds = new List <ulong>();
                foreach (FileInfo vpkFile in new DirectoryInfo(path + m_dirAddons).GetFiles("*.vpk")) //from addons
                {
                    //update process bar
                    WindowCallbacks.Process(current, total, StringAdapter.GetInfo("LoadLocalFile") + " : " + vpkFile.Name);
                    string  key  = vpkFile.Name;
                    L4D2Mod mod  = new L4D2Mod(vpkFile, true);
                    ModInfo info = new ModInfo(this, key, ModState.On, ModSource.Player, mod);
                    m_modStates.Add(key, info);
                    current++;
                    Logging.Log("load from addons : " + vpkFile.Name);
                    //check if it is a workshop item
                    string name = key.Replace(".vpk", "");
                    if (name.IsNumber() && name.Length >= 8 && name.Length <= 11)
                    {
                        fileIds.Add(ulong.Parse(name));
                    }
                }
                if (m_steam != null && fileIds.Count > 0)
                {
                    if (Configure.DelegateSteam)
                    {
                        GetDelegateSteamResult(fileIds, ModSource.Player, false, fileIds.Count);
                    }
                    else
                    {
                        var query = m_steam.Workshop.CreateQuery();
                        query.FileId = fileIds;
                        query.Run();
                        query.Block();
                        Logging.Assert(!query.IsRunning);
                        foreach (var item in query.Items)
                        {
                            if (item.Id > 0)
                            {
                                string key = item.Id.ToString() + ".vpk";
                                Logging.Assert(m_modStates.ContainsKey(key));
                                m_modStates[key].Mod.LoadItem(item);
                            }
                        }
                    }
                }
            }
            WindowCallbacks.Process(1, 1, StringAdapter.GetInfo("LoadComplete"));
            WindowCallbacks.Print(StringAdapter.GetInfo("LoadComplete"));
            WindowCallbacks.OperationEnable(this.GetType().ToString(), true);
        }
Example #24
0
        private void LoadModInfo(L4D2MM.ModInfo mod)
        {
            if (mod == null)
            {
                return;
            }
            LoadedModInfo = mod;
            var fontSize = this.FontSize;

            m_displayedKey = mod.Key;
            ctlFrameText.Document.Blocks.Clear();
            if (mod.Mod.ImageMemoryStream != null)
            {
                ctlImage.SetSource(mod.Mod.GetAndResetImageMemoryStream());
            }
            else
            {
                ctlImage.SetSource(null);//or show the default image
            }
            if (mod.Mod.Title.Length > 0)
            {
                Run run = new Run(mod.Mod.Title);
                run.FontSize   = fontSize + 4;
                run.Foreground = new SolidColorBrush(Colors.Black);
                run.FontWeight = FontWeights.Bold;
                ctlFrameText.Document.Blocks.Add(new Paragraph(run));
            }
            if (mod.Mod.Category.Count > 0)
            {
                Run run = new Run(StringAdapter.GetResource("Category") + " : " + mod.Mod.Category.Aggregate("", (s, c) => s += ", " + c.ToString()).Substring(2));
                run.FontSize   = fontSize;
                run.Foreground = new SolidColorBrush(Colors.Gray);
                run.FontWeight = FontWeights.Normal;
                ctlFrameText.Document.Blocks.Add(new Paragraph(run));
            }

            foreach (var box in CustomInformation.Instance.ViewBoxes)
            {
                if (CheckModInfoReflection(box.Reflection))
                {
                    string content    = (box.TryTranslate ? StringAdapter.GetResource(box.Header) : box.Header) + " : \r\n";
                    string reflection = typeof(L4D2Mod).InvokeMember(box.Reflection, System.Reflection.BindingFlags.GetProperty, null, mod.Mod, null).Display();
                    if (reflection.Length > 0)
                    {
                        Run run = new Run(content + reflection);
                        run.FontSize   = fontSize;
                        run.Foreground = new SolidColorBrush(box.Color);
                        run.FontWeight = FontWeights.Normal;
                        ctlFrameText.Document.Blocks.Add(new Paragraph(run));
                    }
                }
            }

            if (ctlFrameText.Document.Blocks.Count <= 0)
            {
                Run run = new Run('(' + StringAdapter.GetResource("No_Information") + ')');
                run.FontSize   = fontSize;
                run.Foreground = new SolidColorBrush(Colors.Gray);
                run.FontWeight = FontWeights.Normal;
                ctlFrameText.Document.Blocks.Add(new Paragraph(run));
            }
        }