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); } }
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); } } } } } } } }
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); }
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); }