changeset 752:2b9dd22f01e9

Improve packed by adding file exclusion option.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 05 May 2013 01:28:51 +0300
parents 817e792d9360
children 8dd6d512cbb2 cf7612c8de1f
files tools/packed.c
diffstat 1 files changed, 34 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tools/packed.c	Sat May 04 23:43:16 2013 +0300
+++ b/tools/packed.c	Sun May 05 01:28:51 2013 +0300
@@ -28,8 +28,10 @@
     PACK_EXTRACTED = 0x0001,
 };
 
-int    nsrcFilenames = 0;
+int    nsrcFilenames = 0, nexcFilenames = 0;
 char * srcFilenames[SET_MAX_FILES];
+char * excFilenames[SET_MAX_FILES];
+
 char * optPackFilename = NULL;
 BOOL   optCompress = TRUE;
 int    optCommand = CMD_NONE;
@@ -47,6 +49,7 @@
     { 6, 'n', "nocompress",  "No compression", OPT_NONE },
     { 7, 'v', "verbose",     "Increase verbosity", OPT_NONE },
     { 8, 'f', "resflags",    "Set default resource flags (-f 0xff)", OPT_ARGREQ },
+    { 9, 'x', "exclude",     "Exclude name/glob pattern from add", OPT_ARGREQ },
 };
 
 static const int optListN = sizeof(optList) / sizeof(optList[0]);
@@ -61,7 +64,7 @@
     "Examples:\n"
     "$ %s -p test.pak -l         -- list files in test.pak\n"
     "$ %s -a foobar.jpg          -- add foobar.jpg in " SET_DEFAULT_PACK "\n"
-    "$ %s -x foobar.jpg          -- extract foobar.jpg from " SET_DEFAULT_PACK "\n",
+    "$ %s -e foobar.jpg          -- extract foobar.jpg from " SET_DEFAULT_PACK "\n",
     dmProgName, dmProgName, dmProgName);
 }
 
@@ -111,6 +114,20 @@
                 optDefResFlags = i;
             }
             break;
+        
+        case 9:
+            if (nexcFilenames < SET_MAX_FILES)
+            {
+                excFilenames[nsrcFilenames] = currArg;
+                nexcFilenames++;
+            }
+            else
+            {
+                dmError("Maximum number of exclusion patterns (%d) exceeded!\n",
+                      SET_MAX_FILES);
+                return FALSE;
+            }
+            break;
 
         default:
             dmError("Unknown argument '%s'.\n", currArg);
@@ -250,6 +267,18 @@
 }
 
 
+BOOL dmCheckExcluded(const char *filename)
+{
+    int i;
+    for (i = 0; i < nexcFilenames; i++)
+    {
+        if (dm_strmatch(filename, excFilenames[i]))
+            return TRUE;
+    }
+    return FALSE;
+}
+
+
 int main(int argc, char *argv[])
 {
     int i, res = 0;
@@ -260,7 +289,7 @@
 #endif
 
     // Parse arguments
-    dmInitProg("packed", "Pack File Editor", "0.4", NULL, NULL);
+    dmInitProg("packed", "Pack File Editor", "0.5", NULL, NULL);
     dmVerbosity = 1;
     
     if (!dmArgsProcess(argc, argv, optList, optListN,
@@ -302,9 +331,10 @@
         // Add files into PACK
         if (res == DMERR_OK)
         {
-            dmMsg(1, "Adding %d files...\n", nsrcFilenames);
+            dmMsg(1, "Adding files...\n");
 
             for (i = 0; i < nsrcFilenames; i++)
+            if (!dmCheckExcluded(srcFilenames[i]))
             {
                 DMPackEntry *node = NULL;
                 int res = dmPackAddFile(pack, srcFilenames[i], optCompress, optDefResFlags, &node);