4 * Join split WIMs (sometimes named as .swm files) together into one WIM.
8 * Copyright (C) 2012, 2013 Eric Biggers
10 * This file is part of wimlib, a library for working with WIM files.
12 * wimlib is free software; you can redistribute it and/or modify it under the
13 * terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 3 of the License, or (at your option)
17 * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
18 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 * A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with wimlib; if not, see http://www.gnu.org/licenses/.
31 #include "wimlib/types.h"
32 #include "wimlib/util.h"
33 #include "wimlib/wim.h"
35 /* API function documented in wimlib.h */
37 wimlib_join(const tchar * const *swm_names,
39 const tchar *output_path,
42 wimlib_progress_func_t progress_func)
49 unsigned num_additional_swms;
52 swm_open_flags |= WIMLIB_OPEN_FLAG_SPLIT_OK;
54 if (num_swms < 1 || num_swms > 0xffff)
55 return WIMLIB_ERR_INVALID_PARAM;
56 num_additional_swms = num_swms - 1;
58 swms = CALLOC(num_additional_swms, sizeof(swms[0]));
60 return WIMLIB_ERR_NOMEM;
63 for (i = 0, j = 0; i < num_swms; i++) {
66 ret = wimlib_open_wim(swm_names[i], swm_open_flags, &swm,
70 if (swm->hdr.part_number == 1 && swm0 == NULL)
77 ret = WIMLIB_ERR_SPLIT_INVALID;
81 ret = wimlib_create_new_wim(swm0->compression_type, &wim);
85 ret = wimlib_export_image(swm0, WIMLIB_ALL_IMAGES, wim, NULL, NULL, 0,
86 swms, num_additional_swms, progress_func);
90 wim->hdr.flags |= swm0->hdr.flags & (WIM_HDR_FLAG_RP_FIX |
91 WIM_HDR_FLAG_READONLY);
92 if (!(wim_write_flags & (WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
93 WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY)))
95 if (wim_has_integrity_table(swm0))
96 wim_write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
98 if (!(wim_write_flags & (WIMLIB_WRITE_FLAG_PIPABLE |
99 WIMLIB_WRITE_FLAG_NOT_PIPABLE)))
101 if (wim_is_pipable(swm0))
102 wim_write_flags |= WIMLIB_WRITE_FLAG_PIPABLE;
106 ret = wimlib_write(wim, output_path, WIMLIB_ALL_IMAGES,
107 wim_write_flags, 1, progress_func);
111 for (i = 0; i < num_additional_swms; i++)
112 wimlib_free(swms[i]);