]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/mainmenu/dlg_contentstore.lua
Fix games not updating on deletion
[dragonfireclient.git] / builtin / mainmenu / dlg_contentstore.lua
index bab2c73f3c41ea1ec965dfd6a1fdf81c7e941ff6..a9a9363dce433dac5d0796ea0bbb3fa97794c90f 100644 (file)
 --with this program; if not, write to the Free Software Foundation, Inc.,
 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-local store = {}
+local store = { packages = {}, packages_full = {} }
 local package_dialog = {}
 
 -- Screenshot
-local screenshot_dir = os.tempfolder()
+local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb"
 assert(core.create_dir(screenshot_dir))
 local screenshot_downloading = {}
 local screenshot_downloaded = {}
@@ -76,10 +76,17 @@ local function start_install(calling_dialog, package)
                        if not path then
                                gamedata.errormessage = msg
                        else
+                               core.log("action", "Installed package to " .. path)
+
                                local conf_path
                                local name_is_title = false
                                if result.package.type == "mod" then
-                                       conf_path = path .. DIR_DELIM .. "mod.conf"
+                                       local actual_type = pkgmgr.get_folder_type(path)
+                                       if actual_type.type == "modpack" then
+                                               conf_path = path .. DIR_DELIM .. "modpack.conf"
+                                       else
+                                               conf_path = path .. DIR_DELIM .. "mod.conf"
+                                       end
                                elseif result.package.type == "game" then
                                        conf_path = path .. DIR_DELIM .. "game.conf"
                                        name_is_title = true
@@ -178,16 +185,7 @@ local function get_screenshot(package)
                if not success then
                        core.log("warning", "Screenshot download failed for some reason")
                end
-
-               local ele = ui.childlist.store
-               if ele and not ele.hidden then
-                       core.update_formspec(ele:formspec())
-               else
-                       ele = ui.childlist.package_view
-                       if ele and not ele.hidden then
-                               core.update_formspec(ele:formspec())
-                       end
-               end
+               ui.update()
        end
        if core.handle_async(download_screenshot,
                        { dest = filepath, url = package.thumbnail }, callback) then
@@ -222,6 +220,7 @@ function package_dialog.get_formspec()
                formspec[#formspec + 1] = fgettext("Install")
                formspec[#formspec + 1] = "]"
        elseif package.installed_release < package.release then
+               -- The install_ action also handles updating
                formspec[#formspec + 1] = "button[7,0;2,1;install;"
                formspec[#formspec + 1] = fgettext("Update")
                formspec[#formspec + 1] = "]"
@@ -237,7 +236,7 @@ function package_dialog.get_formspec()
        return table.concat(formspec, "")
 end
 
-function package_dialog.handle_submit(this, fields, tabname, tabdata)
+function package_dialog.handle_submit(this, fields)
        if fields.back then
                this:delete()
                return true
@@ -277,9 +276,14 @@ function store.load()
        local show_nonfree = core.settings:get_bool("show_nonfree_packages")
        local url = base_url ..
                "/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
-               core.get_max_supp_proto() ..
-               "&nonfree=" ..
-               (show_nonfree and "true" or "false")
+               core.get_max_supp_proto()
+
+       for _, item in pairs(core.settings:get("contentdb_flag_blacklist"):split(",")) do
+               item = item:trim()
+               if item ~= "" then
+                       url = url .. "&hide=" .. item
+               end
+       end
 
        core.download_file(url, target)
 
@@ -292,6 +296,8 @@ function store.load()
                        package.url = base_url .. "/packages/" ..
                                package.author .. "/" .. package.name ..
                                "/releases/" .. package.release .. "/download/"
+
+                       package.id = package.author .. "/" .. package.name
                end
 
                store.packages = store.packages_full
@@ -306,7 +312,7 @@ function store.update_paths()
        pkgmgr.refresh_globals()
        for _, mod in pairs(pkgmgr.global_mods:get_list()) do
                if mod.author then
-                       mod_hash[mod.name] = mod
+                       mod_hash[mod.author .. "/" .. mod.name] = mod
                end
        end
 
@@ -314,30 +320,30 @@ function store.update_paths()
        pkgmgr.update_gamelist()
        for _, game in pairs(pkgmgr.games) do
                if game.author then
-                       game_hash[game.id] = game
+                       game_hash[game.author .. "/" .. game.id] = game
                end
        end
 
        local txp_hash = {}
        for _, txp in pairs(pkgmgr.get_texture_packs()) do
                if txp.author then
-                       txp_hash[txp.name] = txp
+                       txp_hash[txp.author .. "/" .. txp.name] = txp
                end
        end
 
        for _, package in pairs(store.packages_full) do
                local content
                if package.type == "mod" then
-                       content = mod_hash[package.name]
+                       content = mod_hash[package.id]
                elseif package.type == "game" then
-                       content = game_hash[package.name]
+                       content = game_hash[package.id]
                elseif package.type == "txp" then
-                       content = txp_hash[package.name]
+                       content = txp_hash[package.id]
                end
 
-               if content and content.author == package.author then
+               if content then
                        package.path = content.path
-                       package.installed_release = content.release
+                       package.installed_release = content.release or 0
                else
                        package.path = nil
                end
@@ -380,13 +386,11 @@ function store.filter_packages(query)
 
 end
 
-function store.get_formspec()
-       assert(store.loaded)
-
+function store.get_formspec(dlgdata)
        store.update_paths()
 
-       local pages = math.ceil(#store.packages / num_per_page)
-       if cur_page > pages then
+       dlgdata.pagemax = math.max(math.ceil(#store.packages / num_per_page), 1)
+       if cur_page > dlgdata.pagemax then
                cur_page = 1
        end
 
@@ -415,16 +419,22 @@ function store.get_formspec()
                        "button[8.1,0;1,1;pback;<]",
                        "label[9.2,0.2;",
                        tonumber(cur_page), " / ",
-                       tonumber(pages), "]",
+                       tonumber(dlgdata.pagemax), "]",
                        "button[10.1,0;1,1;pnext;>]",
                        "button[11.1,0;1,1;pend;>>]",
                        "container_end[]",
                }
+
+               if #store.packages == 0 then
+                       formspec[#formspec + 1] = "label[4,3;"
+                       formspec[#formspec + 1] = fgettext("No results")
+                       formspec[#formspec + 1] = "]"
+               end
        else
                formspec = {
                        "size[12,7;true]",
                        "position[0.5,0.55]",
-                       "label[4,3;No packages could be retrieved]",
+                       "label[4,3;", fgettext("No packages could be retrieved"), "]",
                        "button[-0.1,",
                        num_per_page + 1.5,
                        ";3,1;back;",
@@ -432,12 +442,6 @@ function store.get_formspec()
                }
        end
 
-       if #store.packages == 0 then
-               formspec[#formspec + 1] = "label[4,3;"
-               formspec[#formspec + 1] = fgettext("No results")
-               formspec[#formspec + 1] = "]"
-       end
-
        local start_idx = (cur_page - 1) * num_per_page + 1
        for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
                local package = store.packages[i]
@@ -458,35 +462,43 @@ function store.get_formspec()
                formspec[#formspec + 1] = "]"
 
                -- description
-               formspec[#formspec + 1] = "textarea[1.25,0.3;7.5,1;;;"
+               if package.path and package.installed_release < package.release then
+                       formspec[#formspec + 1] = "textarea[1.25,0.3;7.5,1;;;"
+               else
+                       formspec[#formspec + 1] = "textarea[1.25,0.3;9,1;;;"
+               end
                formspec[#formspec + 1] = core.formspec_escape(package.short_description)
                formspec[#formspec + 1] = "]"
 
                -- buttons
                if not package.path then
-                       formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_"
+                       formspec[#formspec + 1] = "button[9.9,0;1.5,1;install_"
                        formspec[#formspec + 1] = tostring(i)
                        formspec[#formspec + 1] = ";"
                        formspec[#formspec + 1] = fgettext("Install")
                        formspec[#formspec + 1] = "]"
-               elseif package.installed_release < package.release then
-                       formspec[#formspec + 1] = "button[8.4,0;1.5,1;update_"
-                       formspec[#formspec + 1] = tostring(i)
-                       formspec[#formspec + 1] = ";"
-                       formspec[#formspec + 1] = fgettext("Update")
-                       formspec[#formspec + 1] = "]"
                else
-                       formspec[#formspec + 1] = "button[8.4,0;1.5,1;uninstall_"
+                       if package.installed_release < package.release then
+                               -- The install_ action also handles updating
+                               formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_"
+                               formspec[#formspec + 1] = tostring(i)
+                               formspec[#formspec + 1] = ";"
+                               formspec[#formspec + 1] = fgettext("Update")
+                               formspec[#formspec + 1] = "]"
+                       end
+
+                       formspec[#formspec + 1] = "button[9.9,0;1.5,1;uninstall_"
                        formspec[#formspec + 1] = tostring(i)
                        formspec[#formspec + 1] = ";"
                        formspec[#formspec + 1] = fgettext("Uninstall")
                        formspec[#formspec + 1] = "]"
                end
-               formspec[#formspec + 1] = "button[9.9,0;1.5,1;view_"
-               formspec[#formspec + 1] = tostring(i)
-               formspec[#formspec + 1] = ";"
-               formspec[#formspec + 1] = fgettext("View")
-               formspec[#formspec + 1] = "]"
+
+               --formspec[#formspec + 1] = "button[9.9,0;1.5,1;view_"
+               --formspec[#formspec + 1] = tostring(i)
+               --formspec[#formspec + 1] = ";"
+               --formspec[#formspec + 1] = fgettext("View")
+               --formspec[#formspec + 1] = "]"
 
                formspec[#formspec + 1] = "container_end[]"
        end
@@ -494,12 +506,11 @@ function store.get_formspec()
        return table.concat(formspec, "")
 end
 
-function store.handle_submit(this, fields, tabname, tabdata)
+function store.handle_submit(this, fields)
        if fields.search or fields.key_enter_field == "search_string" then
                search_string = fields.search_string:trim()
                cur_page = 1
                store.filter_packages(search_string)
-               core.update_formspec(store.get_formspec())
                return true
        end
 
@@ -510,34 +521,28 @@ function store.handle_submit(this, fields, tabname, tabdata)
 
        if fields.pstart then
                cur_page = 1
-               core.update_formspec(store.get_formspec())
                return true
        end
 
        if fields.pend then
-               cur_page = math.ceil(#store.packages / num_per_page)
-               core.update_formspec(store.get_formspec())
+               cur_page = this.data.pagemax
                return true
        end
 
        if fields.pnext then
                cur_page = cur_page + 1
-               local pages = math.ceil(#store.packages / num_per_page)
-               if cur_page > pages then
+               if cur_page > this.data.pagemax then
                        cur_page = 1
                end
-               core.update_formspec(store.get_formspec())
                return true
        end
 
        if fields.pback then
                if cur_page == 1 then
-                       local pages = math.ceil(#store.packages / num_per_page)
-                       cur_page = pages
+                       cur_page = this.data.pagemax
                else
                        cur_page = cur_page - 1
                end
-               core.update_formspec(store.get_formspec())
                return true
        end