ShortcutUtils.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace SharpGLTF
  5. {
  6. public static class ShortcutUtils
  7. {
  8. public static string CreateLink(string localLinkPath, string targetPath)
  9. {
  10. if (string.IsNullOrWhiteSpace(localLinkPath)) throw new ArgumentNullException(nameof(localLinkPath));
  11. if (string.IsNullOrWhiteSpace(targetPath)) throw new ArgumentNullException(nameof(targetPath));
  12. if (!Uri.TryCreate(targetPath, UriKind.Absolute, out Uri uri)) throw new UriFormatException(nameof(targetPath));
  13. var sb = new StringBuilder();
  14. sb.AppendLine("[{000214A0-0000-0000-C000-000000000046}]");
  15. sb.AppendLine("Prop3=19,11");
  16. sb.AppendLine("[InternetShortcut]");
  17. sb.AppendLine("IDList=");
  18. sb.AppendLine($"URL={uri.AbsoluteUri}");
  19. if (uri.IsFile)
  20. {
  21. sb.AppendLine("IconIndex=1");
  22. string icon = targetPath.Replace('\\', '/');
  23. sb.AppendLine("IconFile=" + icon);
  24. }
  25. else
  26. {
  27. sb.AppendLine("IconIndex=0");
  28. }
  29. localLinkPath = System.IO.Path.ChangeExtension(localLinkPath, ".url");
  30. System.IO.File.WriteAllText(localLinkPath, sb.ToString());
  31. return localLinkPath;
  32. }
  33. }
  34. }