Skip to content

Commit d8c6620

Browse files
committed
Improve: Ensure shortcut directories exist in Linux installer.
1 parent 8f04d59 commit d8c6620

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

source/Reloaded.Mod.Installer.Lib/MainWindowViewModel.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ [Desktop Entry]
169169

170170
try
171171
{
172-
File.WriteAllText(shortcutPath, desktopFile);
172+
WriteTextWithDirectory(shortcutPath, desktopFile);
173173

174174
// Write `.desktop` file that integrates into shell.
175175
var shellShortcutPath = $@"Z:/home/{userName}/.local/share/applications/{SanitizeFileName(Path.GetFileName(shortcutPath))}";
176-
File.WriteAllText(shellShortcutPath, desktopFile);
176+
WriteTextWithDirectory(shellShortcutPath, desktopFile);
177177

178178
// Mark as executable.
179179
LinuxTryMarkAsExecutable(shortcutPath);
@@ -192,6 +192,14 @@ void ThrowFailedToCreateShortcut(Exception e)
192192
throw new Exception("Failed to create Reloaded shortcut.\n" +
193193
"If you have `protontricks` installed via `flatpak`, you may need to give it FileSystem permission `flatpak override --user --filesystem=host com.github.Matoking.protontricks`", e);
194194
}
195+
196+
static void WriteTextWithDirectory(string path, string content)
197+
{
198+
var directory = Path.GetDirectoryName(path);
199+
if (!string.IsNullOrEmpty(directory))
200+
Directory.CreateDirectory(directory);
201+
File.WriteAllText(path, content);
202+
}
195203
}
196204

197205
private static void LinuxTryMarkAsExecutable(string windowsPath)

0 commit comments

Comments
 (0)