Files
Yuba/YubaPrefs.php
2020-01-27 03:32:56 -08:00

280 lines
7.0 KiB
PHP

<?php
// Yuba Prefs
// //
//////////////////////////////////////////
// Functions
function makeWindowString($p, $strings, $pstrings) {
$conf = "
# Set window title
*.title = Preferences
*.floating = 1
bdest.type = openbrowser
bdest.filetype = directory
bdest.label = Destination
bdest.default = ".$p['bdest']."
bdest.width = 380
reuse.type = checkbox
reuse.label = Add to existing catalogs
reuse.default = ".$p['reuse']."
postflight.type = popup
postflight.label = When finished
postflight.option = ".$strings[0][0]."
postflight.option = ".$strings[0][1]."
postflight.option = ".$strings[0][2]."
postflight.option = ".$strings[0][3]."
postflight.default = ".$strings[0][$p['postflight']]."
postflight.width = 380
rsync_dest.type = textfield
rsync_dest.label = rsync destination
rsync_dest.default = ".$p['rsync_dest']."
rsync_dest.placeholder = user@server.com:files/
rsync_dest.width = 380
hr0.type = image
hr0.path = ".__DIR__."/hr.png"."
hr0.width = 380
hr0.height = 2
parallel.type = popup
parallel.width = 180
parallel.default = ".$pstrings[$p['parallel']]."
";
foreach ($pstrings as $pstring) {
$conf .= "parallel.option = ".$pstring."\n";
}
$conf .= "
debug.type = checkbox
debug.label = Verbose logging
debug.default = ".$p['debug']."
debug.x = 200
debug.y = 443
hr1.type = image
hr1.path = ".__DIR__."/hr.png"."
hr1.width = 380
hr1.height = 2
stat_mode.type = popup
stat_mode.label = POSIX stat()
stat_mode.option = ".$strings[1][0]."
stat_mode.option = ".$strings[1][1]."
stat_mode.option = ".$strings[1][2]."
stat_mode.option = ".$strings[1][3]."
stat_mode.default = ".$strings[1][$p['stat_mode']]."
stat_mode.width = 380
readability.type = checkbox
readability.label = Abort on read errors
readability.default = ".$p['readability']."
profile.type = checkbox
profile.label = Attach system profile
profile.default = ".$p['profile']."
profile.x = 200
profile.y = 314
hr2.type = image
hr2.path = ".__DIR__."/hr.png"."
hr2.width = 380
hr2.height = 2
thumbs.type = popup
thumbs.label = Thumbnails
thumbs.option = ".$strings[2][0]."
thumbs.option = ".$strings[2][1]."
thumbs.option = ".$strings[2][2]."
thumbs.default = ".$strings[2][$p['thumbs']]."
thumbs.width = 120
thumb_mode.type = popup
thumb_mode.label = Mode
thumb_mode.option = ".$strings[3][0]."
thumb_mode.option = ".$strings[3][1]."
thumb_mode.default = ".$strings[3][$p['thumb_mode']]."
thumb_mode.width = 120
thumb_mode.x = 150
thumb_mode.y = 227
thumb_size.type = textfield
thumb_size.default = ".$p['thumb_size']."
thumb_size.label = Size
thumb_size.placeholder = pixels
thumb_size.width = 60
thumb_size.x = 300
thumb_size.y = 230
icons.type = popup
icons.label = Icons
icons.option = ".$strings[2][0]."
icons.option = ".$strings[2][1]."
icons.option = ".$strings[2][2]."
icons.default = ".$strings[2][$p['icons']]."
icons.width = 120
icon_mode.type = popup
icon_mode.label = Mode
icon_mode.option = ".$strings[4][0]."
icon_mode.option = ".$strings[4][1]."
icon_mode.option = ".$strings[4][2]."
icon_mode.default = ".$strings[4][$p['icon_mode']]."
icon_mode.width = 120
icon_mode.x = 150
icon_mode.y = 162
icon_size.type = textfield
icon_size.default = ".$p['icon_size']."
icon_size.label = Size
icon_size.placeholder = pixels
icon_size.width = 60
icon_size.x = 300
icon_size.y = 165
hash.type = checkbox
hash.label = Generate hashes
hash.default = ".$p['hash']."
hash_label.type = text
hash_label.default = Limit
hash_label.x = 200
hash_label.y = 126
hash_label.width = 40
hash_limit.type = textfield
hash_limit.default = ".$p['hash_limit']."
hash_limit.tooltip = Don't hash files larger than X GB
hash_limit.width = 60
hash_limit.x = 240
hash_limit.y = 123
hash_label_after.type = text
hash_label_after.default = GB
hash_label_after.x = 304
hash_label_after.y = 128
hash_label_after.width = 40
contents.type = checkbox
contents.label = Collect file contents
contents.default = ".$p['contents']."
contents_label.type = text
contents_label.default = Limit
contents_label.x = 200
contents_label.y = 88
contents_label.width = 40
contents_limit.type = textfield
contents_limit.tooltip = Don't save files larger than X kB
contents_limit.default = ".$p['contents_limit']."
contents_limit.width = 60
contents_limit.x = 240
contents_limit.y = 85
contents_label_after.type = text
contents_label_after.default = kB
contents_label_after.x = 304
contents_label_after.y = 88
contents_label_after.width = 40
spotlight.type = checkbox
spotlight.label = Use spotlight
spotlight.default = ".$p['spotlight']."
meta.type = checkbox
meta.label = Collect external metadata
meta.default = ".$p['meta']."
meta.x = 200
meta.y = 48
cb.type = cancelbutton
db.type = defaultbutton
db.label = Save
";
return $conf;
}
// Read Prefs
$prefs_file = "/Users/".get_current_user()."/Library/Preferences/org.profiteroles.Yuba.php";
$p = unserialize(file_get_contents($prefs_file));
if(!$p['bdest']) {
$p['bdest'] = "/Users/".get_current_user()."/Documents/Yuba/";
if (!is_dir($p['bdest'])) { if (!mkdir($p['bdest'])) { echo "Error creating destination directory"; } }
}
// Load strings
$strings[] = array("Do nothing","Reveal result in Finder","Upload result with rsync","Open via localhost URL");
$strings[] = array("Skip","Collect","Collect & verify","Collect & repair atimes");
$strings[] = array("Skip","Generate","Rebuild");
$strings[] = array("Most files","Some files");
$strings[] = array("All files","Most files","Some files");
// Parallel strings
$physicalcpu = trim(shell_exec("sysctl -n hw.physicalcpu"));
$pstrings = array("Sequential","Max (Not advised)");
foreach(range(2, $physicalcpu-1) as $index) {
$pstrings[] = $index." Cores";
}
// Launch Pashua and parse results
$path = __DIR__."/bin/Pashua.app/Contents/MacOS/Pashua";
$raw = shell_exec("echo ".escapeshellarg(makeWindowString($p, $strings, $pstrings))." | ".escapeshellarg($path)." - ");
$result = array();
foreach (explode("\n", $raw) as $line) {
preg_match('/^(\w+)=(.*)$/', $line, $matches);
if (empty($matches) or empty($matches[1])) {
continue;
}
$result[$matches[1]] = $matches[2];
}
// User cancelled
if (@$result['cb']) {
echo "0";
die;
}
// Fix strings
$result['postflight'] = array_search($result['postflight'],$strings[0]);
$result['stat_mode'] = array_search($result['stat_mode'],$strings[1]);
$result['thumbs'] = array_search($result['thumbs'],$strings[2]);
$result['thumb_mode'] = array_search($result['thumb_mode'],$strings[3]);
$result['icons'] = array_search($result['icons'],$strings[2]);
$result['icon_mode'] = array_search($result['icon_mode'],$strings[4]);
$result['parallel'] = array_search($result['parallel'],$pstrings);
// If the user didn't specify a destpath, set to default
if(!$p['bdest']) {
$p['bdest'] = "/Users/".get_current_user()."/Documents/Yuba/";
}
// Fix a Pashua bug
$result['destpath'] = str_replace("Desktop/Desktop","Desktop",$result['destpath']);
// Write Prefs
file_put_contents($prefs_file,serialize($result));
echo "1";
?>