diff --git a/auctions_frame.lua b/auctions_frame.lua index 7bb475c..6100b1f 100644 --- a/auctions_frame.lua +++ b/auctions_frame.lua @@ -74,8 +74,8 @@ function public.scan_auctions() type = 'owner', queries = {{ blizzard_query = {} }}, on_page_loaded = function(page, total_pages) - private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages) - private.status_bar:set_text(format('Scanning (Page %d / %d)', page + 1, total_pages)) + private.status_bar:update_status(100 * (page - 1) / total_pages, 0) + private.status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages)) end, on_auction = function(auction_record) tinsert(auction_records, auction_record) diff --git a/bids_frame.lua b/bids_frame.lua index 9842f34..4fa1601 100644 --- a/bids_frame.lua +++ b/bids_frame.lua @@ -87,8 +87,8 @@ function public.scan_bids() type = 'bidder', queries = {{ blizzard_query = {} }}, on_page_loaded = function(page, total_pages) - private.status_bar:update_status(100 * (page + 1) / total_pages, 100 * (page + 1) / total_pages) - private.status_bar:set_text(format('Scanning (Page %d / %d)', page + 1, total_pages)) + private.status_bar:update_status(100 * (page - 1) / total_pages, 0) + private.status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages)) end, on_auction = function(auction_record) tinsert(auction_records, auction_record) diff --git a/core.lua b/core.lua index ae9933a..da1e684 100644 --- a/core.lua +++ b/core.lua @@ -1,5 +1,5 @@ Aux = { - version = '2.12.2', + version = '2.13.0', blizzard_ui_shown = false, orig = {}, } diff --git a/post_frame.lua b/post_frame.lua index e84df98..97cacd9 100644 --- a/post_frame.lua +++ b/post_frame.lua @@ -776,8 +776,8 @@ function private.refresh_entries() ignore_owner = true, queries = { query }, on_page_loaded = function(page, total_pages) - private.status_bar:update_status(100 * (page + 1) / total_pages, 0) -- TODO - private.status_bar:set_text(format('Scanning Page %d / %d', page + 1, total_pages)) + private.status_bar:update_status(100 * (page - 1) / total_pages, 0) -- TODO + private.status_bar:set_text(format('Scanning Page %d / %d', page, total_pages)) end, on_auction = function(auction_record) if auction_record.item_key == item_key then diff --git a/scan.lua b/scan.lua index 53a22ff..157e7bd 100644 --- a/scan.lua +++ b/scan.lua @@ -6,11 +6,11 @@ local PAGE_SIZE = 50 local state local threads = {} -function private.default_next_page(page, total_pages) +function private.last_page(total_count) + local total_pages = math.ceil(total_count / PAGE_SIZE) local last_page = max(total_pages - 1, 0) - if page < last_page then - return page + 1 - end + local last_page_limit = Aux.util.safe_index(private.current_query().blizzard_query, 'last_page') + return last_page_limit and min(last_page_limit, last_page) or last_page end function private.current_query() @@ -137,7 +137,7 @@ function private.scan() private.current_thread().query_index = private.current_thread().query_index and private.current_thread().query_index + 1 or 1 if private.current_query() then private.wait_for_callback(private.current_thread().params.on_start_query, private.current_thread().query_index, function() - private.current_thread().page = private.current_query().blizzard_query and private.current_query().blizzard_query.start_page or 0 + private.current_thread().page = Aux.util.safe_index(private.current_query().blizzard_query, 'first_page') or 0 return private.process_query() end) else @@ -153,22 +153,19 @@ function private.process_query() private.submit_query(function() - local count, _ = GetNumAuctionItems(private.current_thread().params.type) + local count, total_count = GetNumAuctionItems(private.current_thread().params.type) private.scan_auctions(count, function() private.wait_for_callback(private.current_thread().params.on_page_scanned, function() - if private.current_query().next_page then - private.current_thread().page = private.current_query().next_page(private.current_thread().page, private.current_thread().total_pages) - else - private.current_thread().page = private.default_next_page(private.current_thread().page, private.current_thread().total_pages) - end - if private.current_thread().page then + if private.current_query().blizzard_query and private.current_thread().page < private.last_page(total_count) then + private.current_thread().page = private.current_thread().page + 1 return private.process_query() else return private.scan() end + end) end) end) @@ -230,18 +227,15 @@ function private.submit_query(k) end private.wait_for_results(function() local _, total_count = GetNumAuctionItems(private.current_thread().params.type) - private.current_thread().total_pages = math.ceil(total_count / PAGE_SIZE) - if max(1, private.current_thread().total_pages) >= private.current_thread().page + 1 then - private.wait_for_callback(private.current_thread().params.on_page_loaded, private.current_thread().page, max(1, private.current_thread().total_pages), function() - return k() - end) - else - return k() - end + private.wait_for_callback( + private.current_thread().params.on_page_loaded, + private.current_thread().page - (private.current_query().blizzard_query.first_page or 0) + 1, + private.last_page(total_count) - (private.current_query().blizzard_query.first_page or 0) + 1, + k + ) end) end) else - private.current_thread().total_pages = 1 return k() end end diff --git a/scan_util.lua b/scan_util.lua index 6d9b245..ba19a1f 100644 --- a/scan_util.lua +++ b/scan_util.lua @@ -320,27 +320,32 @@ function m.find(auction_record, status_bar, on_abort, on_failure, on_success) local queries = {} tinsert(queries, {}) + if auction_record.blizzard_query then - local pages = auction_record.page > 0 and { auction_record.page - 1 } or {} - local blizzard_query = Aux.util.copy_table(auction_record.blizzard_query) - blizzard_query.start_page = auction_record.page + + local blizzard_query1 = Aux.util.copy_table(auction_record.blizzard_query) + blizzard_query1.first_page = auction_record.page + blizzard_query1.last_page = auction_record.page tinsert(queries, { - blizzard_query = blizzard_query, - next_page = function() - if getn(pages) == 1 then - status_bar:update_status(50, 50) - end - local page = pages[1] - tremove(pages, 1) - return page - end, + blizzard_query = blizzard_query1, }) - local item_query = m.item_query(auction_record.item_id, 0, true) + + if auction_record.page > 0 then + local blizzard_query2 = Aux.util.copy_table(auction_record.blizzard_query) + blizzard_query2.first_page = auction_record.page - 1 + blizzard_query2.last_page = auction_record.page - 1 + tinsert(queries, { + blizzard_query = blizzard_query1, + }) + end + + local item_query = m.item_query(auction_record.item_id, 0, 0) if not Aux.util.table_eq(auction_record.blizzard_query, item_query.blizzard_query) then tinsert(queries, item_query) end end + local found return Aux.scan.start{ type = auction_record.query_type, @@ -349,6 +354,9 @@ function m.find(auction_record, status_bar, on_abort, on_failure, on_success) status_bar:update_status(0, 0) status_bar:set_text('Searching auction...') end, + on_start_query = function(query_index) + status_bar:update_status((query_index - 1) / getn(queries) * 100, 0) + end, on_auction = function(auction_record, ctrl) if test(auction_record.index) then found = true @@ -390,14 +398,13 @@ function m.filter_builder() } end -function m.item_query(item_id, page, single_page) +function m.item_query(item_id, first_page, last_page) local item_info = Aux.info.item(item_id) if item_info then - local filter = m.filter_from_string(item_info.name..'/exact/@'..(page or 0)) + local filter = m.filter_from_string(item_info.name..'/exact/'..(first_page or '')..':'..(last_page or '')) return { - next_page = single_page and Aux.util.pass, validator = filter.validator, blizzard_query = filter.blizzard_query, } @@ -482,12 +489,14 @@ function m.filter_from_string(filter_term) return false, suggestions, error end end - elseif strfind(str, '@%d+') then - if not blizzard_filter.start_page then - blizzard_filter.start_page = tonumber(({strfind(str, '@(%d+)')})[3]) + elseif strfind(str, '^%d*:%d*$') then + if not blizzard_filter.first_page and not blizzard_filter.last_page then + local _, _, first_page, last_page = strfind(str, '^(%d*):(%d*)$') + blizzard_filter.first_page = tonumber(first_page) + blizzard_filter.last_page = tonumber(last_page) prettified:append(Aux.gui.inline_color({216, 225, 211, 1})..str..'|r') else - return false, {}, 'Erroneous start page modifier' + return false, {}, 'Erroneous page range modifier' end elseif tonumber(str) then if not blizzard_filter.min_level then @@ -672,7 +681,8 @@ function m.blizzard_query(filter) end return { - start_page = filter.start_page or 0, + first_page = filter.first_page and filter.first_page - 1, + last_page = filter.last_page and filter.last_page - 1, name = filter.name, min_level = item_info and item_info.level or filter.min_level, max_level = item_info and item_info.level or filter.max_level, diff --git a/search_frame.lua b/search_frame.lua index 796ccf3..7302a2c 100644 --- a/search_frame.lua +++ b/search_frame.lua @@ -857,9 +857,8 @@ function public.start_search(filter_string, resume) end, on_page_loaded = function(page, total_pages) current_page = page - local current_total_pages = total_pages - private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (current_page) / current_total_pages) - private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), current_page + 1, current_total_pages)) + private.status_bar:update_status(100 * (current_query - 1) / getn(queries), 100 * (page - 1) / total_pages) + private.status_bar:set_text(format('Scanning %d / %d (Page %d / %d)', current_query, getn(queries), page, total_pages)) end, on_page_scanned = function() private.results_listing:SetDatabase() @@ -900,7 +899,7 @@ function public.start_search(filter_string, resume) tremove(queries, 1) end if queries[1].blizzard_query then - queries[1].blizzard_query.start_page = (current_page and current_page + 1 or queries[1].start_page) + queries[1].blizzard_query.first_page = (current_page and (queries[1].blizzard_query.first_page or 0) + current_page or queries[1].blizzard_query.first_page) end aborted_search = queries end,