Skip to content

Commit

Permalink
Desktop menu item fixes: format command line string to insert Destina…
Browse files Browse the repository at this point in the history
…tion dir,

 don't dereference a nil value in revert if fatal() happens before destination
 is set.
  • Loading branch information
icculus committed Feb 15, 2008
1 parent ffa79cc commit 91b6b58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
5 changes: 4 additions & 1 deletion docs.txt
Expand Up @@ -760,7 +760,10 @@ Here are the elements, and the attributes they can possess.
commandline (no default, mustExist, mustBeString, cantBeEmpty)

This is the command line that will be used to launch the application
when the end user clicks on the desktop menu item.
when the end user clicks on the desktop menu item. The string "%0" is
replaced with the install destination, so if you need an absolute path
to mygame.exe, and the user is installing to /home/user/mygame, you should
specify "%0/mygame.exe" to get "/home/user/mygame/mygame.exe".

category (no default, mustExist, mustBeStringOrTableOfStrings)

Expand Down
2 changes: 1 addition & 1 deletion examples/duke3d/scripts/config.lua
Expand Up @@ -78,7 +78,7 @@ Setup.Package
tooltip = "Always bet on Duke!",
builtin_icon = false,
icon = "duke3d.png", -- relative to the dest; you must install it!
commandline = "/home/icculus/duke3d/duke3d",
commandline = "%0/duke3d",
category = "Game",
},

Expand Down
27 changes: 19 additions & 8 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -1017,12 +1017,15 @@ end

local function install_freedesktop_menuitem(pkg, idx, item) -- only for Unix.
local icon
local dest = MojoSetup.destination
if item.builtin_icon then
icon = item.icon
else
icon = MojoSetup.destination .. "/" .. item.icon
icon = dest .. "/" .. item.icon
end

local cmdline = MojoSetup.format(item.commandline, dest)

local str = "[Desktop Entry]\n" ..
"Encoding=UTF-8\n" ..
"Value=1.0\n" ..
Expand All @@ -1031,7 +1034,7 @@ local function install_freedesktop_menuitem(pkg, idx, item) -- only for Unix.
"GenericName=" .. item.genericname .. "\n" ..
"Comment=" .. item.tooltip .. "\n" ..
"Icon=" .. icon .. "\n" ..
"Exec=" .. item.commandline .. "\n" ..
"Exec=" .. cmdline .. "\n" ..
"Categories=" .. flatten_list(item.category) .. "\n"

if item.mimetype ~= nil then
Expand All @@ -1040,16 +1043,16 @@ local function install_freedesktop_menuitem(pkg, idx, item) -- only for Unix.

str = str .. "\n"

local dest = freedesktop_menuitem_filename(pkg, idx)
local fname = freedesktop_menuitem_filename(pkg, idx)
local perms = "0644" -- !!! FIXME
local key = MojoSetup.metadatakey
local desc = MojoSetup.metadatadesc

--MojoSetup.logdebug("Install FreeDesktop file")
--MojoSetup.logdebug(dest)
--MojoSetup.logdebug(fname)
--MojoSetup.logdebug(str)
install_file_from_string(dest, str, perms, desc, key)
if not MojoSetup.platform.installdesktopmenuitem(dest) then
install_file_from_string(fname, str, perms, desc, key)
if not MojoSetup.platform.installdesktopmenuitem(fname) then
MojoSetup.fatal(_("Failed to install desktop menu item"))
end
end
Expand Down Expand Up @@ -1101,6 +1104,7 @@ local function do_install(install)
MojoSetup.downloaded = 0
MojoSetup.totaldownload = 0
MojoSetup.install = install
MojoSetup.installed_menu_items = false

-- !!! FIXME: try to sanity check everything we can here
-- !!! FIXME: (unsupported URLs, bogus media IDs, etc.)
Expand Down Expand Up @@ -1518,7 +1522,10 @@ local function do_install(install)
end
end

install_desktop_menu_items(install)
if install.desktopmenuitems ~= nil then
install_desktop_menu_items(install)
MojoSetup.installed_menu_items = true
end

if install.support_uninstall then
if MojoSetup.info.platform == "windows" then
Expand Down Expand Up @@ -1602,6 +1609,7 @@ local function do_install(install)
MojoSetup.downloaddir = nil
MojoSetup.install = nil
MojoSetup.forceoverwrite = nil
MojoSetup.installed_menu_items = nil
MojoSetup.stages = nil
MojoSetup.files = nil
MojoSetup.media = nil
Expand All @@ -1620,7 +1628,10 @@ local function real_revertinstall()
MojoSetup.loginfo("Cleaning up half-finished installation...")

-- !!! FIXME: callbacks here.
uninstall_desktop_menu_items(MojoSetup.install)
if MojoSetup.installed_menu_items then
uninstall_desktop_menu_items(MojoSetup.install)
end

delete_files(MojoSetup.downloads)
delete_files(flatten_manifest(MojoSetup.manifest, prepend_dest_dir))
do_rollbacks()
Expand Down

0 comments on commit 91b6b58

Please sign in to comment.