changeset 1050:0657ea84efe1

Improve file export.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Nov 2015 15:47:55 +0200
parents 03f4b70a2ce8
children 78449511df14
files faptool.php
diffstat 1 files changed, 52 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }