如何在cx_freeze msi捆绑包中设置快捷方式的工作目录?

3
我正在开发一个处理SQLite3数据库的Python程序。我使用cx_Freeze将其制作成了MSI安装文件。
由于cx_Freeze生成的.msi安装文件不提供快捷方式的工作目录属性,因此,当我使用桌面上创建的快捷方式运行可执行文件时,它会在桌面上创建数据库文件。
为了解决这个问题,需要为快捷方式提供不同的工作目录。如何实现呢?
2个回答

7
我能够通过对cx_Freeze/windist.py进行小改动来解决问题。在add_config()函数的第61行,我做了如下修改:
msilib.add_data(self.db, "Shortcut",
        [("S_APP_%s" % index, executable.shortcutDir,
                executable.shortcutName, "TARGETDIR",
                "[TARGETDIR]%s" % baseName, None, None, None,
                None, None, None, None)])

to

msilib.add_data(self.db, "Shortcut",
        [("S_APP_%s" % index, executable.shortcutDir,
                executable.shortcutName, "TARGETDIR",
                "[TARGETDIR]%s" % baseName, None, None, None,
                None, None, None, "TARGETDIR")]) # <--- Working directory.

感谢大家。

1

另一个问题的答案中找到了解决方案。 基本上,需要设置快捷方式表数据。下面shortcut_table中的最后一个'TARGETDIR'设置工作目录为安装目录。

---从上述答案中复制---

from cx_Freeze import *

# http://msdn.microsoft.com/en-us/library/windows/desktop/aa371847(v=vs.85).aspx
shortcut_table = [
    ("DesktopShortcut",        # Shortcut
     "DesktopFolder",          # Directory_
     "DTI Playlist",           # Name
     "TARGETDIR",              # Component_
     "[TARGETDIR]playlist.exe",# Target
     None,                     # Arguments
     None,                     # Description
     None,                     # Hotkey
     None,                     # Icon
     None,                     # IconIndex
     None,                     # ShowCmd
     'TARGETDIR'               # WkDir
     )
    ]

# Now create the table dictionary
msi_data = {"Shortcut": shortcut_table}

# Change some default MSI options and specify the use of the above defined tables
bdist_msi_options = {'data': msi_data}

setup(
    options = {
        "bdist_msi": bdist_msi_options,
    },
    executables = [
        Executable(
            "MyApp.py",
            )
        ]
    ) 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接