diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2014-06-11 20:57:18 -0700 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2014-06-11 20:57:18 -0700 |
commit | e6e180a4d8dd899c52ded7c523e3743981e9f9e0 (patch) | |
tree | 33531bf9e5a7c4f84fddc42a123979c29cbe6d00 /MobileCydia.mm | |
parent | 10387810f98418edacf59804f0b87073e2c19c58 (diff) |
Truly "over-engineer" source progress indications.
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r-- | MobileCydia.mm | 69 |
1 files changed, 57 insertions, 12 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index e64b7fb..4cf60b0 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1166,6 +1166,7 @@ class SourceStatus : private: _transient NSObject<FetchDelegate> *delegate_; _transient Database *database_; + std::set<std::string> fetches_; public: SourceStatus(NSObject<FetchDelegate> *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<std::string> 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<true>" : "Pulse<false>", *item); + Set(fetch, *item); + } + + std::vector<std::string> stops; + std::set_difference(fetches_.begin(), fetches_.end(), fetches.begin(), fetches.end(), std::back_insert_iterator<std::vector<std::string>>(stops)); + for (std::vector<std::string>::const_iterator stop(stops.begin()); stop != stops.end(); ++stop) { + //printf("Stop(%s)\n", stop->c_str()); + Set(false, *stop); + } + return ![delegate_ isSourceCancelled]; } |