]> wimlib.net Git - wimlib/commitdiff
wimlib-imagex: Add --pack-compress options
authorEric Biggers <ebiggers3@gmail.com>
Thu, 24 Apr 2014 19:36:23 +0000 (14:36 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 24 Apr 2014 19:36:23 +0000 (14:36 -0500)
programs/imagex.c

index 753206d55ecacd917fad6ffa1eae92efc3e364de..d5167e8b25d8c6629d0c8eba6d541eebc6086b05 100644 (file)
@@ -177,6 +177,7 @@ enum {
        IMAGEX_NULLGLOB_OPTION,
        IMAGEX_ONE_FILE_ONLY_OPTION,
        IMAGEX_PACK_CHUNK_SIZE_OPTION,
+       IMAGEX_PACK_COMPRESS_OPTION,
        IMAGEX_PACK_STREAMS_OPTION,
        IMAGEX_PATH_OPTION,
        IMAGEX_PIPABLE_OPTION,
@@ -233,6 +234,8 @@ static const struct option capture_or_append_options[] = {
        {T("chunk-size"),  required_argument, NULL, IMAGEX_CHUNK_SIZE_OPTION},
        {T("pack-chunk-size"), required_argument, NULL, IMAGEX_PACK_CHUNK_SIZE_OPTION},
        {T("solid-chunk-size"),required_argument, NULL, IMAGEX_PACK_CHUNK_SIZE_OPTION},
+       {T("pack-compress"), required_argument, NULL, IMAGEX_PACK_COMPRESS_OPTION},
+       {T("solid-compress"),required_argument, NULL, IMAGEX_PACK_COMPRESS_OPTION},
        {T("pack-streams"), no_argument,      NULL, IMAGEX_PACK_STREAMS_OPTION},
        {T("solid"),       no_argument,      NULL, IMAGEX_PACK_STREAMS_OPTION},
        {T("config"),      required_argument, NULL, IMAGEX_CONFIG_OPTION},
@@ -281,6 +284,8 @@ static const struct option export_options[] = {
        {T("chunk-size"),  required_argument, NULL, IMAGEX_CHUNK_SIZE_OPTION},
        {T("pack-chunk-size"), required_argument, NULL, IMAGEX_PACK_CHUNK_SIZE_OPTION},
        {T("solid-chunk-size"),required_argument, NULL, IMAGEX_PACK_CHUNK_SIZE_OPTION},
+       {T("pack-compress"), required_argument, NULL, IMAGEX_PACK_COMPRESS_OPTION},
+       {T("solid-compress"),required_argument, NULL, IMAGEX_PACK_COMPRESS_OPTION},
        {T("ref"),         required_argument, NULL, IMAGEX_REF_OPTION},
        {T("threads"),     required_argument, NULL, IMAGEX_THREADS_OPTION},
        {T("rebuild"),     no_argument,       NULL, IMAGEX_REBUILD_OPTION},
@@ -348,6 +353,8 @@ static const struct option optimize_options[] = {
        {T("chunk-size"),  required_argument, NULL, IMAGEX_CHUNK_SIZE_OPTION},
        {T("pack-chunk-size"), required_argument, NULL, IMAGEX_PACK_CHUNK_SIZE_OPTION},
        {T("solid-chunk-size"),required_argument, NULL, IMAGEX_PACK_CHUNK_SIZE_OPTION},
+       {T("pack-compress"), required_argument, NULL, IMAGEX_PACK_COMPRESS_OPTION},
+       {T("solid-compress"),required_argument, NULL, IMAGEX_PACK_COMPRESS_OPTION},
        {T("pack-streams"),no_argument,       NULL, IMAGEX_PACK_STREAMS_OPTION},
        {T("solid"),       no_argument,       NULL, IMAGEX_PACK_STREAMS_OPTION},
        {T("threads"),     required_argument, NULL, IMAGEX_THREADS_OPTION},
@@ -1668,6 +1675,7 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
        int compression_type = WIMLIB_COMPRESSION_TYPE_INVALID;
        uint32_t chunk_size = UINT32_MAX;
        uint32_t pack_chunk_size = UINT32_MAX;
+       int pack_ctype = WIMLIB_COMPRESSION_TYPE_INVALID;
        const tchar *wimfile;
        int wim_fd;
        const tchar *name;
@@ -1734,6 +1742,11 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                        if (pack_chunk_size == UINT32_MAX)
                                goto out_err;
                        break;
+               case IMAGEX_PACK_COMPRESS_OPTION:
+                       pack_ctype = get_compression_type(optarg);
+                       if (pack_ctype == WIMLIB_COMPRESSION_TYPE_INVALID)
+                               goto out_err;
+                       break;
                case IMAGEX_PACK_STREAMS_OPTION:
                        write_flags |= WIMLIB_WRITE_FLAG_PACK_STREAMS;
                        break;
@@ -1832,7 +1845,7 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                        compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
                } else {
                        compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
-                       if (!compress_slow) {
+                       if (!compress_slow && pack_ctype != WIMLIB_COMPRESSION_TYPE_LZX) {
                                struct wimlib_lzx_compressor_params params = {
                                        .hdr.size = sizeof(params),
                                        .algorithm = WIMLIB_LZX_ALGORITHM_FAST,
@@ -1842,7 +1855,6 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                                                                     &params.hdr);
                        }
                }
-
        }
 
        if (compress_slow)
@@ -1972,6 +1984,11 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                if (ret)
                        goto out_free_wim;
        }
+       if (pack_ctype != WIMLIB_COMPRESSION_TYPE_INVALID) {
+               ret = wimlib_set_output_pack_compression_type(wim, pack_ctype);
+               if (ret)
+                       goto out_free_wim;
+       }
        if (pack_chunk_size != UINT32_MAX) {
                ret = wimlib_set_output_pack_chunk_size(wim, pack_chunk_size);
                if (ret)
@@ -2568,6 +2585,7 @@ imagex_export(int argc, tchar **argv, int cmd)
        unsigned num_threads = 0;
        uint32_t chunk_size = UINT32_MAX;
        uint32_t pack_chunk_size = UINT32_MAX;
+       int pack_ctype = WIMLIB_COMPRESSION_TYPE_INVALID;
 
        for_opt(c, export_options) {
                switch (c) {
@@ -2603,6 +2621,11 @@ imagex_export(int argc, tchar **argv, int cmd)
                        if (pack_chunk_size == UINT32_MAX)
                                goto out_err;
                        break;
+               case IMAGEX_PACK_COMPRESS_OPTION:
+                       pack_ctype = get_compression_type(optarg);
+                       if (pack_ctype == WIMLIB_COMPRESSION_TYPE_INVALID)
+                               goto out_err;
+                       break;
                case IMAGEX_REF_OPTION:
                        ret = string_set_append(&refglobs, optarg);
                        if (ret)
@@ -2732,6 +2755,11 @@ imagex_export(int argc, tchar **argv, int cmd)
                if (ret)
                        goto out_free_dest_wim;
        }
+       if (pack_ctype != WIMLIB_COMPRESSION_TYPE_INVALID) {
+               ret = wimlib_set_output_pack_compression_type(dest_wim, pack_ctype);
+               if (ret)
+                       goto out_free_dest_wim;
+       }
        if (pack_chunk_size != UINT32_MAX) {
                ret = wimlib_set_output_pack_chunk_size(dest_wim, pack_chunk_size);
                if (ret)
@@ -3408,6 +3436,7 @@ imagex_optimize(int argc, tchar **argv, int cmd)
        int compression_type = WIMLIB_COMPRESSION_TYPE_INVALID;
        uint32_t chunk_size = UINT32_MAX;
        uint32_t pack_chunk_size = UINT32_MAX;
+       int pack_ctype = WIMLIB_COMPRESSION_TYPE_INVALID;
        int ret;
        WIMStruct *wim;
        const tchar *wimfile;
@@ -3447,6 +3476,11 @@ imagex_optimize(int argc, tchar **argv, int cmd)
                        if (pack_chunk_size == UINT32_MAX)
                                goto out_err;
                        break;
+               case IMAGEX_PACK_COMPRESS_OPTION:
+                       pack_ctype = get_compression_type(optarg);
+                       if (pack_ctype == WIMLIB_COMPRESSION_TYPE_INVALID)
+                               goto out_err;
+                       break;
                case IMAGEX_PACK_STREAMS_OPTION:
                        write_flags |= WIMLIB_WRITE_FLAG_PACK_STREAMS;
                        write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
@@ -3491,6 +3525,11 @@ imagex_optimize(int argc, tchar **argv, int cmd)
                if (ret)
                        goto out_wimlib_free;
        }
+       if (pack_ctype != WIMLIB_COMPRESSION_TYPE_INVALID) {
+               ret = wimlib_set_output_pack_compression_type(wim, pack_ctype);
+               if (ret)
+                       goto out_wimlib_free;
+       }
        if (pack_chunk_size != UINT32_MAX) {
                ret = wimlib_set_output_pack_chunk_size(wim, pack_chunk_size);
                if (ret)