2 # -*- coding: utf-8 -*-
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2018-2024 Cool Dude 2k - http://idb.berlios.de/
14 Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15 Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
17 $FileInfo: neocatfile.py - Last Update: 5/15/2024 Ver. 0.11.4 RC 1 - Author: cooldude2k $
20 from __future__
import absolute_import
, division
, print_function
, unicode_literals
24 # Compatibility layer for Python 2 and 3 input
30 # Determine if rar file support is enabled
31 rarfile_support
= pycatfile
.rarfile_support
33 # Set up the argument parser
34 argparser
= argparse
.ArgumentParser(description
="Manipulates concatenated files for various operations like creation, extraction, and validation.")
35 argparser
.add_argument("-V", "--version", action
="version", version
="{0} {1}".format(pycatfile
.__program
_name
__, pycatfile
.__version
__), help="Displays the program's version.")
36 argparser
.add_argument("-i", "--input", required
=True, help="Specifies input file(s) for processing.")
37 argparser
.add_argument("-o", "--output", help="Specifies the output file name.")
38 argparser
.add_argument("-d", "--verbose", action
="store_true", help="Enables verbose mode for detailed information.")
39 argparser
.add_argument("-c", "--create", action
="store_true", help="Creates a new concatenated file from input.")
40 argparser
.add_argument("-e", "--extract", action
="store_true", help="Extracts files from a concatenated archive.")
41 argparser
.add_argument("-l", "--list", action
="store_true", help="Lists contents of a specified concatenated file.")
42 argparser
.add_argument("-r", "--repack", action
="store_true", help="Repacks an existing concatenated file.")
43 argparser
.add_argument("-v", "--validate", action
="store_true", help="Validates a concatenated file's integrity.")
44 argparser
.add_argument("--checksum", default
="crc32", help="Specifies the checksum type (default: crc32).")
45 argparser
.add_argument("--compression", default
="auto", help="Specifies the compression method (default: auto).")
46 argparser
.add_argument("--level", help="Specifies the compression level.")
47 argparser
.add_argument("--preserve", action
="store_true", help="Preserves file attributes when extracting.")
48 argparser
.add_argument("--convert", choices
=['tar', 'zip', 'rar'], help="Convert from an archive format (tar, zip, rar) to a concatenated file.")
49 args
= argparser
.parse_args()
51 # Determine the primary action based on user input
54 primary_action
= 'create'
56 primary_action
= 'repack'
58 primary_action
= 'extract'
60 primary_action
= 'list'
62 primary_action
= 'validate'
64 # Functionality mappings
65 if primary_action
== 'create':
66 if args
.convert
== 'tar':
67 pycatfile
.PackArchiveFileFromTarFile(args
.input, args
.output
, args
.compression
, args
.level
, args
.checksum
, [], pycatfile
.__file
_format
_list
__, args
.verbose
, False)
68 elif args
.convert
== 'zip':
69 pycatfile
.PackArchiveFileFromZipFile(args
.input, args
.output
, args
.compression
, args
.level
, args
.checksum
, [], pycatfile
.__file
_format
_list
__, args
.verbose
, False)
70 elif rarfile_support
and args
.convert
== 'rar':
71 pycatfile
.PackArchiveFileFromRarFile(args
.input, args
.output
, args
.compression
, args
.level
, args
.checksum
, [], pycatfile
.__file
_format
_list
__, args
.verbose
, False)
73 pycatfile
.PackArchiveFile(args
.input, args
.output
, args
.verbose
, args
.compression
, args
.level
, False, args
.checksum
, [], pycatfile
.__file
_format
_list
__, args
.verbose
, False)
74 elif primary_action
== 'repack':
75 pycatfile
.RePackArchiveFile(args
.input, args
.output
, args
.compression
, args
.level
, args
.checksum
, args
.verbose
)
76 elif primary_action
== 'extract':
77 pycatfile
.UnPackArchiveFile(args
.input, args
.output
, args
.verbose
, args
.preserve
)
78 elif primary_action
== 'list':
79 if args
.convert
== 'tar':
80 pycatfile
.TarFileListFiles(args
.input, args
.verbose
, False)
81 elif args
.convert
== 'zip':
82 pycatfile
.ZipFileListFiles(args
.input, args
.verbose
, False)
83 elif rarfile_support
and args
.convert
== 'rar':
84 pycatfile
.RarFileListFiles(args
.input, args
.verbose
, False)
86 pycatfile
.ArchiveFileListFiles(args
.input, args
.verbose
)
87 elif primary_action
== 'validate':
88 is_valid
= pycatfile
.ArchiveFileValidate(args
.input, args
.verbose
)
89 result_msg
= "Validation result for {0}: {1}".format(args
.input, 'Valid' if is_valid
else 'Invalid')