Add Desktop Link for Windows: .bat file
This commit is contained in:
parent
b51b42825e
commit
b13cbe24de
|
@ -76,7 +76,7 @@ class DownloadTab(QWidget):
|
||||||
self.update_layout.addWidget(widget)
|
self.update_layout.addWidget(widget)
|
||||||
widget.update.connect(self.update_game)
|
widget.update.connect(self.update_game)
|
||||||
if QSettings().value("auto_update", False, bool):
|
if QSettings().value("auto_update", False, bool):
|
||||||
self.update_game(igame.app_name)
|
self.update_game(igame.app_name, True)
|
||||||
|
|
||||||
self.updates.setLayout(self.update_layout)
|
self.updates.setLayout(self.update_layout)
|
||||||
self.layout.addWidget(self.updates)
|
self.layout.addWidget(self.updates)
|
||||||
|
@ -264,9 +264,13 @@ class DownloadTab(QWidget):
|
||||||
def get_time(self, seconds: int) -> str:
|
def get_time(self, seconds: int) -> str:
|
||||||
return str(datetime.timedelta(seconds=seconds))
|
return str(datetime.timedelta(seconds=seconds))
|
||||||
|
|
||||||
def update_game(self, app_name: str):
|
def update_game(self, app_name: str, auto=False):
|
||||||
logger.info("Update " + app_name)
|
logger.info("Update " + app_name)
|
||||||
infos = InstallDialog(app_name, self.core, True).get_information()
|
if not auto:
|
||||||
|
infos = InstallDialog(app_name, self.core, True).get_information()
|
||||||
|
else:
|
||||||
|
self.install_game(InstallOptions(app_name=app_name), True)
|
||||||
|
return
|
||||||
if infos != 0:
|
if infos != 0:
|
||||||
path, max_workers, force, ignore_free_space = infos
|
path, max_workers, force, ignore_free_space = infos
|
||||||
self.install_game(InstallOptions(app_name=app_name, max_workers=max_workers, path=path,
|
self.install_game(InstallOptions(app_name=app_name, max_workers=max_workers, path=path,
|
||||||
|
|
|
@ -48,7 +48,6 @@ class GameInfo(QScrollArea):
|
||||||
verify_game = pyqtSignal(str)
|
verify_game = pyqtSignal(str)
|
||||||
verify_threads = {}
|
verify_threads = {}
|
||||||
action = pyqtSignal(str)
|
action = pyqtSignal(str)
|
||||||
desktop_exists = False
|
|
||||||
|
|
||||||
def __init__(self, core: LegendaryCore):
|
def __init__(self, core: LegendaryCore):
|
||||||
super(GameInfo, self).__init__()
|
super(GameInfo, self).__init__()
|
||||||
|
@ -87,10 +86,6 @@ class GameInfo(QScrollArea):
|
||||||
self.install_path.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
self.install_path.setTextInteractionFlags(Qt.TextSelectableByMouse)
|
||||||
right_layout.addWidget(self.install_path)
|
right_layout.addWidget(self.install_path)
|
||||||
|
|
||||||
self.create_desktop_link_button = QPushButton(self.tr("Create Desktop link"))
|
|
||||||
right_layout.addWidget(self.create_desktop_link_button)
|
|
||||||
self.create_desktop_link_button.clicked.connect(self.create_desktop_link)
|
|
||||||
|
|
||||||
top_layout.addLayout(right_layout)
|
top_layout.addLayout(right_layout)
|
||||||
top_layout.addStretch()
|
top_layout.addStretch()
|
||||||
self.game_actions = GameActions()
|
self.game_actions = GameActions()
|
||||||
|
@ -105,19 +100,6 @@ class GameInfo(QScrollArea):
|
||||||
self.widget.setLayout(self.layout)
|
self.widget.setLayout(self.layout)
|
||||||
self.setWidget(self.widget)
|
self.setWidget(self.widget)
|
||||||
|
|
||||||
def create_desktop_link(self):
|
|
||||||
if not self.desktop_exists:
|
|
||||||
create_desktop_link(self.igame.app_name, self.core)
|
|
||||||
self.create_desktop_link_button.setText(self.tr("Remove Desktop link"))
|
|
||||||
self.desktop_exists = True
|
|
||||||
else:
|
|
||||||
if os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.desktop")):
|
|
||||||
os.remove(os.path.expanduser(f"~/Desktop/{self.igame.title}.desktop"))
|
|
||||||
elif os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.lnk")):
|
|
||||||
os.remove(os.path.expanduser(f"~/Desktop/{self.igame.title}.lnk"))
|
|
||||||
self.desktop_exists = False
|
|
||||||
self.create_desktop_link_button.setText(self.tr("Create Desktop link"))
|
|
||||||
|
|
||||||
def repair(self):
|
def repair(self):
|
||||||
repair_file = os.path.join(self.core.lgd.get_tmp_path(), f'{self.game.app_name}.repair')
|
repair_file = os.path.join(self.core.lgd.get_tmp_path(), f'{self.game.app_name}.repair')
|
||||||
if not os.path.exists(repair_file):
|
if not os.path.exists(repair_file):
|
||||||
|
@ -186,13 +168,6 @@ class GameInfo(QScrollArea):
|
||||||
self.game_actions.verify_widget.setCurrentIndex(1)
|
self.game_actions.verify_widget.setCurrentIndex(1)
|
||||||
self.game_actions.verify_progress_bar.setValue(
|
self.game_actions.verify_progress_bar.setValue(
|
||||||
self.verify_threads[app_name].num / self.verify_threads[app_name].total * 100)
|
self.verify_threads[app_name].num / self.verify_threads[app_name].total * 100)
|
||||||
if os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.desktop")) \
|
|
||||||
or os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.lnk")):
|
|
||||||
self.create_desktop_link_button.setText(self.tr("Remove Desktop link"))
|
|
||||||
self.desktop_exists = True
|
|
||||||
else:
|
|
||||||
self.create_desktop_link_button.setText(self.tr("Create Desktop link"))
|
|
||||||
self.desktop_exists = False
|
|
||||||
|
|
||||||
|
|
||||||
class GameActions(QGroupBox):
|
class GameActions(QGroupBox):
|
||||||
|
|
|
@ -104,7 +104,7 @@ class GameSettings(QScrollArea):
|
||||||
if self.game.app_name in self.core.lgd.config.sections() and self.core.lgd.config.get(
|
if self.game.app_name in self.core.lgd.config.sections() and self.core.lgd.config.get(
|
||||||
f"{self.game.app_name}", option, fallback="") != "":
|
f"{self.game.app_name}", option, fallback="") != "":
|
||||||
self.core.lgd.config.remove_option(self.game.app_name, option)
|
self.core.lgd.config.remove_option(self.game.app_name, option)
|
||||||
if self.core.lgd.config[self.game.app_name] == {}:
|
if not self.core.lgd.config.get(self.game.app_name):
|
||||||
self.core.lgd.config.remove_section(self.game.app_name)
|
self.core.lgd.config.remove_section(self.game.app_name)
|
||||||
self.core.lgd.save_config()
|
self.core.lgd.save_config()
|
||||||
|
|
||||||
|
|
|
@ -35,16 +35,17 @@ class BaseInstalledWidget(QGroupBox):
|
||||||
launch = QAction(self.tr("Launch"), self)
|
launch = QAction(self.tr("Launch"), self)
|
||||||
launch.triggered.connect(self.launch)
|
launch.triggered.connect(self.launch)
|
||||||
self.addAction(launch)
|
self.addAction(launch)
|
||||||
|
|
||||||
|
if os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.desktop"))\
|
||||||
|
or os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.lnk")):
|
||||||
|
self.create_desktop = QAction(self.tr("Remove Desktop link"))
|
||||||
|
else:
|
||||||
|
self.create_desktop = QAction(self.tr("Create Desktop link"))
|
||||||
|
|
||||||
|
self.create_desktop.triggered.connect(lambda: self.create_desktop_link("desktop"))
|
||||||
|
self.addAction(self.create_desktop)
|
||||||
|
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
if os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.desktop"))\
|
|
||||||
or os.path.exists(os.path.expanduser(f"~/Desktop/{self.igame.title}.lnk")):
|
|
||||||
self.create_desktop = QAction(self.tr("Remove Desktop link"))
|
|
||||||
else:
|
|
||||||
self.create_desktop = QAction(self.tr("Create Desktop link"))
|
|
||||||
|
|
||||||
self.create_desktop.triggered.connect(lambda: self.create_desktop_link("desktop"))
|
|
||||||
self.addAction(self.create_desktop)
|
|
||||||
|
|
||||||
if os.path.exists(os.path.expanduser(f"~/.local/share/applications/{self.igame.title}.desktop")):
|
if os.path.exists(os.path.expanduser(f"~/.local/share/applications/{self.igame.title}.desktop")):
|
||||||
self.create_start_menu = QAction(self.tr("Remove start menu link"))
|
self.create_start_menu = QAction(self.tr("Remove start menu link"))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -137,7 +137,14 @@ def get_size(b: int) -> str:
|
||||||
|
|
||||||
def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
|
def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
|
||||||
igame = core.get_installed_game(app_name)
|
igame = core.get_installed_game(app_name)
|
||||||
|
if os.path.exists(
|
||||||
|
os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
||||||
|
igame.app_name, 'Thumbnail.png')):
|
||||||
|
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
||||||
|
igame.app_name, 'Thumbnail.png')
|
||||||
|
else:
|
||||||
|
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str),
|
||||||
|
igame.app_name, 'DieselGameBoxTall.png')
|
||||||
# Linux
|
# Linux
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
if type_of_link == "desktop":
|
if type_of_link == "desktop":
|
||||||
|
@ -147,10 +154,6 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.path.exists(os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str), igame.app_name, 'Thumbnail.png')):
|
|
||||||
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str), igame.app_name, 'Thumbnail.png')
|
|
||||||
else:
|
|
||||||
icon = os.path.join(QSettings('Rare', 'Rare').value('img_dir', os.path.expanduser('~/.cache/rare/images'), str), igame.app_name, 'DieselGameBoxTall.png')
|
|
||||||
with open(f"{path}{igame.title}.desktop", "w") as desktop_file:
|
with open(f"{path}{igame.title}.desktop", "w") as desktop_file:
|
||||||
desktop_file.write("[Desktop Entry]\n"
|
desktop_file.write("[Desktop Entry]\n"
|
||||||
f"Name={igame.title}\n"
|
f"Name={igame.title}\n"
|
||||||
|
@ -161,5 +164,15 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
|
||||||
"StartupWMClass=rare-game\n"
|
"StartupWMClass=rare-game\n"
|
||||||
)
|
)
|
||||||
os.chmod(os.path.expanduser(f"~/Desktop/{igame.title}.desktop"), 0o755)
|
os.chmod(os.path.expanduser(f"~/Desktop/{igame.title}.desktop"), 0o755)
|
||||||
|
|
||||||
|
# Windows
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
logger.info("Create a shortcut is currently not supported on windows")
|
if type_of_link == "desktop":
|
||||||
|
path = os.path.expanduser(f"~/Desktop/")
|
||||||
|
elif type_of_link == "start_menu":
|
||||||
|
logger.info("Startmenu link is not supported on windows")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
with open(path+igame.title+".bat", "w") as desktop_file:
|
||||||
|
desktop_file.write(f"rare launch {app_name}")
|
Loading…
Reference in a new issue