@ -10,6 +10,7 @@ using System.IO;
using System.IO.Compression ;
using System.IO.Compression ;
using System.Linq ;
using System.Linq ;
using System.Net ;
using System.Net ;
using System.Reflection ;
using System.Text.RegularExpressions ;
using System.Text.RegularExpressions ;
using System.Threading ;
using System.Threading ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
@ -816,20 +817,33 @@ public partial class MainForm : Form
} ) ;
} ) ;
}
}
string desktopFolder = Environment . GetFolderPath ( Environment . SpecialFolder . Desktop , Environment . SpecialFolderOption . Create ) ;
string shortcutFile = "" ;
try
try
{
{
string desktopFolder = Environment . GetFolderPath ( Environment . SpecialFolder . Desktop , Environment . SpecialFolderOption . Create ) ;
string shortcutFile ;
string shortcutText ;
if ( OS . IsWindows )
if ( OS . IsWindows )
{
{
//TODO: implement this
shortcutFile = $"{desktopFolder}/{profile.Name}.url" ;
const string shortcutTemplate =
"[InternetShortcut]\n" +
"IDList=\n" +
"IconIndex=0\n" +
"URL=EXECUTABLE\n" +
"IconFile=ICONPATH" ;
shortcutText = shortcutTemplate ;
// When providing an exe, Windows uses its icon.
// And for the URL, we just use the file:// protocol
shortcutText = shortcutText . Replace ( "ICONPATH" , $"{Core.ProfilesPath}/{profile.Name}/AM2R.exe" ) ;
shortcutText = shortcutText . Replace ( "EXECUTABLE" , new Uri ( $"{Core.ProfilesPath}/{profile.Name}" , UriKind . Absolute ) . AbsoluteUri ) ;
}
}
else if ( OS . IsLinux )
else if ( OS . IsLinux )
{
{
shortcutFile = $"{desktopFolder}/{profile.Name}.desktop" ;
shortcutFile = $"{desktopFolder}/{profile.Name}.desktop" ;
const string desktopEntryTemplate =
const string shortcut Template =
"[Desktop Entry]\n" +
"[Desktop Entry]\n" +
"Type=Application\n" +
"Type=Application\n" +
"Categories=Game\n" +
"Categories=Game\n" +
@ -840,12 +854,12 @@ public partial class MainForm : Form
"Icon=ICONPATH\n" +
"Icon=ICONPATH\n" +
"Terminal=false" ;
"Terminal=false" ;
string desktopEntryText = desktopEntry Template;
shortcutText = shortcut Template;
// Replace values
// Replace values
desktopEntryText = desktopEntry Text. Replace ( "PROFILENAME" , $"{profile.Name}" ) ;
shortcutText = shortcut Text. Replace ( "PROFILENAME" , $"{profile.Name}" ) ;
desktopEntryText = desktopEntry Text. Replace ( "PROFILEDESCRIPTION" , $"A shortcut for {profile.Name}." ) ;
shortcutText = shortcut Text. Replace ( "PROFILEDESCRIPTION" , $"A shortcut for {profile.Name}." ) ;
desktopEntryText = desktopEntry Text. Replace ( "ICONPATH" , $"{Core.PatchDataPath}/data/files_to_copy/icon.png" ) ;
shortcutText = shortcut Text. Replace ( "ICONPATH" , $"{Core.PatchDataPath}/data/files_to_copy/icon.png" ) ;
string gameName ;
string gameName ;
#if NOAPPIMAGE
#if NOAPPIMAGE
@ -855,12 +869,9 @@ public partial class MainForm : Form
# endif
# endif
log . Info ( $"Game name for shortcut is: {gameName}" ) ;
log . Info ( $"Game name for shortcut is: {gameName}" ) ;
if ( OS . IsThisRunningFromFlatpak )
if ( OS . IsThisRunningFromFlatpak )
desktopEntryText = desktopEntry Text. Replace ( "EXECUTABLE" , $"flatpak run \" - - command = { Core . ProfilesPath } / { profile . Name } / { gameName } \ " io.github.am2r_community_developers.AM2RLauncher" ) ;
shortcutText = shortcut Text. Replace ( "EXECUTABLE" , $"flatpak run \" - - command = { Core . ProfilesPath } / { profile . Name } / { gameName } \ " io.github.am2r_community_developers.AM2RLauncher" ) ;
else
else
desktopEntryText = desktopEntryText . Replace ( "EXECUTABLE" , $"{Core.ProfilesPath}/{profile.Name}/{gameName}" ) ;
shortcutText = shortcutText . Replace ( "EXECUTABLE" , $"{Core.ProfilesPath}/{profile.Name}/{gameName}" ) ;
File . WriteAllText ( shortcutFile , desktopEntryText ) ;
Process . Start ( "chmod" , $"+x \" { shortcutFile } \ "" ) ? . WaitForExit ( ) ;
}
}
else if ( OS . IsMac )
else if ( OS . IsMac )
{
{
@ -871,7 +882,8 @@ public partial class MainForm : Form
log . Error ( $"{OS.Name} has no way of creating shortcuts" ) ;
log . Error ( $"{OS.Name} has no way of creating shortcuts" ) ;
return ;
return ;
}
}
File . WriteAllText ( shortcutFile , shortcutText ) ;
if ( OS . IsUnix ) Process . Start ( "chmod" , $"+x \" { shortcutFile } \ "" ) ? . WaitForExit ( ) ;
CrossPlatformOperations . OpenFolderAndSelectFile ( shortcutFile ) ;
CrossPlatformOperations . OpenFolderAndSelectFile ( shortcutFile ) ;
}
}
// We only care about io exceptions (file not readable, drive not available etc.) The rest should throw normally
// We only care about io exceptions (file not readable, drive not available etc.) The rest should throw normally