Skip to content

Commit 0761d8c

Browse files
authored
Make desktop shortcut filename valid (#844)
Replace all unavailable characters with _
1 parent 07bfdcc commit 0761d8c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Ui/Service/AppStartupHelper.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ private static void ProcessArg(HashSet<string> args)
260260
public static string? MakeIcon(string name, Bitmap? bitmap)
261261
{
262262
if (bitmap == null) return null;
263+
MakeFilenameValid(ref name);
263264
string? iconPath = null;
264265
iconPath = System.IO.Path.Combine(AppPathHelper.Instance.LocalityIconDirPath, $"{name}.ico");
265266
Executor.TryCatch(() =>
@@ -276,6 +277,19 @@ private static void ProcessArg(HashSet<string> args)
276277
return null;
277278
}
278279

280+
private static void MakeFilenameValid(ref string name)
281+
{
282+
name = name.Replace('\\', '_')
283+
.Replace('/', '_')
284+
.Replace(':', '_')
285+
.Replace('*', '_')
286+
.Replace('?', '_')
287+
.Replace('"', '_')
288+
.Replace('<', '_')
289+
.Replace('>', '_')
290+
.Replace('|', '_');
291+
}
292+
279293
public static void InstallDesktopShortcutByTag(string name, string tag, string? iconLocation = null)
280294
{
281295
if (name.StartsWith("Tag=") == false)
@@ -290,6 +304,7 @@ public static void InstallDesktopShortcutByUlid(string name, IEnumerable<string>
290304

291305
public static void InstallDesktopShortcut(bool isInstall, string name = Assert.APP_DISPLAY_NAME, string parameter = "", string? iconLocation = null)
292306
{
307+
MakeFilenameValid(ref name);
293308
try
294309
{
295310
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

0 commit comments

Comments
 (0)