1
0
Fork 0
mirror of synced 2024-06-26 10:11:19 +12:00

Add Desktop Link for Windows: .bat file

This commit is contained in:
Dummerle 2021-04-13 19:08:49 +02:00
parent b51b42825e
commit b13cbe24de
5 changed files with 37 additions and 44 deletions

View file

@ -76,7 +76,7 @@ class DownloadTab(QWidget):
self.update_layout.addWidget(widget)
widget.update.connect(self.update_game)
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.layout.addWidget(self.updates)
@ -264,9 +264,13 @@ class DownloadTab(QWidget):
def get_time(self, seconds: int) -> str:
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)
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:
path, max_workers, force, ignore_free_space = infos
self.install_game(InstallOptions(app_name=app_name, max_workers=max_workers, path=path,

View file

@ -48,7 +48,6 @@ class GameInfo(QScrollArea):
verify_game = pyqtSignal(str)
verify_threads = {}
action = pyqtSignal(str)
desktop_exists = False
def __init__(self, core: LegendaryCore):
super(GameInfo, self).__init__()
@ -87,10 +86,6 @@ class GameInfo(QScrollArea):
self.install_path.setTextInteractionFlags(Qt.TextSelectableByMouse)
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.addStretch()
self.game_actions = GameActions()
@ -105,19 +100,6 @@ class GameInfo(QScrollArea):
self.widget.setLayout(self.layout)
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):
repair_file = os.path.join(self.core.lgd.get_tmp_path(), f'{self.game.app_name}.repair')
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_progress_bar.setValue(
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):

View file

@ -104,7 +104,7 @@ class GameSettings(QScrollArea):
if self.game.app_name in self.core.lgd.config.sections() and self.core.lgd.config.get(
f"{self.game.app_name}", option, fallback="") != "":
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.save_config()

View file

@ -35,16 +35,17 @@ class BaseInstalledWidget(QGroupBox):
launch = QAction(self.tr("Launch"), self)
launch.triggered.connect(self.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.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")):
self.create_start_menu = QAction(self.tr("Remove start menu link"))
else:

View file

@ -137,7 +137,14 @@ def get_size(b: int) -> str:
def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
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
if os.name == "posix":
if type_of_link == "desktop":
@ -147,10 +154,6 @@ def create_desktop_link(app_name, core: LegendaryCore, type_of_link="desktop"):
else:
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:
desktop_file.write("[Desktop Entry]\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"
)
os.chmod(os.path.expanduser(f"~/Desktop/{igame.title}.desktop"), 0o755)
# Windows
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}")