annotate faptool.php @ 1120:b2bca5f6d0ff default tip

Cosmetic cleanup: remove trailing whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 Dec 2020 13:47:13 +0200
parents 0a2117349f46
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/php
1071
76e11ae923a7 Use long tags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1063
diff changeset
2 <?php
943
f1c2cce5a5d5 Add copyright blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 942
diff changeset
3 //
f1c2cce5a5d5 Add copyright blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 942
diff changeset
4 // FAPWeb - Simple Web-based Demoparty Management System
f1c2cce5a5d5 Add copyright blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 942
diff changeset
5 // Special entry/preview/etc backend management commandline utility
1076
659d41090592 Fix copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
6 // (C) Copyright 2014-2017 Tecnic Software productions (TNSP)
943
f1c2cce5a5d5 Add copyright blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 942
diff changeset
7 //
1024
2a96426159f1 Fix configuration file checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 1019
diff changeset
8 if (!file_exists(realpath(dirname(__FILE__))."/mconfig.inc.php"))
1019
22b6442d5cb3 Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents: 1013
diff changeset
9 {
22b6442d5cb3 Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents: 1013
diff changeset
10 die(
22b6442d5cb3 Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents: 1013
diff changeset
11 "ERROR: Missing site configuration file. Please copy ".
22b6442d5cb3 Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents: 1013
diff changeset
12 "'mconfig.inc.php.example' to 'mconfig.inc.php' and ".
22b6442d5cb3 Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents: 1013
diff changeset
13 "edit it as needed.\n");
22b6442d5cb3 Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents: 1013
diff changeset
14 }
22b6442d5cb3 Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents: 1013
diff changeset
15
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 require_once "mconfig.inc.php";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 require_once "msite.inc.php";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
20 function wtGetExecutable($name, $path = FALSE)
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
21 {
1043
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
22 if (stChkSetting($name."_exe"))
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
23 return stGetSetting($name."_exe");
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
24 else
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
25 return $name;
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
26 }
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
27
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
28
1043
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
29 function wtGetExecutableArgs($name)
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
30 {
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
31 if (stChkSetting($name."_args"))
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
32 return " ".stGetSetting($name."_args")." ";
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
33 else
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
34 return "";
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
35 }
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
36
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
37
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
38 function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
39 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
40 global $setPreviewPath;
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
41 $isTemp = FALSE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
42
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
43 if ($useGfxConv)
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
44 {
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
45 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit
951
6549fb84a814 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 950
diff changeset
46 $tmpFilename = tempnam($setPreviewPath, "tmp");
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
47 $isTemp = TRUE;
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
48 if (wtExec(wtGetExecutable("gfxconv"),
1043
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
49 wtGetExecutableArgs("gfxconv").
970
9c93a3c4f95c Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 969
diff changeset
50 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($tmpFilename),
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
51 0) === FALSE)
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
52 return FALSE;
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
53
951
6549fb84a814 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 950
diff changeset
54 if (!file_exists($tmpFilename))
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
55 {
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
56 echo "ERROR: gfxconv did not output a temporary conversion inbetween.\n";
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
57 return FALSE;
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
58 }
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
59 }
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
60 else
951
6549fb84a814 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 950
diff changeset
61 $tmpFilename = $inFilename;
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
62
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
63 // Create conversion entity
951
6549fb84a814 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 950
diff changeset
64 $img = new Imagick($tmpFilename);
1004
76e26fc5d544 false/FALSE.
Matti Hamalainen <ccr@tnsp.org>
parents: 1001
diff changeset
65 if ($img === FALSE)
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
66 {
951
6549fb84a814 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 950
diff changeset
67 echo "ERROR: Oh noes! ImageMagick could not digest the file '".$tmpFilename."' (".$inFilename.")\n";
912
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
68 return FALSE;
514d460c60a9 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
69 }
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
70
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
71 if ($outDim !== FALSE)
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
72 {
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
73 // Get dimensions, setup background
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
74 $dim = $img->getImageGeometry();
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
75 // $img->setBackgroundColor(imagick::COLOR_BLACK);
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
76 $img->setGravity(imagick::GRAVITY_CENTER);
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
77
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
78 // Act based on image size vs. desired size and $thumb mode
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
79 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1])
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
80 {
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
81 // Image is larger
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
82 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1);
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
83 $img->setImageExtent($outDim[0], $outDim[1]);
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
84 $img->normalizeImage();
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
85 $img->unsharpMaskImage(0, 0.5, 1, 0.05);
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
86 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
87 else
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
88 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1])
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
89 {
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
90 // Image is smaller than requested dimension(s)?
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
91 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_POINT, 1);
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
92 $img->setImageExtent($outDim[0], $outDim[1]);
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
93 }
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
94 }
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
95
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
96 $img->setFormat($outFormat);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
97 $img->setCompressionQuality($outQuality);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
98
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
99 $img->stripImage();
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
100 $img->writeImage($outFilename);
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
101 $img->removeImage();
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
102 return TRUE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
103 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
104
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
105
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
106 function wtRenderSample($inFilename, $outFilename)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
107 {
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
108 $sfreq = intval(stGetSetting("sampleFreq"));
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
109 $sduration = intval(stGetSetting("sampleDuration"));
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
110 $schannels = intval(stGetSetting("sampleChannels"));
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
111
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
112 return wtExec(
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
113 wtGetExecutable("openmpt123")
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
114 ,
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
115 "--force --quiet ".
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
116 "--samplerate ".$sfreq." ".
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
117 "--channels ".$schannels." ".
1026
37901bdbc545 Switch to the official --end-time parameter of openmpt123
Matti Hamalainen <ccr@tnsp.org>
parents: 1024
diff changeset
118 "--end-time ".($sduration)." ".
1043
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
119 wtGetExecutableArgs("openmpt123").
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
120 escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename),
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
121 0);
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
122 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
123
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
124
948
1334b93939a3 Change how output options are handled in wtConvertSample().
Matti Hamalainen <ccr@tnsp.org>
parents: 947
diff changeset
125 function wtConvertSample($inFilename, $outFilename, $outOpts)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
126 {
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
127 $sfreq = intval(stGetSetting("sampleFreq"));
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
128 $sduration = intval(stGetSetting("sampleDuration"));
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
129 $schannels = intval(stGetSetting("sampleChannels"));
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
130
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
131 $optStr = "";
948
1334b93939a3 Change how output options are handled in wtConvertSample().
Matti Hamalainen <ccr@tnsp.org>
parents: 947
diff changeset
132 foreach ($outOpts as $okey => $oval)
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
133 $optStr .= $okey." ".$oval." ";
939
dc3ac7470ec0 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 938
diff changeset
134
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
135 return wtExec(
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
136 wtGetExecutable("avconv"),
1043
c0e21a405256 Change external tool handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1042
diff changeset
137 wtGetExecutableArgs("avconv").
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
138 "-y -v 1 -t ".intval($sduration)." ".
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
139 "-i ".escapeshellarg($inFilename).
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
140 " ".$optStr." -ac ".$schannels.
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
141 " -map_metadata -1 ".
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
142 escapeshellarg($outFilename));
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
143 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
144
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
145
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
146 function wtEntryToSource($compo, $inFilename, $edata, $entryFilename, &$outData, &$outFilename, $force)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
147 {
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
148 // Does compo preview type match this file class?
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
149 if ($edata["class"] != $compo["preview_type"])
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
150 return FALSE;
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
151
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
152 switch ($edata["class"])
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
153 {
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
154 case EFILE_AUDIO: $fext = "wav"; break;
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
155 case EFILE_IMAGE: $fext = "png"; break;
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
156 default:
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
157 return FALSE;
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
158 }
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
159
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
160 $outFilename = stReplaceFileExt($entryFilename, "_preview.".$fext);
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
161 if (!$force && file_exists($outFilename) && filemtime($outFilename) >= filemtime($entryFilename))
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
162 return TRUE;
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
163
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
164 printf("GENERATING: %s -> %s\n", $inFilename, $outFilename);
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
165
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
166 switch ($edata["class"])
939
dc3ac7470ec0 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 938
diff changeset
167 {
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
168 case EFILE_AUDIO:
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
169 if ($edata["mime"] == "audio/x-mod")
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
170 $res = wtRenderSample($inFilename, $outFilename);
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
171 else
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
172 $res = wtConvertSample($inFilename, $outFilename,
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
173 array("-f" => "wav"));
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
174 break;
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
175
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
176 case EFILE_IMAGE:
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
177 $res = wtConvertImage(
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
178 $inFilename,
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
179 $outFilename,
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
180 FALSE, "PNG", 9,
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
181 FALSE, ($edata["mime"] == "gfx"));
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
182 break;
939
dc3ac7470ec0 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 938
diff changeset
183 }
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
184
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
185 return $res;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
186 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
187
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
188
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
189 function wtUnpackArchiveTo($atype, $filename, $path)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
190 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
191 // Check file type before doing anything
953
3b18afe14e46 Message consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
192 echo "INFO: Preparing to unpack archive file '".$filename."' ...\n";
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
193 switch ($atype)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
194 {
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
195 case "LHA":
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
196 $exe = wtGetExecutable("lha");
967
62c90ec5edce Use extract.
Matti Hamalainen <ccr@tnsp.org>
parents: 966
diff changeset
197 $args = "x ".escapeshellarg($filename);
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
198 break;
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
199
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
200 case "ZIP":
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
201 $exe = wtGetExecutable("unzip");
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
202 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename);
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
203 break;
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
204
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
205 case "RAR":
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
206 $exe = wtGetExecutable("rar");
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
207 $args = "x -w".escapeshellarg($path)." ".escapeshellarg($filename);
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
208 break;
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
209
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
210 case "7ZIP":
1042
b17c41ffe43b Implement wtGetExecutable() and use it for getting executable names for
Matti Hamalainen <ccr@tnsp.org>
parents: 1033
diff changeset
211 $exe = wtGetExecutable("7z");
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
212 $args = "x -o".escapeshellarg($path)." ".escapeshellarg($filename);
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
213 break;
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
214
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
215 default:
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
216 echo "Unsupported archive file type: ".$atype."\n";
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
217 return FALSE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
218 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
219
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
220 // Delete any pre-existing directory
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
221 wtPurgeDir($path);
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
222
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
223 // Create temporary directory for unpacking
1051
78449511df14 Fix permissions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1050
diff changeset
224 wtMakeDir($path, 0755);
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
225
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
226 // Save current working directory and chdir to target
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
227 $cwd = getcwd();
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
228 if (!is_dir($path) || chdir($path) === FALSE)
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
229 {
953
3b18afe14e46 Message consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
230 echo "ERROR: Failed to chdir to '".$path."', can't unpack archive.\n";
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
231 return FALSE;
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
232 }
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
233
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
234 // Unpack archive
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
235 $ret = wtExec($exe, $args);
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
236
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
237 // Return to stored cwd
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
238 chdir($cwd);
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
239 return $ret;
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
240 }
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
241
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
242
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
243 function wtHandleEntryPreview($compo, $entry, $mode)
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
244 {
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
245 global $fileTypeData, $setEntryPath;
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
246
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
247 // Get current preview file(s) data
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
248 if (!stGetPreviewFileData($compo, $entry, $pdata))
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
249 return FALSE;
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
250
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
251 // Get entry file data
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
252 $efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"]);
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
253
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
254 // Check preview file(s) status
949
2179600710d1 Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
255 if ($mode == "sta" || $mode == "lis")
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
256 {
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
257 printf(" %03d | %s%s%s | %-40s | %-5s | %s\n",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
258 $entry["id"],
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
259 ($efile !== FALSE) ? "E" : ".",
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
260 isset($pdata["file"]) ? "P" : ".",
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
261 $pdata["valid"] ? "V" : ".",
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
262 substr($entry["name"]." by ".$entry["author"], 0, 40),
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
263 isset($pdata["file"]) ? $pdata["file"]["filetype"] : "",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
264 isset($pdata["file"]) ? $pdata["file"]["filename"] : ""
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
265 );
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
266 return TRUE;
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
267 }
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
268 else
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
269 if ($mode != "gen" && $mode != "upd")
953
3b18afe14e46 Message consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
270 die("ERROR: Unsupported previews mode ".$mode."\n");
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
271
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
272 $force = ($mode == "upd");
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
273
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
274 // Check validity of previews
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
275 if ($pdata["valid"] && !$force)
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
276 return TRUE;
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
277
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
278 // Okay, no valid previews .. lets see what we can do ..
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
279 // First, check if we have a source preview file
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
280 if (!isset($pdata["file"]))
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
281 {
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
282 // No source preview, check if we have entry file either?
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
283 if ($efile === FALSE)
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
284 {
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
285 echo
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
286 "INFO: No entry file for ".wtNiceName($compo, $entry, $efile).
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
287 ", can't attempt to generate preview.\n";
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
288 return FALSE;
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
289 }
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
290
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
291 // Actual entry filename + path
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
292 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"]));
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
293 if (!file_exists($filename))
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
294 {
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
295 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n";
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
296 return FALSE;
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
297 }
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
298
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
299 // Preview source file does not exist, let's see ..
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
300 $edata = stProbeFileInfo($filename, TRUE);
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
301 if ($edata === FALSE)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
302 {
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
303 echo
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
304 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n";
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
305 return FALSE;
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
306 }
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
307
942
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
308 $found = FALSE;
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
309 if ($edata["class"] == EFILE_ARCHIVE)
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
310 {
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
311 // Entry is an archive file ..
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
312 $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $efile["filename"]));
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
313
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
314 if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === FALSE)
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
315 return FALSE;
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
316
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
317 // Scan through files ...
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
318 $dir = opendir($path);
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
319 while (($dentry = readdir($dir)) !== FALSE)
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
320 {
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
321 $fname = $path."/".$dentry;
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
322 if ($dentry != "." && $dentry != "..")
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
323 {
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
324 if (is_dir($fname))
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
325 echo "XXX: ".$dentry." :: ".$fname."\n";
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
326 else
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
327 if (is_file($fname) &&
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
328 ($mdata = stProbeFileInfo($fname, TRUE)) !== FALSE &&
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
329 ($found = wtEntryToSource($compo, $fname, $mdata, $filename, $pdata, $outFilename, $force)) === TRUE)
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
330 break;
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
331 }
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
332 }
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
333
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
334 // Cleanup
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
335 closedir($dir);
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
336 wtPurgeDir($path);
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
337 }
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
338 else
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
339 if ($edata["class"] == $compo["preview_type"])
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
340 {
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
341 // Single file
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
342 $found = wtEntryToSource($compo, $filename, $edata, $filename, $pdata, $outFilename, $force);
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
343 }
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
344
950
527e62f39af6 More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
345 if (!$found)
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
346 {
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
347 echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n";
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
348 return FALSE;
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
349 }
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
350
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
351 $inFilename = $outFilename;
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
352 }
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
353 else
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
354 $inFilename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $pdata["file"]["filename"]));
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
355
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
356 // Check validity vs.
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
357 if (!$force)
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
358 {
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
359 $valid = TRUE;
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
360 $inMTime = filemtime($inFilename);
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
361 foreach ($pdata["files"] as $stype => $sdata)
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
362 {
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
363 if (!file_exists($sdata["file"]) || filemtime($sdata["file"]) < $inMTime)
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
364 {
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
365 $valid = FALSE;
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
366 break;
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
367 }
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
368 }
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
369 if ($valid)
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
370 return TRUE;
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
371 }
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
372
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
373 //
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
374 // Either we now have a "user specified" source file or
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
375 // a generated source file - in any case, now convert it
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
376 // to the final form(s).
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
377 //
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
378 switch ($compo["preview_type"])
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
379 {
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
380 case EFILE_AUDIO:
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
381 // Convert to each specified sample type (MP3, Ogg, etc.)
950
527e62f39af6 More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
382 foreach (stGetSetting("sampleTypes") as $stype => $sopts)
942
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
383 {
950
527e62f39af6 More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
384 wtConvertSample(
527e62f39af6 More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
385 $inFilename,
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
386 $pdata["files"][$stype]["file"],
950
527e62f39af6 More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
387 $sopts
527e62f39af6 More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 949
diff changeset
388 );
942
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
389 }
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
390 break;
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
391
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
392 case EFILE_IMAGE:
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
393 // Images we convert to bigger image and thumbnail
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
394 wtConvertImage(
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
395 $inFilename,
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
396 $pdata["files"]["image"]["file"],
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
397 stGetSetting("previewImageSize"),
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
398 stGetSetting("previewImageType"),
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
399 stGetSetting("previewImageQuality"),
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
400 FALSE, FALSE);
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
401
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
402 wtConvertImage(
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
403 $inFilename,
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
404 $pdata["files"]["thumb"]["file"],
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
405 stGetSetting("previewThumbSize"),
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
406 stGetSetting("previewThumbType"),
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
407 stGetSetting("previewThumbQuality"),
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
408 TRUE, FALSE);
942
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
409 break;
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
410 }
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
411
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
412 return TRUE;
882
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
413 }
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
414
25bcbd6d5682 Moar work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 881
diff changeset
415
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
416 function wtHandleEntry($compo, $entry, $mode)
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
417 {
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
418 }
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
419
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
420
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
421 //
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
422 // Crop a filename to specified length
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
423 //
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
424 function wtCropFilename($filename, $len)
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
425 {
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
426 if ($len !== FALSE && strlen($filename) > $len)
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
427 {
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
428 // Check if the filename has a path and attempt
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
429 // to get the filename extension
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
430 $fext = "";
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
431 $dpos = strrpos($filename, "/");
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
432 if (($spos = strrpos($filename, ".")) !== FALSE &&
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
433 ($dpos === FALSE || $dpos < $spos))
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
434 $fext = substr($filename, $spos);
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
435
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
436 // Is the filename extension too long, if yes, just dump it
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
437 if (strlen($fext) >= $len)
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
438 $fext = "";
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
439
987
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
440 return substr($filename, 0, $len - strlen($fext) - 1).$fext;
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
441 }
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
442 else
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
443 return $filename;
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
444 }
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
445
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
446
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
447 //
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
448 // Recursively goes through directory/files and subdirectories,
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
449 // cropping file/dir names to specified length.
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
450 //
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
451 function wtCropFilenamesRec($path, $len)
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
452 {
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
453 $dir = opendir($path);
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
454 while (($dentry = readdir($dir)) !== FALSE)
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
455 {
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
456 $fname = $path."/".$dentry;
987
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
457 $nname = $path."/".wtCropFilename($dentry, $len);
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
458 if ($dentry != "." && $dentry != "..")
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
459 {
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
460 if (is_dir($fname))
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
461 {
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
462 wtCropFilenamesRec($fname, $len);
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
463 if (rename($fname, $nname) === FALSE)
987
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
464 {
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
465 echo "ERROR: Could not rename DIR '".$fname."' -> '".$nname."'.\n";
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
466 return FALSE;
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
467 }
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
468 }
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
469 else
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
470 if (is_file($fname) && rename($fname, $nname) === FALSE)
987
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
471 {
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
472 echo "ERROR: Could not rename FILE '".$fname."' -> '".$nname."'.\n";
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
473 return FALSE;
06e45615b46b Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 986
diff changeset
474 }
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
475 }
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
476 }
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
477 closedir($dir);
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
478 }
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
479
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
480
991
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
481 function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig, $cropNames, $copyOnly)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
482 {
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
483 global $setEntryPath;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
484
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
485 // Get latest file for the entry
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
486 if (($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"])) === FALSE)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
487 {
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
488 echo "INFO: No entry file for ".wtNiceName($compo, $entry, $efile)."\n";
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
489 return FALSE;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
490 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
491
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
492 // Create source file full path
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
493 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"]));
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
494
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
495 // Check if the file exists
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
496 if (!file_exists($filename))
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
497 {
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
498 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n";
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
499 return FALSE;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
500 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
501
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
502 // Get file data
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
503 $edata = stProbeFileInfo($filename, TRUE);
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
504 if ($edata === FALSE)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
505 {
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
506 echo
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
507 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n";
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
508 return FALSE;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
509 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
510
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
511 // Make information file contents
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
512 $sbinfo = [
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
513 "FAP Entry Information",
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
514 "=====================",
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
515 "Compo : ".$compo["name"]." (ID #".$compo["id"].")",
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
516 "Entry : '".$entry["name"]."' by ".$entry["author"]." (ID #".$entry["id"].")",
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
517 "Show # : ".($entry["show_id"] > 0 ? $entry["show_id"] : "NOT SET!"),
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
518 ];
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
519
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
520 if (strlen($entry["info"]) > 0)
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
521 {
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
522 $sbinfo[] = "";
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
523 $sbinfo[] = "INFO:";
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
524 foreach (preg_split("/\r\n|\n|\r/", $entry["info"]) as $sline)
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
525 $sbinfo[] = $sline;
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
526 }
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
527
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
528 if (strlen($entry["notes"]) > 0)
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
529 {
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
530 $sbinfo[] = "";
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
531 $sbinfo[] = "INTERNAL NOTES:";
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
532 foreach (preg_split("/\r\n|\n|\r/", $entry["notes"]) as $sline)
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
533 $sbinfo[] = $sline;
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
534 }
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
535
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
536 $sbinfo[] = "";
1063
85e268f6a822 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1053
diff changeset
537 $sbinfoStr = implode("\n", $sbinfo);
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
538
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
539 // Create the destination directory
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
540 if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === FALSE)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
541 return FALSE;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
542
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
543 // Form the destination path and/or filename
991
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
544 if ($copyOnly)
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
545 $dstFileBase = $useOrig ? $efile["origname"] : $efile["filename"];
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
546 else
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
547 $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames);
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
548
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
549 $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, "")));
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
550
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
551 // Handle based on class/type and whether we are just copying or not
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
552 if ($copyOnly)
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
553 {
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
554 $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase));
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
555 if (copy($filename, $dstFilename) === FALSE)
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
556 {
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
557 echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n";
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
558 return FALSE;
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
559 }
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
560 }
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
561 else
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
562 if ($edata["class"] == EFILE_ARCHIVE)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
563 {
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
564 // Entry is an archive file, so unpack it
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
565 if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === FALSE)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
566 return FALSE;
986
a8ed8295fcd2 Implement name cropping.
Matti Hamalainen <ccr@tnsp.org>
parents: 985
diff changeset
567
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
568 // Crop the filenames from the unpacked archive, if we need to
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
569 if ($cropNames !== FALSE)
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
570 wtCropFilenamesRec($dstPath, $cropNames);
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
571
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
572 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
573 else
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
574 {
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
575 // We have a single file (or copyOnly mode)
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
576 if (wtMakeDir($dstPath, 0755) === FALSE)
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
577 return FALSE;
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
578
1053
e706cbcaf566 Fix export filenames.
Matti Hamalainen <ccr@tnsp.org>
parents: 1051
diff changeset
579 $dstFilename = stMakePath(FALSE, FALSE, array($dstPath, wtCropFilename($efile["origname"], $cropNames)));
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
580 if (copy($filename, $dstFilename) === FALSE)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
581 {
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
582 echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n";
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
583 return FALSE;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
584 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
585 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
586
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
587 $dstFilename = stMakePath(FALSE, FALSE, array($dstPath, "fapinfo.txt"));
1063
85e268f6a822 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1053
diff changeset
588 if (@file_put_contents($dstFilename, $sbinfoStr) === FALSE)
1050
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
589 {
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
590 echo "ERROR: Failed to output '".$dstFilename."'\n";
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
591 return FALSE;
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
592 }
0657ea84efe1 Improve file export.
Matti Hamalainen <ccr@tnsp.org>
parents: 1043
diff changeset
593
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
594 return TRUE;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
595 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
596
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
597
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 //
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
599 // Misc helper functions
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 //
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
601
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
602 function wtNiceName($compo, $entry, $efile = FALSE)
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
603 {
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
604 return sprintf(
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
605 "%d: %s by %s%s",
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
606 $entry["id"],
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
607 $entry["name"],
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
608 $entry["author"],
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
609 ($efile !== FALSE) ? " [".$efile["filename"]." / TYPE: '".$efile["filetype"]."']" : "");
993
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
610 }
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
611
fbc2e6514dfa Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 991
diff changeset
612
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
613 function wtExec($exe, $args, $expect = 0)
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
614 {
984
03b245ef3a47 Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 983
diff changeset
615 echo "EXEC: ".$exe." @ ".$args."\n";
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
616 exec(escapeshellcmd($exe)." ".$args, $output, $code);
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
617 if ($code !== $expect)
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
618 {
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
619 echo
953
3b18afe14e46 Message consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
620 "ERROR: Executing ".$exe.": ".$code."\n".$args."\n".
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
621 "------------------------------------------------\n".
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
622 implode("\n", $output).
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
623 "------------------------------------------------\n";
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
624 return FALSE;
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
625 }
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
626 return TRUE;
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
627 }
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
628
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
629
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
630 function wtExecOrDie($exe, $args)
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
631 {
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
632 if (wtExec($exe, $args) === FALSE)
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
633 die();
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
634 }
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
635
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
636
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
637 function wtPurgeDir($path)
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
638 {
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
639 if ($path != "" && $path !== FALSE && file_exists($path) && is_dir($path))
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
640 {
969
26ae3f21a3bb Moar work on previews.
Matti Hamalainen <ccr@tnsp.org>
parents: 968
diff changeset
641 // echo "PURGING: ".$path."\n";
942
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
642 foreach (scandir($path) as $file)
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
643 if ($file !== "." && $file !== "..")
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
644 {
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
645 $sub = $path."/".$file;
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
646 if (is_dir($sub))
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
647 wtPurgeDir($sub);
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
648 else
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
649 unlink($sub);
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
650 }
7fa6c39ef851 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
651 rmdir($path);
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
652 }
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
653 }
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
654
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
655
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
656 function wtMakeDir($path, $perm)
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 {
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 if (!file_exists($path))
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 {
953
3b18afe14e46 Message consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
660 echo "INFO: Creating ".$path."\n";
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
661 if (mkdir($path, $perm, TRUE) === FALSE)
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 die("Could not create directory '".$path."'\n");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
667 function wtInitializeDirs()
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 {
902
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
669 global
5d7e525b0eb5 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 901
diff changeset
670 $setEntryPath, $setPreviewPath, $setThumbDir,
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 $setEntryPathPerms, $setPrevPathPerms;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 echo "Checking for missing directories ...\n";
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
674 wtMakeDir($setEntryPath, $setEntryPathPerms);
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
675 wtMakeDir($setPreviewPath, $setPrevPathPerms);
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 {
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
679 wtMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms);
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
680 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms);
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
681 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms);
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
686 function wtPrintCompoHeader($compo)
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
687 {
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
688 global $setTermWidth;
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
689 printf("==%'=-".($setTermWidth-2)."s\n",
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
690 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40))
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
691 );
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
692 }
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
693
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
694
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
695 function wtPrintDivider($chr = "-")
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
696 {
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
697 global $setTermWidth;
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
698 echo str_repeat($chr, $setTermWidth)."\n";
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
699 }
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
700
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
701
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
702 function wtShowHelp()
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 {
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
704 global $argv;
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 echo
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 "faptool - Do stuff with FAPWeb database\n".
1076
659d41090592 Fix copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 1072
diff changeset
707 "(C) Copyright 2014-2017 ccr/TNSP\n".
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 "\n".
917
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
709 "Usage: ".$argv[0]." <command> [args]\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
710 "Where command is one of following:\n".
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 "\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 " init\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 " Create directories for entries and previews, if needed.\n".
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 "\n".
928
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
715 /*
917
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
716 " clean [delete|crap]\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
717 " Clean files marked to be deleted and 'stale' files. This includes\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
718 " any old or stale preview files and entry files.\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
719 " Without 'delete' parameter just checks and shows what would deleted.\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
720 " 'crap' parameter will purge EVERYTHING that is NOT in the database,\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
721 " e.g. any other files, like temp files, etc. DANGEROUS IF YOU DO NOT\n".
eda104823649 Work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
722 " KNOW WHAT YOU ARE DOING!!!!!\n".
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
723 "\n".
928
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
724 */
938
7accae8e896c More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 935
diff changeset
725 " probe <filename> [filename2 ..]\n".
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
726 " Probe specified file for file information.\n".
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
727 "\n".
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
728 " previews <cmd> [args]\n".
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
729 " Where <cmd> is one of:\n".
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
730 " status [cid] - List files and show what is missing, etc. (All or <cid>)\n".
970
9c93a3c4f95c Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 969
diff changeset
731 " generate - Generate preview files that are missing OR out of date.\n".
928
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
732 " (older then preview source file OR entry file where appropriate)\n".
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
733 "\n".
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
734 " entry <cmd> [args]\n".
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
735 " status [cid] - List entries for all compos or <cid>.\n".
966
eea2b92287ca Update help.
Matti Hamalainen <ccr@tnsp.org>
parents: 964
diff changeset
736 " unpack <path> - Create subdirs and copy all entries UNPACKED there.\n".
991
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
737 " release <path> - Like unpack, but just copies files (does not unpack archives).\n".
1031
bada991641ba Cleaning up.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
738 "\n".
bada991641ba Cleaning up.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
739 " add <cid> <filename> - Add a new entry with file.\n".
bada991641ba Cleaning up.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
740 " Entry info + notes for internal use will be prompted.\n".
bada991641ba Cleaning up.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
741 " pre <eid> <filename> - Add file as preview for entry id.\n".
bada991641ba Cleaning up.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
742 " del <eid> - Delete entry (does not delete files).\n".
928
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
743 /*
1031
bada991641ba Cleaning up.
Matti Hamalainen <ccr@tnsp.org>
parents: 1028
diff changeset
744 "\n".
928
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
745 " package <lha|zip|rar|7z>\n".
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
746 " Repackages/packages entries (unpacks first if archive),\n".
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
747 " and adds generated infofile.txt to packages.\n".
980f15768103 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
748 */
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 "\n";
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
750 }
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
751
1005
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
752
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
753 function wtSigHandler($signo)
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
754 {
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
755 global $flagQuit;
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
756 switch ($signo)
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
757 {
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
758 case SIGTERM:
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
759 mgFatal("Received SIGTERM.\n");
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
760 break;
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
761
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
762 case SIGQUIT:
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
763 case SIGINT:
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
764 $flagQuit = TRUE;
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
765 break;
1013
720078ca799e Oops, a missing bracket. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1006
diff changeset
766 }
1005
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
767 }
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
768
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
769
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
770 //
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
771 // Main program starts
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
772 //
944
535466595a5a Move CLI exec check to program start.
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
773 stCheckCLIExec();
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
774 if ($argc < 2)
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
775 {
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
776 wtShowHelp();
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 exit;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779
1005
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
780 pcntl_signal(SIGTERM, "wtSigHandler");
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
781 pcntl_signal(SIGHUP, "wtSigHandler");
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
782 pcntl_signal(SIGQUIT, "wtSigHandler");
f650ae251d8c Add signal handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1004
diff changeset
783 pcntl_signal(SIGINT, "wtSigHandler");
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
784
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785 // Try to connect to database
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786 $spec = stGetSetting("sqlDB");
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
787 if (($db = stConnectSQLDBSpec($spec)) === FALSE)
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 die("Could not connect to SQL database '".$spec."'.\n");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 echo "Using database spec '".$spec."'.\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 // Fetch non-"hardcoded" settings from SQL database
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 stReloadSettings();
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 // Set some globals for our benefit
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
796 $setTermWidth = 75;
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 $setEntryPath = stGetSetting("entryPath");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 $setPreviewPath = stGetSetting("previewPath");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 $setPreviewURL = stGetSetting("previewURL");
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 $setThumbDir = stGetSetting("thumbnailSubDir");
832
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
801 $setEntryPathPerms = stGetSetting("entryPathPerms");
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
802 $setPrevPathPerms = stGetSetting("previewPathPerms");
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
803
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804 if ($setEntryPath === FALSE || $setPreviewPath === FALSE ||
832
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
805 $setPreviewURL === FALSE || $setThumbDir === FALSE ||
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
806 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE)
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 {
922
b92549a3372d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 917
diff changeset
808 die("Some required settings are not defined in mconfig.inc.php!\n");
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 // Act according to specified command
1006
cb23b23a2d8b Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1005
diff changeset
813 switch (stCArgLC(1, 3))
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 {
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
815 case "-?": case "--h":
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
816 wtShowHelp();
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
817 exit;
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
818 break;
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
819
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
820 case "ini":
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821 //
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822 // Initialize the data directories etc
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
823 //
953
3b18afe14e46 Message consistency.
Matti Hamalainen <ccr@tnsp.org>
parents: 951
diff changeset
824 echo "INFO: Checking for missing directories ...\n";
935
7fdf03e6a80d More work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
825 wtInitializeDirs();
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
826 break;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
828 case "pro":
945
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
829 //
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
830 // Probe specified files
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
831 //
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
832 if ($argc < 2)
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
833 die("No filename specified.\n");
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
834
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
835 if (($finfo = finfo_open()) === FALSE)
954
24f155a2e501 More work ... on faptool!
Matti Hamalainen <ccr@tnsp.org>
parents: 953
diff changeset
836 die("Internal error. Failed to initialize finfo().");
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
837
945
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
838 for ($i = 2; $i < $argc; $i++)
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
839 {
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
840 // Probe one file
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
841 $filename = $argv[$i];
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
842 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE);
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
843 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE);
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
844
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
845 echo
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
846 "\n".
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
847 "File : ".$filename."\n".
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
848 "Probed : ".$sdata."\n".
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
849 "Mime : ".$smime."\n";
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
850
1104
0a2117349f46 s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents: 1083
diff changeset
851 if (($info = stProbeFileInfo($filename, TRUE)) !== FALSE)
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
852 {
945
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
853 $tmp = array();
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
854 foreach ($info as $ikey => $ival)
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
855 $tmp[] = $ikey."='".$ival."'";
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
856
025f5e3e27d7 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 944
diff changeset
857 echo "Data : ".implode(", ", $tmp)."\n";
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
858 }
946
99086b6afcdb Oops, 10L!
Matti Hamalainen <ccr@tnsp.org>
parents: 945
diff changeset
859 }
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
860
946
99086b6afcdb Oops, 10L!
Matti Hamalainen <ccr@tnsp.org>
parents: 945
diff changeset
861 finfo_close($finfo);
925
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
862 break;
5d53b9d6c319 Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 922
diff changeset
863
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
864 case "cle":
947
f709816c71cd Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
865 //
f709816c71cd Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
866 // File cleanup / deletion
f709816c71cd Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
867 //
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
868 $mode = stCArgLC(2, 3);
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
869 switch ($mode)
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
870 {
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
871 case "del":
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
872 case FALSE:
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
873 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
874 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0)
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
875 {
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
876 wtPrintCompoHeader($compo);
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
877 wtPrintDivider();
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
878
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
879 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
880 {
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
881 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile)
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
882 {
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
883 if ($efile["deleted"] != 0)
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
884 {
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
885 echo "X";
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
886 }
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
887 }
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
888 }
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
889 echo "\n";
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
890 wtPrintDivider();
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
891 }
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
892 break;
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
893
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
894 case "cra":
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
895 echo "Not implemented. :D\n";
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
896 break;
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
897
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
898 default:
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
899 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n");
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
900 break;
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
901 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
902 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
903
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
904 case "ent":
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
905 //
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
906 // Entry files handling
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
907 //
1006
cb23b23a2d8b Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1005
diff changeset
908 $mode = stCArgLC(2, 3);
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
909 switch ($mode)
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
910 {
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
911 case "sta":
949
2179600710d1 Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
912 case "lis":
1006
cb23b23a2d8b Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1005
diff changeset
913 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : "";
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
914 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo)
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
915 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0)
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
916 {
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
917 wtPrintCompoHeader($compo);
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
918 wtPrintDivider();
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
919
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
920 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
921 wtHandleEntry($compo, $entry, $mode);
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
922
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
923 wtPrintDivider();
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
924 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
925 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
926
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
927 case "unp":
1006
cb23b23a2d8b Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1005
diff changeset
928 if (($setPrefix = stCArg(3)) === FALSE)
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
929 die("Unpack needs a destination path.\n");
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
930
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
931 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
932 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
933 {
991
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
934 // wtUnpackEntry($compo, $entry, $setPrefix, TRUE, 32, FALSE);
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
935 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, FALSE);
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
936 }
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
937 break;
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
938
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
939 case "rel":
1006
cb23b23a2d8b Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1005
diff changeset
940 if (($setPrefix = stCArg(3)) === FALSE)
991
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
941 die("Releases needs a destination path.\n");
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
942
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
943 if (!file_exists($setPrefix) || is_dir($setPrefix))
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
944 {
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
945 // Create new one
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
946 wtMakeDir($setPrefix, 0755);
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
947
991
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
948 // Create results.txt if it does not exist
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
949 $resultsFile = stMakePath(FALSE, TRUE, array($setPrefix, "results.txt"));
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
950 if (!file_exists($resultsFile))
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
951 {
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
952 // Use a header file if it exists
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
953 $resultsHeader = "results.logo";
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
954 if (file_exists($resultsHeader) && is_file($resultsHeader))
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
955 $resultsText = file_get_contents($resultsHeader);
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
956 else
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
957 {
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
958 $resultsText = $pageTitle." results";
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
959 $resultsText .= "\n".str_repeat("=", strlen($resultsText))."-- -\n\n";
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
960 }
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
961
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
962 file_put_contents(
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
963 $resultsFile,
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
964 $resultsText.stGetCompoResultsASCIIStr(FALSE, 0)
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
965 );
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
966 }
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
967
991
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
968 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
969 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
970 {
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
971 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, TRUE);
3e9e0aa21a18 Add releases dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
972 }
963
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
973 }
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
974 break;
003af1c4ae1f Implement 'entry unpack'.
Matti Hamalainen <ccr@tnsp.org>
parents: 954
diff changeset
975
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
976 case "pac":
929
Matti Hamalainen <ccr@tnsp.org>
parents: 928
diff changeset
977 echo "Not implemented. :D\n";
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
978 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
979
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
980 case "add":
929
Matti Hamalainen <ccr@tnsp.org>
parents: 928
diff changeset
981 echo "Not implemented. :D\n";
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
982 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
983
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
984 default:
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
985 if ($mode == FALSE)
901
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
986 die("ERROR! Entry command requires a sub-command argument.\n");
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
987 else
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
988 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n");
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
989 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
990 }
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
991 break;
dfa1277786c1 Some more work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 900
diff changeset
992
884
bc64949e7a97 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 882
diff changeset
993 case "pre":
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
994 //
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
995 // Preview files handling
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
996 //
1006
cb23b23a2d8b Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1005
diff changeset
997 $mode = stCArgLC(2, 3);
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
998 switch ($mode)
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
999 {
970
9c93a3c4f95c Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 969
diff changeset
1000 case "gen":
983
1e347288712d Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents: 971
diff changeset
1001 case "upd":
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1002 case "sta":
949
2179600710d1 Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents: 948
diff changeset
1003 case "lis":
1006
cb23b23a2d8b Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1005
diff changeset
1004 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : "";
933
f05c896622e1 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 929
diff changeset
1005 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo)
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
1006 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0)
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1007 {
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1008 wtPrintCompoHeader($compo);
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1009 printf(
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
1010 "PrevType : %s\n",
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
1011 $previewTypeList[$compo["preview_type"]][0]);
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1012
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1013 if ($mode == "sta" || $mode == "lis")
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1014 {
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1015 printf(" %-3s | %-3s | %-40s |\n",
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1016 "#ID", "EPV", "Entry name/author");
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1017 }
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1018
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1019 wtPrintDivider("-");
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1020
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1021 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1022 wtHandleEntryPreview($compo, $entry, $mode);
898
750b3b57ec61 More prototyping.
Matti Hamalainen <ccr@tnsp.org>
parents: 884
diff changeset
1023
968
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1024 wtPrintDivider("=");
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1025 }
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1026 if ($mode == "sta" || $mode == "lis")
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1027 {
c71afc1a3a85 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 967
diff changeset
1028 echo "Flags: E = Entry has file, P = Has preview file, V = Generated previews are up to date.\n";
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1029 }
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1030 break;
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1031
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1032 default:
1083
1f77195b4f95 Some work on faptool.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
1033 if ($mode == FALSE)
881
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1034 die("ERROR! Previews command requires a sub-command argument.\n");
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1035 else
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1036 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n");
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1037 break;
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1038 }
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1039 break;
7c805dccd4f7 Work on the tool.
Matti Hamalainen <ccr@tnsp.org>
parents: 880
diff changeset
1040
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1041 default:
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1042 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n";
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1043 break;
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1044 }
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1045
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1046 /* Dummy
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1047 {
1120
b2bca5f6d0ff Cosmetic cleanup: remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
1048
941
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1049 }
f3c6c56098ed And moar.
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1050 */
827
2e18d8102504 Initial import of faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1051 ?>