src/tools/chdman.c
| r14648 | r14649 | |
| 1552 | 1552 | printf("Logical size: %s\n", big_int_string(tempstr, input_end - input_start)); |
| 1553 | 1553 | |
| 1554 | 1554 | // catch errors so we can close & delete the output file |
| 1555 | chd_rawfile_compressor* chd = NULL; |
| 1555 | 1556 | try |
| 1556 | 1557 | { |
| 1557 | 1558 | // create the new CHD |
| 1558 | | chd_rawfile_compressor chd(input_file, input_start, input_end); |
| 1559 | chd = new chd_rawfile_compressor(input_file, input_start, input_end); |
| 1559 | 1560 | chd_error err; |
| 1560 | 1561 | if (output_parent.opened()) |
| 1561 | | err = chd.create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent); |
| 1562 | err = chd->create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent); |
| 1562 | 1563 | else |
| 1563 | | err = chd.create(*output_chd_str, input_end - input_start, hunk_size, unit_size, compression); |
| 1564 | err = chd->create(*output_chd_str, input_end - input_start, hunk_size, unit_size, compression); |
| 1564 | 1565 | if (err != CHDERR_NONE) |
| 1565 | 1566 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 1566 | 1567 | |
| 1567 | 1568 | // if we have a parent, copy forward all the metadata |
| 1568 | 1569 | if (output_parent.opened()) |
| 1569 | | chd.clone_all_metadata(output_parent); |
| 1570 | chd->clone_all_metadata(output_parent); |
| 1570 | 1571 | |
| 1571 | 1572 | // compress it generically |
| 1572 | | compress_common(chd); |
| 1573 | compress_common(*chd); |
| 1574 | delete chd; |
| 1573 | 1575 | } |
| 1574 | 1576 | catch (...) |
| 1575 | 1577 | { |
| r14648 | r14649 | |
| 1577 | 1579 | astring *output_chd_str = params.find(OPTION_OUTPUT); |
| 1578 | 1580 | if (output_chd_str != NULL) |
| 1579 | 1581 | osd_rmfile(*output_chd_str); |
| 1582 | if (chd != NULL) |
| 1583 | delete chd; |
| 1580 | 1584 | throw; |
| 1581 | 1585 | } |
| 1582 | 1586 | } |
| r14648 | r14649 | |
| 1810 | 1814 | printf("Logical size: %s\n", big_int_string(tempstr, UINT64(totalsectors) * CD_FRAME_SIZE)); |
| 1811 | 1815 | |
| 1812 | 1816 | // catch errors so we can close & delete the output file |
| 1817 | chd_cd_compressor* chd = NULL; |
| 1813 | 1818 | try |
| 1814 | 1819 | { |
| 1815 | | // create the new hard drive |
| 1816 | | chd_cd_compressor chd(toc, track_info); |
| 1820 | // create the new CD |
| 1821 | chd = new chd_cd_compressor(toc, track_info); |
| 1817 | 1822 | chd_error err; |
| 1818 | 1823 | if (output_parent.opened()) |
| 1819 | | err = chd.create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, compression, output_parent); |
| 1824 | err = chd->create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, compression, output_parent); |
| 1820 | 1825 | else |
| 1821 | | err = chd.create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, CD_FRAME_SIZE, compression); |
| 1826 | err = chd->create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, CD_FRAME_SIZE, compression); |
| 1822 | 1827 | if (err != CHDERR_NONE) |
| 1823 | 1828 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 1824 | 1829 | |
| 1825 | 1830 | // add the standard CD metadata; we do this even if we have a parent because it might be different |
| 1826 | | err = cdrom_write_metadata(&chd, &toc); |
| 1831 | err = cdrom_write_metadata(chd, &toc); |
| 1827 | 1832 | if (err != CHDERR_NONE) |
| 1828 | 1833 | report_error(1, "Error adding CD metadata: %s", chd_file::error_string(err)); |
| 1829 | 1834 | |
| 1830 | 1835 | // compress it generically |
| 1831 | | compress_common(chd); |
| 1836 | compress_common(*chd); |
| 1837 | delete chd; |
| 1832 | 1838 | } |
| 1833 | 1839 | catch (...) |
| 1834 | 1840 | { |
| r14648 | r14649 | |
| 1836 | 1842 | astring *output_chd_str = params.find(OPTION_OUTPUT); |
| 1837 | 1843 | if (output_chd_str != NULL) |
| 1838 | 1844 | osd_rmfile(*output_chd_str); |
| 1845 | if (chd != NULL) |
| 1846 | delete chd; |
| 1839 | 1847 | throw; |
| 1840 | 1848 | } |
| 1841 | 1849 | } |
| r14648 | r14649 | |
| 1922 | 1930 | printf("Logical size: %s\n", big_int_string(tempstr, UINT64(input_end - input_start) * hunk_size)); |
| 1923 | 1931 | |
| 1924 | 1932 | // catch errors so we can close & delete the output file |
| 1933 | chd_avi_compressor* chd = NULL; |
| 1925 | 1934 | try |
| 1926 | 1935 | { |
| 1927 | 1936 | // create the new CHD |
| 1928 | | chd_avi_compressor chd(*input_file, info, input_start, input_end); |
| 1937 | chd = new chd_avi_compressor(*input_file, info, input_start, input_end); |
| 1929 | 1938 | chd_error err; |
| 1930 | 1939 | if (output_parent.opened()) |
| 1931 | | err = chd.create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, compression, output_parent); |
| 1940 | err = chd->create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, compression, output_parent); |
| 1932 | 1941 | else |
| 1933 | | err = chd.create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, info.bytes_per_frame, compression); |
| 1942 | err = chd->create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, info.bytes_per_frame, compression); |
| 1934 | 1943 | if (err != CHDERR_NONE) |
| 1935 | 1944 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 1936 | 1945 | |
| 1937 | 1946 | // write the core A/V metadata |
| 1938 | 1947 | astring metadata; |
| 1939 | 1948 | metadata.format(AV_METADATA_FORMAT, info.fps_times_1million / 1000000, info.fps_times_1million % 1000000, info.width, info.height, info.interlaced, info.channels, info.rate); |
| 1940 | | err = chd.write_metadata(AV_METADATA_TAG, 0, metadata); |
| 1949 | err = chd->write_metadata(AV_METADATA_TAG, 0, metadata); |
| 1941 | 1950 | if (err != CHDERR_NONE) |
| 1942 | 1951 | report_error(1, "Error adding AV metadata: %s\n", chd_file::error_string(err)); |
| 1943 | 1952 | |
| 1944 | 1953 | // create the compressor and then run it generically |
| 1945 | | compress_common(chd); |
| 1954 | compress_common(*chd); |
| 1946 | 1955 | |
| 1947 | 1956 | // write the final LD metadata |
| 1948 | 1957 | if (info.height == 524/2 || info.height == 624/2) |
| 1949 | 1958 | { |
| 1950 | | err = chd.write_metadata(AV_LD_METADATA_TAG, 0, chd.ldframedata()); |
| 1959 | err = chd->write_metadata(AV_LD_METADATA_TAG, 0, chd->ldframedata()); |
| 1951 | 1960 | if (err != CHDERR_NONE) |
| 1952 | 1961 | report_error(1, "Error adding AVLD metadata: %s\n", chd_file::error_string(err)); |
| 1953 | 1962 | } |
| 1963 | delete chd; |
| 1954 | 1964 | } |
| 1955 | 1965 | catch (...) |
| 1956 | 1966 | { |
| r14648 | r14649 | |
| 1958 | 1968 | astring *output_chd_str = params.find(OPTION_OUTPUT); |
| 1959 | 1969 | if (output_chd_str != NULL) |
| 1960 | 1970 | osd_rmfile(*output_chd_str); |
| 1971 | if (chd != NULL) |
| 1972 | delete chd; |
| 1961 | 1973 | throw; |
| 1962 | 1974 | } |
| 1963 | 1975 | } |
| r14648 | r14649 | |
| 2026 | 2038 | printf("Logical size: %s\n", big_int_string(tempstr, input_end - input_start)); |
| 2027 | 2039 | |
| 2028 | 2040 | // catch errors so we can close & delete the output file |
| 2041 | chd_chdfile_compressor* chd = NULL; |
| 2029 | 2042 | try |
| 2030 | 2043 | { |
| 2031 | 2044 | // create the new CHD |
| 2032 | | chd_chdfile_compressor chd(input_chd, input_start, input_end); |
| 2045 | chd = new chd_chdfile_compressor(input_chd, input_start, input_end); |
| 2033 | 2046 | chd_error err; |
| 2034 | 2047 | if (output_parent.opened()) |
| 2035 | | err = chd.create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent); |
| 2048 | err = chd->create(*output_chd_str, input_end - input_start, hunk_size, compression, output_parent); |
| 2036 | 2049 | else |
| 2037 | | err = chd.create(*output_chd_str, input_end - input_start, hunk_size, input_chd.unit_bytes(), compression); |
| 2050 | err = chd->create(*output_chd_str, input_end - input_start, hunk_size, input_chd.unit_bytes(), compression); |
| 2038 | 2051 | if (err != CHDERR_NONE) |
| 2039 | 2052 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 2040 | 2053 | |
| r14648 | r14649 | |
| 2054 | 2067 | } |
| 2055 | 2068 | |
| 2056 | 2069 | // otherwise, clone it |
| 2057 | | err = chd.write_metadata(metatag, CHDMETAINDEX_APPEND, metadata); |
| 2070 | err = chd->write_metadata(metatag, CHDMETAINDEX_APPEND, metadata); |
| 2058 | 2071 | if (err != CHDERR_NONE) |
| 2059 | 2072 | report_error(1, "Error writing cloned metadata: %s", chd_file::error_string(err)); |
| 2060 | 2073 | } |
| r14648 | r14649 | |
| 2066 | 2079 | if (cdrom == NULL) |
| 2067 | 2080 | report_error(1, "Error upgrading CD metadata"); |
| 2068 | 2081 | const cdrom_toc *toc = cdrom_get_toc(cdrom); |
| 2069 | | err = cdrom_write_metadata(&chd, toc); |
| 2082 | err = cdrom_write_metadata(chd, toc); |
| 2070 | 2083 | if (err != CHDERR_NONE) |
| 2071 | 2084 | report_error(1, "Error writing upgraded CD metadata: %s", chd_file::error_string(err)); |
| 2072 | 2085 | } |
| 2073 | 2086 | |
| 2074 | 2087 | // compress it generically |
| 2075 | | compress_common(chd); |
| 2088 | compress_common(*chd); |
| 2089 | delete chd; |
| 2076 | 2090 | } |
| 2077 | 2091 | catch (...) |
| 2078 | 2092 | { |
| r14648 | r14649 | |
| 2080 | 2094 | astring *output_chd_str = params.find(OPTION_OUTPUT); |
| 2081 | 2095 | if (output_chd_str != NULL) |
| 2082 | 2096 | osd_rmfile(*output_chd_str); |
| 2097 | if (chd != NULL) |
| 2098 | delete chd; |
| 2083 | 2099 | throw; |
| 2084 | 2100 | } |
| 2085 | 2101 | } |