Last active
June 7, 2019 19:52
-
-
Save iuridiniz/85403545d0fd7e4a0000 to your computer and use it in GitHub Desktop.
Fix Wine Desktop entry for unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Requisites: | |
# Python 2.7 | |
# pyxdg | |
# pylnk | |
# | |
# Quick install all the requisites: | |
# $ sudo pip install pylnk pyxdg | |
# | |
# Quick use: | |
# $ python fix-wine-desktop-entry.py FILE.desktop | |
# | |
# Quick fix all .desktop entries of a wine default installation: | |
# $ find ~/.local/share/applications/wine -name "*.desktop" -exec python fix-wine-desktop-entry.py {} \; | |
import sys | |
from xdg.DesktopEntry import DesktopEntry | |
from pylnk import parse as lnk_parse | |
# we expect a .desktop file as first argument | |
if len(sys.argv) < 2: | |
print >>sys.stderr, "%s <program.desktop>" % (sys.argv[0], ) | |
sys.exit(1) | |
desktop_path = sys.argv[1] | |
# open desktopEntry | |
d = DesktopEntry(desktop_path) | |
# exit if already have StartupWMClass | |
if d.hasKey('StartupWMClass'): | |
print >>sys.stderr, "%s already has 'StartupWMClass'" % (desktop_path,) | |
sys.exit(1) | |
# make sure that passed desktop file is a valid wine.desktop file | |
exec_info = d.getExec() | |
if (not "wine" in exec_info or | |
not "/Unix " in exec_info or | |
not "start.exe" in exec_info): | |
print >>sys.stderr, "%s does not seem a wine desktop file" % ( | |
desktop_path,) | |
sys.exit(1) | |
# let's descovery path to lnk | |
lnk_path = exec_info.split("/Unix ")[-1].replace('\\','') | |
# open the lnk | |
l = lnk_parse(lnk_path) | |
# let's discovery .exe program | |
app_exe = l.path.split("\\")[-1] | |
# make a backup before | |
d.write(desktop_path + "~") | |
# setup correct StartupWMClass entry | |
d.set("StartupWMClass", app_exe) | |
# so write | |
d.write(desktop_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Requisites: | |
# Python 2.7 | |
# pyxdg | |
# | |
# Quick install all the requisites: | |
# $ sudo pip install pyxdg | |
# | |
# Quick use: | |
# $ python fix-wine-msoffice.py FILE.desktop | |
# | |
# Quick fix all .desktop entries of a wine default installation: | |
# $ find ~/.local/share/applications -name "*.desktop" -exec python fix-wine-msoffice.py {} \; | |
# | |
# UNDO previous command with: | |
# $ find ~/.local/share/applications -name '*.desktop~' -print0 | xargs -0 rename -f 's/~$//' | |
# | |
# How to install office 2007: https://wiki.archlinux.org/index.php/Microsoft_Office_2007 | |
# 1. setup a win32 env | |
# 2. install msxml3 | |
# 3. install office 2007 | |
# 4. install service pack | |
# 5. use this fix. | |
import sys | |
from xdg.DesktopEntry import DesktopEntry | |
# we expect a .desktop file as first argument | |
if len(sys.argv) < 2: | |
print >>sys.stderr, "%s <program.desktop>" % (sys.argv[0], ) | |
sys.exit(1) | |
desktop_path = sys.argv[1] | |
# open desktopEntry | |
d = DesktopEntry(desktop_path) | |
# make sure that desktop file is a valid wine.desktop file | |
exec_info = d.getExec() | |
if not "WINEPREFIX" in exec_info: | |
print >>sys.stderr, "%r does not seem a wine desktop file" % ( | |
desktop_path,) | |
sys.exit(1) | |
# make sure that desktop file is from office | |
if not "Microsoft Office" in d.getName(): | |
print >>sys.stderr, "%r does not seem from Microsoft Office" % ( | |
desktop_path,) | |
sys.exit(1) | |
# exit if already have XMODIFIERS | |
if "XMODIFIERS" in exec_info: | |
print >>sys.stderr, "%r seems patched with XMODIFIERS" % (desktop_path,) | |
sys.exit(1) | |
# exit if already have WINEDLLOVERRIDES | |
if "WINEDLLOVERRIDES" in exec_info: | |
print >>sys.stderr, "%r seems patched with WINEDLLOVERRIDES" % (desktop_path,) | |
sys.exit(1) | |
# let's inject XMODIFIERS before WINEPREFIX | |
pos = exec_info.index('WINEPREFIX') | |
before_wineprefix, rest = exec_info[:pos], exec_info[pos:] | |
patch = "WINEDLLOVERRIDES='riched20=n' XMODIFIERS=''" | |
exec_info = "%s %s %s" % (before_wineprefix, patch, rest) | |
# make a backup before | |
d.write(desktop_path + "~") | |
# new exec info | |
d.set("Exec",exec_info) | |
# so write | |
print >>sys.stderr, "%r was PATCHED" % (desktop_path,) | |
d.write(desktop_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#! Fix "open with" with multiple duplicated names on nautilus | |
find ~/.local/share/applications -name 'wine-extension-*.desktop' | while read f; do | |
perl -i~ -lpe 's/^\s*(Name=Microsoft Office (Excel|Word|PowerPoint|OneNote|Groove|PowerPoint Viewer))\s*$/$1 ('$(basename "$f" .desktop | cut -d'-' -f 3)')/' "$f"; | |
done | |
update-mime-database ~/.local/share/mime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pylnk | |
pyxdg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment