comparison faptool.php @ 1050:0657ea84efe1

Improve file export.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Nov 2015 15:47:55 +0200
parents c0e21a405256
children 78449511df14
comparison
equal deleted inserted replaced
1049:03f4b70a2ce8 1050:0657ea84efe1
506 echo 506 echo
507 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; 507 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n";
508 return FALSE; 508 return FALSE;
509 } 509 }
510 510
511 // Make information file contents
512 $sbinfo = [
513 "FAP Entry Information",
514 "=====================",
515 "Compo : ".$compo["name"]." (ID #".$compo["id"].")",
516 "Entry : '".$entry["name"]."' by ".$entry["author"]." (ID #".$entry["id"].")",
517 "Show # : ".($entry["show_id"] > 0 ? $entry["show_id"] : "NOT SET!"),
518 ];
519
520 if (strlen($entry["info"]) > 0)
521 {
522 $sbinfo[] = "";
523 $sbinfo[] = "INFO:";
524 foreach (preg_split("/\r\n|\n|\r/", $entry["info"]) as $sline)
525 $sbinfo[] = $sline;
526 }
527
528 if (strlen($entry["notes"]) > 0)
529 {
530 $sbinfo[] = "";
531 $sbinfo[] = "INTERNAL NOTES:";
532 foreach (preg_split("/\r\n|\n|\r/", $entry["notes"]) as $sline)
533 $sbinfo[] = $sline;
534 }
535
536 $sbinfo[] = "";
537
538
511 // Create the destination directory 539 // Create the destination directory
512 if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false) 540 if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false)
513 return FALSE; 541 return FALSE;
514 542
515 // Form the destination path and/or filename 543 // Form the destination path and/or filename
516 if ($copyOnly) 544 if ($copyOnly)
517 $dstFileBase = $useOrig ? $efile["origname"] : $efile["filename"]; 545 $dstFileBase = $useOrig ? $efile["origname"] : $efile["filename"];
518 else 546 else
519 $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames); 547 $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames);
520 548
549 $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, "")));
521 550
522 // Handle based on class/type and whether we are just copying or not 551 // Handle based on class/type and whether we are just copying or not
523 if (!$copyOnly && $edata["class"] == EFILE_ARCHIVE) 552 if ($copyOnly)
553 {
554 $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase));
555 if (copy($filename, $dstFilename) === false)
556 {
557 echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n";
558 return FALSE;
559 }
560 }
561 else
562 if ($edata["class"] == EFILE_ARCHIVE)
524 { 563 {
525 // Entry is an archive file, so unpack it 564 // Entry is an archive file, so unpack it
526 $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, "")));
527 if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === false) 565 if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === false)
528 return FALSE; 566 return FALSE;
529 567
530 // Crop the filenames from the unpacked archive, if we need to 568 // Crop the filenames from the unpacked archive, if we need to
531 if ($cropNames !== false) 569 if ($cropNames !== false)
532 wtCropFilenamesRec($dstPath, $cropNames); 570 wtCropFilenamesRec($dstPath, $cropNames);
571
533 } 572 }
534 else 573 else
535 { 574 {
536 // We have a single file (or copyOnly mode) 575 // We have a single file (or copyOnly mode)
537 $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase)); 576 if (wtMakeDir($dstPath, 0755) === false)
577 return FALSE;
578
579 $dstFilename = stMakePath(FALSE, FALSE, array($dstPath, $dstFileBase));
538 if (copy($filename, $dstFilename) === false) 580 if (copy($filename, $dstFilename) === false)
539 { 581 {
540 echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n"; 582 echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n";
541 return FALSE; 583 return FALSE;
542 } 584 }
585 }
586
587 $dstFilename = stMakePath(FALSE, FALSE, array($dstPath, "fapinfo.txt"));
588 if (@file_put_contents($dstFilename, implode("\r\n", $sbinfo)) === FALSE)
589 {
590 echo "ERROR: Failed to output '".$dstFilename."'\n";
591 return FALSE;
543 } 592 }
544 593
545 return TRUE; 594 return TRUE;
546 } 595 }
547 596