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