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/swm.h"
33 #include "wimlib/util.h"
34 #include "wimlib/wim.h"
36 /* API function documented in wimlib.h */
38 wimlib_join(const tchar * const *swm_names,
40 const tchar *output_path,
43 wimlib_progress_func_t progress_func)
49 WIMStruct **additional_swms;
50 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 additional_swms = CALLOC(num_additional_swms, sizeof(additional_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)
73 additional_swms[j++] = swm;
77 ret = WIMLIB_ERR_SPLIT_INVALID;
81 ret = verify_swm_set(swm0, additional_swms, num_additional_swms);
85 merge_lookup_tables(swm0, additional_swms, num_additional_swms);
87 ret = wimlib_write(swm0, output_path, WIMLIB_ALL_IMAGES,
88 wim_write_flags, 1, progress_func);
90 for (i = 0; i < num_additional_swms; i++)
91 wimlib_free(additional_swms[i]);
92 FREE(additional_swms);