示例#1
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);
            }
        }
示例#2
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);
        }
示例#3
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();
 }
示例#4
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);
        }