void BuyoutManager::BuyoutFromTabName(std::vector<std::string> tabs) { for (auto tab : tabs) { std::string clean_tab = tab; std::string tab_hash = "stash:" + tab; if (ExistsTab(tab)) continue; //Lowercase, remove spaces std::transform(tab.begin(), tab.end(), tab.begin(), ::tolower); tab = Util::StringReplace(tab, " ", ""); Buyout bo; bo.type = BUYOUT_TYPE_NONE; bo.value = 0; bo.currency = CURRENCY_NONE; if (clean_tab == "no price") bo.type = BUYOUT_TYPE_NO_PRICE; std::string srt = Util::StringReplace(tab, "~price", ""); if (tab != srt) bo.type = BUYOUT_TYPE_FIXED; tab = srt; for (unsigned int i=0; i<CurrencyMultiTag.size();i++) { std::vector<std::string> tags = Util::StringSplit(CurrencyMultiTag[i],','); for (auto curr : tags) { if (curr.empty()) continue; std::string srt = Util::StringReplace(tab, curr, ""); if (tab != srt) { bool ok; bo.value = QString(srt.c_str()).toDouble(&ok); if(!ok) continue; if (bo.type == BUYOUT_TYPE_NONE) bo.type = BUYOUT_TYPE_BUYOUT; bo.currency = static_cast<Currency>(i); break; } } } if (bo.type != BUYOUT_TYPE_NONE) { SetTab(tab_hash, bo); qDebug() << clean_tab.c_str() << bo.value << CurrencyAsString[bo.currency].c_str() << BuyoutTypeAsTag[bo.type].c_str(); } } }
void BuyoutManager::UpdateTabItems(const Bucket &tab, bool force) { std::string hash = tab.location().GetGeneralHash(); bool set = ExistsTab(hash); Buyout buyout; if (set) buyout = GetTab(hash); // Set buyouts on items with the "set_by" flag set to the tab for (auto &item : tab.items()) { if (set) { Buyout b; b.currency = buyout.currency; b.type = buyout.type; b.value = buyout.value; if (!Exists(*item)) { // It's new! b.last_update = QDateTime::currentDateTime(); } else if (!IsItemManuallySet(*item)) { Buyout curr = Get(*item); if (!Equal(buyout, curr)) { b.last_update = buyout.last_update; } else { continue; } } else if (!force){ continue; } Set(*item, b, QString::fromStdString(hash)); } else if (!set && Exists(*item) && (!IsItemManuallySet(*item) || force)) { Delete(*item); } } Save(); }