我正在编写一个处理SQLite3数据库的Python程序。我使用cx_Freeze将其作为MSI设置文件。
由cx_Freeze生成的。msi设置文件生成的Windows快捷方式不提供快捷方式的工作目录属性。因此,当我使用在桌面上创建的快捷方式运行可执行文件时,它正在桌面上创建数据库文件。
可以通过为快捷方式提供不同的工作目录来更改。我怎么做呢?
我能够通过对cx_Freeze/windist.py做一个小的改变来解决这个问题。在第61行add_config()中,我更改了:
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)])
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.
谢谢每一个人。
在另一个问题的答案中找到了答案。实际上,需要设置快捷表数据。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",
)
]
)