]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
implement WIMLIB_INIT_FLAG_ASSUME_UTF8
[wimlib] / programs / imagex.c
index b78fa325abd37488f4954947c15771fe1ac68171..c74bdb253ef183efcef45a542a9675298edd672f 100644 (file)
@@ -145,6 +145,7 @@ IMAGEX_PROGNAME" mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
 [OPTIMIZE] =
 T(
 IMAGEX_PROGNAME" optimize WIMFILE [--check] [--recompress]\n"
+"                      [--threads=NUM_THREADS]\n"
 ),
 [SPLIT] =
 T(
@@ -262,6 +263,7 @@ static const struct option mount_options[] = {
 static const struct option optimize_options[] = {
        {T("check"),      no_argument, NULL, IMAGEX_CHECK_OPTION},
        {T("recompress"), no_argument, NULL, IMAGEX_RECOMPRESS_OPTION},
+       {T("threads"),    required_argument, NULL, IMAGEX_THREADS_OPTION},
        {NULL, 0, NULL, 0},
 };
 
@@ -2254,6 +2256,7 @@ imagex_optimize(int argc, tchar **argv)
        const tchar *wimfile;
        off_t old_size;
        off_t new_size;
+       unsigned num_threads = 0;
 
        for_opt(c, optimize_options) {
                switch (c) {
@@ -2264,6 +2267,11 @@ imagex_optimize(int argc, tchar **argv)
                case IMAGEX_RECOMPRESS_OPTION:
                        write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
                        break;
+               case IMAGEX_THREADS_OPTION:
+                       num_threads = parse_num_threads(optarg);
+                       if (num_threads == UINT_MAX)
+                               return -1;
+                       break;
                default:
                        usage(OPTIMIZE);
                        return -1;
@@ -2291,7 +2299,8 @@ imagex_optimize(int argc, tchar **argv)
        else
                tprintf(T("%"PRIu64" KiB\n"), old_size >> 10);
 
-       ret = wimlib_overwrite(w, write_flags, 0, imagex_progress_func);
+       ret = wimlib_overwrite(w, write_flags, num_threads,
+                              imagex_progress_func);
 
        if (ret == 0) {
                new_size = file_get_size(argv[0]);
@@ -2517,11 +2526,16 @@ main(int argc, char **argv)
 {
        const struct imagex_command *cmd;
        int ret;
+       int init_flags = 0;
 
 #ifndef __WIN32__
-       setlocale(LC_ALL, "");
-       {
-               char *codeset = nl_langinfo(CODESET);
+       if (getenv("WIMLIB_IMAGEX_USE_UTF8")) {
+               init_flags |= WIMLIB_INIT_FLAG_ASSUME_UTF8;
+       } else {
+               char *codeset;
+
+               setlocale(LC_ALL, "");
+               codeset = nl_langinfo(CODESET);
                if (!strstr(codeset, "UTF-8") &&
                    !strstr(codeset, "UTF8") &&
                    !strstr(codeset, "utf-8") &&
@@ -2529,7 +2543,10 @@ main(int argc, char **argv)
                {
                        fputs(
 "WARNING: Running "IMAGEX_PROGNAME" in a UTF-8 locale is recommended!\n"
-"         (Maybe try: `export LANG=en_US.UTF-8'?\n", stderr);
+"         Maybe try: `export LANG=en_US.UTF-8'?\n"
+"         Alternatively, set the environmental variable WIMLIB_IMAGEX_USE_UTF8\n"
+"         to any value to force wimlib to use UTF-8.\n",
+                       stderr);
 
                }
        }
@@ -2552,7 +2569,7 @@ main(int argc, char **argv)
        wimlib_set_print_errors(true);
 
        /* Do any initializations that the library needs */
-       ret = wimlib_global_init();
+       ret = wimlib_global_init(init_flags);
        if (ret)
                goto out_check_status;