示例#1
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);
 }
示例#2
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);
            }
        }
示例#3
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);
            }
        }
示例#4
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);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            Logging.Log("window load success");
            //this.Height += ctlProgressText.ActualHeight;

            //set up
            WindowCallbacks.SetProcessCallback(ProcessBarOperation);
            WindowCallbacks.SetPrintCallback(PrintOperation);
            WindowCallbacks.SetOperationEnableCallback(EnableOperation);
            WindowCallbacks.SetNotifyUpdateCallback(NotifyUpdate);

#if DEBUG
#else
            LoadModManager();
#endif
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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);
 }
示例#9
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();
 }
示例#10
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);
 }
示例#11
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);
        }
示例#12
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];
        }