From: Jay Freeman (saurik) Date: Thu, 12 Jun 2014 03:57:18 +0000 (-0700) Subject: Truly "over-engineer" source progress indications. X-Git-Tag: v1.1.10~8 X-Git-Url: https://git.saurik.com/cydia.git/commitdiff_plain/e6e180a4d8dd899c52ded7c523e3743981e9f9e0?ds=inline Truly "over-engineer" source progress indications. --- diff --git a/MobileCydia.mm b/MobileCydia.mm index e64b7fbf..4cf60b0c 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1166,6 +1166,7 @@ class SourceStatus : private: _transient NSObject *delegate_; _transient Database *database_; + std::set fetches_; public: SourceStatus(NSObject *delegate, Database *database) : @@ -1174,30 +1175,74 @@ class SourceStatus : { } - void Set(bool fetch, pkgAcquire::ItemDesc &desc) { - desc.Owner->ID = 0; - [database_ setFetch:fetch forURI:desc.Owner->DescURI().c_str()]; + void Set(bool fetch, const std::string &uri) { + if (fetch) { + if (!fetches_.insert(uri).second) + return; + } else { + if (fetches_.erase(uri) == 0) + return; + } + + //printf("Set(%s, %s)\n", fetch ? "true" : "false", uri.c_str()); + [database_ setFetch:fetch forURI:uri.c_str()]; + } + + _finline void Set(bool fetch, pkgAcquire::Item *item) { + /*unsigned long ID(fetch ? 1 : 0); + if (item->ID == ID) + return; + item->ID = ID;*/ + Set(fetch, item->DescURI()); + } + + void Log(const char *tag, pkgAcquire::Item *item) { + //printf("%s(%s) S:%u Q:%u\n", tag, item->DescURI().c_str(), item->Status, item->QueueCounter); } virtual void Fetch(pkgAcquire::ItemDesc &desc) { - Set(true, desc); + Log("Fetch", desc.Owner); + Set(true, desc.Owner); } virtual void Done(pkgAcquire::ItemDesc &desc) { - Set(false, desc); + Log("Done", desc.Owner); + Set(false, desc.Owner); } virtual void Fail(pkgAcquire::ItemDesc &desc) { - Set(false, desc); + Log("Fail", desc.Owner); + Set(false, desc.Owner); } virtual bool Pulse_(pkgAcquire *Owner) { - for (pkgAcquire::ItemCIterator item = Owner->ItemsBegin(); item != Owner->ItemsEnd(); ++item) - if ((*item)->ID != 0); - else if ((*item)->Status == pkgAcquire::Item::StatIdle) { - (*item)->ID = 1; - [database_ setFetch:true forURI:(*item)->DescURI().c_str()]; - } else (*item)->ID = 0; + std::set fetches; + for (pkgAcquire::ItemCIterator item(Owner->ItemsBegin()); item != Owner->ItemsEnd(); ++item) { + bool fetch; + if ((*item)->QueueCounter == 0) + fetch = false; + else switch ((*item)->Status) { + case pkgAcquire::Item::StatFetching: + fetches.insert((*item)->DescURI()); + fetch = true; + break; + + default: + fetch = false; + break; + } + + Log(fetch ? "Pulse" : "Pulse", *item); + Set(fetch, *item); + } + + std::vector stops; + std::set_difference(fetches_.begin(), fetches_.end(), fetches.begin(), fetches.end(), std::back_insert_iterator>(stops)); + for (std::vector::const_iterator stop(stops.begin()); stop != stops.end(); ++stop) { + //printf("Stop(%s)\n", stop->c_str()); + Set(false, *stop); + } + return ![delegate_ isSourceCancelled]; }