# HG changeset patch # User Matti Hamalainen # Date 1448113675 -7200 # Node ID 0657ea84efe1471874a85ed7096914cb7d7397a4 # Parent 03f4b70a2ce8af5ac6c84d584dfb5d8b3d3413dc Improve file export. diff -r 03f4b70a2ce8 -r 0657ea84efe1 faptool.php --- a/faptool.php Sat Nov 21 11:41:23 2015 +0200 +++ b/faptool.php Sat Nov 21 15:47:55 2015 +0200 @@ -508,6 +508,34 @@ return FALSE; } + // Make information file contents + $sbinfo = [ + "FAP Entry Information", + "=====================", + "Compo : ".$compo["name"]." (ID #".$compo["id"].")", + "Entry : '".$entry["name"]."' by ".$entry["author"]." (ID #".$entry["id"].")", + "Show # : ".($entry["show_id"] > 0 ? $entry["show_id"] : "NOT SET!"), + ]; + + if (strlen($entry["info"]) > 0) + { + $sbinfo[] = ""; + $sbinfo[] = "INFO:"; + foreach (preg_split("/\r\n|\n|\r/", $entry["info"]) as $sline) + $sbinfo[] = $sline; + } + + if (strlen($entry["notes"]) > 0) + { + $sbinfo[] = ""; + $sbinfo[] = "INTERNAL NOTES:"; + foreach (preg_split("/\r\n|\n|\r/", $entry["notes"]) as $sline) + $sbinfo[] = $sline; + } + + $sbinfo[] = ""; + + // Create the destination directory if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false) return FALSE; @@ -518,23 +546,37 @@ else $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames); + $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, ""))); // Handle based on class/type and whether we are just copying or not - if (!$copyOnly && $edata["class"] == EFILE_ARCHIVE) + if ($copyOnly) + { + $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase)); + if (copy($filename, $dstFilename) === false) + { + echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n"; + return FALSE; + } + } + else + if ($edata["class"] == EFILE_ARCHIVE) { // Entry is an archive file, so unpack it - $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, ""))); if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === false) return FALSE; // Crop the filenames from the unpacked archive, if we need to if ($cropNames !== false) wtCropFilenamesRec($dstPath, $cropNames); + } else { // We have a single file (or copyOnly mode) - $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase)); + if (wtMakeDir($dstPath, 0755) === false) + return FALSE; + + $dstFilename = stMakePath(FALSE, FALSE, array($dstPath, $dstFileBase)); if (copy($filename, $dstFilename) === false) { echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n"; @@ -542,6 +584,13 @@ } } + $dstFilename = stMakePath(FALSE, FALSE, array($dstPath, "fapinfo.txt")); + if (@file_put_contents($dstFilename, implode("\r\n", $sbinfo)) === FALSE) + { + echo "ERROR: Failed to output '".$dstFilename."'\n"; + return FALSE; + } + return TRUE; }