desktop.pl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/perl
  2. # Make .desktop files for the puzzles.
  3. #
  4. # At present, this script is intended for developer usage: if you're
  5. # working on the puzzles and want to play your bleeding-edge locally
  6. # modified and compiled versions, run this script and it will create a
  7. # collection of desktop files in ~/.local/share/applications where
  8. # XFCE can pick them up and add them to its main menu. (Be sure to run
  9. # 'xfdesktop --reload' after running this.)
  10. #
  11. # (If you don't use XFCE, patches to support other desktop
  12. # environments are welcome :-)
  13. use strict;
  14. use warnings;
  15. use Cwd 'abs_path';
  16. die "usage: desktop.pl [<outdir> [<bindir> <icondir>]]\n"
  17. unless @ARGV == 0 or @ARGV == 1 or @ARGV == 3;
  18. my ($outdir, $bindir, $icondir) = @ARGV;
  19. $outdir = $ENV{'HOME'}."/.local/share/applications" unless defined $outdir;
  20. $bindir = "." unless defined $bindir;
  21. $icondir = "./icons" unless defined $icondir;
  22. $bindir = abs_path($bindir);
  23. $icondir = abs_path($icondir);
  24. open my $desc, "<", "gamedesc.txt"
  25. or die "gamedesc.txt: open: $!\n";
  26. while (<$desc>) {
  27. chomp;
  28. my ($id, $win, $displayname, $description, $summary) = split /:/, $_;
  29. open my $desktop, ">", "$outdir/$id.desktop"
  30. or die "$outdir/$id.desktop: open: $!\n";
  31. my $path = "$bindir/$id";
  32. my $upath = "$bindir/unfinished/$id";
  33. $path = $upath if ! -f $path && -f $upath;
  34. print $desktop "[Desktop Entry]\n";
  35. print $desktop "Version=1.0\n";
  36. print $desktop "Type=Application\n";
  37. print $desktop "Name=$displayname\n";
  38. print $desktop "Comment=$description\n";
  39. print $desktop "Exec=$path\n";
  40. print $desktop "Icon=$icondir/$id-48d24.png\n";
  41. print $desktop "StartupNotify=false\n";
  42. print $desktop "Categories=Game;\n";
  43. print $desktop "Terminal=false\n";
  44. close $desktop
  45. or die "$outdir/$id.desktop: close: $!\n";
  46. }